users@jaxb.java.net

AW: Mapping of SAX events to corresponding JAXB classes

From: Claus Nagel <claus.nagel_at_gmail.com>
Date: Sun, 30 Sep 2007 18:48:33 +0200

Hi.

> 1) parse "com.acme.foo:com.acme.bar" into a list of packages ->
> "com.acme.foo", "com.acme.bar"
> 2) for each package construct an object factory class name - >
> "com.acme.foo.ObjectFactory", "com.acme.bar.ObjectFactory"
> 3) load the classes via Class.forName or whatever.

Ok, everything works just fine now. Thanks :)

> Let me know if you need to solve a wider problem.

Well, indeed I am facing a wider problem. Consider the following excerpt of
an XML instance document:

<doc>
  <AAA id="a1" xlink:href="#a2"/>
  <AAA id="a2">
    <BBB id="b1>
    ..
    </BBB>
    <BBB id="b2">
       <BBB>
       ..
       </BBB>
    </BBB>
  </AAA>
  <AAA>
     <BBB id="b4" xlink:href="#b2"/>
  </AAA>
</doc>

There are some things to mention here:

1. Only one <AAA>-chunk of that XML document is considered at the same time.
It is read via SAX, unmarshalled using multi-threaded JAXB, written to a
database and afterwards removed from main memory. Unmarshalling the whole
document at once is no choice since it might be very large.

2. A <BBB> element again may contain <BBB> elements. So there is a recursive
relation of arbitrary depth. In fact, according to the XSD schema this is
true for many other elements as well.

3. Each element may contain an optional unique id-attribute and therefore
may be referenced from any other element of the same type.

At the moment keeping track of elements with a unique id and references to
these elements gives me a headache. Having unmarshalled an <AAA>-chunk this
would mean going through many recursive lists searching for objects
containing an id and/or an xlink. Since XJC generated more than 1000 classes
from the XSD schema a lot of coding would be needed.

So my idea was to recognize the type of an element containing an id or a
reference whilst SAX-parsing the file. Thanks to your help this is working
now.

There are still many open questions. But they are not related to JAXB. In
contrast, JAXB is doing a great job. Nevertheless, perhaps someone out there
had to deal with similar problems and can share some experience with me?!

Again, many thanks for your help!
Best regards,
Claus

P.S.: For those interested: The XSD schema mentioned is CityGML - an
application schema for the Geography Markup Language (GML)
http://www.citygml.org/.