Hi Werner,
I want to be able to define a map where 'key' attribute of pupil is used as the
key to a map...
E.g.
Map<Key <Pupil.key> Value<Pupil>>
When I looked at the 'how to' for creating mapping it seems that the map key
needs to be defined outside of the pupil element.
Something similar to...
<classRoom>
<childList>
<pupilwrapper key="01">
<pupil key="01">
<name>Joe</name>
</pupil>
</pupilwrapper>
<pupilwrapper key="02">
<pupil key="02">
<name>Jane</name>
</pupil>
</pupilwrapper>
<pupilwrapper key="03">
<pupil key="03">
<name>Jack</name>
</pupil>
</pupilwrapper>
</childList>
</classRoom>
Since I can not change existing XML to have a wrapper is there another way to
define this mapping?
Thanks
Declan
-----Original Message-----
From: Werner Guttmann [mailto:[email protected]]
Sent: 11 February 2010 07:55
To: [email protected]
Cc: Maguire, Declan
Subject: Re: [castor-user] Mapping a Element to a Map where the key is part of
the element
Hi Declan,
what problems are you actually having with your current mapping ? In
other words, can you please make your questions a bit more specific ?
Regards
Werner
On 02.02.2010 18:31, Maguire, Declan wrote:
> Hi,
>
> I hope you can help. I have the following scenario...
>
> <classRoom>
> <childList>
> <pupil key="01">
> <name>Joe</name>
> </pupil>
> <pupil key="02">
> <name>Jane</name>
> </pupil>
> <pupil key="03">
> <name>Jack</name>
> </pupil>
> </childList>
> </classRoom>
>
> And I want to be able to map this to the following classes
>
> public class ClassRoom {
>
> public Map children = new HashMap();
>
> public ClassRoom() {
> }
> }
>
> public class Child {
>
> public String id = null;
> public String name = null;
>
> public Child() {
> }
> }
>
> I have tried to map the classes in the following way...
>
> <mapping>
> <class name="castor.ClassRoom">
> <map-to xml="classRoom"/>
>
> <field name="children" collection="map" direct="true">
> <bind-xml location="childList">
> <class name="org.exolab.castor.mapping.MapItem">
> <field name="key" type="java.lang.String">
> <bind-xml name="key" location="pupil" node="attribute"/>
> </field>
> <field name="value" type="castor.Child">
> <bind-xml name="pupil" node="element"/>
> </field>
> </class>
> </bind-xml>
> </field>
> </class>
>
> <class name="castor.Child">
> <field name="id" type="string" direct="true">
> <bind-xml name="key" node="attribute"/>
> </field>
>
> <field name="name" type="string" direct="true">
> <bind-xml name="name" node="element"/>
> </field>
> </class>
> </mapping>
>
> Can you please advise as to what I am doing wrong or if another approach is
> available, unfortunately I can not change the original XML data file.
>
> Thanks
>
> Declan
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email