Property Binding Declarations
Property Binding Declarations
Property Binding Declarations
Of particular interest here is the generateIsSetMethod customization, which causes two
additional property methods, isSetQuantity and unsetQuantity, to be generated. These
methods enable a client application to distinguish between schema default values and values
occurring explicitly within an instance document.
For example, in po.xsd:
<xsd:complexType name=
"Items">
<xsd:sequence>
<xsd:element name=
"item" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name=
"productName" type="xsd:string"/>
<xsd:element name=
"quantity" default="10">
<xsd:annotation>
<xsd:appinfo>
<jxb:property generateIsSetMethod=
"true"/>
</xsd:appinfo>
</xsd:annotation>
...
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
The @generateIsSetMethod applies to the quantity element, which is bound to a property
within the Items.ItemType interface. unsetQuantity and isSetQuantity methods are
generated in the Items.ItemType interface.
MyDatatypeConverter
Class
The class
tut-install/javaeetutorial5/examples/jaxb/inline-customize/src/inlinecustomize/primer/MyDatatypeConverter,
shown below, provides a way to customize the translation of XML data types to and from Java
data types by means of a <javaType> customization.
package primer;
import java.math.BigInteger;
import javax.xml.bind.DatatypeConverter;
public class MyDatatypeConverter {
public static short parseIntegerToShort(String value) {
BigInteger result = DatatypeConverter.parseInteger(value);
return (short)(result.intValue());
}
Customizing JAXB Bindings
The Java EE 5 Tutorial · September 2007
530