users@jaxb.java.net

Re: [understanding] JAXB generated sources structure

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Tue, 13 Mar 2007 09:42:02 -0700

Rockz wrote:
> Hello,
>
> I generated nearly 2.0 MB Java classes from 2 XML schemas with JAXB2.
> With HyperJAXB2, I automatically created an Hibernate binding file.
> So now, from a XML file, I can create associated Java object, and store it
> in an HSQLDB database.
> So this JAXB application is not Java-driven, but Schema-driven.

Cool.

> Now I want to create an XML file, and the associated database recording,
> from a Java object that I would
> create on my own.
> The problem is that I can't understand the Java architecture/structure
> generated by XJC : when I observe code generated for my root object, I don't
> see any method that would permit to link this root-object to sub-objects. I
> just have some setters methods available for ComplexTypes.
> So, I'd like to know how JAXB's unmarshaller is doing the work when
> converting from an XML file to a Java set of objects. Finally, can you point
> me to some information or quickly explain me how JAXB Java Objects can be
> linked together ?

The best reference is the spec. I think some of the JavaOne
presentations downloadable from the downloads section also includes a
few slides about how this works in general. It would be nice to have
more comprehensive yet accessible documentation (like a book, maybe?),
but there's none yet.

JAXB runtime looks at properties (getter/setter) and fields (normally
public ones, but also the ones with explicit JAXB annotations.)

Beyond that, I think you should probably look at examples in the RI
distribution, and do some experiments.

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com