You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tuscany.apache.org by Jawad <ja...@gmail.com> on 2010/10/05 13:10:25 UTC

Tuscany SDO, static objects and context

Hi everyone!

I'm currently working on the implementation of an SCA component, exposed and called via SOAP,  and I'm trying to dynamically load an XML file that contains an instance of an XSD type.
I have generated the Java classes associated with this XSD and when I send SOAP request to Tuscany using such types as parameters, I get the static types associated with the data.

Here is my XML file:
<?xml version="1.0" encoding="utf-8"?>
<data:compte xmlns:data="http://localhost/testns" xsi:type="data:Compte" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <data:intitule>Test</data:intitule>    
    <data:numero>1</data:numero>
</data:compte>

I'm using the following code:
FileInputStream fis = new FileInputStream("/Development/default_data/file.xml");
XMLStreamHelperImpl strHelper = new XMLStreamHelperImpl(org.apache.tuscany.sca.databinding.sdo.SDOContextHelper.getDefaultHelperContext());
XMLDocument doc = XMLHelper.INSTANCE.load(fis);
XMLStreamReader reader = strHelper.createXMLStreamReader(doc);
                  
reader.next();
DataObject obj = strHelper.loadObject(reader);

If I execute it I get the following ClassCastException : The feature 'compte's type 'DataObject' does not permit a value of type 'Compte'

I tried to load my XSD using XSDHelper:
FileInputStream xsdfis = new FileInputStream("/Development/default_data/Schemas.xsd");
XSDHelper.INSTANCE.define(xsdfis, null);

The exception is not raised anymore but I get a DynamicDataObject and not a static one.

If I correctly understand the way Tuscany SDO works, the first exception is raised because the TypeHelper of the default context is "empty" (it only contains default types). When I call the XSDHelper.define method, my schemas are loaded but no link is done with my generated classes.

How can I solve it ? What is the best way to get the same context as Tuscany ?
I thought that I could use org.apache.tuscany.sca.databinding.sdo.SDOContextHelper.getHelperContext(Operation op) but I cannot figure out how to find the current operation.

Best,
Jawad

Re: Tuscany SDO, static objects and context

Posted by Jawad <ja...@gmail.com>.
Hi Frank,

thanks for you quick and perfect answer, it works great!

Jawad.

Le 5 oct. 2010 à 16:10, Frank Budinsky a écrit :

> Jawad,
> 
> You're right that the first problem was because the types were not defined/registered.
> 
> The XSDHelper.define() method is used to define types that will be implemented using dynamic SDO. If, you want to use static (generated) SDO classes, then you must call the generated Factory.register() method, instead of XSDHelper.define() to define the types.
> 
> Frank.
> 
> Jawad <ja...@gmail.com> wrote on 10/05/2010 07:10:25 AM:
> 
> > [image removed] 
> > 
> > Tuscany SDO, static objects and context
> > 
> > Jawad 
> > 
> > to:
> > 
> > user
> > 
> > 10/05/2010 07:12 AM
> > 
> > Please respond to user
> > 
> > Hi everyone!
> > 
> > I'm currently working on the implementation of an SCA component, 
> > exposed and called via SOAP,  and I'm trying to dynamically load an 
> > XML file that contains an instance of an XSD type.
> > I have generated the Java classes associated with this XSD and when 
> > I send SOAP request to Tuscany using such types as parameters, I get
> > the static types associated with the data.
> > 
> > Here is my XML file:
> > <?xml version="1.0" encoding="utf-8"?>
> > <data:compte xmlns:data="http://localhost/testns" 
> > xsi:type="data:Compte" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> >     <data:intitule>Test</data:intitule>    
> >     <data:numero>1</data:numero>
> > </data:compte>
> > 
> > I'm using the following code:
> > FileInputStream fis = new FileInputStream("/Development/
> > default_data/file.xml");
> > XMLStreamHelperImpl strHelper = new XMLStreamHelperImpl
> > (org.apache.tuscany.sca.databinding.sdo.SDOContextHelper.getDefaultHelperContext
> > ());
> > XMLDocument doc = XMLHelper.INSTANCE.load(fis);
> > XMLStreamReader reader = strHelper.createXMLStreamReader(doc);
> >                   
> > reader.next();
> > DataObject obj = strHelper.loadObject(reader);
> > 
> > If I execute it I get the following ClassCastException : The feature
> > 'compte's type 'DataObject' does not permit a value of type 'Compte'
> > 
> > I tried to load my XSD using XSDHelper:
> > FileInputStream xsdfis = new FileInputStream("/Development/
> > default_data/Schemas.xsd");
> > XSDHelper.INSTANCE.define(xsdfis, null);
> > 
> > The exception is not raised anymore but I get a DynamicDataObject 
> > and not a static one.
> > 
> > If I correctly understand the way Tuscany SDO works, the first 
> > exception is raised because the TypeHelper of the default context is
> > "empty" (it only contains default types). When I call the 
> > XSDHelper.define method, my schemas are loaded but no link is done 
> > with my generated classes.
> > 
> > How can I solve it ? What is the best way to get the same context asTuscany ?
> > I thought that I could use 
> > org.apache.tuscany.sca.databinding.sdo.SDOContextHelper.getHelperContext
> > (Operation op) but I cannot figure out how to find the current operation.
> > 
> > Best,
> > Jawad
> 


Re: Tuscany SDO, static objects and context

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

You're right that the first problem was because the types were not
defined/registered.

The XSDHelper.define() method is used to define types that will be
implemented using dynamic SDO. If, you want to use static (generated) SDO
classes, then you must call the generated Factory.register() method,
instead of XSDHelper.define() to define the types.

Frank.

Jawad <ja...@gmail.com> wrote on 10/05/2010 07:10:25 AM:

> [image removed]
>
> Tuscany SDO, static objects and context
>
> Jawad
>
> to:
>
> user
>
> 10/05/2010 07:12 AM
>
> Please respond to user
>
> Hi everyone!
>
> I'm currently working on the implementation of an SCA component,
> exposed and called via SOAP,  and I'm trying to dynamically load an
> XML file that contains an instance of an XSD type.
> I have generated the Java classes associated with this XSD and when
> I send SOAP request to Tuscany using such types as parameters, I get
> the static types associated with the data.
>
> Here is my XML file:
> <?xml version="1.0" encoding="utf-8"?>
> <data:compte xmlns:data="http://localhost/testns"
> xsi:type="data:Compte"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>     <data:intitule>Test</data:intitule>
>     <data:numero>1</data:numero>
> </data:compte>
>
> I'm using the following code:
> FileInputStream fis = new FileInputStream("/Development/
> default_data/file.xml");
> XMLStreamHelperImpl strHelper = new XMLStreamHelperImpl
>
(org.apache.tuscany.sca.databinding.sdo.SDOContextHelper.getDefaultHelperContext

> ());
> XMLDocument doc = XMLHelper.INSTANCE.load(fis);
> XMLStreamReader reader = strHelper.createXMLStreamReader(doc);
>
> reader.next();
> DataObject obj = strHelper.loadObject(reader);
>
> If I execute it I get the following ClassCastException : The feature
> 'compte's type 'DataObject' does not permit a value of type 'Compte'
>
> I tried to load my XSD using XSDHelper:
> FileInputStream xsdfis = new FileInputStream("/Development/
> default_data/Schemas.xsd");
> XSDHelper.INSTANCE.define(xsdfis, null);
>
> The exception is not raised anymore but I get a DynamicDataObject
> and not a static one.
>
> If I correctly understand the way Tuscany SDO works, the first
> exception is raised because the TypeHelper of the default context is
> "empty" (it only contains default types). When I call the
> XSDHelper.define method, my schemas are loaded but no link is done
> with my generated classes.
>
> How can I solve it ? What is the best way to get the same context
asTuscany ?
> I thought that I could use
> org.apache.tuscany.sca.databinding.sdo.SDOContextHelper.getHelperContext
> (Operation op) but I cannot figure out how to find the current operation.
>
> Best,
> Jawad