Hi Matthew,

Castor does allow add-method for collections...give it a shot:

<field name="values" ..... set-method="addValue"/>

--Keith


Matthew Mower wrote:
> 
> Hi there,
> 
> I am wondering if I am using Castor wrong somehow because it seems to me that
> the way it handles collections violates the principles of good encapsulation.
> 
> If I specify in my mappings.xml file something like
> 
> <class name="Item">
>         <map-to xml="item">
>         ....
> </class>
> 
> <class name="Order">
>         <map-to xml="order">
> 
>         <field name="items" type="Item" direct="false" collection="vector">
>                 ...
>         </field>
> </class>
> 
> Then, to unmarshall a collection, Castor will do the following:
> 
> For each <item> it encounters within an <order> it will:
> 
> 1) Call getItems() on the Order
> 2.1) If the call returns null, create new Vector(), add Item to it and call
> Order.setItems() with the new collection
> 2.2) Otherwise add the new Item directly to the vector
> 
> This means that I am obliged to let Castor manage a collection that I believe
> should be managed by my bean.  Other than the problem in principle, it
> complicates the logic of my application.  For example I might want clients of
> my bean to use an addLineItem() interface because it keeps a running total in
> the order.  Now I also have to account for items that might have been added
> without using that interface.
> 
> I *think* that I would like Castor to support an "add-method" parameter to
> the <field> tag to replace the "set-method" semantics.
> 
> Is this a real problem?
> 
> Regards,
> 
> matt.
> 
> ---
> To guess is cheap. To guess wrong is expensive - Old Chinese Proverb

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to