01: import java.util.ArrayList;
02: import org.w3c.dom.DOMImplementation;
03: import org.w3c.dom.Document;
04: import org.w3c.dom.ls.DOMImplementationLS;
05: import org.w3c.dom.ls.LSSerializer;
06: 
07: /**
08:    This program tests the item list builder. It prints the XML file 
09:    corresponding to a DOM document containing a list of items.
10: */
11: public class ItemListBuilderTester
12: {
13:    public static void main(String[] args) throws Exception
14:    {
15:       ArrayList<LineItem> items = new ArrayList<LineItem>();
16:       items.add(new LineItem(new Product("Toaster", 29.95), 3));
17:       items.add(new LineItem(new Product("Hair dryer", 24.95), 1));
18: 
19:       ItemListBuilder builder = new ItemListBuilder();
20:       Document doc = builder.build(items);         
21:       DOMImplementation impl = doc.getImplementation();
22:       DOMImplementationLS implLS 
23:             = (DOMImplementationLS) impl.getFeature("LS", "3.0");
24:       LSSerializer ser = implLS.createLSSerializer();
25:       String out = ser.writeToString(doc);
26:       
27:       System.out.println(out);
28:    }
29: }