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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

AdapterPurchaseListToHashMap with field HashMap basket. This pairing will cause the<br />

marshal/unmarshal method of AdapterPurchaseListToHashMap to be called for any<br />

corresponding marshal/unmarshal action on KitchenWorldBasket.<br />

Building and Running the XmlAdapter Field Example Using NetBeans<br />

IDE<br />

Follow these instructions to build and run the XmlAdapter Field example on your Application<br />

Server instance using NetBeans IDE.<br />

1. In NetBeans IDE, select File→Open Project.<br />

2. In the Open Project dialog, navigate to tut-install/javaeetutorial5/examples/jaxb/.<br />

3. Select the j2s-xmlAdapter-field folder.<br />

4. Select the Open as Main Project check box.<br />

5. Click Open Project.<br />

6. Right-click the j2s-xmlAdapter-field project and select Run.<br />

Building and Running the XmlAdapter Field Example Using Ant<br />

To compile and run the XmlAdapter Field example using Ant, in a terminal window, go to the<br />

tut-install/javaeetutorial5/examples/jaxb/j2s-xmlAdapter-field/ directory and type the<br />

following:<br />

ant runapp<br />

XmlAttribute Field Example<br />

<strong>The</strong> XmlAttribute Field example shows how to use the @XmlAttribute annotation to define a<br />

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

<strong>The</strong> @XmlAttribute annotation maps a field or <strong>Java</strong>Bean property to an XML attribute. <strong>The</strong><br />

following rules are imposed:<br />

■ A static final field is mapped to a XML fixed attribute.<br />

<strong>Java</strong>-to-Schema Examples<br />

■ When the field or property is a collection type, the items of the collection type must map to a<br />

schema simple type.<br />

■ When the field or property is other than a collection type, the type must map to a schema<br />

simple type.<br />

When following the <strong>Java</strong>Bean programming paradigm, a property is defined by a get and set<br />

prefix on a field name.<br />

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

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

Saved successfully!

Ooh no, something went wrong!