1 42 43 package org.jfree.xml.parser.coretypes; 44 45 import java.util.ArrayList ; 46 import java.util.LinkedList ; 47 import java.util.List ; 48 import java.util.Stack ; 49 import java.util.Vector ; 50 51 import org.jfree.xml.parser.AbstractXmlReadHandler; 52 import org.jfree.xml.parser.XmlReadHandler; 53 import org.jfree.xml.parser.XmlReaderException; 54 import org.xml.sax.Attributes ; 55 import org.xml.sax.SAXException ; 56 57 60 public class ListReadHandler extends AbstractXmlReadHandler { 61 62 63 private List retval; 64 65 66 private ArrayList handlers; 67 68 69 private String listType; 70 71 74 public ListReadHandler() { 75 super(); 76 } 77 78 85 protected void startParsing(final Attributes attrs) throws SAXException { 86 this.listType = attrs.getValue("type"); 87 if (this.listType == null) { 88 this.listType = "array-list"; 89 } 90 this.handlers = new ArrayList (); 91 } 92 93 104 protected XmlReadHandler getHandlerForChild(final String tagName, final Attributes atts) 105 throws XmlReaderException, SAXException { 106 final XmlReadHandler handler = getRootHandler().createHandler(Object .class, tagName, atts); 107 this.handlers.add(handler); 108 return handler; 109 } 110 111 118 protected void doneParsing() throws SAXException , XmlReaderException { 119 final XmlReadHandler[] handler = (XmlReadHandler[]) 120 this.handlers.toArray(new XmlReadHandler[this.handlers.size()]); 121 this.retval = createList(handler.length); 122 for (int i = 0; i < handler.length; i++) { 123 this.retval.add(handler[i].getObject()); 124 } 125 this.handlers.clear(); 126 } 127 128 135 private List createList(final int initialSize) { 136 if (this.listType.equals("stack")) { 137 return new Stack (); 138 } 139 if (this.listType.equals("linked-list")) { 140 return new LinkedList (); 141 } 142 if (this.listType.equals("vector")) { 143 return new Vector (initialSize); 144 } 145 return new ArrayList (initialSize); 146 } 147 148 153 public Object getObject() { 154 return this.retval; 155 } 156 157 } 158 | Popular Tags |