1
/* ========================================================================
2
* JCommon : a free general purpose class library for the Java(tm) platform
3
* ========================================================================
5
* (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
7
* Project Info: http://www.jfree.org/jcommon/index.html
9
* This library is free software; you can redistribute it and/or modify it
10
* under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation; either version 2.1 of the License, or
12
* (at your option) any later version.
14
* This library is distributed in the hope that it will be useful, but
15
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
* License for more details.
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with this library; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25
* in the United States and other countries.]
27
* --------------------
28
* ListReadHandler.java
29
* --------------------
30
* (C)opyright 2003, 2004, by Thomas Morgner and Contributors.
32
* Original Author: Thomas Morgner;
33
* Contributor(s): David Gilbert (for Object Refinery Limited);
35
* $Id: ListReadHandler.java,v 1.3 2005/10/18 13:33:32 mungady Exp $
39
* 12-Nov-2003 : Initial version (TM);
43
package org.jfree.xml.parser.coretypes;
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;
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;
58
* A SAX handler for reading a list from an XML element.
60
public class ListReadHandler extends AbstractXmlReadHandler {
62
/** The list under construction. */
66
private ArrayList handlers;
68
/** The type of list ('array-list', 'linked-list', 'stack', 'vector'). */
69
private String listType;
72
* Default constructor.
74
public ListReadHandler() {
81
* @param attrs the attributes.
83
* @throws SAXException if there is a parsing error.
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";
90
this.handlers = new ArrayList();
94
* Gets a handler for a child.
96
* @param tagName the tag name.
97
* @param atts the attributes.
101
* @throws XmlReaderException if there is a problem with the reader.
102
* @throws SAXException if there is a parsing error.
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);
112
* Parsing is finished.
114
* @throws SAXException if there is a parsing error.
115
* @throws XmlReaderException if there is a problem with the reader.
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());
125
this.handlers.clear();
131
* @param initialSize the initial size.
133
* @return A new list.
135
private List createList(final int initialSize) {
136
if (this.listType.equals("stack")) {
139
if (this.listType.equals("linked-list")) {
140
return new LinkedList();
142
if (this.listType.equals("vector")) {
143
return new Vector(initialSize);
145
return new ArrayList(initialSize);
149
* Returns the object under construction.
153
public Object getObject() {