KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > arooa > handlers > TypicalElementHandler


1 package org.oddjob.arooa.handlers;
2
3 import org.oddjob.arooa.ArooaHandler;
4 import org.oddjob.arooa.ArooaContext;
5 import org.oddjob.arooa.ArooaConstants;
6 import org.oddjob.arooa.RuntimeConfiguration;
7 import org.oddjob.arooa.reflect.IntrospectionHelper;
8 import org.xml.sax.Attributes JavaDoc;
9 import org.xml.sax.SAXParseException JavaDoc;
10
11 /**
12  * Abstract Base Class for handlers which handle text and and child
13  * elements in the same way. Only the onStartElement method will differ in
14  * subclasses.
15  *
16  * @see ArooaHandler
17  * @author Rob Gordon
18  */

19
20 abstract public class TypicalElementHandler extends ArooaHandler {
21     
22     abstract public void onStartElement(String JavaDoc uri, String JavaDoc tag, String JavaDoc qname,
23                Attributes JavaDoc attrs,
24                ArooaContext context) throws SAXParseException JavaDoc;
25     
26     /**
27      * Adds text to the component, using the wrapper
28      *
29      * @param buf A character array of the text within the element.
30      * Will not be <code>null</code>.
31      * @param start The start element in the array.
32      * @param count The number of characters to read from the array.
33      * @param context The current context.
34      *
35      * @exception SAXParseException if the element doesn't support text
36      *
37      */

38     public void characters(char[] buf, int start, int count,
39                            ArooaContext context)
40         throws SAXParseException JavaDoc {
41         RuntimeConfiguration wrapper =
42             (RuntimeConfiguration)context.get(ArooaConstants.CURRENTLY_CONFIGURING);
43         wrapper.addText(buf, start, count);
44     }
45
46     /**
47      * Handle a child tag.
48      *
49      * @param uri The namespace uri.
50      * @param name The element tag.
51      * @param qname The element qualified name.
52      * @param attrs The attributes of the element.
53      * @param context The current context.
54      * @return The handler that handles this subelement.
55      * @exception SAXParseException if the qualified name is not "project".
56      */

57     public ArooaHandler onStartChild(String JavaDoc uri, String JavaDoc tag, String JavaDoc qname,
58                                    Attributes JavaDoc attrs,
59                                    ArooaContext context)
60             throws SAXParseException JavaDoc {
61         RuntimeConfiguration currentWrapper
62             = (RuntimeConfiguration ) context.get(
63                     ArooaConstants.CURRENTLY_CONFIGURING);
64         Object JavaDoc object = currentWrapper.getWrappedObject();
65         
66         IntrospectionHelper ih = IntrospectionHelper.getHelper(object.getClass());
67         ArooaHandler nextHandler = ih.provideHandler(object, tag, context);
68         if (nextHandler == null) {
69             throw new IllegalStateException JavaDoc("No handler for [" + tag
70                     + "] in object [" + currentWrapper.getWrappedObject() + "]");
71         }
72         return nextHandler;
73     }
74         
75 }
76
77  
Popular Tags