Frames | No Frames |
1: /* =========================================================== 2: * JFreeChart : a free chart library for the Java(tm) platform 3: * =========================================================== 4: * 5: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. 6: * 7: * Project Info: http://www.jfree.org/jfreechart/index.html 8: * 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. 13: * 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. 18: * 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, 22: * USA. 23: * 24: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25: * in the United States and other countries.] 26: * 27: * ---------------- 28: * RootHandler.java 29: * ---------------- 30: * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): -; 34: * 35: * $Id: RootHandler.java,v 1.3.2.1 2005/10/25 21:36:10 mungady Exp $ 36: * 37: * Changes 38: * ------- 39: * 23-Jan-2003 : Version 1 (DG); 40: * 41: */ 42: 43: package org.jfree.data.xml; 44: 45: import java.util.Stack; 46: 47: import org.xml.sax.SAXException; 48: import org.xml.sax.helpers.DefaultHandler; 49: 50: /** 51: * A SAX handler that delegates work to sub-handlers. 52: */ 53: public class RootHandler extends DefaultHandler implements DatasetTags { 54: 55: /** The sub-handlers. */ 56: private Stack subHandlers; 57: 58: /** 59: * Creates a new handler. 60: */ 61: public RootHandler() { 62: this.subHandlers = new Stack(); 63: } 64: 65: /** 66: * Returns the stack of sub handlers. 67: * 68: * @return The sub-handler stack. 69: */ 70: public Stack getSubHandlers() { 71: return this.subHandlers; 72: } 73: 74: /** 75: * Receives some (or all) of the text in the current element. 76: * 77: * @param ch character buffer. 78: * @param start the start index. 79: * @param length the length of the valid character data. 80: * 81: * @throws SAXException for errors. 82: */ 83: public void characters(char[] ch, int start, int length) 84: throws SAXException { 85: DefaultHandler handler = getCurrentHandler(); 86: if (handler != this) { 87: handler.characters(ch, start, length); 88: } 89: } 90: 91: /** 92: * Returns the handler at the top of the stack. 93: * 94: * @return The handler. 95: */ 96: public DefaultHandler getCurrentHandler() { 97: DefaultHandler result = this; 98: if (this.subHandlers != null) { 99: if (this.subHandlers.size() > 0) { 100: Object top = this.subHandlers.peek(); 101: if (top != null) { 102: result = (DefaultHandler) top; 103: } 104: } 105: } 106: return result; 107: } 108: 109: /** 110: * Pushes a sub-handler onto the stack. 111: * 112: * @param subhandler the sub-handler. 113: */ 114: public void pushSubHandler(DefaultHandler subhandler) { 115: this.subHandlers.push(subhandler); 116: } 117: 118: /** 119: * Pops a sub-handler from the stack. 120: * 121: * @return The sub-handler. 122: */ 123: public DefaultHandler popSubHandler() { 124: return (DefaultHandler) this.subHandlers.pop(); 125: } 126: 127: }