001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * ---------------------------
028: * CategoryDatasetHandler.java
029: * ---------------------------
030: * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: CategoryDatasetHandler.java,v 1.3.2.1 2005/10/25 21:36:10 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 23-Jan-2003 : Version 1 (DG);
040: *
041: */
042:
043: package org.jfree.data.xml;
044:
045: import org.jfree.data.category.CategoryDataset;
046: import org.jfree.data.category.DefaultCategoryDataset;
047: import org.xml.sax.Attributes;
048: import org.xml.sax.SAXException;
049: import org.xml.sax.helpers.DefaultHandler;
050:
051: /**
052: * A SAX handler for reading a {@link CategoryDataset} from an XML file.
053: */
054: public class CategoryDatasetHandler extends RootHandler implements
055: DatasetTags {
056:
057: /** The dataset under construction. */
058: private DefaultCategoryDataset dataset;
059:
060: /**
061: * Creates a new handler.
062: */
063: public CategoryDatasetHandler() {
064: this .dataset = null;
065: }
066:
067: /**
068: * Returns the dataset.
069: *
070: * @return The dataset.
071: */
072: public CategoryDataset getDataset() {
073: return this .dataset;
074: }
075:
076: /**
077: * Adds an item to the dataset.
078: *
079: * @param rowKey the row key.
080: * @param columnKey the column key.
081: * @param value the value.
082: */
083: public void addItem(Comparable rowKey, Comparable columnKey,
084: Number value) {
085: this .dataset.addValue(value, rowKey, columnKey);
086: }
087:
088: /**
089: * The start of an element.
090: *
091: * @param namespaceURI the namespace.
092: * @param localName the element name.
093: * @param qName the element name.
094: * @param atts the element attributes.
095: *
096: * @throws SAXException for errors.
097: */
098: public void startElement(String namespaceURI, String localName,
099: String qName, Attributes atts) throws SAXException {
100:
101: DefaultHandler current = getCurrentHandler();
102: if (current != this ) {
103: current.startElement(namespaceURI, localName, qName, atts);
104: } else if (qName.equals(CATEGORYDATASET_TAG)) {
105: this .dataset = new DefaultCategoryDataset();
106: } else if (qName.equals(SERIES_TAG)) {
107: CategorySeriesHandler subhandler = new CategorySeriesHandler(
108: this );
109: getSubHandlers().push(subhandler);
110: subhandler.startElement(namespaceURI, localName, qName,
111: atts);
112: } else {
113: throw new SAXException("Element not recognised: " + qName);
114: }
115:
116: }
117:
118: /**
119: * The end of an element.
120: *
121: * @param namespaceURI the namespace.
122: * @param localName the element name.
123: * @param qName the element name.
124: *
125: * @throws SAXException for errors.
126: */
127: public void endElement(String namespaceURI, String localName,
128: String qName) throws SAXException {
129:
130: DefaultHandler current = getCurrentHandler();
131: if (current != this) {
132: current.endElement(namespaceURI, localName, qName);
133: }
134:
135: }
136:
137: }
|