David Sean Taylor wrote:
> 
> New to Castor mailing list, hope its appropriate to ask these kinds of
> questions.
> 
> The set-method is never called for a vector node:
> 
> <mapping>
>   <class name="org.apache.jetspeed.om.profile.psml.PsmlPortlets">
>     <map-to xml="portlets"/>
> ...
>     <field name="references"
>            type="org.apache.jetspeed.om.profile.psml.PsmlReference"
>           set-method="setReferences"
>        collection="vector">
>       <bind-xml name="reference"/>
>     </field>
> 
> If I don't specify 'set-method', Castor calls the default get-method by
> name, and then sets adds each element to the vector itself.

This is the correct behavior...Castor obtains the vector and adds
the item to the vector. There is no need to call the set-method.

If you want more control over the vector...create an add-method and
specify
this as the set-method instead.

> 
> If I use the set-method as above, neither the set nor get is called.

If you specify only a set method you are disabling the get-method.

Specify both methods if you want both to be used. However, in your
above case, the set method will not get called unless it represents
a method that incrementally adds each item.

The fact that Castor never calls the set-method in your example is
a because it can't call the get-method to obtain the vector, since
you disabled the get-method by only specifying a set-method.

It is a bug though that the Vector is not created and set using
the set method during the unmarshalling of each item.

We are making some internal changes to how we handle collections, so
hopefully this case will work in the future. My plans are to
keep a reference to the collection and add each item and then
make one set call at the end after the collection is complete.
Unless of course the user has specified an incremental add method.

> 
> The PsmlPortlets class has a method:
> 
>     public void setReferences(Vector refs)
> 
> Is there anyway to get my set-method called on a vector?

If the get-method returns null, the set-method should be called
once when it's created.

Other wise, you can create an add-method as such:

public void addReference(PsmlReference ref) {
   refs.addElement(ref);
}

Then modify your mapping as such:

  <field name="references"
         type="org.apache.jetspeed.om.profile.psml.PsmlReference"
         set-method="addReference"
         get-method="getReferences"
         collection="vector">
         <bind-xml name="reference"/>
  </field>


--Keith

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

Reply via email to