JAXB 2.0 | Tools | JAXB 1.0.x | JAXB RI Extensions | JAXB Community |
The JAXB RI provides additional customizations that are not defined by the JAXB specification. Note the following:
The <xjc:superClass> customization allows you to specify the fully qualified name of the Java class that is to be used as the super class of all the generated implementation classes. The <xjc:superClass> customization can only occur within your <jaxb:globalBindings> customization on the <xs:schema> element:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0"> <xs:annotation> <xs:appinfo> <jaxb:globalBindings> <xjc:superClass name="org.acme.RocketBooster"/> </jaxb:globalBindings> </xs:appinfo> </xs:annotation> . . . </xs:schema>
In the sample above, the <xjc:superClass> customization will cause all of the generated implementation classes to extend the named class, org.acme.RocketBooster.
The <xjc:superInterface> customization allows you to specify the fully qualified name of the Java interface that is to be used as the root interface of all the generated interfaces. This customization has no effect unless you are specifically generating interfaces with the <globalBindings generateValueClass="false" switch. The <xjc:superInterface> customization can only occur within your <jaxb:globalBindings> customization on the <xs:schema> element:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0"> <xs:annotation> <xs:appinfo> <jaxb:globalBindings generateValueClass="false"> <xjc:superInterface name="org.acme.RocketBooster"/> </jaxb:globalBindings> </xs:appinfo> </xs:annotation> . . . </xs:schema>
In the sample above, the <xjc:superInterface> customization will cause all of the generated interfaces to extend the named interface, org.acme.RocketBooster.
The <xjc:javaType> customization can be used just like the standard <jaxb:javaType> customization, except that it allows you to specify an XmlAdapter
-derived class, instead of parse&print method pair.
This customization can be used in all the places <jaxb:javaType> is used, but nowhere else:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0"> . . . <xsd:simpleType name="LayerRate_T"> <xsd:annotation><xsd:appinfo> <xjc:javaType name="org.acme.foo.LayerRate" adapter="org.acme.foo.LayerRateAdapter" /> </xsd:appinfo></xsd:annotation> ... gory simple type definition here ... </xsd:simpleType> </xsd:schema>
In the above example, LayerRate_T simple type is adapted by org.acme.foo.LayerRateAdapter, which extends from XmlAdapter.
This experimental binding mode can be enabled as a part of the global binding. See below:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.0"> <xs:annotation> <xs:appinfo> <jaxb:globalBindings generateValueClass="false"> <xjc:simple /> </jaxb:globalBindings> </xs:appinfo> </xs:annotation> . . . </xs:schema>
When enabled, XJC produces Java source code that are more concise and easier to use. Improvements include:
// schema <xs:complexType name="foo"> <xs:choice> <xs:sequence> <xs:element name="a" type="xs:int" /> <xs:element name="b" type="xs:int" /> </xs:sequence> <xs:sequence> <xs:element name="b" type="xs:int" /> <xs:element name="c" type="xs:int" /> </xs:sequence> </xs:choice> </xs:complexType> // before class Foo { List<JAXBElement<Integer>> content; } // in <xjc:simple> binding class Foo { Integer a; int b; // notice that b is effectively mandatory, hence primitive Integer c; }
// schema <xs:complexType name="person"> <xs:sequence> <xs:element name="child" type="xs:string" maxOccurs="unbounded" /> <xs:element name="parent" type="xs:string" maxOccurs="unbounded" /> </xs:sequence> </xs:complexType> // before public class Person { protected List<String> child; protected List<String> parent; } // in <xjc:simple> binding public class Person { protected List<String> children; protected List<String> parents; }
Once again, readers are warned that this is an experimental binding mode, and therefore the binding is subject to change in future versions of the JAXB RI without notice. Please send feedbacks on this binding to users@jaxb.dev.java.net