I'm currently generating my first JAXB data binding. I have a schema which contains within it a xs:simpleType:
<xs:simpleType name="NINumberType">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z]{2}\d{6}[A-D]{0,1}"/>
</xs:restriction>
</xs:simpleType>
In my binding.xjb I have this:
<jxb:bindings version="1.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jxb:extensionBindingPrefixes="xjc">
<jxb:bindings schemaLocation="mySchema.xsd" node="/xs:schema">
<jxb:globalBindings mapSimpleTypeDef="true" />
<jxb:schemaBindings>
<jxb:package name="com.company.jaxb.mySchema"/>
</jxb:schemaBindings>
</jxb:bindings>
</jxb:bindings>
Then, through Eclipse (well RAD 7.5) I right click the schema, and choose Generate->Java. This produces data binding objects as expected, except that the NINumberType
has no built in restrictions:
/**
* <p>Java class for NINumberType simple type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* <simpleType name="NINumberType">
* <restriction base="{http://www.w3.org/2001/XMLSchema}string">
* <pattern value="[A-Z]{2}\d{6}[A-Z]{0,1}"/>
* </restriction>
* </simpleType>
* </pre>
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "NINumberType", propOrder = {"value"})
public class NINumberType {
@XmlValue
protected String value;
public String getValue() {return value;}
public void setValue(String value) {this.value = value;}
}
No mention is made of the regular expression restriction specified in my schema, except in the class level javadoc. JAXB appears to have the information it needs to generate the restriction code, but is not using it. Can anyone help me ensure that the restriction code is generated such that attempting to bind a poorly formatted NI number will fail?