KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > designer > arooa > DesignStartHandler


1 package org.oddjob.designer.arooa;
2
3 import org.oddjob.arooa.ArooaHandler;
4 import org.oddjob.arooa.ArooaContext;
5 import org.oddjob.arooa.ArooaConstants;
6 import org.oddjob.arooa.Lifecycle;
7 import org.oddjob.arooa.reflect.IntrospectionHelper;
8 import org.xml.sax.Attributes JavaDoc;
9 import org.xml.sax.SAXParseException JavaDoc;
10
11 /**
12  * Handles the document element. This handler behaves just like
13  * a component handler except that it doesn't create a component,
14  * the root component must have been provided. Likewise it
15  * doesn't attempt to add the component to any parent because there
16  * is none. The id attribute and other attributes
17  * are processed as per the ComponentHandler.
18  *
19  * @see ArooaHandler.
20  * @author Rob Gordon.
21  */

22 public class DesignStartHandler extends ArooaHandler {
23
24     /** The root object */
25     private final Object JavaDoc rootComponent;
26     /**
27     
28     /**
29      * Constructor.
30      *
31      * @param rootObject The root object which is to be built up.
32      */

33     public DesignStartHandler(Object JavaDoc rootObject) {
34         this.rootComponent = rootObject;
35     }
36     
37     /**
38      * Handle the top level element.
39      *
40      * @param uri The namespace uri.
41      * @param name The element tag.
42      * @param qname The element qualified name.
43      * @param attrs The attributes of the element.
44      * @param context The current context.
45      * @return The handler that handles the top level elelement.
46      * @exception SAXParseException if the qualified name is not "project".
47      */

48     public void onStartElement(String JavaDoc uri, String JavaDoc tag, String JavaDoc qname,
49                                    Attributes JavaDoc attrs,
50                                    ArooaContext context)
51             throws SAXParseException JavaDoc {
52
53         HandlerUtils.setAttributes(uri, attrs, rootComponent);
54         
55         context.set(ArooaConstants.CURRENTLY_CONFIGURING, rootComponent);
56     }
57
58     /**
59      * Handle a child tag.
60      *
61      * @param uri The namespace uri.
62      * @param name The element tag.
63      * @param qname The element qualified name.
64      * @param attrs The attributes of the element.
65      * @param context The current context.
66      * @return The handler that handles this subelement.
67      * @exception SAXParseException if the qualified name is not "project".
68      */

69     public ArooaHandler onStartChild(String JavaDoc uri, String JavaDoc name, String JavaDoc qname,
70             Attributes JavaDoc attrs,
71             ArooaContext context)
72     throws SAXParseException JavaDoc {
73         IntrospectionHelper ih = IntrospectionHelper.getHelper(rootComponent.getClass());
74         return ih.provideHandler(rootComponent, name, context);
75     }
76     
77     /**
78      * Adds text to the component, using the wrapper
79      *
80      * @param buf A character array of the text within the element.
81      * Will not be <code>null</code>.
82      * @param start The start element in the array.
83      * @param count The number of characters to read from the array.
84      * @param context The current context.
85      *
86      * @exception SAXParseException if the element doesn't support text
87      *
88      */

89     public void characters(char[] buf, int start, int count,
90                            ArooaContext context)
91         throws SAXParseException JavaDoc {
92         IntrospectionHelper ih = IntrospectionHelper.getHelper(rootComponent.getClass());
93         ih.addText(rootComponent, new String JavaDoc(buf, start, count));
94     }
95
96     /**
97      * Handles the end of the element.
98      *
99      * @param uri The namespace URI for the element.
100      * @param tag The name of the element.
101      * @param context The current context.
102      */

103     public void onEndElement(String JavaDoc uri, String JavaDoc tag, ArooaContext context) {
104         Lifecycle.init(rootComponent);
105     }
106         
107 }
108
109  
Popular Tags