users@jaxb.java.net

Re: Making generated classes serializable

From: Ryan O'Connell <Ryan.Oconnell_at_Sun.COM>
Date: Fri, 12 Jun 2009 07:59:16 -0400

Hi Wolfgang,

Thank you for the response. I assume that the schemaLocation attribute
should be a URI to the DTD I'm compiling? If so, I tried a few
variations of URIs and still received the exact same error.

I'm also a little surprised I would need to put the URI of the DTD I'm
compiling in the custom binding file. It was not required in the
previous version of JAXB and it would also mean I need to have a binding
file for each schema/DTD I'm compiling which seems inefficient.

I must be doing something else wrong. Wish I knew what it was :-).

Any further thoughts appreciated.
--ryano



Wolfgang Laun wrote:
> Wrap the globalBindings element in a jaxb:bindings, specifying the
> schema locatiion
>
> <jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
> version="2.0">
> <jaxb:bindings schemaLocation="uri">
> <jaxb:globalBindings>
> <jaxb:serializable/>
> </jaxb:globalBindings>
> </jaxb:bindings>
> </jaxb:bindings>
>
> This will give you "implements Serializable", but no serialVersionUID;
> you can request this
> by specifying attribute uid="<int>" but this value is used in all classes.
>
> -W
>
> On Thu, Jun 11, 2009 at 11:41 PM, Ryan O'Connell
> <Ryan.Oconnell_at_sun.com <mailto:Ryan.Oconnell_at_sun.com>> wrote:
>
> Hello,
>
> In the past I was able to compile DTDs using JAXB. I also
> specified a custom binding that made each implementation class
> Serializable. The version of JAXB I was using created interfaces
> for all XML content as well as impls of those interfaces
>
> The binding file contained the following content:
>
> <?xml version="1.0" ?>
> <xml-java-binding-schema
> xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
> <xjc:serializable uid="1" />
> </xml-java-binding-schema>
>
> And I invoked the JAXB compiler using the xjc task like so:
>
> <xjc schema="${ts.home}/lib/dtds/sun-application_5_0-0.dtd"
> binding="${ts.home}/src/${porting.package.dir}/jaxb-cust.xml"
> target="${ts.home}/src"
> package="${porting.package}.app">
> <arg value="-dtd"/>
> <depends dir="${ts.home}/lib/dtds"
> includes="sun-application_6_0-0.dtd"/>
> <produces dir="${ts.home}/src/${porting.package.dir}/app"
> includes="**/*"/>
> </xjc>
>
>
> At some point I upgraded to JAXB 2.x and I noticed interfaces were
> no longer generated just plain Java classes, and I also noticed my
> classes did not implement Serializable. I have tried many
> variations of binding file and I can't seem to make it work. This
> binding file seems like it should work:
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
> version="2.0">
> <jaxb:globalBindings>
> <jaxb:serializable/>
> </jaxb:globalBindings>
> </jaxb:bindings>
>
> but I keep getting the following error:
>
> [xjc] [ERROR] cvc-elt.1: Cannot find the declaration of element
> 'jaxb:globalBindings'.
> [xjc] line 3 of
> file:/Users/ryanoconnell/Documents/workspace/spider/src/com/sun/ts/lib/implementation/sun/javaee/runtime/jaxb-cust.xml
>
>
> Can anyone tell me where I fell off the beam?
>
> Thanks in advance.
> --ryano
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> <mailto:users-unsubscribe_at_jaxb.dev.java.net>
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
> <mailto:users-help_at_jaxb.dev.java.net>
>
>