You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tuscany.apache.org by Upeka Bulumulle <ca...@gmail.com> on 2007/07/25 20:20:51 UTC

Dynamic Type Definition...

Hi All,

Tuscany SDO version: Tuscany SDO 1.0 beta1.

I'm trying to dynamically create and use types without the use of an XSD
file. What i want to do is something a little different to what is described
in the samples provided. I want to have elements within each nested type. i
also want to to be able to support lists (String lists, Interger lists etc).

My dynamically defined XSD should look like this (complete xsd is
attached...),

    <xsd:element name="dataType" type="DataType"/>
    <xsd:complexType name="DataType">
        <xsd:sequence>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="item"
type="ItemType"/>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="list"
type="ListItemType"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="ItemType">
        <xsd:sequence>
            <xsd:element name="type" type="xsd:string"/>
            <xsd:element name="name" type="xsd:string"/>
            <xsd:element name="boolean" type="xsd:boolean"/>
        </xsd:sequence>
 <xsd:complexType name="ListItemType">
        <xsd:sequence>
            <xsd:element name="listType" type="xsd:string"/>
            <xsd:element name="listName" type="xsd:string"/>
            <xsd:element name="booleanList" type="BooleanListType"/>
        </xsd:sequence>
    </xsd:complexType>
     <xsd:complexType name="BooleanListType">
        <xsd:sequence>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name=
"booleanValue" type="xsd:boolean"/>
        </xsd:sequence>
    </xsd:complexType>

I added the many true option when creating the property for each data object
which resulted in type, name and boolean resulting in elements.
        // create data graph root
        DataGraph dataGraph = SDOUtil.createDataGraph();
        DataObject dynamic = dataGraph.createRootObject("commonj.sdo",
"Type");
        dynamic.set("uri", "http://www.dynamic.com/dynamic");
        dynamic.set("name", "DataType");
        dynamic.set("dataType", false);

        // primitive type.. ints
        DataObject custNumProperty = dynamic.createDataObject("property");
        custNumProperty.set("name", "custNum");
        custNumProperty.set("type", intType);
        custNumProperty.set("many", true);

However i am unable set values to the data object once i do this.I get the
following stack trace when i do this,
    DataObject createdDO = DataFactory.INSTANCE.create("
http://www.dynamic.com/dynamic", "DataType");
    createdDO.setInt("custNum", 1000);

java.lang.ClassCastException: java.lang.Integer
    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:150)
    at org.apache.tuscany.sdo.impl.DataObjectImpl.eSet(DataObjectImpl.java
:1442)
    at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(
BasicEObjectImpl.java:654)
    at org.apache.tuscany.sdo.impl.DataObjectImpl.set(DataObjectImpl.java
:143)
    at org.apache.tuscany.sdo.util.DataObjectUtil.setInt(DataObjectUtil.java
:532)
    at org.apache.tuscany.sdo.impl.DataObjectImpl.setInt(DataObjectImpl.java
:526)

(if i leave out the many true flag, then the xsd displays them as attributes
and i am able to set values to them)

My code is attached for your review.

I would appreciate your help in this regard. The reason i want to
dynamically define the type is because my client requires high performant
code. The time taken to execute the dynamic xsd is quite less compared to
the time taken to read the xsd. Almost a whole second.

Thanks and regards
Roshan

The samples provide an example where the dynamically defined types result in
attributes and not elements.

RE: Dynamic Type Definition...

Posted by Dean Povey <De...@quest.com>.
I think the problem is that when you set many=true then the attribute
becomes a list rather than a bare type (otherwise there is no way to add
multiple attributes).  You need to do:

List<int> custNum = new ArrayList();
custNum.add(1000);
createdDO.setList("custNum", custNum);

I didn't see the custNum element in your XSD so I don't know if you want
to do the above or remove the many=true property.

Dean.

> -----Original Message-----
> From: Upeka Bulumulle [mailto:catsupandgrapejelly@gmail.com]
> Sent: Thursday, 26 July 2007 4:21 AM
> To: tuscany-dev@ws.apache.org; tuscany-user@ws.apache.org
> Subject: Dynamic Type Definition...
> 
> Hi All,
> 
> Tuscany SDO version: Tuscany SDO 1.0 beta1.
> 
> I'm trying to dynamically create and use types without the use of an
XSD
> file. What i want to do is something a little different to what is
> described in the samples provided. I want to have elements within each
> nested type. i also want to to be able to support lists (String lists,
> Interger lists etc).
> 
> My dynamically defined XSD should look like this (complete xsd is
> attached...),
> 
>     <xsd:element name="dataType" type="DataType"/>
>     <xsd:complexType name="DataType">
>         <xsd:sequence>
>             <xsd:element maxOccurs="unbounded" minOccurs="0"
name="item"
> type="ItemType"/>
>             <xsd:element maxOccurs="unbounded" minOccurs="0"
name="list"
> type="ListItemType"/>
>         </xsd:sequence>
>     </xsd:complexType>
>     <xsd:complexType name="ItemType">
>         <xsd:sequence>
>             <xsd:element name="type" type="xsd:string"/>
>             <xsd:element name="name" type="xsd:string"/>
>             <xsd:element name="boolean" type="xsd:boolean"/>
>         </xsd:sequence>
> <xsd:complexType name="ListItemType">
>         <xsd:sequence>
>             <xsd:element name="listType" type= "xsd:string"/>
>             <xsd:element name="listName" type= "xsd:string"/>
>             <xsd:element name="booleanList" type= "BooleanListType"/>
>         </xsd:sequence>
>     </xsd:complexType>
>     <xsd:complexType name="BooleanListType">
>         <xsd:sequence>
>             <xsd:element maxOccurs="unbounded" minOccurs= "0"
> name="booleanValue" type="xsd:boolean"/ >
>         </xsd:sequence>
>     </xsd:complexType>
> 
> I added the many true option when creating the property for each data
> object which resulted in type, name and boolean resulting in elements.
>         // create data graph root
>         DataGraph dataGraph = SDOUtil.createDataGraph();
>         DataObject dynamic = dataGraph.createRootObject("commonj.sdo",
> "Type");
>         dynamic.set("uri", "http://www.dynamic.com/dynamic ");
>         dynamic.set("name", "DataType");
>         dynamic.set("dataType", false);
> 
>         // primitive type.. ints
>         DataObject custNumProperty = dynamic.createDataObject
> ("property");
>         custNumProperty.set("name", "custNum");
>         custNumProperty.set("type", intType);
>         custNumProperty.set("many", true);
> 
> However i am unable set values to the data object once i do this.I get
the
> following stack trace when i do this,
>     DataObject createdDO =
> DataFactory.INSTANCE.create("http://www.dynamic.com/dynamic",
"DataType");
>     createdDO.setInt("custNum", 1000);
> 
> java.lang.ClassCastException: java.lang.Integer
>     at org.eclipse.emf.ecore.util.EcoreEList.set(EcoreEList.java:448)
>     at
>
org.eclipse.emf.ecore.impl.EStructuralFeatureImpl$InternalSettingDelegat
eM
> any.dynamicSet (EStructuralFeatureImpl.java:1647)
>     at
>
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eDynamicSet(BasicEObjectImpl
.j
> ava:709)
>     at
>
org.apache.tuscany.sdo.impl.DynamicDataObjectImpl.eDynamicSet(DynamicDat
aO
> bjectImpl.java :150)
>     at
>
org.apache.tuscany.sdo.impl.DataObjectImpl.eSet(DataObjectImpl.java:1442
)
>     at
>
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:6
54
> )
>     at org.apache.tuscany.sdo.impl.DataObjectImpl.set
> (DataObjectImpl.java:143)
>     at
>
org.apache.tuscany.sdo.util.DataObjectUtil.setInt(DataObjectUtil.java:53
2)
>     at
>
org.apache.tuscany.sdo.impl.DataObjectImpl.setInt(DataObjectImpl.java:52
6)
> 
> (if i leave out the many true flag, then the xsd displays them as
> attributes and i am able to set values to them)
> 
> My code is attached for your review.
> 
> I would appreciate your help in this regard. The reason i want to
> dynamically define the type is because my client requires high
performant
> code. The time taken to execute the dynamic xsd is quite less compared
to
> the time taken to read the xsd. Almost a whole second.
> 
> Thanks and regards
> Roshan
> 
> The samples provide an example where the dynamically defined types
result
> in attributes and not elements.
> 




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


RE: Dynamic Type Definition...

Posted by Dean Povey <De...@quest.com>.
I think the problem is that when you set many=true then the attribute
becomes a list rather than a bare type (otherwise there is no way to add
multiple attributes).  You need to do:

List<int> custNum = new ArrayList();
custNum.add(1000);
createdDO.setList("custNum", custNum);

I didn't see the custNum element in your XSD so I don't know if you want
to do the above or remove the many=true property.

Dean.

> -----Original Message-----
> From: Upeka Bulumulle [mailto:catsupandgrapejelly@gmail.com]
> Sent: Thursday, 26 July 2007 4:21 AM
> To: tuscany-dev@ws.apache.org; tuscany-user@ws.apache.org
> Subject: Dynamic Type Definition...
> 
> Hi All,
> 
> Tuscany SDO version: Tuscany SDO 1.0 beta1.
> 
> I'm trying to dynamically create and use types without the use of an
XSD
> file. What i want to do is something a little different to what is
> described in the samples provided. I want to have elements within each
> nested type. i also want to to be able to support lists (String lists,
> Interger lists etc).
> 
> My dynamically defined XSD should look like this (complete xsd is
> attached...),
> 
>     <xsd:element name="dataType" type="DataType"/>
>     <xsd:complexType name="DataType">
>         <xsd:sequence>
>             <xsd:element maxOccurs="unbounded" minOccurs="0"
name="item"
> type="ItemType"/>
>             <xsd:element maxOccurs="unbounded" minOccurs="0"
name="list"
> type="ListItemType"/>
>         </xsd:sequence>
>     </xsd:complexType>
>     <xsd:complexType name="ItemType">
>         <xsd:sequence>
>             <xsd:element name="type" type="xsd:string"/>
>             <xsd:element name="name" type="xsd:string"/>
>             <xsd:element name="boolean" type="xsd:boolean"/>
>         </xsd:sequence>
> <xsd:complexType name="ListItemType">
>         <xsd:sequence>
>             <xsd:element name="listType" type= "xsd:string"/>
>             <xsd:element name="listName" type= "xsd:string"/>
>             <xsd:element name="booleanList" type= "BooleanListType"/>
>         </xsd:sequence>
>     </xsd:complexType>
>     <xsd:complexType name="BooleanListType">
>         <xsd:sequence>
>             <xsd:element maxOccurs="unbounded" minOccurs= "0"
> name="booleanValue" type="xsd:boolean"/ >
>         </xsd:sequence>
>     </xsd:complexType>
> 
> I added the many true option when creating the property for each data
> object which resulted in type, name and boolean resulting in elements.
>         // create data graph root
>         DataGraph dataGraph = SDOUtil.createDataGraph();
>         DataObject dynamic = dataGraph.createRootObject("commonj.sdo",
> "Type");
>         dynamic.set("uri", "http://www.dynamic.com/dynamic ");
>         dynamic.set("name", "DataType");
>         dynamic.set("dataType", false);
> 
>         // primitive type.. ints
>         DataObject custNumProperty = dynamic.createDataObject
> ("property");
>         custNumProperty.set("name", "custNum");
>         custNumProperty.set("type", intType);
>         custNumProperty.set("many", true);
> 
> However i am unable set values to the data object once i do this.I get
the
> following stack trace when i do this,
>     DataObject createdDO =
> DataFactory.INSTANCE.create("http://www.dynamic.com/dynamic",
"DataType");
>     createdDO.setInt("custNum", 1000);
> 
> java.lang.ClassCastException: java.lang.Integer
>     at org.eclipse.emf.ecore.util.EcoreEList.set(EcoreEList.java:448)
>     at
>
org.eclipse.emf.ecore.impl.EStructuralFeatureImpl$InternalSettingDelegat
eM
> any.dynamicSet (EStructuralFeatureImpl.java:1647)
>     at
>
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eDynamicSet(BasicEObjectImpl
.j
> ava:709)
>     at
>
org.apache.tuscany.sdo.impl.DynamicDataObjectImpl.eDynamicSet(DynamicDat
aO
> bjectImpl.java :150)
>     at
>
org.apache.tuscany.sdo.impl.DataObjectImpl.eSet(DataObjectImpl.java:1442
)
>     at
>
org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:6
54
> )
>     at org.apache.tuscany.sdo.impl.DataObjectImpl.set
> (DataObjectImpl.java:143)
>     at
>
org.apache.tuscany.sdo.util.DataObjectUtil.setInt(DataObjectUtil.java:53
2)
>     at
>
org.apache.tuscany.sdo.impl.DataObjectImpl.setInt(DataObjectImpl.java:52
6)
> 
> (if i leave out the many true flag, then the xsd displays them as
> attributes and i am able to set values to them)
> 
> My code is attached for your review.
> 
> I would appreciate your help in this regard. The reason i want to
> dynamically define the type is because my client requires high
performant
> code. The time taken to execute the dynamic xsd is quite less compared
to
> the time taken to read the xsd. Almost a whole second.
> 
> Thanks and regards
> Roshan
> 
> The samples provide an example where the dynamically defined types
result
> in attributes and not elements.
> 




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


Re: Dynamic Type Definition...

Posted by kelvin goodson <ke...@gmail.com>.
I think you need the fix in
https://issues.apache.org/jira/browse/TUSCANY-1408 that is part of the
1.0-incubating release which is currently being voted on.

Regards, Kelvin.

On 25/07/07, Upeka Bulumulle <ca...@gmail.com> wrote:
> Hi All,
>
> Tuscany SDO version: Tuscany SDO 1.0 beta1.
>
> I'm trying to dynamically create and use types without the use of an XSD
> file. What i want to do is something a little different to what is described
> in the samples provided. I want to have elements within each nested type. i
> also want to to be able to support lists (String lists, Interger lists etc).
>
> My dynamically defined XSD should look like this (complete xsd is
> attached...),
>
>     <xsd:element name="dataType" type="DataType"/>
>     <xsd:complexType name="DataType">
>         <xsd:sequence>
>             <xsd:element maxOccurs="unbounded" minOccurs="0" name="item"
> type="ItemType"/>
>             <xsd:element maxOccurs="unbounded" minOccurs="0" name="list"
> type="ListItemType"/>
>         </xsd:sequence>
>     </xsd:complexType>
>     <xsd:complexType name="ItemType">
>         <xsd:sequence>
>             <xsd:element name="type" type="xsd:string"/>
>             <xsd:element name="name" type="xsd:string"/>
>             <xsd:element name="boolean" type="xsd:boolean"/>
>         </xsd:sequence>
>  <xsd:complexType name="ListItemType">
>          <xsd:sequence>
>              <xsd:element name="listType" type= "xsd:string"/>
>              <xsd:element name="listName" type= "xsd:string"/>
>              <xsd:element name="booleanList" type= "BooleanListType"/>
>         </xsd:sequence>
>      </xsd:complexType>
>      <xsd:complexType name="BooleanListType">
>          <xsd:sequence>
>              <xsd:element maxOccurs="unbounded" minOccurs= "0"
> name="booleanValue" type="xsd:boolean"/ >
>          </xsd:sequence>
>      </xsd:complexType>
>
> I added the many true option when creating the property for each data object
> which resulted in type, name and boolean resulting in elements.
>         // create data graph root
>         DataGraph dataGraph = SDOUtil.createDataGraph();
>         DataObject dynamic = dataGraph.createRootObject("commonj.sdo",
> "Type");
>         dynamic.set("uri", "http://www.dynamic.com/dynamic ");
>         dynamic.set("name", "DataType");
>         dynamic.set("dataType", false);
>
>         // primitive type.. ints
>         DataObject custNumProperty = dynamic.createDataObject ("property");
>         custNumProperty.set("name", "custNum");
>         custNumProperty.set("type", intType);
>         custNumProperty.set("many", true);
>
> However i am unable set values to the data object once i do this.I get the
> following stack trace when i do this,
>     DataObject createdDO =
> DataFactory.INSTANCE.create("http://www.dynamic.com/dynamic", "DataType");
>     createdDO.setInt("custNum", 1000);
>
> java.lang.ClassCastException: java.lang.Integer
>     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
> :150)
>     at
> org.apache.tuscany.sdo.impl.DataObjectImpl.eSet(DataObjectImpl.java:1442)
>     at
> org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSet(BasicEObjectImpl.java:654)
>     at org.apache.tuscany.sdo.impl.DataObjectImpl.set
> (DataObjectImpl.java:143)
>     at
> org.apache.tuscany.sdo.util.DataObjectUtil.setInt(DataObjectUtil.java:532)
>     at
> org.apache.tuscany.sdo.impl.DataObjectImpl.setInt(DataObjectImpl.java:526)
>
> (if i leave out the many true flag, then the xsd displays them as attributes
> and i am able to set values to them)
>
> My code is attached for your review.
>
> I would appreciate your help in this regard. The reason i want to
> dynamically define the type is because my client requires high performant
> code. The time taken to execute the dynamic xsd is quite less compared to
> the time taken to read the xsd. Almost a whole second.
>
> Thanks and regards
> Roshan
>
> The samples provide an example where the dynamically defined types result in
> attributes and not elements.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> tuscany-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: tuscany-dev-help@ws.apache.org
>

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