Keith, FieldHandlers for collections still isn't working for me with RC2 (although the processContainerAttributes() fix is in it). My FieldHandler is still passed an object of type J2CollectionHandlers$IteratorEnumerator when I try to marshal an object with a collection field that requires a handler. The behavior works as expected when unmarshalling - the convertUponSet() is called once per-item in the collection. However, when marshalling, it calls convertUponGet() with an instance of the aforementioned class.
The line that my application is currently breaking on is Marshaller.java:1381 where it simply calls getValue() on the field handler, passing in the enumeration. I am digging through the code, but I am sure you are much more familiar with the algorithm (we really need to break it into smaller methods =) If you could look at this, I would really appreciate it. Thanks, Jeremy On Tue, 24 Feb 2004 15:16:02 -0600, "Keith Visco" <[EMAIL PROTECTED]> said: > > > A modified version of the "enumeration" patch from Balaji was included > in RC2, actually, I modified his code to include a while loop instead of > a single if statement, since that would only handle the first item from > the enumeration. > > --Keith > > Jeremy Haile wrote: > > > > Thanks Balaji! > > > > Keith, should this be integrated into CVS? > > > > Jeremy > > > > On Tue, 24 Feb 2004 12:34:19 -0500, "Adikesavelu, Balaji" > > <[EMAIL PROTECTED]> said: > > > I had the same issue with Arrays and to fix it, I changed the > > > marshaller.java to handle enumerators. > > > > > > Here's the change I made to processContainerAttributes method in > > > Marshaller.java to fix the issue: > > > > > > private void processContainerAttributes( > > > Object target, > > > XMLFieldDescriptor containerFieldDesc, > > > AttributeListImpl atts) > > > throws MarshalException { > > > if (target.getClass().isArray()) { > > > int length = Array.getLength(target); > > > for (int j = 0; j < length; j++) { > > > Object item = Array.get(target, j); > > > if (item != null) > > > processContainerAttributes(item, > > > containerFieldDesc, atts); > > > } > > > return; > > > } else if (target instanceof Enumeration) { > > > Enumeration enum = (Enumeration) target; > > > if (enum.hasMoreElements()) { > > > Object item = enum.nextElement(); > > > if (item != null) > > > processContainerAttributes(item, > > > containerFieldDesc, atts); > > > > > > } > > > return; > > > } > > > > > > Thanks > > > > > > Balaji > > > > > > -----Original Message----- > > > From: Jeremy Haile [mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > > > ] > > > Sent: Tuesday, February 24, 2004 11:46 AM > > > To: [EMAIL PROTECTED] > > > Subject: [castor-dev] FieldHandlers and collections > > > > > > > > > > > > Maybe this has been explained before, but I'm still unclear. I have a > > > collection where each object in the collection needs to be processed by a > > > fieldhandler. I am using the following mapping right now: > > > > > > <field name="inputs" > > > type="string" > > > handler="mypackage.InputFieldHandler" > > > get-method="getInputs" > > > set-method="setInputs" > > > collection="collection"> > > > <bind-xml name="input" > > > node="element" /> > > > </field> > > > > > > An example of how this field would be used: > > > <input>someInput</input> > > > <input>anotherInput</input> > > > > > > This seems to work fine on unmarshalling - with convertUponSet() being > > > called on my GeneralizedFieldHandler implementation for each input. > > > However, for marshalling, a J2CollectionHandlers.IteratorEnumerator > > > (internal class) object is being passed into my convertUponGet(). Why > > > does > > > Castor not simply call my GeneralizedFieldHandler for each object in the > > > collection as opposed to passing in the entire collection (or enumeration > > > in > > > this case) to my field handler? Is this behavior appropriate? If not, > > > how > > > hard would it be to change? > > > > > > Jeremy > > > -- > > > 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 > -- Jeremy Haile [EMAIL PROTECTED] ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev