users@jaxb.java.net

Re: On-demand-validation problem

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Wed, 05 Jan 2005 17:46:56 +0100

Hi.

> I have a xml file with a sequence of complexe types. I want to check
> simply some value elements and log an error with a record id (one of the
> element of my complex type). I can't do validation during the
> unmarshalling process cause I don't have the id yet. So I'm trying to
> validate-on-demand each java objects after the unmarshalling process.
> But, when I catch the ValidationException, I don't see the field that
> trigger the exception.

You might be interested in jaxb-verification project.

http://jaxb-verification.dev.java.net/

Consider the following XML Schema fragment:

   <xs:element name="root" type="rootType"/>

   <xs:complexType name="rootType">
     <xs:sequence>
       <xs:element name="elementWithListAttribute1"
type="elementWithListAttribute1" minOccurs="0"/>
     </xs:sequence>
   </xs:complexType>

   <xs:complexType name="elementWithListAttribute1">
     <xs:attribute name="list1" type="listType1" use="optional"/>
   </xs:complexType>

   <xs:simpleType name="listType1">
     <xs:list itemType="patternType1"/>
   </xs:simpleType>

   <xs:simpleType name="patternType1">
     <xs:restriction base="xs:string">
       <xs:length value="9"/>
       <xs:pattern value="[A-Z]{2}([0-9]|[A-Z]){7}"/>
     </xs:restriction>
   </xs:simpleType>

And an object structure which is created as follows:

final Root root = new RootImpl();
root.setElementWithListAttribute1(new ElementWithListAttribute1Impl());
root.getElementWithListAttribute1().getList1().add("abcd");

Below is the message of the verification event reported by the generated
object verifier:

Object:
de.fzi.dbs.verification.tests.one.impl.ElementWithListAttribute1Impl_at_8bdcd2.
Field: List1.
Entry index: 0.
EL: ElementWithListAttribute1.List1[0]
JXPath: ElementWithListAttribute1/List1[0].
Problem:
The value (abcd) has wrong length (the length is 4, the allowed length
is 9).

Bye.
/lexi

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net