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.

Example Code<br />

570<br />

int eventType = xmlr.getEventType();<br />

while(xmlr.hasNext()){<br />

eventType = xmlr.next();<br />

//Get all "Book" elements as XMLEvent object<br />

if(eventType == XMLStreamConstants.START_ELEMENT &&<br />

xmlr.getLocalName().equals("Book")){<br />

//get immutable XMLEvent<br />

StartElement event = getXMLEvent(xmlr).asStartElement();<br />

System.out.println("EVENT: " + event.toString());<br />

}<br />

}<br />

Creating the Allocator Method<br />

<strong>The</strong> final step is to create the XMLEventAllocator method:<br />

private static XMLEvent getXMLEvent(XMLStreamReader reader)<br />

throws XMLStreamException {<br />

return allocator.allocate(reader);<br />

}<br />

Building and Running the Cursor-to-Event Example Using NetBeans<br />

IDE<br />

Follow these instructions to build and run the Cursor-to-Event 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 the tut-install/javaeetutorial5/examples/stax/<br />

directory.<br />

3. Select the cursor2event folder.<br />

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

5. Click Open Project.<br />

6. In the Projects tab, right-click the cursor2event project and select Properties. <strong>The</strong> Project<br />

Properties dialog is displayed.<br />

7. Enter the following in the Arguments field:<br />

BookCatalog.xml<br />

8. Click OK.<br />

9. Right-click the cursor2event project and select Run.<br />

Note how the Book events are returned as strings.<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!