I like your idea of creating the abstract class for a generic party type, 
but I still have the issue of whether to map to a Person or a Business 
depending on the value of an attribute in my input xml.  For example, the 
input xml is as follows

<ns:Party xsi:type='person'>  <!-- Maps to Person Object -->
         <ns:Id>1111111111111111111</ns:Id> 
         <ns:CommonType>P</ns:CommonType> 
         <ns:BirthDate>P</ns:BirthDate> 
 </ns:Party>

 or

 <ns:Party xsi:type='business'>    <!-- Maps to Business Object -->
         <ns:Id>22222222222222222</ns:Id> 
         <ns:CommonType>O</ns:CommonType> 
         <ns:BusinessType>1</ns:BusinessType>
 </ns:Party>


As you can see,  the <Party> tag can map to both Person or Business 
depending on the value of the xsi:type attribute and never both in the 
same request.  So I need to do some sort of dynamic binding that allows me 
to map to either Person or Business base of the xsi:type value.  Do you 
know of a way to map this sort of input.

Barry





Varghese C V <[EMAIL PROTECTED]>
 
Sent by: [EMAIL PROTECTED]




06/26/2007 06:07 AM
Please respond to JiBX users <jibx-users@lists.sourceforge.net>

From
Varghese C V <[EMAIL PROTECTED]>
To
JiBX users <jibx-users@lists.sourceforge.net>
cc

Subject
Re: [jibx-users] JiBX dynamic binding question






I was thinking of a concrete Party object with a reference to the base 
class for the Person and Business object.

abstract class PartyReference{
}

class Party{
    PartyReference reference;
}

class Person extends PartyReference{}
class Business extends PartyReference{}

The mappings
    <mapping class="PartyReference" abstract="true">
    </mapping>
    <mapping class="Person" extends="PartyReference">
       <structure map-as="PartyReference"/>
    </mapping>
    <mapping class="Party">
         <structure field="reference"/>
    </mapping>

This way the bindings are simpler. What do you think?

regards
Varghese

[EMAIL PROTECTED] wrote: 

Thank you for the quick response.  In the examples that I have found when 
using abstract mappings, you know ahead of time that there are different 
types of data to be mapped to one abstract class.  In my case, if I choose 
the abstract mapping approach, I will still need to split the abstract 
Party object out into either a Person or a Business element once I marshal 
back into xml for my application.  I need to do this because my input xml 
is defined in a structure that does not conform to the backend 
application's schema.  So on input,  I have either a Person or Business 
which gets mapped to one abstract Party class, but the Party class will 
need to be mapped to either a Person or Business when I marshal the xml 
into a form understood by my receiving application. 

Is there a way to do this? 

Thanks! 

Barry




Varghese C V <[EMAIL PROTECTED]> 
  
Sent by: [EMAIL PROTECTED] 




06/25/2007 03:19 AM 
Please respond to JiBX users <jibx-users@lists.sourceforge.net> 

From
Varghese C V <[EMAIL PROTECTED]> 
To
JiBX users <jibx-users@lists.sourceforge.net> 
cc

Subject
Re: [jibx-users] JiBX dynamic binding question










Since the Party object can contain a Person or a Business object, 
wouldn't it be better modeled if you have a abstract base class for 
these objects?
Then Party object would contain a reference to this base type. In Jibx, 
you would then have a abstract mapping for the base type, mappings for 
each inherited type and a mapping for the Party type. This approach 
assumes that you have the liberty to define the input xml and that you 
can change your model classes.

Varghese

[EMAIL PROTECTED] wrote:
>
> Hello All,
>
> I have a question about unmarshalling to specific objects based off an 
> attribute value in the input xml.   At any given time, my input xml 
> tag will remain the same.  However, the *xsi:type* attribute could be 
> different.  I need to map/bind to a specific object based off the 
> value in the attribute.  I have not found anywhere in the 
> documentation where I can bind to a specific object dynamically, but I 
> have been trying to get this to work using method hooks. 
> .
> For example, my input xml will contain one of the following entries....
>
> <ns:Party xsi:type='person'> 
>         <ns:Id>1111111111111111111</ns:Id> 
>         <ns:CommonType>P</ns:CommonType> 
>         <ns:BirthDate>P</ns:BirthDate> 
> </ns:Party>
>
> or
>
> <ns:Party xsi:type='business'> 
>         <ns:Id>22222222222222222</ns:Id> 
>         <ns:CommonType>O</ns:CommonType> 
>         <ns:BusinessType>1</ns:BusinessType>
> </ns:Party>
>
>
> My binding definition contains the following....
>
>   <mapping name="Party " class="commonparty.Party" post-set="postset" 
>  ordered="false">
>     <namespace prefix="obj" uri="http://input.common.com"; 
> default="elements"/>
>     <namespace prefix="xsi" 
> uri="http://www.w3.org/2001/XMLSchema-instance"; default="attributes"/>
>     <value name="type" field ="type" style="attribute" 
> usage="optional" />
>     <value name="Id" field="partyId" usage="optional"/>
>     <value name="CommonType" field="commonType" usage="optional"/>
>   </mapping>
>
>
> My java class structure declares that a Party object is composed of a 
> Person and Business object.  However, at any give time the Party 
> object would contain a reference to either Person or Business.
>
> public class Party {
>         public String type;
>         public Person person;
>         public Business business;
>
>         public void postset(IUnmarshallingContext ctx) {
>                 if ( type.equals("Person") ) {
>                         //Copy fields from Party to new instance of 
> Person
>                         //Replace Party object  on the stack with Person
> 
>                 } else {
>                         //Copy fields from Party to new instance of 
> Business
>                         //Replace Party object  on the stack with of
>                 }
>         }
> .
> .
> .
> }
>
> public class Person {
>         public String birthDate;
> .
> .
> .
> }
>
> public class Business{
>         public String businessType;
> .
> .
> .
> }
>
>
> As you can see, I am always mapping the "Party" tag to a Party object. 
>  The party object contains a post-set method that accepts the 
> IUnmarshallingContext signature.  In the postset method, I am 
> evaluating the xsi:type.  If the type is "Person", then I want to pop 
> the current Party object from the stack and push a new instance of a 
> Person object for JiBX to unmarshall.   After coming to this idea, I 
> realized that I do not have a specific mapping for a Person object.  I 
> definitly need a Person and a Business object because they contain 
> different fields ( as listed in my input example above ).
>
> Does anyone know if there is a binding syntax that will allow me to 
> handle this work in the binding.xml?  If not, is there another 
> solution without modifying JiBX?
>
> Thanks for the help!
>
> Barry
>
> ------------------------------------------------------------------------
>
> 
-------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> ------------------------------------------------------------------------
>
> _______________________________________________
> jibx-users mailing list
> jibx-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jibx-users
> 


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/


_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users
 
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to