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.

■ customizes the <strong>Java</strong>doc tool annotations for the property’s getter method.<br />

javaType Binding Declarations<br />

<strong>The</strong> declaration provides a way to customize the translation of XML data types to<br />

and from <strong>Java</strong> data types. XML provides more data types than <strong>Java</strong>, and so the <br />

declaration lets you specify custom data type bindings when the default JAXB binding cannot<br />

sufficiently represent your schema.<br />

<strong>The</strong> target <strong>Java</strong> data type can be a <strong>Java</strong> built-in data type or an application-specific <strong>Java</strong> data<br />

type. If an application-specific data type is used as the target, your implementation must also<br />

provide parse and print methods for unmarshalling and marshalling data. To this end, the<br />

JAXB specification supports a parseMethod and printMethod:<br />

■ <strong>The</strong> parseMethod is called during unmarshalling to convert a string from the input<br />

document into a value of the target <strong>Java</strong> data type.<br />

■ <strong>The</strong> printMethod is called during marshalling to convert a value of the target type into a<br />

lexical representation.<br />

If you prefer to define your own data type conversions, JAXB defines a static class,<br />

DatatypeConverter, to assist in the parsing and printing of valid lexical representations of the<br />

XML Schema built-in data types.<br />

<strong>The</strong> syntax for the customization is:<br />

<br />

■ name is the <strong>Java</strong> data type to which xmlType is to be bound.<br />

■ xmlType is the name of the XML Schema data type to which javaType is to be bound; this<br />

attribute is required when the parent of the declaration is .<br />

■ hasNsContext allows a namespace context to be specified as a second parameter to a print or<br />

a parse method; can be either true, false, 1,or0. By default, this attribute is false, and in<br />

most cases you will not need to change it.<br />

■ parseMethod is the name of the parse method to be called during unmarshalling.<br />

■ printMethod is the name of the print method to be called during marshalling.<br />

<strong>The</strong> declaration can be used in:<br />

■ A declaration<br />

Customizing JAXB Bindings<br />

■ An annotation element for simple type definitions, GlobalBindings, and <br />

declarations<br />

Chapter 17 • Binding between XML Schema and <strong>Java</strong> Classes 521

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

Saved successfully!

Ooh no, something went wrong!