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 ; 10 import org.xml.sax.SAXParseException ; 11 12 13 16 public class DesignSkipHandler extends ArooaHandler { 17 18 private DesignElementType introduce; 19 20 public DesignSkipHandler(DesignElementType introduce) { 21 this.introduce = introduce; 22 } 23 24 28 public void onStartElement(String uri, String tag, String qname, 29 Attributes attrs, 30 ArooaContext context) 31 throws SAXParseException { 32 33 Object parent = context.getParent().get( 34 ArooaConstants.CURRENTLY_CONFIGURING); 35 if (!(parent instanceof DesignAdult)) { 36 throw new SAXParseException ("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 ("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 ("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 61 public ArooaHandler onStartChild(String uri, String tag, String qname, 62 Attributes attrs, 63 ArooaContext context) 64 throws SAXParseException { 65 Object object = context.get(ArooaConstants.CURRENTLY_CONFIGURING); 66 67 IntrospectionHelper ih = IntrospectionHelper.getHelper(object.getClass()); 68 return ih.provideHandler(object, tag, context); 69 } 70 71 75 public void onEndElement(String uri, String 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 elementName = (String ) context.get(ArooaConstants.ELEMENT_NAME); 82 IntrospectionHelper ih = IntrospectionHelper.getHelper(parent.getClass()); 83 ih.storeConfiguredElement(parent, object, elementName); 84 } 85 } 86 | Popular Tags |