background image

Modify Marshal Example

<< JAXBContext instance | JAXB Examples Output >>
<< JAXBContext instance | JAXB Examples Output >>
M
ODIFY
M
ARSHAL
E
XAMPLE
31
9. The
Items
list branch is walked, and item information is printed to
sys-
tem.out
.
public static void displayItems( Items items ) {
// the items object contains a List of
//primer.po.ItemType objects
List itemTypeList = items.getItem();
10.Walking of the
Items
branch is iterated until all items have been printed.
for(Iterator iter = itemTypeList.iterator();
iter.hasNext();) {
Items.ItemType item = (Items.ItemType)iter.next();
System.out.println( "\t" + item.getQuantity() +
" copies of \"" + item.getProductName() +
"\"" );
}
Sample Output
Running
java Main
for this example produces the following output:
Ship the following items to:
Alice Smith
123 Maple Street
Cambridge, MA 12345
US
5 copies of "Nosferatu - Special Edition (1929)"
3 copies of "The Mummy (1959)"
3 copies of "Godzilla and Mothra: Battle for Earth/Godzilla
vs. King Ghidora"
Modify Marshal Example
The purpose of the Modify Marshal example is to demonstrate how to modify a
Java content tree.
1. The
<INSTALL>/examples/jaxb/modify-marshal/
Main.java
class declares imports for three standard Java classes plus four
JAXB binding framework classes and
primer.po
package:
import java.io.FileInputStream;
import java.io.IOException;