Hi Jeremy,

Jeremy Haile wrote:
> 
> OK, I guess I'm the only one posting about my problem =)


Sorry, my activity on the list will be very limited over the next couple
days, as I only have a dial-up modem to work with. My Cable Modem is
down and Time Warner is not the least bit interested in being prompt
about addressing the problem. Despite the fact that I reported the issue
yesterday, they won't be out until sometime tomorrow (whenever it's
convenient for them of course) to even look at the problem.

Anyway...

> 
> Anyways, I figured out the way Castor is operating.  It gets my Set..if
> it is null it creates a new one and sets it.  Otherwise it just adds it
> to the existing set.  Unfortunately I have custom processing that needs
> to take place on each element that gets added (that thing called
> encapsulation)  Can I make castor use an addXXX method instead?

This is known issue (you should be able to find a number of past threads
regarding this).

So..yes, you need to use an add method to work around this issue.
Actually, what I need to do is expose a flag that indicates whether the
collection can be built incrementally or if it needs to be handled all
at once. It's been on my list forever. But an add method will work.

The method needs to start with "add", just specifiy in the set-method as
such:

<field name="foo" collection="..." set-method="addFoo"
get-method="getFoo"/>

Since you are specifying a set-method, you must also specify a
get-method. Obviously the get-method will be your normal getter that
returns the entire collection.

--Keith

> 
> Jeremy
> 
> On Wed, 03 Mar 2004 16:31:26 -0500, "Jeremy Haile" <[EMAIL PROTECTED]>
> said:
> >
> > To follow up more debug information: It appears that Castor IS somehow
> > setting my property correctly with multiple values in the java.util.Set.
> > However, my setXXX method is only being called once.  Why does Castor not
> > call my set method with the entire collection.  My setXXX() method has
> > special processing which causes my application to fail if not performed.
> >
> > Also, my instance variables have private access.  My set methods of
> > course have public access.
> >
> > Jeremy
> >
> >
> > On Wed, 03 Mar 2004 15:18:24 -0500, "Jeremy Haile" <[EMAIL PROTECTED]>
> > said:
> > >
> > > By the way, I am using 0.9.5.3 rc2.
> > >
> > >
> > > On Wed, 03 Mar 2004 15:11:32 -0500, "Jeremy Haile" <[EMAIL PROTECTED]>
> > > said:
> > > > I have several collections that are only saving the first element in a
> > > > set.  My field type is a java.util.Set.  When castor parses the XML file,
> > > > it only calls the setXXX() method one time (as it should), but passes in
> > > > a java.util.Set that contains only one element.  Why would castor not be
> > > > processing the whole collection before calling setXXXX?????
> > > >
> > > >
> > > > The mapping for one of the classes I'm having a problem with this with
> > > > follows:
> > > >
> > > >   <class name="ex.Organization"
> > > >          access="shared"
> > > >          auto-complete="false">
> > > >
> > > >     <field name="name"
> > > >            type="java.lang.String"
> > > >            get-method="getName"
> > > >            set-method="setName">
> > > >       <bind-xml
> > > >                 node="attribute" />
> > > >     </field>
> > > >
> > > >     <field name="taxId"
> > > >            type="java.lang.String"
> > > >            get-method="getTaxId"
> > > >            set-method="setTaxId">
> > > >       <bind-xml
> > > >                 node="attribute" />
> > > >     </field>
> > > >
> > > >     <field name="emailAddresses"
> > > >            type="ex.EmailAddress"
> > > >            get-method="getEmailAddresses"
> > > >            set-method="setEmailAddresses"
> > > >            collection="set">
> > > >       <bind-xml name="email-address"
> > > >                 node="element" />
> > > >     </field>
> > > >
> > > >     <field name="phoneNumbers"
> > > >            type="ex.PhoneNumber"
> > > >            get-method="getPhoneNumbers"
> > > >            set-method="setPhoneNumbers"
> > > >            collection="set">
> > > >       <bind-xml name="phone-number"
> > > >                 node="element" />
> > > >     </field>
> > > >
> > > >     <field name="postalAddresses"
> > > >            type="ex.PostalAddress"
> > > >            get-method="getPostalAddresses"
> > > >            set-method="setPostalAddresses"
> > > >            collection="set">
> > > >       <bind-xml name="postal-address"
> > > >                 node="element" />
> > > >     </field>
> > > >
> > > >   </class>
> > > >
> > > >
> > > > The debug output from Castor is below.  You can see where my
> > > > setPhoneNumbers( Set phoneNumbers ) method is called.  I print out the
> > > > size of the set being passed in as a parameter.  You can also see Castor
> > > > parse another phone number immediately after, but not call the set
> > > > method.
> > > >
> > > > [configurator]
> > > > [configurator] #startElement: organization
> > > > [configurator] #characters:
> > > >
> > > > [configurator]
> > > > [configurator] #startElement: email-address
> > > > [configurator] #endElement: email-address
> > > > [configurator] #characters:
> > > >
> > > > [configurator]
> > > > [configurator] #startElement: phone-number
> > > > [configurator] #endElement: phone-number
> > > > [configurator] 14:58:44,181 DEBUG [Organization] Setting 1 phone
> > > > numbers(s) into party.
> > > > [configurator] #characters:
> > > >
> > > > [configurator]
> > > > [configurator] #startElement: phone-number
> > > > [configurator] #endElement: phone-number
> > > > [configurator] #characters:
> > > >
> > > > [configurator]
> > > > [configurator] #startElement: postal-address
> > > > [configurator] #endElement: postal-address
> > > > [configurator] #characters:
> > > >
> > > > [configurator]
> > > > [configurator] #endElement: organization
> > > > [configurator] #characters:
> > > >
> > > >
> > > > Just in case you are curious, the setter method with the debug call looks
> > > > like:
> > > >
> > > >     public void setPhoneNumbers(Set phoneNumbers) {
> > > >         logger.debug(  "Setting " + phoneNumbers.size() + " phone
> > > >         numbers(s) into party." );
> > > >         this.phoneNumbers = phoneNumbers;
> > > >     }
> > > > --
> > > >   Jeremy Haile
> > > >   [EMAIL PROTECTED]
> > > --
> > >   Jeremy Haile
> > >   [EMAIL PROTECTED]
> > >
> > > -----------------------------------------------------------
> > > If you wish to unsubscribe from this mailing, send mail to
> > > [EMAIL PROTECTED] with a subject of:
> > >         unsubscribe castor-dev
> > >
> > --
> >   Jeremy Haile
> >   [EMAIL PROTECTED]
> >
> > -----------------------------------------------------------
> > If you wish to unsubscribe from this mailing, send mail to
> > [EMAIL PROTECTED] with a subject of:
> >         unsubscribe castor-dev
> >
> --
>   Jeremy Haile
>   [EMAIL PROTECTED]
> 
> -----------------------------------------------------------
> 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