Hi.
>> My point is that:
>>
>> - there are many other sources that can feed constraints into
>> the object validator (say, RDBMS)
>> - you often want to add more constraints into the object validator
>> - the object validator can be used by many frameworks (JSF, for example)
>
>
> I'd like to find JAXB-specific solution first...
If anyone's interested, I've started a small add-on that would produce
"object verifiers".
For instance let's take a complex type:
<xs:complexType name="bookType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="ISBN" type="xs:long"/>
<xs:element name="price" type="xs:string"/>
<xs:element name="authors" >
<xs:complexType>
<xs:sequence>
<xs:element name="authorName" type="xs:string" minOccurs="1"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="description" type="xs:string" minOccurs="0"/>
<xs:element name="promotion">
<xs:complexType>
<xs:choice>
<xs:element name="Discount" type="xs:string" />
<xs:element name="None" type="xs:string"/>
</xs:choice>
</xs:complexType>
</xs:element>
<!--xs:element name="publicationDate" type="xs:date"/-->
<xs:element name="bookCategory">
<xs:simpleType>
<xs:restriction base="xs:NCName">
<xs:enumeration value="magazine" />
<xs:enumeration value="novel" />
<xs:enumeration value="fiction" />
<xs:enumeration value="other" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
<xs:attribute name="itemId" type="xs:string" />
</xs:complexType>
The add-on produces the code like:
public void check(generated.BookType master) {
if (null == master.getItemId()) {
// Optional - nothing to report
} else {
// Check value
}
if (null == master.getName()) {
// Optional - nothing to report
} else {
// Check value
}
// No check for primitive values
if (null == master.getPrice()) {
// Optional - nothing to report
} else {
// Check value
}
if (null == master.getAuthors()) {
// Optional - nothing to report
} else {
// Check value
}
if (null == master.getDescription()) {
// Optional - nothing to report
} else {
// Check value
}
if (null == master.getPromotion()) {
// Optional - nothing to report
} else {
// Check value
}
if (null == master.getBookCategory()) {
// Optional - nothing to report
} else {
// Check value
}
}
...
public void check(generated.BookType.AuthorsType master) {
if (null == master.getAuthorName()) {
// Optional - nothing to report
} else {
// Check value
}
}
or, for a choice:
public static class PromotionTypeVerifier {
public void report(generated.BookType.PromotionType master,
java.lang.String field) {
}
public void check(generated.BookType.PromotionType master) {
if ((null!= master.getDiscount())&&(!(null!=
master.getNone()))) {
// left exists
if (null == master.getDiscount()) {
// Optional - nothing to report
} else {
// Check value
}
} else {
if ((!(null!= master.getDiscount()))&&(null!=
master.getNone())) {
// right exists
if (null == master.getNone()) {
// Optional - nothing to report
} else {
// Check value
}
} else {
if ((!(null!= master.getDiscount()))&&(!(null!=
master.getNone()))) {
// todo: report both absent
} else {
// todo: report both present
}
}
}
}
}
"Check value" comment denotes a place to check field value - using
datatype or other check methods.
Such methods could perform quite thorough diagnostics of JAXB objects
and provide detailed verification information.
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