Index: src/main/java/org/exolab/castor/xml/Introspector.java =================================================================== --- src/main/java/org/exolab/castor/xml/Introspector.java (Revision 6994) +++ src/main/java/org/exolab/castor/xml/Introspector.java (Arbeitskopie) @@ -1187,6 +1187,22 @@ //-- make sure type is not Void, or Class; if (type == Void.class || type == Class.class ) return false; + float javaVersion = Float.valueOf(System.getProperty("java.specification.version")).floatValue(); + if (javaVersion >= 1.5) { + try { + Method isEnumMethod = type.getClass().getMethod("isEnum", (Class[]) null); + Boolean isEnum = (Boolean) isEnumMethod.invoke(type, (Object[]) null); + if (isEnum.booleanValue()) { + return true; + } + } catch (Exception e) { + // nothing to report; implies that there's no such method + } +// if (type.isEnum()) { +// return true; +// } + } + if ( (!type.isInterface()) && (type != Object.class) && (!isPrimitive(type))) { Index: src/main/java/org/exolab/castor/xml/MarshalFramework.java =================================================================== --- src/main/java/org/exolab/castor/xml/MarshalFramework.java (Revision 6994) +++ src/main/java/org/exolab/castor/xml/MarshalFramework.java (Arbeitskopie) @@ -51,6 +51,7 @@ import org.exolab.castor.mapping.MappingException; import org.exolab.castor.mapping.loader.CollectionHandlers; +import java.lang.reflect.Method; import java.util.Iterator; import java.util.Vector; @@ -204,6 +205,47 @@ } //-- isPrimitive /** + * Returns true if the given class should be treated as an enum type. This method + * will return true for all Java 5 (or later) enums, and for enum-style + * classes. + * + * @return true if the given class should be treated as an enum + **/ + static boolean isEnum(Class type) { + + if (type == null) { + return false; + } + + float javaVersion = Float.valueOf(System.getProperty("java.specification.version")).floatValue(); + if (javaVersion >= 1.5) { + try { + Method isEnumMethod = type.getClass().getMethod("isEnum", (Class[]) null); + Boolean isEnum = (Boolean) isEnumMethod.invoke(type, (Object[]) null); + return isEnum.booleanValue(); + } catch (Exception e) { + // nothing to report; implies that there's no such method + } +// if (type.isEnum()) { +// return true; +// } + } + + return false; + + //TODO: investigate whether this code should apply to 1.4 as well ? +// try { +// Method isEnumMethod = type.getMethod("isEnum", (Class[]) null); +// Boolean isEnum = (Boolean) isEnumMethod.invoke(type, (Object[]) null); +// return isEnum.booleanValue(); +// } catch (Exception e) { +// return false; +// } + + } //-- isPrimitive + + + /** * Returns true if any of the fields associated with the given * XMLClassDescriptor are located at, or beneath, the given location. * Index: src/main/java/org/exolab/castor/xml/Marshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/Marshaller.java (Revision 6994) +++ src/main/java/org/exolab/castor/xml/Marshaller.java (Arbeitskopie) @@ -1706,6 +1706,16 @@ throw new MarshalException(sx); } } + else if (isEnum(_class)) { + char[] chars = object.toString().toCharArray(); + try { + handler.characters(chars,0,chars.length); + } + catch(org.xml.sax.SAXException sx) { + throw new MarshalException(sx); + } + + } } //--------------------------- Index: .settings/org.eclipse.jdt.core.prefs