KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > data > xml > RootHandler


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 License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * ----------------
27  * RootHandler.java
28  * ----------------
29  * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: RootHandler.java,v 1.3 2005/02/13 22:07:34 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 23-Jan-2003 : Version 1 (DG);
39  *
40  */

41
42 package org.jfree.data.xml;
43
44 import java.util.Stack JavaDoc;
45
46 import org.xml.sax.SAXException JavaDoc;
47 import org.xml.sax.helpers.DefaultHandler JavaDoc;
48
49 /**
50  * A SAX handler that delegates work to sub-handlers.
51  */

52 public class RootHandler extends DefaultHandler JavaDoc implements DatasetTags {
53
54     /** The sub-handlers. */
55     private Stack JavaDoc subHandlers;
56
57     /**
58      * Creates a new handler.
59      */

60     public RootHandler() {
61         this.subHandlers = new Stack JavaDoc();
62     }
63
64     /**
65      * Returns the stack of sub handlers.
66      *
67      * @return The sub-handler stack.
68      */

69     public Stack JavaDoc getSubHandlers() {
70         return this.subHandlers;
71     }
72
73     /**
74      * Receives some (or all) of the text in the current element.
75      *
76      * @param ch character buffer.
77      * @param start the start index.
78      * @param length the length of the valid character data.
79      *
80      * @throws SAXException for errors.
81      */

82     public void characters(char[] ch, int start, int length)
83         throws SAXException JavaDoc {
84         DefaultHandler JavaDoc handler = getCurrentHandler();
85         if (handler != this) {
86             handler.characters(ch, start, length);
87         }
88     }
89
90     /**
91      * Returns the handler at the top of the stack.
92      *
93      * @return The handler.
94      */

95     public DefaultHandler JavaDoc getCurrentHandler() {
96         DefaultHandler JavaDoc result = this;
97         if (this.subHandlers != null) {
98             if (this.subHandlers.size() > 0) {
99                 Object JavaDoc top = this.subHandlers.peek();
100                 if (top != null) {
101                     result = (DefaultHandler JavaDoc) top;
102                 }
103             }
104         }
105         return result;
106     }
107
108     /**
109      * Pushes a sub-handler onto the stack.
110      *
111      * @param subhandler the sub-handler.
112      */

113     public void pushSubHandler(DefaultHandler JavaDoc subhandler) {
114         this.subHandlers.push(subhandler);
115     }
116
117     /**
118      * Pops a sub-handler from the stack.
119      *
120      * @return The sub-handler.
121      */

122     public DefaultHandler JavaDoc popSubHandler() {
123         return (DefaultHandler JavaDoc) this.subHandlers.pop();
124     }
125
126 }
127
Popular Tags