users@jaxb.java.net

Validation & (Enums & Attributes & ErrorCollector & exceptions) ?

From: David Halonen <david.halonen_at_compuware.com>
Date: Thu, 27 Mar 2003 08:10:14 -0700

I'm playing w/ JAXB's validation objects and attempting to verify various behaviors. In particular, the ValidationEventCollector. During the course of my evaluation, the following has occured:

1. I have an attribute that can only contain an enumerated value. These values are a part of the TypeSafeEnumeration mechanism. In my test XML, the attribute value was set to an illegal value "fooString". My expectation was that this problem would simply get noted as one of many in the event collector. Instead, the following exception(s) were thrown:

java.lang.IllegalArgumentException
  at jaxbdatamodel.FieldType_ENUM.fromValue(FieldType_ENUM.java:115)
  at jaxbdatamodel.FieldType_ENUM.fromString(FieldType_ENUM.java:119)
  at jaxbdatamodel.impl.JaxbFieldImpl$Unmarshaller.text(JaxbFieldImpl.java:1005)
  at com.sun.xml.bind.unmarshaller.SAXUnmarshallerHandlerImpl.consumeText(SAXUnmarshallerHandlerImpl.java:211)
  at com.sun.xml.bind.unmarshaller.SAXUnmarshallerHandlerImpl.consumeAttribute(SAXUnmarshallerHandlerImpl.java:395)

...buncha stuff cut out...

--------------- linked to ------------------
javax.xml.bind.UnmarshalException: Unexpected text "fooString"
 - with linked exception:
[java.lang.IllegalArgumentException]
  at com.sun.xml.bind.unmarshaller.UnreportedException.createUnmarshalException(UnreportedException.java:58)
  at com.sun.xml.bind.unmarshaller.SAXUnmarshallerHandlerImpl.reportAndThrow(SAXUnmarshallerHandlerImpl.java:498)
  at com.sun.xml.bind.unmarshaller.SAXUnmarshallerHandlerImpl.startElement(SAXUnmarshallerHandlerImpl.java:112)
  at org.iso_relax.verifier.impl.ForkContentHandler.startElement(Unknown Source)
  at com.sun.xml.bind.validator.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:104)

What am I doing wrong or am confused about?


2. We have several attributes that are required. Only the 1st missing attribute is reported. Is there any reason why all missing attributes cannot be reported?


3. If the schema has the following sequence:
        <xsd:sequence>
            <xsd:element name="elementA" type="typeA"/>
            <xsd:element name="elementB" type="typeB"/>
            <xsd:element name="elementC" type="typeC"/>
        </xsd:sequence>

    when unmarshalling an XML stream that DOES NOT have elements elementA & elementB, the following exception is thrown:
javax.xml.bind.UnmarshalException: Unexpected element {}:elementC
  at com.sun.xml.bind.unmarshaller.UnreportedException.createUnmarshalException(UnreportedException.java:58)
  at com.sun.xml.bind.unmarshaller.SAXUnmarshallerHandlerImpl.reportAndThrow(SAXUnmarshallerHandlerImpl.java:498)
  at com.sun.xml.bind.unmarshaller.SAXUnmarshallerHandlerImpl.startElement(SAXUnmarshallerHandlerImpl.java:112)
  at org.iso_relax.verifier.impl.ForkContentHandler.startElement(Unknown Source)
  at com.sun.xml.bind.validator.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:104)
  at org.apache.xerces.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:452)

Shouldn't this simply be another error added to the list?


4. If the schema has the following sequence:
        <xsd:sequence>
            <xsd:element name="elementD" type="typeD" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="elementE" type="typeE" minOccurs="1" maxOccurs="unbounded"/>
        </xsd:sequence>

  where elementG encapsulates this, when unmarshalling an XML stream that DOES NOT have elements elementD & elementE, the following exception is thrown:
javax.xml.bind.UnmarshalException: Unexpected end of element {}:elementG
  at com.sun.xml.bind.unmarshaller.UnreportedException.createUnmarshalException(UnreportedException.java:58)
  at com.sun.xml.bind.unmarshaller.SAXUnmarshallerHandlerImpl.reportAndThrow(SAXUnmarshallerHandlerImpl.java:498)
  at com.sun.xml.bind.unmarshaller.SAXUnmarshallerHandlerImpl.endElement(SAXUnmarshallerHandlerImpl.java:130)
  at org.iso_relax.verifier.impl.ForkContentHandler.endElement(Unknown Source)
  at org.apache.xerces.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:552)

Shouldn't this simply be another error added to the list?

Regards,
David Halonen
Compuware
248.737.7300 ext 13578