Hi,
I had a case that resembles this one and I found a workaround without using a 
custom marshaller/unmarshaller.
My case had some 'lucky' conditions but maybe they will also apply to you.

I created an abstract mapping which reads the 'type' tag value into a field.
The extending mappings are as usual and matched this same xml structure.
(This means that only the first type of concrete class will ever get created 
but it will hold its correct type
String in the 'type' field.).

In the class containing these polymorphic objects (hopefully you have one since 
this is the trick here) I created a post-set method.
This method iterates over the polymorphic objects, checks their 'type' string 
field and creates a different
Instance according to that type (if it differs from instanceof what I expect). 

Perhaps I didn't explain this too well, but I hope you get the general idea.

Cheers,

Ori

--------------------------------------------------------

Dennis Sosnoski
Tue, 18 Jul 2006 17:44:01 -0700
Hi Jonas,

So you want to bind to different objects, depending on the actual value 
in an element. The only way I can suggest to handle that is by using a 
custom marshaller/unmarshaller for this structure. It'd need to parse 
past the <object> start tag and get the <type> element contents in order 
to know what type of object to create for the value.

You can find out the basics of custom marshaller/unmarshallers at 
http://jibx.sourceforge.net/tutorial/binding-custom.html#marunmar

  - Dennis

Dennis M. Sosnoski
SOA, Web Services, and XML
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-296-6194 - Wellington, NZ +64-4-298-6117



bill vezÿffffe9 wrote:
> hi all,
> I'm new to JiBX, and I'm not sure how to solve my problem. I didn't 
> find any answer in the mailing list. Here's the point:
> I got an XML structure like this
> <object>
>     <type>type1</type>
>     <value>val</value>
> </object>
> <object>
>     <type>type2</type>
>     <value>value</value>
> </object>
>
> an i need to bind this to one of these classes according to the 
> element value of type
>
> type1 -> Foo
> type2 -> Bar
>
> Is there a straight method to do that with JiBX in the binding 
> definition ?
> is someone can show me an xml binding structure that solve this case
>
> thanks for your help
>
> Jonas
>


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to