KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.oddjob.arooa.handlers;
2
3 import org.oddjob.arooa.ArooaContext;
4 import org.oddjob.arooa.ArooaConstants;
5 import org.oddjob.arooa.ArooaRuntime;
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 /**
13  * Handler for a nested element.
14  */

15 public class NestedElementHandler extends TypicalElementHandler {
16         
17     /**
18      * Initialisation routine called after handler creation
19      * with the element name and attributes. This configures
20      * the element with its attributes and sets it up with
21      * its parent container (if any). Nested elements are then
22      * added later as the parser encounters them.
23      *
24      * @param uri The namespace URI for this element.
25      * @param tag Name of the element which caused this handler
26      * to be created. Must not be <code>null</code>.
27      * @param qname The qualified name for this element.
28      * @param attrs Attributes of the element which caused this
29      * handler to be created. Must not be <code>null</code>.
30      * @param context The current context.
31      *
32      * @exception SAXParseException in case of error (not thrown in
33      * this implementation)
34      */

35     public void onStartElement(String JavaDoc uri, String JavaDoc tag, String JavaDoc qname,
36                                Attributes JavaDoc attrs,
37                                ArooaContext context)
38             throws SAXParseException JavaDoc {
39         RuntimeConfiguration parentWrapper
40             = (RuntimeConfiguration ) context.getParent().get(
41                     ArooaConstants.CURRENTLY_CONFIGURING);
42         Object JavaDoc parent = parentWrapper.getWrappedObject();
43         IntrospectionHelper ih = IntrospectionHelper.getHelper(parent.getClass());
44
45         Object JavaDoc object = ih.createElement(uri, parent, tag);
46
47         final ArooaRuntime wrapper
48             = new ArooaRuntime(object, tag, context);
49
50         AttributeHelper ah = new AttributeHelper(uri, attrs);
51         
52         ah.process(new AttributeHelper.Processor() {
53             public void process(String JavaDoc name, String JavaDoc value) {
54                 wrapper.setAttribute(name, value);
55             }
56         });
57         
58         parentWrapper.addChild(wrapper);
59         context.set(ArooaConstants.CURRENTLY_CONFIGURING, wrapper);
60     }
61
62 }
63
Popular Tags