1 41 42 package org.jfree.data.xml; 43 44 import java.util.Iterator ; 45 46 import org.jfree.data.DefaultKeyedValues; 47 import org.xml.sax.Attributes ; 48 import org.xml.sax.SAXException ; 49 import org.xml.sax.helpers.DefaultHandler ; 50 51 54 public class CategorySeriesHandler extends DefaultHandler 55 implements DatasetTags { 56 57 58 private RootHandler root; 59 60 61 private Comparable seriesKey; 62 63 64 private DefaultKeyedValues values; 65 66 71 public CategorySeriesHandler(RootHandler root) { 72 this.root = root; 73 this.values = new DefaultKeyedValues(); 74 } 75 76 81 public void setSeriesKey(Comparable key) { 82 this.seriesKey = key; 83 } 84 85 91 public void addItem(Comparable key, final Number value) { 92 this.values.addValue(key, value); 93 } 94 95 105 public void startElement(String namespaceURI, 106 String localName, 107 String qName, 108 Attributes atts) throws SAXException { 109 110 if (qName.equals(SERIES_TAG)) { 111 setSeriesKey(atts.getValue("key")); 112 ItemHandler subhandler = new ItemHandler(this.root, this); 113 this.root.pushSubHandler(subhandler); 114 } 115 else if (qName.equals(ITEM_TAG)) { 116 ItemHandler subhandler = new ItemHandler(this.root, this); 117 this.root.pushSubHandler(subhandler); 118 subhandler.startElement(namespaceURI, localName, qName, atts); 119 } 120 121 else { 122 throw new SAXException ( 123 "Expecting <Series> or <Item> tag...found " + qName 124 ); 125 } 126 } 127 128 135 public void endElement(String namespaceURI, 136 String localName, 137 String qName) { 138 139 if (this.root instanceof CategoryDatasetHandler) { 140 CategoryDatasetHandler handler = (CategoryDatasetHandler) this.root; 141 142 Iterator iterator = this.values.getKeys().iterator(); 143 while (iterator.hasNext()) { 144 Comparable key = (Comparable ) iterator.next(); 145 Number value = this.values.getValue(key); 146 handler.addItem(this.seriesKey, key, value); 147 } 148 149 this.root.popSubHandler(); 150 } 151 152 } 153 154 } 155 | Popular Tags |