You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tuscany.apache.org by Chris Mildebrandt <tu...@plasticfrog.info> on 2007/05/25 17:10:35 UTC

Question about setting an element's value

Hi,

I have the following schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:ext="urn:Extension"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   targetNamespace="urn:Extension"
   elementFormDefault="unqualified" attributeFormDefault="unqualified"
version="1.0">
   <xs:element name="Extension">
      <xs:complexType>
         <xs:sequence>
            <xs:element ref="ext:SubCategory" minOccurs="0"
maxOccurs="unbounded" />
         </xs:sequence>
      </xs:complexType>
   </xs:element>

   <xs:element name="SubCategory">
      <xs:complexType>
         <xs:simpleContent>
            <xs:extension base="xs:string">
               <xs:attribute name="displayable" type="xs:boolean"
use="optional" />
            </xs:extension>
         </xs:simpleContent>
      </xs:complexType>
   </xs:element>
</xs:schema>


And I'd like to create this xml:

<?xml version="1.0" encoding="ASCII"?>
<ext:Extension xmlns:ext="urn:Extension">
  <ext:SubCategory displayable="true">myCategory</SubCategory>
</ext:Extension>


I'm having problems setting the value "myCategory". In examples I've
seen where the element does not contain an attribute, a simple
set("SubCategory", "myCategory") would work. It seems that I can't use
that in this case. Here's my current code:

        HelperContext context = SDOUtil.createHelperContext();

        InputStream in = new File("Extension.xsd").toURL().openStream();
        context.getXSDHelper().define(in, null);

        DataObject extension =
context.getDataFactory().create("urn:Extension", "Extension");

        DataObject subCategory = extension.createDataObject("SubCategory");
        subCategory.setBoolean("displayable", true);

        extension.set("SubCategory", "myCategory");

        context.getXMLHelper().save(extension, "urn:Extension",
"Extension", System.out);


When the set() method is called, i get the following exception:

Exception in thread "main" java.lang.ClassCastException: java.lang.String
	at org.eclipse.emf.ecore.util.EcoreEList.set(EcoreEList.java:448)
	at org.eclipse.emf.ecore.impl.EStructuralFeatureImpl$InternalSettingDelegateMany.dynamicSet(EStructuralFeatureImpl.java:1647)
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eDynamicSet(BasicEObjectImpl.java:709)
	at org.apache.tuscany.sdo.impl.DynamicDataObjectImpl.eDynamicSet(DynamicDataObjectImpl.java:159)
	at org.apache.tuscany.sdo.impl.DataObjectImpl.eSet(DataObjectImpl.java:1459)
	at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:654)
	at org.apache.tuscany.sdo.impl.DataObjectImpl.set(DataObjectImpl.java:142)
	at org.apache.tuscany.sdo.util.DataObjectUtil.set(DataObjectUtil.java:730)
	at org.apache.tuscany.sdo.impl.DataObjectImpl.set(DataObjectImpl.java:225)
	at Test.valueTest(Test.java:186)
	at Test.main(Test.java:197)


I've tried looking through the samples and test cases, but couldn't
find a similar example. Any help in pointing me to the correct API
would be appreciated.

Thanks,
-Chris

---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-user-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-user-help@ws.apache.org


Re: Question about setting an element's value

Posted by Chris Mildebrandt <ch...@plasticfrog.info>.
Thanks, I figured I was missing something simple.

Thanks again,
-Chris

On 5/25/07, Frank Budinsky <fr...@ca.ibm.com> wrote:
> Hi Chris,
>
> A complexType that extends a simpleType exposes the simple content as a
> property named "value". So, you would set it like this:
>
>   subCategory.set("value", "myCategory");
>
> Frank
>
> eyeofthefrog@gmail.com wrote on 05/25/2007 11:10:35 AM:
>
> > Hi,
> >
> > I have the following schema:
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xs:schema xmlns:ext="urn:Extension"
> >    xmlns:xs="http://www.w3.org/2001/XMLSchema"
> >    targetNamespace="urn:Extension"
> >    elementFormDefault="unqualified" attributeFormDefault="unqualified"
> > version="1.0">
> >    <xs:element name="Extension">
> >       <xs:complexType>
> >          <xs:sequence>
> >             <xs:element ref="ext:SubCategory" minOccurs="0"
> > maxOccurs="unbounded" />
> >          </xs:sequence>
> >       </xs:complexType>
> >    </xs:element>
> >
> >    <xs:element name="SubCategory">
> >       <xs:complexType>
> >          <xs:simpleContent>
> >             <xs:extension base="xs:string">
> >                <xs:attribute name="displayable" type="xs:boolean"
> > use="optional" />
> >             </xs:extension>
> >          </xs:simpleContent>
> >       </xs:complexType>
> >    </xs:element>
> > </xs:schema>
> >
> >
> > And I'd like to create this xml:
> >
> > <?xml version="1.0" encoding="ASCII"?>
> > <ext:Extension xmlns:ext="urn:Extension">
> >   <ext:SubCategory displayable="true">myCategory</SubCategory>
> > </ext:Extension>
> >
> >
> > I'm having problems setting the value "myCategory". In examples I've
> > seen where the element does not contain an attribute, a simple
> > set("SubCategory", "myCategory") would work. It seems that I can't use
> > that in this case. Here's my current code:
> >
> >         HelperContext context = SDOUtil.createHelperContext();
> >
> >         InputStream in = new File("Extension.xsd").toURL().openStream();
> >         context.getXSDHelper().define(in, null);
> >
> >         DataObject extension =
> > context.getDataFactory().create("urn:Extension", "Extension");
> >
> >         DataObject subCategory =
> extension.createDataObject("SubCategory");
> >         subCategory.setBoolean("displayable", true);
> >
> >         extension.set("SubCategory", "myCategory");
> >
> >         context.getXMLHelper().save(extension, "urn:Extension",
> > "Extension", System.out);
> >
> >
> > When the set() method is called, i get the following exception:
> >
> > Exception in thread "main" java.lang.ClassCastException:
> java.lang.String
> >    at org.eclipse.emf.ecore.util.EcoreEList.set(EcoreEList.java:448)
> >    at org.eclipse.emf.ecore.impl.
> > EStructuralFeatureImpl$InternalSettingDelegateMany.
> > dynamicSet(EStructuralFeatureImpl.java:1647)
> >    at org.eclipse.emf.ecore.impl.BasicEObjectImpl.
> > eDynamicSet(BasicEObjectImpl.java:709)
> >    at org.apache.tuscany.sdo.impl.DynamicDataObjectImpl.
> > eDynamicSet(DynamicDataObjectImpl.java:159)
> >    at org.apache.tuscany.sdo.impl.DataObjectImpl.
> > eSet(DataObjectImpl.java:1459)
> >    at org.eclipse.emf.ecore.impl.BasicEObjectImpl.
> > eSet(BasicEObjectImpl.java:654)
> >    at
> org.apache.tuscany.sdo.impl.DataObjectImpl.set(DataObjectImpl.java:142)
> >    at
> org.apache.tuscany.sdo.util.DataObjectUtil.set(DataObjectUtil.java:730)
> >    at
> org.apache.tuscany.sdo.impl.DataObjectImpl.set(DataObjectImpl.java:225)
> >    at Test.valueTest(Test.java:186)
> >    at Test.main(Test.java:197)
> >
> >
> > I've tried looking through the samples and test cases, but couldn't
> > find a similar example. Any help in pointing me to the correct API
> > would be appreciated.
> >
> > Thanks,
> > -Chris
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tuscany-user-unsubscribe@ws.apache.org
> > For additional commands, e-mail: tuscany-user-help@ws.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tuscany-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-user-help@ws.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-user-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-user-help@ws.apache.org


Re: Question about setting an element's value

Posted by Frank Budinsky <fr...@ca.ibm.com>.
Hi Chris,

A complexType that extends a simpleType exposes the simple content as a 
property named "value". So, you would set it like this:

  subCategory.set("value", "myCategory");

Frank

eyeofthefrog@gmail.com wrote on 05/25/2007 11:10:35 AM:

> Hi,
> 
> I have the following schema:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:ext="urn:Extension"
>    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>    targetNamespace="urn:Extension"
>    elementFormDefault="unqualified" attributeFormDefault="unqualified"
> version="1.0">
>    <xs:element name="Extension">
>       <xs:complexType>
>          <xs:sequence>
>             <xs:element ref="ext:SubCategory" minOccurs="0"
> maxOccurs="unbounded" />
>          </xs:sequence>
>       </xs:complexType>
>    </xs:element>
> 
>    <xs:element name="SubCategory">
>       <xs:complexType>
>          <xs:simpleContent>
>             <xs:extension base="xs:string">
>                <xs:attribute name="displayable" type="xs:boolean"
> use="optional" />
>             </xs:extension>
>          </xs:simpleContent>
>       </xs:complexType>
>    </xs:element>
> </xs:schema>
> 
> 
> And I'd like to create this xml:
> 
> <?xml version="1.0" encoding="ASCII"?>
> <ext:Extension xmlns:ext="urn:Extension">
>   <ext:SubCategory displayable="true">myCategory</SubCategory>
> </ext:Extension>
> 
> 
> I'm having problems setting the value "myCategory". In examples I've
> seen where the element does not contain an attribute, a simple
> set("SubCategory", "myCategory") would work. It seems that I can't use
> that in this case. Here's my current code:
> 
>         HelperContext context = SDOUtil.createHelperContext();
> 
>         InputStream in = new File("Extension.xsd").toURL().openStream();
>         context.getXSDHelper().define(in, null);
> 
>         DataObject extension =
> context.getDataFactory().create("urn:Extension", "Extension");
> 
>         DataObject subCategory = 
extension.createDataObject("SubCategory");
>         subCategory.setBoolean("displayable", true);
> 
>         extension.set("SubCategory", "myCategory");
> 
>         context.getXMLHelper().save(extension, "urn:Extension",
> "Extension", System.out);
> 
> 
> When the set() method is called, i get the following exception:
> 
> Exception in thread "main" java.lang.ClassCastException: 
java.lang.String
>    at org.eclipse.emf.ecore.util.EcoreEList.set(EcoreEList.java:448)
>    at org.eclipse.emf.ecore.impl.
> EStructuralFeatureImpl$InternalSettingDelegateMany.
> dynamicSet(EStructuralFeatureImpl.java:1647)
>    at org.eclipse.emf.ecore.impl.BasicEObjectImpl.
> eDynamicSet(BasicEObjectImpl.java:709)
>    at org.apache.tuscany.sdo.impl.DynamicDataObjectImpl.
> eDynamicSet(DynamicDataObjectImpl.java:159)
>    at org.apache.tuscany.sdo.impl.DataObjectImpl.
> eSet(DataObjectImpl.java:1459)
>    at org.eclipse.emf.ecore.impl.BasicEObjectImpl.
> eSet(BasicEObjectImpl.java:654)
>    at 
org.apache.tuscany.sdo.impl.DataObjectImpl.set(DataObjectImpl.java:142)
>    at 
org.apache.tuscany.sdo.util.DataObjectUtil.set(DataObjectUtil.java:730)
>    at 
org.apache.tuscany.sdo.impl.DataObjectImpl.set(DataObjectImpl.java:225)
>    at Test.valueTest(Test.java:186)
>    at Test.main(Test.java:197)
> 
> 
> I've tried looking through the samples and test cases, but couldn't
> find a similar example. Any help in pointing me to the correct API
> would be appreciated.
> 
> Thanks,
> -Chris
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tuscany-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-user-help@ws.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-user-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-user-help@ws.apache.org