users@jaxb.java.net

XML namespace to Java package name

From: Gary Gregory <ggregory_at_seagullsw.com>
Date: Wed, 8 Oct 2003 14:08:17 -0400

Hell JAXB,

This is a 2 parter.

(1) Somewhere deep in the guts of JAXB there must be code that converts an
XML namespace string into a Java package name. Is this code accessible in
the generated runtime? I do need to call such a conversion utility.

Why? Read on. The following contains some details of our system but it makes
it all easier to explain.

(2) Our product comes with many pluggable "connectors" (akin to JCA
connectors) and each connector comes in its own Jar file. When our server
starts up we look in a "config/connector" dir and for each .cfg file we
finds, we call JAXB to load that cfg. So far so good, thank you JAXB!

For each connector, we have an XML Schema that describes its config file,
and each schema is defined in a namespace. All connector schemas derive from
a root connector schema which holds some common attributes. When we use JAXB
to load a config file for a specific connector, we get an instance of a
subclass of Connector, like FooConnector. Again, thank you JAXB.

Our current hack is to create a JAXB context with a path that includes *ALL
possible* kinds of connector schemas that we know about in advance. This is
a big problem for us now because we want to allow custom connectors to be
loaded in, that is connectors that the server does not know about at compile
time. Since a custom or new connector will have its own XML schema in its
own namespace, our server cannot know that namespace in advance.

Our first thought was to create yet another config file which would hold the
JAXB path to use to load all connectors. A user would just add to this
config file to load another kind of connector. Messy and too error prone.

A quick look at our config files show that the XML default namespace for a
config file tells us exactly what to put on the JAXB context path. So we
simply use SAX for quick extraction of the default namespace, turn that into
a Java package name (not implemented yet), and use that as the JAXB context
to load that connector. We are not worried about performance at this point
since (1) SAX is quite fast and we abort parsing when we get the NS and (2)
this happens only during server init.

All of this to ask: can we use a JAXB piece to convert the XML namespace
into a Java package name as XJC and the runtime do.

Thanks,
Gary