Sorry, I didn't notice that your xsd:any had maxOccurs > 1:

> >          <xsd:any namespace="##other" processContents="lax" 
minOccurs="0" maxOccurs="unbounded"/>

If it was maxOccurs="1" then you could do what I suggested. 

Because it is many valued, however, you need to do this:

         person.getList(addressProperty).add(address);

Notice that the isMany value of a global property is not statically known, 
it depends on where it's being used.

Frank.


[EMAIL PROTECTED] wrote on 05/07/2007 09:54:04 AM:

> Hi Frank,
> 
> I replaced my code with what you suggested:
> 
>         Property addressProperty =
> 
context.getXSDHelper().getGlobalProperty("http://www.example.org/Address";,
> "Address",
>             true);
>         person.setDataObject(addressProperty, address);
> 
> The call to setDataObject() generates the following exception:
> 
> Exception in thread "main" java.lang.ClassCastException:
> org.apache.tuscany.sdo.impl.DynamicDataObjectImpl
>    at org.eclipse.emf.ecore.util.BasicFeatureMap.
> set(BasicFeatureMap.java:1026)
>    at org.eclipse.emf.ecore.impl.BasicEObjectImpl.
> eOpenSet(BasicEObjectImpl.java:723)
>    at org.eclipse.emf.ecore.impl.BasicEObjectImpl.
> eSet(BasicEObjectImpl.java:658)
>    at 
org.apache.tuscany.sdo.impl.DataObjectImpl.set(DataObjectImpl.java:142)
>    at org.apache.tuscany.sdo.util.DataObjectUtil.
> setDataObject(DataObjectUtil.java:122)
>    at org.apache.tuscany.sdo.impl.DataObjectImpl.
> setDataObject(DataObjectImpl.java:1105)
>    at com.ibm.isd.mapper.impl.Test.main(Test.java:33)
> 
> 
> Any Ideas? Thanks for your help this far,
> 
> -Chris
> 
> On 5/7/07, Frank Budinsky <[EMAIL PROTECTED]> wrote:
> > Hi Chris,
> >
> > The problem is this line of code:
> >
> > >         person.setDataObject("address:Address", address);
> >
> > SDO doesn't support qualified names in string (path) get/set methods.
> > That's why it ignores the "address:" prefix, and simply demand-creates
> > another "Address" property ("PersonType:address").
> >
> > To accomplish what you want, you can explicitly locate the 
address:Address
> > property like this:
> >
> > Property addressProperty =
> > xsdHelper.getGlobalProperty("http://www.example.org/Address";, 
"Address",
> > true);
> >
> > Then you can set it like this:
> >
> > person.setDataObject(addressProperty, address);
> >
> > Frank.
> >
> >
> > [EMAIL PROTECTED] wrote on 05/06/2007 04:08:33 PM:
> >
> > > Hi Frank (or anyone else that may be able to help),
> > >
> > > I have a related question to Ashish's. I have the following two 
schemas:
> > >
> > > <?xml version="1.0" encoding="UTF-8"?>
> > > <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
> > > targetNamespace="http://www.example.org/Person";
> > > xmlns:person="http://www.example.org/Person";
> > > elementFormDefault="qualified">
> > >     <xsd:element name="Person" 
type="person:PersonType"></xsd:element>
> > >
> > >     <xsd:complexType name="PersonType">
> > >        <xsd:sequence>
> > >           <xsd:element name="Name" type="xsd:string"></xsd:element>
> > >           <xsd:element name="Age" type="xsd:string"></xsd:element>
> > >          <xsd:any namespace="##other" processContents="lax"
> > minOccurs="0"
> > > maxOccurs="unbounded"/>
> > >        </xsd:sequence>
> > >     </xsd:complexType>
> > > </xsd:schema>
> > >
> > > <?xml version="1.0" encoding="UTF-8"?>
> > > <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
> > > targetNamespace="http://www.example.org/Address";
> > > xmlns:address="http://www.example.org/Address";
> > > elementFormDefault="qualified">
> > >
> > >     <xsd:element name="Address"
> > type="address:AddressType"></xsd:element>
> > >
> > >     <xsd:complexType name="AddressType">
> > >        <xsd:sequence>
> > >           <xsd:element name="Street" 
type="xsd:string"></xsd:element>
> > >           <xsd:element name="City" type="xsd:string"></xsd:element>
> > >           <xsd:element name="Zip" type="xsd:string"></xsd:element>
> > >        </xsd:sequence>
> > >     </xsd:complexType>
> > > </xsd:schema>
> > >
> > >
> > > I use the following code to generate my XML:
> > >
> > >     public static void main(String[] args) throws Exception
> > >     {
> > >         HelperContext context = SDOUtil.createHelperContext();
> > >
> > >         context.getXSDHelper().define(new
> > > FileInputStream("./Person.xsd"), (new
> > > File("./Base.xsd")).toURI().toString());
> > >         context.getXSDHelper().define(new
> > > FileInputStream("./Address.xsd"), (new
> > > File("./Additional.xsd")).toURI().toString());
> > >
> > >         DataObject person =
> > > context.getDataFactory().create("http://www.example.org/Person";,
> > > "PersonType");
> > >         DataObject address =
> > > context.getDataFactory().create("http://www.example.org/Address";,
> > > "AddressType");
> > >
> > >         person.set("Name", "Bart");
> > >         person.set("Age", "10");
> > >
> > >         address.set("Street", "123 Fake St.");
> > >         address.set("City", "Springfield");
> > >         address.set("Zip", "46392");
> > >
> > >         person.setDataObject("address:Address", address);
> > >
> > >         context.getXMLHelper().save(person,
> > > "http://www.example.org/Person";, "Person", System.out);
> > >     }
> > >
> > > This gives the following XML:
> > >
> > > <?xml version="1.0" encoding="ASCII"?>
> > > <person:Person
> > xmlns:PersonType="http://www.example.org/Person/PersonType";
> > > xmlns:address="http://www.example.org/Address";
> > >     xmlns:person="http://www.example.org/Person";>
> > >   <person:Name>Bart</person:Name>
> > >   <person:Age>10</person:Age>
> > >   <PersonType:Address>
> > >     <address:Street>123 Fake St.</address:Street>
> > >     <address:City>Springfield</address:City>
> > >     <address:Zip>46392</address:Zip>
> > >   </PersonType:Address>
> > > </person:Person>
> > >
> > > My concern is the "PersonType:Address" element. I'd like that to be
> > > "address:Address" instead. Am I doing something wrong in my schema
> > > definitions and/or code?
> > >
> > > Thanks for any help you can provide,
> > > -Chris
> > >
> > > On 4/16/07, Frank Budinsky <[EMAIL PROTECTED]> wrote:
> > > > Ashish,
> > > >
> > > > I implemented the on-the-fly property creation support over the
> > weekend
> > > > (see https://issues.apache.org/jira/browse/TUSCANY-1211).
> > > >
> > > > You should now be able to do what you asked:
> > > >
> > > > body.setDataObject("anyType",DataObject);
> > > >
> > > > Let me know how it works.
> > > >
> > > > Thanks,
> > > > Frank
> > > >
> > >
> > > 
---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to