KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > arooa > ArooaHandler


1 /*
2  * This source code is heavily based on source code from the Apache
3  * Ant project. As such the following is included:
4  * ------------------------------------------------------------------
5  *
6  * The Apache Software License, Version 1.1
7  *
8  * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
9  * reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * 1. Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * 2. Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in
20  * the documentation and/or other materials provided with the
21  * distribution.
22  *
23  * 3. The end-user documentation included with the redistribution, if
24  * any, must include the following acknowlegement:
25  * "This product includes software developed by the
26  * Apache Software Foundation (http://www.apache.org/)."
27  * Alternately, this acknowlegement may appear in the software itself,
28  * if and wherever such third-party acknowlegements normally appear.
29  *
30  * 4. The names "Ant" and "Apache Software
31  * Foundation" must not be used to endorse or promote products derived
32  * from this software without prior written permission. For written
33  * permission, please contact apache@apache.org.
34  *
35  * 5. Products derived from this software may not be called "Apache"
36  * nor may "Apache" appear in their names without prior written
37  * permission of the Apache Group.
38  *
39  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
40  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
41  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
43  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
46  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
47  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
48  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
49  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  * ====================================================================
52  *
53  * This software consists of voluntary contributions made by many
54  * individuals on behalf of the Apache Software Foundation. For more
55  * information on the Apache Software Foundation, please see
56  * <http://www.apache.org/>.
57  */

58 package org.oddjob.arooa;
59
60 import org.xml.sax.Attributes JavaDoc;
61 import org.xml.sax.SAXParseException JavaDoc;
62
63 /**
64  * The common superclass for all SAX event handlers used to parse
65  * the configuration file.
66  * <p>
67  * The context will hold all state information. At each time
68  * there is one active handler for the current element. It can
69  * use onStartChild() to set an alternate handler for the child.
70  * <p>
71  * Based on the original by <b>duncan@x180.com</b> and <b>Costin Manolache</b>.
72  */

73 public class ArooaHandler {
74
75     /**
76      * Handles the start of an element. This base implementation does
77      * nothing.
78      *
79      * @param uri the namespace URI for the tag
80      * @param tag The name of the element being started.
81      * Will not be <code>null</code>.
82      * @param qname The qualified name of the element.
83      * @param attrs Attributes of the element being started.
84      * Will not be <code>null</code>.
85      * @param context The context that this element is in.
86      *
87      * @exception SAXParseException if this method is not overridden, or in
88      * case of error in an overridden version
89      */

90     public void onStartElement(String JavaDoc uri, String JavaDoc tag, String JavaDoc qname,
91                                Attributes JavaDoc attrs,
92                                ArooaContext context)
93         throws SAXParseException JavaDoc {
94     }
95     
96     /**
97      * Handles the start of an element. This base implementation just
98      * throws an exception - you must override this method if you expect
99      * child elements.
100      *
101      * @param uri The namespace uri for this element.
102      * @param tag The name of the element being started.
103      * Will not be <code>null</code>.
104      * @param qname The qualified name for this element.
105      * @param attrs Attributes of the element being started.
106      * Will not be <code>null</code>.
107      * @param context The current context.
108      * @return a handler (in the derived classes)
109      *
110      * @exception SAXParseException if this method is not overridden, or in
111      * case of error in an overridden version
112      */

113     public ArooaHandler onStartChild(String JavaDoc uri, String JavaDoc tag, String JavaDoc qname,
114                                    Attributes JavaDoc attrs,
115                                    ArooaContext context)
116         throws SAXParseException JavaDoc {
117         throw new SAXParseException JavaDoc("Unexpected element \"" + qname
118             + " \"", context.getLocator());
119     }
120     
121     /**
122      * Handle the end of a element.
123      *
124      * @param uri the namespace uri of the element
125      * @param tag the tag of the element
126      * @param qname the qualified name of the element
127      * @param context the current context
128      * @exception SAXParseException if an error occurs
129      */

130     public void onEndChild(String JavaDoc uri, String JavaDoc tag, String JavaDoc qname,
131                                  ArooaContext context)
132         throws SAXParseException JavaDoc {
133     }
134     
135     /**
136      * Called when this element and all elements nested into it have been
137      * handled (i.e. at the </end_tag_of_the_element> ).
138      * @param uri the namespace uri for this element
139      * @param tag the element name
140      * @param context the current context
141      */

142     public void onEndElement(String JavaDoc uri, String JavaDoc tag,
143                              ArooaContext context) {
144     }
145     
146     /**
147      * Handles text within an element. This base implementation just
148      * throws an exception, you must override it if you expect content.
149      *
150      * @param buf A character array of the text within the element.
151      * Will not be <code>null</code>.
152      * @param start The start element in the array.
153      * @param count The number of characters to read from the array.
154      * @param context The current context.
155      *
156      * @exception SAXParseException if this method is not overridden, or in
157      * case of error in an overridden version
158      */

159     public void characters(char[] buf, int start, int count, ArooaContext context)
160         throws SAXParseException JavaDoc {
161         String JavaDoc s = new String JavaDoc(buf, start, count).trim();
162     
163         if (s.length() > 0) {
164             throw new SAXParseException JavaDoc("Unexpected text \"" + s
165                 + "\"", context.getLocator());
166         }
167     }
168     
169     /**
170      * Will be called every time a namespace is reached.
171      * It'll verify if the ns was processed, and if not load the task
172      * definitions.
173      * @param uri The namespace uri.
174      */

175     protected void checkNamespace(String JavaDoc uri) {
176     
177     }
178 }
179
180
Popular Tags