Any idea for this problem ?

Thanks,
Greg

2008/2/13, Grégoire Dariel <[EMAIL PROTECTED]>:
>
> Here is the stack trace :
>
> Caused by: java.lang.IllegalStateException:
> java.lang.IllegalArgumentException: No enum const class
> com.sgss.veristat.service.publisher.impl.TaskType.S
>         at
> org.exolab.castor.mapping.handlers.EnumFieldHandler.convertUponSet(
> EnumFieldHandler.java:151)
>         at org.exolab.castor.mapping.GeneralizedFieldHandler.setValue(
> GeneralizedFieldHandler.java:274)
>         at org.exolab.castor.mapping.GeneralizedFieldHandler.setValue(
> GeneralizedFieldHandler.java:274)
>         at
> org.exolab.castor.xml.UnmarshalHandler.setAttributeValueOnObject(
> UnmarshalHandler.java:3127)
>         at org.exolab.castor.xml.UnmarshalHandler.processAttribute(
> UnmarshalHandler.java:3074)
>         at org.exolab.castor.xml.UnmarshalHandler.processAttributes(
> UnmarshalHandler.java:2751)
>         at org.exolab.castor.xml.UnmarshalHandler.startElement(
> UnmarshalHandler.java:2388)
>         at org.exolab.castor.xml.UnmarshalHandler.startElement(
> UnmarshalHandler.java:1418)
>         at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown
> Source)
>         at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement
> (Unknown
> Source)
>         at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch
> (Unknown
> Source)
>         at
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
> Source)
>         at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
> Source)
>         at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
> Source)
>         at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
>         at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown
> Source)
>         at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown
> Source)
>         at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java
> :715)
>         at
> com.sgss.veristat.service.publisher.impl.PublisherManager.getPublisherExtraction
> (PublisherManager.java:27)
>         at
> com.sgss.test.veristat.service.publisher.PublisherManagerTest.testGetPublisherExtraction
> (PublisherManagerTest.java:20)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(
> NativeMethodAccessorImpl.java:39)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(
> DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:597)
>         at junit.framework.TestCase.runTest(TestCase.java:168)
>         at junit.framework.TestCase.runBare(TestCase.java:134)
>         at junit.framework.TestResult$1.protect(TestResult.java:110)
>         at junit.framework.TestResult.runProtected(TestResult.java:128)
>         at junit.framework.TestResult.run(TestResult.java:113)
>         at junit.framework.TestCase.run(TestCase.java:124)
>         at junit.framework.TestSuite.runTest(TestSuite.java:232)
>         at junit.framework.TestSuite.run(TestSuite.java:227)
>         at org.junit.internal.runners.JUnit38ClassRunner.run(
> JUnit38ClassRunner.java:81)
>         at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(
> JUnit4TestReference.java:38)
>         at org.eclipse.jdt.internal.junit.runner.TestExecution.run(
> TestExecution.java:38)
>         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
> (RemoteTestRunner.java:460)
>         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
> (RemoteTestRunner.java:673)
>         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(
> RemoteTestRunner.java:386)
>         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> RemoteTestRunner.java:196)
>
> Greg
>
> 2008/2/13, Matthias Epheser <[EMAIL PROTECTED]>:
> > Grégoire Dariel schrieb:
> > > 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.
> >
> > As I implemented this new java5 support, i'm currently trying to
> > reproduce your problem.
> >
> >   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);
> > >     }
> >
> > Yep, as castor only gets the value string during unmarshalling, we need
> > this method to "map" the string value "S" to the actual enum constant.
> >
> > >
> > > 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
> >
> > Can you please provide the whole stacktrace, then I will have a look at
> > the castor code that calls the fromValue method.
> >
> > regards
> > matthias
> >
> > > 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
> > >
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list, please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
> >
>

Reply via email to