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.

Basic JAXB Examples<br />

510<br />

5. A Marshaller instance is created, and the updated XML content is marshalled to<br />

system.out. <strong>The</strong> setProperty API is used to specify output encoding; in this case<br />

formatted (human readable) XML format.<br />

Marshaller m = jc.createMarshaller();<br />

m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);<br />

m.marshal( po, System.out );<br />

Building and Running the Modify Marshal Example Using NetBeans IDE<br />

Follow these instructions to build and run the Modify Marshal 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 modify-marshal folder.<br />

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

5. Click Open Project.<br />

6. Right-click the modify-marshal project and select Run.<br />

Building and Running the Modify Marshal Example Using Ant<br />

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

tut-install/javaeetutorial5/examples/jaxb/modify-marshal/ directory and type the<br />

following:<br />

ant runapp<br />

UnmarshalValidate Example<br />

<strong>The</strong> Unmarshal Validate example demonstrates how to enable validation during<br />

unmarshalling. Note that JAXB provides functions for validation during unmarshalling but not<br />

during marshalling. Validation is explained in more detail in “More about Validation” on<br />

page 490.<br />

1. <strong>The</strong><br />

tut-install/javaeetutorial5/examples/jaxb/unmarshal-validate/src/unmarshalvalidate/Main.jav<br />

class declares imports for three standard <strong>Java</strong> classes plus seven JAXB binding framework<br />

classes and the primer.po package:<br />

import java.io.FileInputStream;<br />

import java.io.IOException;<br />

import java.math.BigDecimal;<br />

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

import javax.xml.bind.JAXBException;<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!