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.

SAAJ Coffee Supplier Service<br />

1028<br />

<strong>The</strong> next lines of code drill down another level to retrieve the coffee-name and price elements<br />

contained in it3. <strong>The</strong>n the message getValue retrieves the text (a coffee name or a price) that<br />

the SAAJ coffee supplier added to the coffee-name and price elements when it gave content to<br />

response. <strong>The</strong> final line in the following code fragment adds the coffee name or price to the<br />

Vector object list. Note that because of the nested while loops, for each coffee element that<br />

the code retrieves, both of its child elements (the coffee-name and price elements) are<br />

retrieved.<br />

}<br />

}<br />

Iterator it3 = child2.getChildElements();<br />

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

SOAPElement child3 = (SOAPElement)it3.next();<br />

String value = child3.getValue();<br />

list.addElement(value);<br />

}<br />

<strong>The</strong> final code fragment adds the coffee names and their prices (as a PriceListItem) to the<br />

ArrayList priceItems, and prints each pair on a separate line. Finally it constructs and returns<br />

a PriceListBean.<br />

ArrayList items = new ArrayList();<br />

for(inti=0;i

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

Saved successfully!

Ooh no, something went wrong!