Hi,
I found this comment in the source code (UnmarshalHandler.java, in processConstructorArgs method):
//-- NOTE: Due to IDREF being able to reference an
//-- un-yet unmarshalled object, we cannot handle
//-- references as constructor arguments.
//-- kvisco - 20030421If I understand this correctly, it means that a mapping such as the following is not allowed, because of the reference attribute:
<field name="foo" type="SomeClass" set-method="%1" get-method="getFoo">
<bind-xml name="foo" reference="true" node="attribute"/>
</field>
And indeed, I tried it without success. I wish this comment makes it to the documentation (or perhaps should I add it myself to the Castor wiki?). It took me quite a while to find it in the code using a debugger, as the exception message was not giving any hint:
java.lang.IllegalStateException: The Java class X is not constructable -- it does not contain a default public constructor or a matching public constructor for the given arguments.
So my second wish is to have a better error condition check, perhaps when loading the mapping file, to warn that using mapped constructor argument on a reference attribute is not supported.
By the way, my problem was the following: I have several fields which depend on a specific field "A". You cannot do setB() before setA(). So, I would need to either get A unmarshalled before any other field, or to use a non-default constructor, which receives all the fields at once (allowing me to set A before the others).
My workaround was to use the default constructor (obviously), have the setB save B in a temporary variable, and really set B inside the unmarshalled() method from the UnmarshalListener interface.
Ugly hack indeed. Any better idea is welcome!
Cheers, Benoit
----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user
