users@jaxb.java.net

Re: XSd key's and keyref's

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Mon, 12 Sep 2005 16:59:06 -0700

Vincent Lamareille wrote:
> Thanks Kohsuke,
>
> What I need exactly is to enforce some kind of referential integrity
> between Java objects which are marshalled to XML documents and later
> unmarshalled.
> So I will use JAXB for binding, and apply constraints in Java classes.
>
> As constraints are easy to write in code and difficult to express in
> XSD, is it possible to add them into Java classes with a plugin?

I'd imagine it's probably easier to write them as a part of your
application logic internal/external (depending on whether you need to
regenerate classes often from a schema or not) to the generated code.

You can certainly write a plugin that injects referential integrity
checks into the generated code, if you prefer. Having such a plug-in
that can work with arbitrary constraints (not just your particular one)
would be very useful, but personally I don't really have a good idea
about how to approach this problem. If you have some idea, by all means
please try. I'm happy to help you with any plug-in questions.

If you look at the current state of referential integrity support in
schema languages for XML, it's really quite pathetic (perhaps except
Schematron, but it doesn't express constraints in a way usable for a
databinding tool like JAXB.)

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com