users@jaxb.java.net

Re: ValidationEventHandler returns strange Locator.Object

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Wed, 19 May 2004 15:12:31 -0700

> Hi Kohsuke,
>
> I use the JAXB classes as internal data model of my application. Because of
> that fact it is possible to programatically handle 'constraints' errors
> that are defined in the xsd.
>
> You are right, if locator returns the leaf Object its not clear in which
> parent this leaf lives. But returnling always the parent of a leaf is only
> a little bit more exact. Maybe the parrent appears several times in the
> schema...

I don't know if we document it somewhere, but we've defined a
vendor-exntesion interface com.sun.xml.bind.ValidationEventLocatorEx
that extends javax.xml.bind.ValidationEventLocator.

I believe in the on-demand validation, the EventLocator object
implements this interface, and it gives you which field of the object is
causing the problem. (For example, you can figure out that the FirstName
field of a Person object is causing the error.)

Does that help you?

> From endusers point of view, response has more impact if user can search
> all leafs with name xxx where constraint may be validated, than look on all
> leafs of the parent (user doesn't know fullfiled constraints). Especially
> because of the reported error tells the user about the concrete violation
> (in may case String length).

I'm not sure what you mean here...

> I'm not a xml expert, but returning a XPATH expression or returning (only)
> the leaf whould be a consistent way for locating validation errors.

If you can work with errors at the infoset level, you might want to work
with an XML validator, like MSV (http://msv.dev.java.net/) It can
validate a document and pinpoint errors in the document.

I've been assuming that this doesn't fit the problem like yours, since
you typically don't want to interpret this error location information
(of the form like "/order/customer[0]/address/_at_zipCode") into a human
readable form ("the zip code of the address"), because this seems
awfully hard to me.

> Is it possible to (over)write/hook Locator functionality in JAXB to solve
> my problem (examples)?

Let me know if this field name extension is of any help.

Or maybe we can just give you both the parent and the child node. Does
that help?

regards,
--
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net