users@jaxb.java.net

Re: Simple mode and extra classes problem

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Mon, 14 May 2007 16:45:54 -0700

Jarek Gilewski wrote:
> Hello,
>
> I'm using JAXB 2.1.3 and i have the following XSD:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:include schemaLocation="CommonTypes.xsd"/>
> ...
> <xsd:element name="DocumentIdentifier" type="max35Identifier"/>
> <xsd:element name="Name" type="max70text"/>
> <xsd:element name="Description" type="max210text"/>
> <xsd:complexType name="Party">
> <xsd:sequence>
> <xsd:element name="Identifier" type="PartyIdentType" minOccurs="0"/>
> <xsd:element ref="Name" minOccurs="0"/>
> <xsd:element name="AdditionalName" type="max70text" minOccurs="0"/>
> <xsd:element ref="Description" minOccurs="0"/>
> <xsd:element ref="Address" minOccurs="0"/>
> </xsd:sequence>
> </xsd:complexType>
> ...
> </xsd:schema>
>
> max35Identifier, max70text and max210text are defined in CommonTypes.xsd
>
> I compile this xsd using <xjc:simple/> mode and I got:
>
> public class Party {
> @XmlElement(name = "Identifier")
> protected PartyIdentType identifier;
> @XmlElement(name = "Name")
> protected Name name;
> @XmlElement(name = "AdditionalName")
> protected Name additionalName;
> @XmlElement(name = "Description")
> protected Description description;
> @XmlElement(name = "Address")
> protected Address address;
> ..
> }
>
> The problem is that simple mode generate additional classes like Name and
> Description but I don't want it.

XJC generates them because they are declared as global elements. But
maybe you are essentially saying that those elements will never appear
as root elements, in which case perhaps we can define a customization so
that you can tell XJC so that XJC can further optimize things away.

> I want to have:
>
> @XmlElement(name = "Name")
> protected Max70Text name;
> @XmlElement(name = "Description")
> protected Max210Text description;
>
> Max70Text and Max210Text are already generated compiling CommonTypes.xsd
>
> This generation extra classes appears whereever there is:
>
> <xsd:element name="someName" type="someType"/>
> <xsd:element ref="someName" minOccurs="0"/>
>
> How to make xjc to use someType directly instead of generating additional
> class someName which extends someType.
> I would like to do it using xjb file (without touching xsd files).
>
> Please help me. I'm stuck with this problem for few days after looking on
> google and this list.
>
> Regards Jarek.
>


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com