Title: NotConstructable Exception and FieldHandler

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.

Reply via email to