I was using the 1.1.2.1 but I've just tried with the 1.2 and that
doesn't work anymore.
I saw that there was an improvement in the 1.2 for Java5 enum. We have
to define the following method in the enum type :

public static CompositeType fromValue(final java.lang.String value) {
        for (CompositeType c: CompositeType.values()) {
            if (c.value.equals(value)) {
                return c;
            }
        }
        throw new IllegalArgumentException(value);
    }

I tried using no handler and defining this method. The method
fromValue is actually called and returned the right value but I still
have the Exception :
java.lang.IllegalArgumentException: No enum const class TaskType.S

Where am I wrong ?

Thanks for your help :)
Greg

2008/2/8, Werner Guttmann <[EMAIL PROTECTED]>:
> What version are you using, if I may ask  ?
>
> Werner
>
> Grégoire Dariel wrote:
> > I'm trying to unmarshal an XML field to a Java5 Enum.
> > I'm using a GeneralizedFieldHandler to do this.
> >
> > Unfortunatly, I'm getting the following error trying to unmarshall :
> > java.lang.IllegalArgumentException: No enum const class TaskType.S
> > at java.lang.Enum.valueOf(Enum.java:192)
> > at TaskType.valueOf(TaskType.java:1)
> > ...
> >
> > Here is the mapping.xml :
> > <class name="Task">
> >                 <field name="type" type="TaskType" 
> > handler="TaskTypeHandler">
> >                           <bind-xml name="type" node="attribute" />
> >                 </field>
> > </class>
> >
> > Here is the xml data file :
> > <tache type="S">
> >
> >   Here is Task.java :
> > public class Task {
> >         private TaskType type;
> >         public TaskType getType() {
> >                 return type;
> >         }
> >
> >         public void setType(TaskType pType) {
> >                 type = pType;
> >           }
> > }
> >
> > Here is TaskType.java :
> > public enum TaskType {
> >         SCHEDULED('S'), OPTIONAL('O'), PROVOKED('P');
> >
> >         private char string;
> >
> >         TaskType(char pChar) {
> >                   string = pChar;
> >         }
> >
> >         public char getChar() {
> >                 return string;
> >         }
> > }
> >
> > And here is TaskTypeHandler :
> > public class TaskTypeHandler extends GeneralizedFieldHandler {
> >
> >         public TaskTypeHandler() {
> >                 super();
> >         }
> >
> >         public Object convertUponGet(Object pValue) {
> >                 return null;
> >         }
> >
> >         public Object convertUponSet(Object pValue) {
> >                   String tString = (String) pValue;
> >                 if (tString.equals("S")) {
> >                         return TaskType.SCHEDULED;
> >                   } else if (tString.equals("O")) {
> >                         return TaskType.OPTIONAL;
> >                 } else if (tString.equals("P")) {
> >                         return TaskType.PROVOKED;
> >                   } else {
> >                         return null;
> >                 }
> >         }
> >
> >         public Class<TaskType> getFieldType() {
> >                 return TaskType.class;
> >         }
> > }
> >
> >
> > It seems that Castor does not use the GeneralizedFieldHandler and uses
> > the default behaviour instead, that is calling TaskType.valueOf("S").
> >
> > Am I something wrong ? Is there a way to bypass the default behaviour ?
> >
> > Thanks,
> > Greg
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list, please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to