JAXB2 Inheritance Plugin (original) (raw)
Inheritance Plugin
Makes schema-derived classes extend certain class or implement certain interfaces.
Activation
Activate the plugin using -Xinheritance
switch.
Configuration
- Declare the http://jaxb2-commons.dev.java.net/basic/inheritance customization namespace (or starting with v3 of the plugin, the new
urn:jaxb.jvnet.org:plugin:inheritance
namespace). - Use
<inheritance:extends>com.acme.foo.MyClass</inheritance:extends>
or<inheritance:implements>com.acme.foo.MyInterface</inheritance:implements>
customization elements to specify which classes or interfaces should your schema-derived class extend or implement. - Use
<inheritance:objectFactory packageName="com.acme.foo"/>
to customize the object factory class.
Works with class outlines, enum outlines, element and package outlines.
Example XSD / XJB (JAXB 2)
schema.xsd
example file :
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance" jaxb:version="2.1" jaxb:extensionBindingPrefixes="inheritance">
xs:annotation xs:appinfo jaxb:schemaBindings <jaxb:package name="com.acme.foo" /> <inheritance:objectFactory packageName="com.acme.foo"> inheritance:implementsjava.lang.Cloneable
<xs:complexType name="WillBeMadeCloneableType"> xs:annotation xs:appinfo inheritance:implementsjava.lang.Cloneable
bindings.xjb
example file :
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance" jaxb:extensionBindingPrefixes="inheritance" jaxb:version="2.1">
<jaxb:bindings schemaLocation="schema.xsd" node="/xsd:schema"> <jaxb:bindings node="xsd:simpleType[@name='issueJIIB38Type']"> inheritance:implementsjava.lang.Cloneable <jaxb:bindings node="xsd:element[@name='issueJIIB38']"> jaxb:class/ inheritance:implementsjava.lang.Cloneable
Example XSD / XJB (JAXB 3)
schema.xsd
example file :
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb" xmlns:inheritance="urn:jaxb.jvnet.org:plugin:inheritance" jaxb:version="3.0" jaxb:extensionBindingPrefixes="inheritance">
xs:annotation xs:appinfo jaxb:schemaBindings <jaxb:package name="com.acme.foo" /> <inheritance:objectFactory packageName="com.acme.foo"> inheritance:implementsjava.lang.Cloneable
<xs:complexType name="WillBeMadeCloneableType"> xs:annotation xs:appinfo inheritance:implementsjava.lang.Cloneable
bindings.xjb
example file :
<jaxb:bindings xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:inheritance="urn:jaxb.jvnet.org:plugin:inheritance" jaxb:extensionBindingPrefixes="inheritance" jaxb:version="3.0">
<jaxb:bindings schemaLocation="schema.xsd" node="/xsd:schema"> <jaxb:bindings node="xsd:simpleType[@name='issueJIIB38Type']"> inheritance:implementsjava.lang.Cloneable <jaxb:bindings node="xsd:element[@name='issueJIIB38']"> jaxb:class/ inheritance:implementsjava.lang.Cloneable
Support for generics
Assume you have a generic interface :
public interface IssueJIIB48Interface { public T getValue(); }
You can now use the following customization :
<xs:complexType name="issueJIIB48Type"> xs:annotation xs:appinfo inheritance:implementsorg.jvnet.jaxb2_commons.tests.issues.IssueJIIB48Interface<java.lang.String> xs:sequence <xs:element name="value" type="xs:string"/>
You'll get the following code :
public class IssueJIIB48Type implements IssueJIIB48Interface {
@XmlElement(required = true)
protected String value;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
// ...
}