Hi Keith,

Your first solution works very well. Thanks very much for your
help. You have really rescue me in my tricky problem.
"ciao e grazie molto"
Christian Nicolas

-----Original Message-----
From: Keith Visco [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 29, 2003 8:53 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] Unmarshalling problem using a mapping file.



A few notes about Castor.

The value of xsi:type tells Castor which class to instantiate upon
unmarshalling. This is done either by specifying the schema type name,
or using a castor specific feature "java:" and specifying the class
name.

So upon Marshalling, Castor will determine that because you have a
collection of mixed types that it needs to add the xsi:type information
in order to be able to correctly unmarshal the document back.

However, in your situation, you are trying to "transform" the class name
from yyy.MyDevice to xxx.MyDevice.

If your values were not part of a collection, this would be fairly easy
to change, but since you are using a collection of mixed types it's a
bit more difficult.

The first thing you could try would be the following:

        <class name="xxx.Device">
               <map-to xml="MyDevice"/>
               <field name="elements" collection="..."
container="false"/>
        </class>

This should change your output a bit, to something like:

 <devices>
     <elements>
         <MyDevice>
             <name>XV234</name>
             <type>Engine</type>
         </MyDevice>
     </elements>

This will make it easier for castor to unmarshal into your client object
model. 

That should solve the problem.

If you really need to keep the XML format the same, and use the
xsi:type, then you'll need to use an XSLT transformation to change all
"yyy.MyDevice" into "xxx.MyDevice" before you try to unmarshal.

--Keith

Nicolas Christian wrote:
> 
> Thanks very much Keith for your quick response, but your proposal
> does not works in my specific problem. To be more precise, I try to
> exchange data between a server and a client application, and a class
> A on the server side must be replaced by a class B on the client side.
> Furthermore, only the client application can use mapping file for
> transformation.
> 
> But the bigest problem comes from the use of collection. Because, my list
of
> 
> 'elements' contains heterogenous classes.
> 
> e.g of xml instance:
> <devices>
>     <elements xsi:type="java:yyy.MyDevice">
>          <name>XV234</name>
>          <type>Engine</type>
>     </elements>
>     <elements xsi:type="java:yyy.Coder">
>          <name>COD4120</name>
>          <type>coder</type>
>     </elements>
>     <elements xsi:type="java:yyy.Transrater">
>          <name>TR123</name>
>          <type>transrater</type>
>     </elements>
> </devices>
> 
> This following mapping works very well for the marshalling,
>        <class name="xxx.Device" auto-complete="true" >
>               <map-to xml="java:yyy.MyDevice"/>
>        </class>
> then each instance of the class 'xxx.Device' will be converted like
> this in the xml instance:
>     <elements xsi:type="java:yyy.MyDevice">
>          <name>...</name>
>          <type>...</type>
>     </elements>
> 
> But unfortunatly this mapping is insufficient to insure the
> unmarshalling of this xml instance, castor does not create the
> expected instance of 'xxx.Device' but simply create the unexpected
> instance of 'yyy.MyDevice'.
> 
> I am not sure if it is possible doing that i want with a mapping file ?
> 
> 
> -----Original Message-----
> From: Keith Visco [mailto:[EMAIL PROTECTED]
> Sent: Monday, July 28, 2003 11:07 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [castor-dev] Unmarshalling problem using a mapping file.
> 
> Your mapping file should look more like:
> 
>        <class name="xxx.Device" auto-complete="true" >
>               <map-to xml="elements"/>
>        </class>
> 
> I'm not sure what you're trying to do with the following:
> 
>   <map-to xml="java:yyy.MyDevice"/>
> 
> Since no element of that name exists in your XML instance.
> 
> --Keith
> 
> Nicolas Christian wrote:
> >
> > Hi everyone,
> >
> > I am using mapping file for marshalling and unmarshalling. The
marshalling
> > works wery well, I have succeded to change the class name from the java
> > class
> > to the xml instance, but the unmarshalling does not take account of my
> > mapping file
> > for the reverse operation. I do not know why...
> >
> > Problem description:
> > I have succeded to marshall the class 'xxx.Device' and changed its name
by
> > 'yyy.MyDevice' within
> > the xml schema instance, but when I unmarshall 'yyy.MyDevice' from the
xml
> > instance then castor
> > does not take account of my mapping file and try to create an instance
of
> > 'yyy.MyDevice' while
> > 'xxx.Device' was expected. Both java beans 'xxx.Device' and
'yyy.MyDevice'
> > have the same properties.
> >
> > My mapping file is as follow:
> >
> > <?xml version="1.0"?>
> > <!DOCTYPE databases PUBLIC "-//EXOLAB/Castor Mapping DTD Version
1.0//EN"
> >                            "http://castor.exolab.org/mapping.dtd";>
> > <mapping>
> >   <description>Mapping intended for the client side</description>
> >
> >       <class name="xxx.Device" auto-complete="true" >
> >              <map-to xml="java:yyy.MyDevice"/>
> >       </class>
> >
> > </mapping>
> >
> > My Xml instance is as follow:
> > <SetOfDevices>
> >     <profite>123</profite>
> >     <devices>
> >         <elements xsi:type="java:yyy.MyDevice"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
> >             <name>XV234</name>
> >             <type>Engine</type>
> >         </elements>
> >
> >         <elements xsi:type="java:yyy.MyDevice"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
> >             <name>GH67</name>
> >             <type>Gear</type>
> >         </elements>
> >     </devices>
> > </SetOfDevices>
> >
> > Is there any description missing in my mapping file ?
> > Christian Nicolas
> >
> > -----------------------------------------------------------
> > If you wish to unsubscribe from this mailing, send mail to
> > [EMAIL PROTECTED] with a subject of:
> >         unsubscribe castor-dev
> 
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-dev
> 
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-dev

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to