KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.oddjob.designer.arooa;
2
3 import org.oddjob.arooa.ArooaConstants;
4 import org.oddjob.arooa.ArooaContext;
5 import org.oddjob.arooa.ArooaHandler;
6 import org.oddjob.arooa.reflect.IntrospectionHelper;
7 import org.oddjob.designer.model.DesignAdult;
8 import org.oddjob.designer.model.DesignElementType;
9 import org.xml.sax.Attributes JavaDoc;
10 import org.xml.sax.SAXParseException JavaDoc;
11
12
13 /**
14  * Handler for a nested element that skips a level.
15  */

16 public class DesignSkipHandler extends ArooaHandler {
17
18     private DesignElementType introduce;
19     
20     public DesignSkipHandler(DesignElementType introduce) {
21         this.introduce = introduce;
22     }
23     
24     /*
25      * (non-Javadoc)
26      * @see org.oddjob.arooa.ArooaHandler#onStartElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes, org.oddjob.arooa.ArooaXMLContext)
27      */

28     public void onStartElement(String JavaDoc uri, String JavaDoc tag, String JavaDoc qname,
29                                Attributes JavaDoc attrs,
30                                ArooaContext context)
31     throws SAXParseException JavaDoc {
32         
33         Object JavaDoc parent = context.getParent().get(
34                 ArooaConstants.CURRENTLY_CONFIGURING);
35         if (!(parent instanceof DesignAdult)) {
36             throw new SAXParseException JavaDoc("Parent of element [" + tag
37                     + "], class [" + parent.getClass()
38                     + "] must be an instance of DesignAdult.", context.getLocator());
39         }
40         
41         if (attrs.getLength() > 0) {
42             throw new SAXParseException JavaDoc("Element [" + tag
43                     + "], class [" + parent.getClass()
44                     + "] is not expected to have attributes.", context.getLocator());
45         }
46  
47         if (context.get(ArooaConstants.ELEMENT_NAME) == null) {
48             throw new SAXParseException JavaDoc("Element [" + tag
49                     + "], class [" + parent.getClass()
50                     + "] must set ELEMENT_NAME to use this handler.", context.getLocator());
51         }
52         
53         context.set(ArooaConstants.CURRENTLY_CONFIGURING, introduce);
54     }
55
56
57     /*
58      * (non-Javadoc)
59      * @see org.oddjob.arooa.ArooaHandler#onStartChild(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes, org.oddjob.arooa.ArooaXMLContext)
60      */

61     public ArooaHandler onStartChild(String JavaDoc uri, String JavaDoc tag, String JavaDoc qname,
62                                    Attributes JavaDoc attrs,
63                                    ArooaContext context)
64     throws SAXParseException JavaDoc {
65         Object JavaDoc object = context.get(ArooaConstants.CURRENTLY_CONFIGURING);
66         
67         IntrospectionHelper ih = IntrospectionHelper.getHelper(object.getClass());
68         return ih.provideHandler(object, tag, context);
69     }
70
71     /*
72      * (non-Javadoc)
73      * @see org.oddjob.arooa.ArooaHandler#onEndElement(java.lang.String, java.lang.String, org.oddjob.arooa.ArooaXMLContext)
74      */

75     public void onEndElement(String JavaDoc uri, String JavaDoc tag, ArooaContext context) {
76         DesignElementType object = (DesignElementType) context.get(
77                 ArooaConstants.CURRENTLY_CONFIGURING);
78         DesignAdult parent = (DesignAdult) context.getParent().get(
79                 ArooaConstants.CURRENTLY_CONFIGURING);
80
81         String JavaDoc elementName = (String JavaDoc) context.get(ArooaConstants.ELEMENT_NAME);
82         IntrospectionHelper ih = IntrospectionHelper.getHelper(parent.getClass());
83         ih.storeConfiguredElement(parent, object, elementName);
84     }
85 }
86
Popular Tags