Index: src/main/java/org/exolab/castor/xml/UnmarshalHandler.java =================================================================== --- src/main/java/org/exolab/castor/xml/UnmarshalHandler.java (Revision 6884) +++ src/main/java/org/exolab/castor/xml/UnmarshalHandler.java (Arbeitskopie) @@ -3105,8 +3105,14 @@ Object value = atts.getValue(index); //-- check for proper type and do type //-- conversion - if (isPrimitive(args.types[argIndex])) + if (isPrimitive(args.types[argIndex])) { value = toPrimitiveObject(args.types[argIndex], (String)value, descriptor); + } else { + // check whether we are looking at an enum-style object, and if so, + // convert the (string) value + value = convertToEnumObject(descriptor, value); + } + //check if the value is a QName that needs to //be resolved (ns:value -> {URI}value) String valueType = descriptor.getSchemaType(); @@ -3123,6 +3129,40 @@ } //-- processConstructorArgs /** + * Checks whether the actual value passed in should be converted to an enum-style class + * instance + * @param descriptor The {@link XMLFieldDescriptor} instance in question. + * @param value The actual value (which might need conversion). + * @return The value, potentially converted to an enum-style class. + */ + private Object convertToEnumObject(XMLFieldDescriptor descriptor, Object value) { + Class fieldType = descriptor.getFieldType(); + Method valueOfMethod; + try { + valueOfMethod = fieldType.getMethod("valueOf", new Class[] { String.class }); + if (valueOfMethod != null + && Modifier.isStatic(valueOfMethod.getModifiers())) { + Class returnType = valueOfMethod.getReturnType(); + if (returnType.isAssignableFrom(fieldType)) { + Object enumObject = valueOfMethod.invoke(null, new Object[] { value }); + value = enumObject; + } + } + } catch (SecurityException e) { + // TODO: well, cannot do anything about it + } catch (NoSuchMethodException e) { + // TODO: nothing to do, as it simply isn't an enum-style class + } catch (IllegalArgumentException e) { + // TODO: cannot really happen + } catch (IllegalAccessException e) { + // TODO: indicates that the valueOf() method isn't public + } catch (InvocationTargetException e) { + // TODO: hmm .. what else + } + return value; + } + + /** * Processes the given IDREF * * @param idRef the ID of the object in which to reference Index: src/build.xml =================================================================== --- src/build.xml (Revision 6885) +++ src/build.xml (Arbeitskopie) @@ -382,7 +382,7 @@ - + Index: xmlctf/tests/MasterTestSuite/mapping/constructor/withEnum/mapping.xml =================================================================== --- xmlctf/tests/MasterTestSuite/mapping/constructor/withEnum/mapping.xml (Revision 0) +++ xmlctf/tests/MasterTestSuite/mapping/constructor/withEnum/mapping.xml (Revision 0) @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ Kein Zeilenvorschub am Ende der Datei Index: xmlctf/tests/MasterTestSuite/mapping/constructor/withEnum/Severity.java =================================================================== --- xmlctf/tests/MasterTestSuite/mapping/constructor/withEnum/Severity.java (Revision 0) +++ xmlctf/tests/MasterTestSuite/mapping/constructor/withEnum/Severity.java (Revision 0) @@ -0,0 +1,27 @@ +public final class Severity { + + public static final Severity ERROR = new Severity("Error"); + + public static final Severity WARNING = new Severity("Warning"); + + public static final Severity OK = new Severity("OK"); + + private final transient String name; + + private Severity(String name) { + this.name = name; + } + + public String toString() { + return name; + } + + public static Severity valueOf(String value) { + if (value.equals("Error")) { + return ERROR; + } else if (value.equals("Warning")) { + return WARNING; + } + return OK; + } +} Index: xmlctf/tests/MasterTestSuite/mapping/constructor/withEnum/TestDescriptor.xml =================================================================== --- xmlctf/tests/MasterTestSuite/mapping/constructor/withEnum/TestDescriptor.xml (Revision 0) +++ xmlctf/tests/MasterTestSuite/mapping/constructor/withEnum/TestDescriptor.xml (Revision 0) @@ -0,0 +1,26 @@ + + + + Mapping-Constructors-With-Enum + Werner Guttmann + + + Tests the special handling of constructor arguments in the case where one or more + arguments are of type 'enum'. + + + basic capability + + + SimpleMessage + + + Test01 + mapping.xml + input.xml + input.xml + + + + + Index: xmlctf/tests/MasterTestSuite/mapping/constructor/withEnum/input.xml =================================================================== --- xmlctf/tests/MasterTestSuite/mapping/constructor/withEnum/input.xml (Revision 0) +++ xmlctf/tests/MasterTestSuite/mapping/constructor/withEnum/input.xml (Revision 0) @@ -0,0 +1,2 @@ + + Index: xmlctf/tests/MasterTestSuite/mapping/constructor/withEnum/SimpleMessage.java =================================================================== --- xmlctf/tests/MasterTestSuite/mapping/constructor/withEnum/SimpleMessage.java (Revision 0) +++ xmlctf/tests/MasterTestSuite/mapping/constructor/withEnum/SimpleMessage.java (Revision 0) @@ -0,0 +1,20 @@ +public final class SimpleMessage { + + private Severity severity; + + private String text; + + public SimpleMessage(String text, Severity severity) { + this.text = text; + this.severity = severity; + } + + public Severity severity() { + return severity; + } + + public String formattedText() { + return text; + } + +} Index: xmlctf/tests/MasterTestSuite/mapping/constructor/Foo.java =================================================================== --- xmlctf/tests/MasterTestSuite/mapping/constructor/Foo.java (Revision 6884) +++ xmlctf/tests/MasterTestSuite/mapping/constructor/Foo.java (Arbeitskopie) @@ -1,22 +0,0 @@ - -public class Foo { - - private int size = 20; - - public Foo() { - // Nothing to do - } - - public Foo(int size) { - this.size = size; - } - - public int getSize() { - return size; - } - - public void setSize(int size) { - this.size = size; - } - -} Index: xmlctf/tests/MasterTestSuite/mapping/constructor/mapping.xml =================================================================== --- xmlctf/tests/MasterTestSuite/mapping/constructor/mapping.xml (Revision 6884) +++ xmlctf/tests/MasterTestSuite/mapping/constructor/mapping.xml (Arbeitskopie) @@ -1,8 +0,0 @@ - - - - - - - - Index: xmlctf/tests/MasterTestSuite/mapping/constructor/TestDescriptor.xml =================================================================== --- xmlctf/tests/MasterTestSuite/mapping/constructor/TestDescriptor.xml (Revision 6884) +++ xmlctf/tests/MasterTestSuite/mapping/constructor/TestDescriptor.xml (Arbeitskopie) @@ -1,25 +0,0 @@ - - - - Mapping-Constructors - Keith Visco - - - Tests the special handling of constructor arguments. - - - basic capability - - - Foo - - - Test01 - mapping.xml - input.xml - input.xml - - - - - Index: xmlctf/tests/MasterTestSuite/mapping/constructor/input.xml =================================================================== --- xmlctf/tests/MasterTestSuite/mapping/constructor/input.xml (Revision 6884) +++ xmlctf/tests/MasterTestSuite/mapping/constructor/input.xml (Arbeitskopie) @@ -1,2 +0,0 @@ - -