users@jaxb.java.net

Re: jaxb 1.0 and jaxb2.0 differences and simple binding (migration)

From: Aron Vaughan <aronvaughan_at_gmail.com>
Date: Tue, 30 Jan 2007 10:47:34 -0600

Yes, given the following example schema:



<?xml version="1.0" encoding="UTF-8"?>

 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<!--

 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"

 xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"

  jaxb:version="1.0"

  xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"

  jaxb:extensionBindingPrefixes="xjc">

<xsd:annotation>

    <xsd:appinfo>

      <jaxb:globalBindings>

        <xjc:simple />

      </jaxb:globalBindings>

    </xsd:appinfo>

  </xsd:annotation>

-->

     <xsd:element name="booking" type="courseBooking"/>

     <xsd:complexType name="courseBooking">

      <xsd:sequence>

       <xsd:element ref="company" />

       <xsd:element ref="student" minOccurs="1" maxOccurs="unbounded"/>

      </xsd:sequence>

      <xsd:attribute name="courseReference" type="xsd:string"
use="required"/>

      <xsd:attribute name="courseDate" type="xsd:date" use="required"/>

      <xsd:attribute name="invoiceReference" type="xsd:string"
use="required"/>

      <xsd:attribute name="totalPrice" type="xsd:decimal" use="required"/>

     </xsd:complexType>

     <xsd:element name="student" type="studentType"/>

     <xsd:complexType name="studentType">

       <xsd:attribute name="firstName" type="xsd:string" use="required"/>

       <xsd:attribute name="surname" type="xsd:string" use="required"/>

     </xsd:complexType>

     <xsd:element name="company" type="companyType"/>

     <xsd:complexType name="companyType">

      <xsd:sequence>

       <xsd:element name="address"/>

       <xsd:element ref="contact" />

      </xsd:sequence>

      <xsd:attribute name="name" type="xsd:string"/>

     </xsd:complexType>

      <xsd:element name="contact" type="contactType"/>

      <xsd:complexType name="contactType">

       <xsd:attribute name="name" type="xsd:string" use="required"/>

       <xsd:attribute name="telephone" type="xsd:string" use="required"/>

       <xsd:attribute name="email" type="xsd:string" use="required"/>

     </xsd:complexType>

    </xsd:schema>





Using normal bindings the following files are created: CompanyType,
ContactType, CourseBooking, StudentType and the objectFactory (each
top-level element (Company, Contact, Booking, Student) gets an objectFactory
create method which must be used for marshalling)



Using simple bindings (with the global bindings uncommented in the above
schema) the following files are created: Company, CompanyType, Contact,
ContactType, Booking, CourseBooking, Student, StudentType and the
objectFactory (i.e. each top-level element gets a generated class that can
be 'new'ed and marshaled)



thanks,

Aron.


On 1/29/07, Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_sun.com> wrote:
>
> Aron Vaughan wrote:
> > Greetings,
> >
> > I work for a large company with quite a bit of jaxb1.0 code (jaxb1
> 15,000
> > generated classes from .xsds (Jaxb2 8286 using simple bindings, 5232
> using
> > normal bindings)) -- we're attempting to upgrade to Jaxb2.0 code and are
> > looking for a good path.
>
> This is interesting. Simple binding mode creates more classes?
>
> > Jaxb 2.0 simple binding mode creates java classes that are closer to
> what we
> > are looking for (each toplevel element has its own class with @xmlRoot
> so
> > they can marshal without the ObjectFactory interaction; except for the
> > 'experimental - can change anytime' and the pluralization bits).
> >
> > Anyone written a plugin to create a class for each top level element
> (with
> > XmlRoot attribute) ?
> >
> > <xsd:complexType name="AMQuery_t">
> > <xsd:sequence>
> > <xsd:element name="QueryReq" type="AMQueryReq_t"/>
> > </xsd:sequence>
> > </xsd:complexType>
> > <xsd:element name="AMQuery" type="AMQuery_t" />
> >
> > so we'd get a first class AMQuery object we can new() and marshal (vs.
> > ObjectFactory create method).
> >
> > Anyone done a similar migration (scripting a migration path, or
> stories)?
> >
> > thanks for your time,
> > -Aron Vaughan
> >
>
>
> --
> Kohsuke Kawaguchi
> Sun Microsystems kohsuke.kawaguchi_at_sun.com
>
>
>