Change you mapping to the following:
<class name="com.Coordinates" access="shared">
<description>Default mapping for Coordinates</description>
<map-to xml="Coordinates"/>
<field name="format" type="string"
handler="com.CoordinateFormatEnumFieldHandler">
<bind-xml name="Format" node="attribute"/>
</field>
</class>
Note that I changed the "type" to "string" instead of
"com.CoordinateFormatEnum". When using a handler you need to specify the
type that the handler is expecting to recieve in a call to the setObject
and returns in a call to the getObject.
--Keith
> Matthias David wrote:
>
> Hi,
>
> I have written a FieldHandler for a class (CoordinateFormatEnum) that
> has no public constructor. When Unmarshalling I get the following
> exception:
>
> Nested error: org.exolab.castor.mapping.MappingException: The Java
> class CoordinateFormatEnum is not constructable -- it does not contain
> a default public constructor)
>
> The problem is that the class CoordinateFormatEnum is a tool-generated
> class, so I have no chance to make the constructor public. So How can
> this problem be solved? I thought that the Unmarshaller does not need
> to call the constructor of the class since the FieldHandler is
> responsible for that, e.g. using the method "newInstance".
>
> Here's the handler's code:
>
> public class CoordinateFormatEnumFieldHandler implements FieldHandler
> {
>
> public Object getValue(Object object)
> throws IllegalStateException {
> return ((Coordinates)object).getFormat().getValue();
> }
>
> public void setValue(Object object, Object value)
> throws IllegalStateException, IllegalArgumentException {
>
> ((Coordinates)object).setFormat(CoordinateFormatEnum.fromString((String)value));
>
> }
>
> public void resetValue(Object object)
> throws IllegalStateException, IllegalArgumentException {
> }
>
> public void checkValidity(Object object)
> throws ValidityException, IllegalStateException {
> }
>
> public Object newInstance(Object parent)
> throws IllegalStateException {
> return CoordinateFormatEnum.Mercator;
> }
> }
>
> And here's the mapping:
>
> <class name="com.Coordinates" access="shared">
> <description>Default mapping for Coordinates</description>
> <map-to xml="Coordinates"/>
> <field name="format" type="com.CoordinateFormatEnum"
> handler="com.CoordinateFormatEnumFieldHandler">
> <bind-xml name="Format" node="attribute"/>
> </field>
> </class>
>
> Any clues for that?
>
> Thanks,
> Matthias.
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev