users@jaxb.java.net

Re: Validating unmarshalling from chameleon schemas

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Mon, 18 Sep 2006 09:10:06 -0700

Raymond Wold wrote:
> I'm trying to design chameleon schemas, as there are certain types I
> need in many different namespaces. I use XJC to compile java classes
> from the schemas, and JAXB to unmarshal (and eventually marshal) objects.
>
> XJC doesn't complain, but I get an extra set of classes under the
> package "generated", one for each complexType. This isn't a significan
> problem, but it makes me think I am doing something wrong.

Chameleon schema is really just a short hand to let you define multiple
similar looking schema components from a single XML file.

JAXB generates classes from schema components, so when you use your
chameleon schema in multiple places, you'll get multiple copies of a
similarly looking classes.


> More important is that I get an error when I try to unmarshal;
>
> Caused by: org.xml.sax.SAXParseException: src-resolve: Cannot resolve
> the name 'myns:phonenumber' to a(n) 'type definition' component.
>
> I am passing both the generic schema file and all the specific schemas
> to both XJC and to the unmarshaller, is this wrong? If I leave out the
> "generated" package and its schema from the marshaller I get the same
> error. I haven't tried leaving out the general schema from the XJC
> argument list (since I simply do *.xsd; there's a lot of files), is this
> worth trying?

I'm not sure where that above error is coming from. Is that when you
construct a Schema object?

The error sounds like it's coming from Xerces, and if so maybe it's
because you added your chameleon schema to the list of Source objects.

I think the complete stack trace would be useful.

> Below follow a simplified set of files. Any comments are welcome, even
> if it's just to not use chameleon schemas (though I'd appreciate a
> suggestion for an alternative that doesn't involve copy/paste)

A long time ago I wrote an article against doing that. I think the best
way to avoid using it is by changing the vocabulary design, though I
don't know if it's an option for you or not.


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com