Keith-

First, thanks for the backup on this one.  Second, for my own
information, where does this code reside?  Is it in the
UnmarshalHandler, ClassDescriptor, or somewhere else?  I looked
through the J2CollectionHandlers class and did a few usage searches
for the CollectionHandler class, but didn't find the guts of the
logic.  Any hints you can provide would be appreciated...  It's a
large codebase to be sifting through sometimes :)

Thanks again,
Stephen


On 3/9/06, Keith Visco <[EMAIL PROTECTED]> wrote:
> Stephen is pretty much correct here. The set-method attribute is used on
> the first item, if the getter returns null. Castor will instantiate a
> new collection and add it using the set-method. It will then use the
> getter on subsequent items. The set-method attribute can also be used to
> specify a method which takes one object and adds it to the collection
> (an "add method") as Stephen mentioned.
>
> We may also at some point provide a configuration for having Castor
> manage the collection and only call the setter once the collection is full.
>
> --Keith
>
> Stephen Bash wrote:
> > Jason-
> >
> > I looked through some of the in-code comments last night, so I can
> > attempt to answer your question.  I think the fundamental issue here
> > is Castor is based on SAX parsing which is event based, and as such
> > when parsing
> XML from (for example) an ArrayList, each element is
> > treated completely independently of all the others.  So when it is
> > time to add an object to an ArrayList it is easiest for the framework
> > to simply call get to retrieve the current list and add to it.  This
> > requires minimal knowledge of the state of the list, and avoids Castor
> > having to keep extra objects in memory while it "builds" the ArrayList
> > object.  I'm not saying this is the best way to go, but that's the
> > impression I get from reading some of the comments.  I think all the
> > Collections API classes are handled this way.  An alternative is if
> > you supply an add method, i.e. addFoo( Foo foo ), I think Castor can
> > use that to add to a list rather than getting the list (you might have
> > to specify it as the set-method in the mapping file).
> >
> > Sorry I can't provide a more satisfactory answer.  Let us know if you
> > have further questions.
> >
> > Stephen
> >
> >
> > On 3/8/06, Jason Wood <[EMAIL PROTECTED]> wrote:
> >
> >>How can calling get instead of set be a 1.5 feature? The generics are
> >>1.5 but how come Castor is not using the set methods? Why call get over
> >>and over again to add elements to the collection? This does not make
> >>sense and makes adding the attribute set-method useless.
> >>
> >>-----Original Message-----
> >>From: Bill Leng [mailto:[EMAIL PROTECTED]
> >>Sent: Wednesday, March 08, 2006 2:55 PM
> >>To: [email protected]
> >>Subject: Re: [castor-user] set-method
> >>
> >>that is jdk1.5 feature and castor does not use jdk1.5 yet, I guess.
> >>
> >>Jason Wood wrote:
> >>
> >>>Wondering what's the purpose of set-method attribute if the framework
> >>>calls getNames() to set the names member variable?
> >>>
> >>>
> >>>
> >>>So if I have ...
> >>>
> >>>
> >>>
> >>>Class myClass {
> >>>
> >>>  private ArrayList names;
> >>>
> >>>
> >>>
> >>>  public void setNames(ArrayList<String> names) {}
> >>>
> >>>  public ArrayList<String> getNames() {}
> >>>
> >>>}
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>How come Castor calls getNames() for each name it needs to add? Why
> >>
> >>not
> >>
> >>>Create and ArrayList<String> and call setName()?
> >>>
> >>>
> >>>
> >>>J
> >>>
> >>>
> >>>
> >>>
> >>>
> >>
> >>-------------------------------------------------
> >>If you wish to unsubscribe from this list, please
> >>send an empty message to the following address:
> >>
> >>[EMAIL PROTECTED]
> >>-------------------------------------------------
> >>
> >>
> >>-------------------------------------------------
> >>If you wish to unsubscribe from this list, please
> >>send an empty message to the following address:
> >>
> >>[EMAIL PROTECTED]
> >>-------------------------------------------------
> >>
> >>
> >
> >
> >
>
>
> -------------------------------------------------
> If you wish to unsubscribe from this list, please
> send an empty message to the following address:
>
> [EMAIL PROTECTED]
> -------------------------------------------------
>
>

Reply via email to