I am working with some code, which uses Castor to map XML to custom
objects.  Some of those objects contain java 5 enums.  Castor does
parse those and sets the values properly, however if an invalid value
for an Enum is submitted and I try to unmarshal the XML I get this
Exception:

java.lang.IllegalArgumentException: Foo{File: [not available]; line:
2; column: 32}
      at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:740)
      at bcc.Test.test(Test.java:81)
      at bcc.Test.main(Test.java:102)
Caused by: java.lang.IllegalStateException:
java.lang.IllegalArgumentException: Foo
      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.endElement(UnmarshalHandler.java:1043)
      at 
org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:1108)
      at org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1403)
      at 
org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator.java:1436)
      at 
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1205)
      at 
org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
      at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1035)
      at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:726)
      ... 2 more

I'd like to find a way to reliably get the following information when
an Exception occurs:

1. What was the name of the XML tag that was being parsed?
2. What was the Class castor was trying to create or convert to?
3. What was the raw value castor was trying to convert?

With this information, I could give an error message showing what
element had a problem, what the invalid value was and I could lookup
my Enum and give a list of valid values (If the type was an Enum).

Is there a way to do this?  I suppose I could do this with a Custom
field handler, but I don't want to create a custom field handler for
every Enum in the code. I tried writing a GeneralizedFieldHandler, but
I could not get it to work with more than 1 enum type.



Thanks.

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

   http://xircles.codehaus.org/manage_email

Reply via email to