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
BEGIN:VCARD
VERSION:2.1
N:Mower;Matt
FN:Matt Mower
ORG:Hipbone, Inc;Sales
TITLE:Systems Engineer
TEL;WORK;VOICE:+44 (1932) 895902
TEL;CELL;VOICE:+44 (7977) 076709
ADR;WORK:;;3000 Hillswood Drive;Chertsey;Surry;KT16 0RS;United Kingdom
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:3000 Hillswood Drive=0D=0AChertsey, Surry KT16 0RS=0D=0AUnited Kingdom
EMAIL;PREF;INTERNET:[EMAIL PROTECTED]
EMAIL;INTERNET:[EMAIL PROTECTED]
REV:20010723T144203Z
END:VCARD

Reply via email to