users@jaxb.java.net

Re: xjc: how to make a class implement Serialiazable without changing the schema?

From: Dmitri Colebatch <dim_at_colebatch.com>
Date: Wed, 5 Apr 2006 17:03:36 +1000

Hi Kohsuke,

I've been meaing to follow up on this for _ages_, so my apologies for the delay.

It strikes me as odd that despite the fact that I can only have one
globalBindings in my binding.xjb file, I have to add a schemaLocation
to it. This binding file:

<jxb:bindings version="1.0"
              xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
              xmlns:xs="http://www.w3.org/2001/XMLSchema">

        <jxb:bindings>
                <jxb:globalBindings />
        </jxb:bindings>

</jxb:bindings>

results in this:

jaxb-tJunction:
      [xjc] Consider using <depends>/<produces> so that XJC won't do
unnecessary compilation
      [xjc] Compiling
file:/C:/dev/tmp/tJunction/schema/tJunction/vehicleaccessories/2004/11/04/VehicleAccessories.xsd
and others
      [xjc] [ERROR] The "jxb:globalBindings" customization is not
associated with any schema element.
      [xjc] line 6 of file:/C:/dev/tJunction/papis/access/etc/binding.xjb

yet if I change it to this:

<jxb:bindings version="1.0"
              xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
              xmlns:xs="http://www.w3.org/2001/XMLSchema">

        <jxb:bindings schemaLocation="../../../../tmp/tJunction/schema/tJunction/vehiclespecification/2004/04/01/VehicleSpecification.xsd"
node="/xs:schema">
                <jxb:globalBindings />
        </jxb:bindings>

</jxb:bindings>

it works fine.

I would have thought that "global" meant I didn't need the schema
location. Am I misunderstanding this, or is it not supposed to be
that way?

cheers
dim



On 6/1/05, Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_sun.com> wrote:
> Dmitri Colebatch wrote:
> > Hi all,
> >
> > I want to use xjc to generate java classes for 3rd party schemas - as
> > such I don't have control over the schemas and would like to avoid
> > having to xslt them in order to have the generated classes implement
> > Serializable.
> >
> > Is it possible to direct xjc to make all generated classes implement
> > the Serializable interface without changing the schemas?
>
> Yes. The customization to do this is:
>
> <jaxb:globalBindings>
> <jaxb:serializable/>
> </jaxb:globalBindings>
>
> And you can use external customizations to set this outside the schema
> file. See one of the bundled sample applications for how to use external
> customizations. (I think I also blogged recently about to how to use
> external binding files quickly, although I used different customizations
> [1].)
>
>
> [1]
> http://weblogs.java.net/blog/kohsuke/archive/2005/05/compiling_mathm_1.html
> --
> Kohsuke Kawaguchi
> Sun Microsystems kohsuke.kawaguchi_at_sun.com
>
>
>