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.

TABLE 17–11 <strong>Java</strong>-to-Schema JAXB Examples<br />

Example Name Description<br />

“Create Marshal Example” on<br />

page 535<br />

“XmlAccessorOrder Example” on<br />

page 536<br />

“XmlAdapter Field Example” on<br />

page 538<br />

“XmlAttribute Field Example” on<br />

page 541<br />

“XmlRootElement Example” on<br />

page 542<br />

“XmlSchemaType Class Example”<br />

on page 543<br />

Illustrates how to marshal and unmarshal JAXB-annotated classes to<br />

XML schema. <strong>The</strong> example also shows how to enable JAXP 1.3 validation<br />

at unmarshal time using a schema file that was generated from the JAXB<br />

mapped classes.<br />

Illustrates how to use the @XmlAccessorOrder and @XmlType.propOrder<br />

mapping annotations in <strong>Java</strong> classes to control the order in which XML<br />

content is marshalled/unmarshalled by a <strong>Java</strong> type.<br />

Illustrates how to use the interface XmlAdapter and the annotation<br />

@Xml<strong>Java</strong>TypeAdapter to provide a a custom mapping of XML content<br />

into and out of a HashMap (field) that uses an int as the key and a String<br />

as the value.<br />

Illustrates how to use the annotation @XmlAttribute to define a property<br />

or field to be handled as an XML attribute.<br />

Illustrates how to use the annotation @XmlRootElement to define an XML<br />

element name for the XML schema type of the corresponding class.<br />

Illustrates how to use the annotation @XmlSchemaType to customize the<br />

mapping of a property or field to an XML built-in type.<br />

“XmlType Example” on page 544 Illustrates how to use the annotation @XmlType to map a class or enum type<br />

to an XML schema type.<br />

JAXB Compiler Options<br />

<strong>The</strong> JAXB XJC schema binding compiler transforms, or binds, a source XML schema to a set of<br />

JAXB content classes in the <strong>Java</strong> programming language. <strong>The</strong> compiler, xjc, is provided in two<br />

flavors in the Application Server: xjc.sh (Solaris/Linux) and xjc.bat (Windows). Both xjc.sh<br />

and xjc.bat take the same command-line options. You can display quick usage instructions by<br />

invoking the scripts without any options, or with the -help switch. <strong>The</strong> syntax is as follows:<br />

xjc [-options ...] schema<br />

JAXB Examples<br />

<strong>The</strong> xjc command line options are as follows:<br />

-nv Do not perform strict validation of the input schema or schemas. By<br />

default, xjc performs strict validation of the source schema before<br />

processing. Note that this does not mean the binding compiler will not<br />

perform any validation; it simply means that it will perform less-strict<br />

validation.<br />

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

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

Saved successfully!

Ooh no, something went wrong!