Hi Sathya,
You do something like via a custom FieldHandler:
<field name="attrivalPorts" type="....Port"
handler="com.acme.MyPortHandler"/>
There are two main methods in a FieldHandler, the getValue and the
setValue methods which Castor uses to obtain the value of the field. You
can do all your custom filtering in those methods.
If you don't want Castor to marshal something...just return null.
Warning about collections:
Normally when Castor marshals (java->xml) it calls the getValue method
and when it unmarshals (xml->java) it calls the setValue method. When
dealing with collections, however, Castor will call the getValue()
methods to add the items to the existing collection. So when dealing
with Custom FieldHandler's you need to be aware of this. To work around
this limitation you can use two mapping files, one for marshalling and
one for unmarshalling. It's a pain, I know...hopefully that'll get fixed
up soon.
--Keith
"Krishnasamy, Sathya" wrote:
>
> Keith,
>
> Is it possible to have conditional logic to do the marshalling of an
> arraylist ?.
> For example., if the arraylist has 10 elements of Port objects , and 6 of
> them have the sequence to be "i", then
> I want to have only 6 arrival tags under AllArrivals tag, as opposed to 10.
>
> Thanks,
> Sathya
>
> The mapping file:
>
> <mapping>
> <class name="com.cpships.vss.schedule.Schedule">
> <map-to xml="schedule"/>
> <field name="arrivalPorts" ( Do this only if the sequence is
> i ) type="com.cpships.vss.domain.Port" collection="arraylist">
> <bind-xml name="arrival" location="AllArrivals"/>
> </field>
> </class>
> <class name="com.cpships.vss.domain.Port">
> <field name="sequence" type="java.lang.String">
> <bind-xml name="sequence" node="attribute"/>
> </field>
> <field name="portCode" type="java.lang.String">
> <bind-xml name="portcode" node="element"/>
> </field>
> </class>
> </mapping>
>
> Thanks,
> Sathya
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev