1 41 42 package org.jfree.data.xml; 43 44 import org.xml.sax.Attributes ; 45 import org.xml.sax.SAXException ; 46 import org.xml.sax.helpers.DefaultHandler ; 47 48 51 public class ItemHandler extends DefaultHandler implements DatasetTags { 52 53 54 private RootHandler root; 55 56 57 private DefaultHandler parent; 58 59 60 private Comparable key; 61 62 63 private Number value; 64 65 71 public ItemHandler(RootHandler root, DefaultHandler parent) { 72 this.root = root; 73 this.parent = parent; 74 this.key = null; 75 this.value = null; 76 } 77 78 83 public Comparable getKey() { 84 return this.key; 85 } 86 87 92 public void setKey(Comparable key) { 93 this.key = key; 94 } 95 96 101 public Number getValue() { 102 return this.value; 103 } 104 105 110 public void setValue(Number value) { 111 this.value = value; 112 } 113 114 124 public void startElement(String namespaceURI, 125 String localName, 126 String qName, 127 Attributes atts) throws SAXException { 128 129 if (qName.equals(ITEM_TAG)) { 130 KeyHandler subhandler = new KeyHandler(this.root, this); 131 this.root.pushSubHandler(subhandler); 132 } 133 else if (qName.equals(VALUE_TAG)) { 134 ValueHandler subhandler = new ValueHandler(this.root, this); 135 this.root.pushSubHandler(subhandler); 136 } 137 else { 138 throw new SAXException ( 139 "Expected <Item> or <Value>...found " + qName 140 ); 141 } 142 143 } 144 145 152 public void endElement(String namespaceURI, 153 String localName, 154 String qName) { 155 156 if (this.parent instanceof PieDatasetHandler) { 157 PieDatasetHandler handler = (PieDatasetHandler) this.parent; 158 handler.addItem(this.key, this.value); 159 this.root.popSubHandler(); 160 } 161 else if (this.parent instanceof CategorySeriesHandler) { 162 CategorySeriesHandler handler = (CategorySeriesHandler) this.parent; 163 handler.addItem(this.key, this.value); 164 this.root.popSubHandler(); 165 } 166 167 } 168 169 } 170 | Popular Tags |