I think you can - again - use a custom FieldHandler on e.g. <items< (or
the corresponding Java class) that queries the array sizes before
calling the setters for them, and 'injects' the size of the arrays in
the corresponding attributes.

Werner 

> -----Original Message-----
> From: Drew Beechum [mailto:[EMAIL PROTECTED] 
> Sent: Mittwoch, 21. Februar 2007 10:26
> To: [email protected]
> Subject: Re: [castor-user] Duplicate Attribute/Element and 
> List size attribute
> 
> Sure thing,
> 
> Sample xml...
> 
> <playlist>
>   <items audios=0 videos=2 games=1 playlists=0>
>       <video>....</video>
>       <video>....</video>
>       <game>....</game>
>   </items>
> </playlist>
> 
> This gens out to code that has 4 arrays: audio, video, game, playlist.
> I'd like to automagically tie the attributes on the items 
> node (audios, videos, etc) to the size of the arrays.
> 
> Thanks for the help
> 
> 
> On 2/21/07, Werner Guttmann <[EMAIL PROTECTED]> wrote:
> > Sorry, but your second question isn't really clear to me. 
> Can you show 
> > me some sample XMl that demonstrates what you are trying to 
> achieve ?
> >
> > Werner
> >
> > > -----Original Message-----
> > > From: Werner Guttmann [mailto:[EMAIL PROTECTED]
> > > Sent: Mittwoch, 21. Februar 2007 10:02
> > > To: [email protected]
> > > Subject: RE: [castor-user] Duplicate Attribute/Element 
> and List size 
> > > attribute
> > >
> > > On the first problem, using a mapping file to set your 
> custom field 
> > > handler is not the solution recommended. Can you please use a 
> > > binding file to instruct the XML code generator to use 
> your custom 
> > > field handler and set it onto the according class(es).
> > >
> > > Werner
> > >
> > > > -----Original Message-----
> > > > From: Drew Beechum [mailto:[EMAIL PROTECTED]
> > > > Sent: Mittwoch, 21. Februar 2007 00:54
> > > > To: [email protected]
> > > > Subject: Re: [castor-user] Duplicate Attribute/Element and
> > > List size
> > > > attribute
> > > >
> > > > I have been just using castor-1.1with no mapping file and using 
> > > > the default source generated classes.
> > > > But that doesn't seem to be sufficient so here's what I'm
> > > facing now.
> > > >
> > > > Problem number 1 - Mapping dates from a non-standard format
> > > >
> > > > I have a basic type:
> > > >
> > > >        <xs:complexType name="itemType">
> > > >                <xs:complexContent>
> > > >                        <xs:extension base="baseDomain">
> > > >                        <xs:sequence>
> > > >                                <xs:element 
> ref="availabilityStart"/>
> > > >                                <xs:element 
> ref="availabilityEnd"/>
> > > >                        </xs:sequence>
> > > >                <xs:attribute name="title" type="xs:string"/>
> > > >                </xs:extension>
> > > >                </xs:complexContent>
> > > >        </xs:complexType>
> > > >
> > > >        <xs:element name="availabilityStart" type="xs:dateTime"/>
> > > >        <xs:element name="availabilityEnd" type="xs:dateTime"/>
> > > >
> > > > This is extended  to a playlist object
> > > >
> > > >        <xs:element name="playlist"> <xs:complexType>
> > > >                <xs:complexContent>
> > > >                        <xs:extension base="itemType">
> > > >                                <xs:sequence>
> > > >                                        <xs:element ref="items"/>
> > > >                                        <xs:element 
> > > > ref="canSortPlaylist"/>
> > > >                                        <xs:element 
> > > > ref="canSetLanguage"/>
> > > >                                        <xs:element 
> ref="canRepeat"/>
> > > >                                </xs:sequence>
> > > >                        </xs:extension>
> > > >                </xs:complexContent>
> > > >        </xs:complexType>
> > > >        </xs:element>
> > > >
> > > > The availabilityStart and End dates come back as 01/01/2007
> > > - 12:00:00
> > > > AM, which causes the unmarshalling to fail.
> > > >
> > > > I followed the example online for field handlers
> > > > (http://www.castor.org/xml-fieldhandlers.html) and I can
> > > see it create
> > > > the handlers, but never access the methods when I map using
> > > this file:
> > > > (note AvailabilityStartHandler is a version of the first
> > > example, the
> > > > ItemTypeDateHandler is the generic version)
> > > >
> > > > <?xml version="1.0"?>
> > > > <mapping>
> > > >
> > > >  <class name="com.fool.domain.Playlist">
> > > >     <field name="availabilityStart" type="string"
> > > > handler="com.foo.domain.handler.AvailabilityStartHandler">
> > > >        <bind-xml node="text"/>
> > > >     </field>
> > > >     <field name="availabilityEnd" type="string"
> > > > handler="com.foo.domain.handler.ItemTypeDateHandler">
> > > >        <bind-xml node="text"/>
> > > >     </field>
> > > >  </class>
> > > >
> > > >  <class name="com.foo.domain.ItemType">
> > > >     <field name="availabilityStart" type="string"
> > > > handler="com.disney.disl.domain.handler.ItemTypeDateHandler">
> > > >        <bind-xml node="text"/>
> > > >     </field>
> > > >     <field name="availabilityEnd" type="string"
> > > > handler="com.foo.domain.handler.ItemTypeDateHandler">
> > > >        <bind-xml node="text"/>
> > > >     </field>
> > > >  </class>
> > > >
> > > > </mapping>
> > > >
> > > > I get errors still on the mapping since it doesn't like 
> the date 
> > > > formats in the field by default. Is it possible to bind on the 
> > > > ItemType class and have the mapping picked up by 
> children classes 
> > > > (e.g. Playlist) and others?
> > > >
> > > > 2nd problem - I don't know how to map this, but I have 
> the complex 
> > > > type items that contains a series of arrays (videos, audios, 
> > > > playlists, games) and a set of attributes that are the
> > > array size. How
> > > > do I map videos.size to the videos attribute?
> > > >
> > > > <xs:element name="items">
> > > >                <xs:complexType>
> > > >                        <xs:sequence>
> > > >                                <xs:element name="video"
> > > > type="videoType" minOccurs="0"
> > > > maxOccurs="unbounded"/>
> > > >                                <xs:element name="game"
> > > type="gameType"
> > > > minOccurs="0"
> > > > maxOccurs="unbounded"/>
> > > >                                <xs:element name="audio"
> > > > type="audioType" minOccurs="0"
> > > > maxOccurs="unbounded"/>
> > > >                                <xs:element name="playlist"
> > > > type="playlistType" minOccurs="0"
> > > > maxOccurs="unbounded"/>
> > > >                        </xs:sequence>
> > > >                        <xs:attribute name="games" 
> type="xs:int"/>
> > > >                        <xs:attribute name="audios" 
> type="xs:int"/>
> > > >                        <xs:attribute name="videos" 
> type="xs:int"/>
> > > >                        <xs:attribute name="playlists"
> > > type="xs:int"/>
> > > >                </xs:complexType>
> > > >        </xs:element>
> > > >
> > > >
> > > > Thanks!
> > > >
> > > > On 2/16/07, Werner Guttmann <[EMAIL PROTECTED]> wrote:
> > > > > Hi Drew,
> > > > >
> > > > > can you please provide us with a bit more information,
> > > such as what
> > > > > the relevant XML schema (fragment) and the binding file
> > > looks like ?
> > > > >
> > > > > Regards
> > > > > Werner
> > > > >
> > > > > Drew Beechum wrote:
> > > > > > Hi,
> > > > > >
> > > > > > I've just been handed a project that needs to support
> > > > pulling in and
> > > > > > manipulating an xml response from a legacy service.
> > > I've got most
> > > > > > everything bound in, but I'm running into a few problems
> > > > and I don't
> > > > > > know how to resolve them. For the record I'm using
> > > castor 1.1 and
> > > > > > the ant sourcegen tools to build the classes.
> > > > > >
> > > > > > sample xml looks like this
> > > > > >
> > > > > > <playlist id=123>
> > > > > >   <id>123</id>
> > > > > >    <items videos=1 playlists=1>
> > > > > >       <video id=124>
> > > > > >          <id>124</id>
> > > > > >       </video>
> > > > > >       <playlist id=125>
> > > > > >          <id>125</id>
> > > > > >       </playlist>
> > > > > >    </items>
> > > > > > </playlist>
> > > > > >
> > > > > > Do source generation with the id attribute in place in
> > > the schema
> > > > > > causes a conflict error. Big surprise, right? Is there
> > > > anyway to resolve this?
> > > > > > Preferably I'd like to map to the same member in the class, 
> > > > > > but every time I try to do "/[EMAIL PROTECTED]" it fails.
> > > > > >
> > > > > > Is there a clean way to populate the videos/playlists count 
> > > > > > attributes with the ArrayList<video>.size()?
> > > > > >
> > > > > > Thanks
> > > > >
> > > > >
> > > > >
> > > >
> > > 
> --------------------------------------------------------------------
> > > -
> > > > > 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
> > > >
> > >
> > > 
> --------------------------------------------------------------------
> > > - 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
> >
> >
> 
> ---------------------------------------------------------------------
> 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

Reply via email to