Inventory.java.

Graphic Java
Create XML files using JSP
David Geary
Listing 3. Inventory.java.


package com.companyName.beans.model;

import java.util.*;
import java.io.*;

public class Inventory implements java.io.Serializable {
	private Vector items = new Vector();

	public Inventory() {
	  items.addElement(new Item("Antique broach",
						"from the early 1700's",
						(float)1238.99));

	// more items like the one above ...
	}
	public Iterator getItems() {
		return items.iterator();
	}
	public void printXml(PrintStream s) {
		s.println("<inventory>");

		Iterator it = getItems();
		while(it.hasNext()) {
			Item item = (Item)it.next();
			item.printXml(s, 1);
		}
		s.println("</inventory>");
}
}

About the Author

David Geary was the lead engineer for the Java Management API GUI toolkit, and is now an independent Java consultant. David is the author of Graphic Java—Mastering the JFC. He can be contacted at [email protected].