10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Customizing JAXB Bindings<br />

528<br />

Property Binding Declarations<br />

Of particular interest here is the generateIsSetMethod customization, which causes two<br />

additional property methods, isSetQuantity and unsetQuantity, to be generated. <strong>The</strong>se<br />

methods enable a client application to distinguish between schema default values and values<br />

occurring explicitly within an instance document.<br />

For example, in po.xsd:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

...<br />

<br />

<br />

<br />

<br />

<strong>The</strong> @generateIsSetMethod applies to the quantity element, which is bound to a property<br />

within the Items.ItemType interface. unsetQuantity and isSetQuantity methods are<br />

generated in the Items.ItemType interface.<br />

MyDatatypeConverter Class<br />

<strong>The</strong> class<br />

tut-install/javaeetutorial5/examples/jaxb/inline-customize/src/inlinecustomize/primer/MyDatat<br />

shown below, provides a way to customize the translation of XML data types to and from <strong>Java</strong><br />

data types by means of a customization.<br />

package primer;<br />

import java.math.BigInteger;<br />

import javax.xml.bind.DatatypeConverter;<br />

public class MyDatatypeConverter {<br />

public static short parseIntegerToShort(String value) {<br />

BigInteger result = DatatypeConverter.parseInteger(value);<br />

return (short)(result.intValue());<br />

}<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!