Mark,

1. Remove one of the "aaa" field mappings in the test.Abba class
mapping, you
   can only have one field mapping for a collection.

2. Change the other field mapping to:

<field name="aaa" type="test.Aaa" collection="collection">
    <bind-xml auto-naming="deriveByClass"/>
</field>

Both Bbb and Ccc should be correctly mapped. If you have any problems
with the above,
you can also add a matches attribute as such:

    <bind-xml auto-naming="deriveByClass" matches="Bbb Ccc"/>


--Keith

Mark Katheklakis wrote:
> 
> Hello
> 
> Is there any way to bind two XML elements (Bbb and Ccc) to the same java
> field...???
> 
> I'm trying to obtain a polymorphic data structure using castor XML
> Mapping....
> The example below fails, but illustrates what I'm attempting to do......
> 
> Any assistance or pointers greatly appreciated...
> 
> Cheers
> Mark
> 
> ------------------------------
> -- Java Objects
> ------------------------------
> 
> Class Aaa {
>    String name;
>    String desc;
> }
> 
> Class Bbb extends Aaa {
>    String blah;
> }
> 
> Class Ccc extends Aaa {
>    String fooo;
> }
> 
> Class Abba {
>    Collection aaa;    //contains descendants of Aaa ie Bbb | Ccc
> }
> 
> -----------------------------
> -- XML
> ------------------------------
> 
> <Abba>
>         <Bbb>
>                 <name>bbb name</name>
>                 <desc>bbb desc</desc>
>                 <blah>bbb blah</blah>
>         </Bbb>
>         <Ccc>
>                 <name>ccc name</name>
>                 <desc>ccc desc</desc>
>                 <fooo>ccc fooo</fooo>
>         </Ccc>
> </Abba>
> 
> -------------------------------
> -- Mapping
> ------------------------------
> 
> <mapping>
>         <class name="test.Abba">
> 
>                 <map-to xml="Abba"/>
> 
>                 <field name="aaa" type="test.Bbb" collection="collection">
>                         <bind-xml name="Bbb"/>
>                 </field>
>                 <field name="aaa" type="test.Ccc" collection="collection">
>                         <bind-xml name="Ccc"/>
>                 </field>
>         </class>
> 
>         <class name="test.Aaa">
>                 <field name="name" type="string">
>                         <bind-xml name="name" node="element"/>
>                 </field>
>                 <field name="desc" type="string">
>                         <bind-xml name="desc" node="element"/>
>                 </field>
>         </class>
> 
>         <class name="test.Bbb" extends="test.Aaa">
>                 <field name="blah" type="string">
>                         <bind-xml name="blah" node="element"/>
>                 </field>
>         </class>
> 
>         <class name="test.Ccc" extends="test.Aaa">
>                 <field name="fooo" type="string">
>                         <bind-xml name="fooo" node="element"/>
>                 </field>
>         </class>
> 
> </mapping>
> 
> -----------------------------------------------------------
> 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