1 package org.oddjob.designer.arooa; 2 3 import org.oddjob.arooa.ArooaException; 4 import org.oddjob.arooa.ArooaHandler; 5 import org.oddjob.arooa.ArooaContext; 6 import org.oddjob.arooa.ArooaConstants; 7 import org.oddjob.arooa.reflect.IntrospectionHelper; 8 import org.oddjob.designer.model.DesignAdult; 9 import org.oddjob.designer.model.DesignElementType; 10 import org.xml.sax.Attributes ; 11 import org.xml.sax.SAXParseException ; 12 13 14 17 public class DesignElementHandler extends ArooaHandler { 18 19 23 public void onStartElement(String uri, String tag, String qname, 24 Attributes attrs, 25 ArooaContext context) 26 throws SAXParseException { 27 28 Object parent = context.getParent().get( 29 ArooaConstants.CURRENTLY_CONFIGURING); 30 if (parent instanceof DesignAdult) { 31 Object element = ((DesignAdult)parent).createType(tag); 32 if (element == null) { 33 throw new ArooaException("Class [" + parent.getClass() 34 + "] doesn't support the element [" + tag + "]"); 35 } 36 HandlerUtils.setAttributes(uri, attrs, element); 37 context.set(ArooaConstants.CURRENTLY_CONFIGURING, element); 38 } 39 else { 40 throw new ArooaException("Parent of element [" + tag 41 + "], class [" + parent.getClass() 42 + "] must be an instance of DesignAdult"); 43 } 44 } 45 46 50 public void characters(char[] buf, int start, int count, 51 ArooaContext context) 52 throws SAXParseException { 53 Object object = context.get(ArooaConstants.CURRENTLY_CONFIGURING); 54 IntrospectionHelper ih = IntrospectionHelper.getHelper(object.getClass()); 55 ih.addText(object, new String (buf, start, count)); 56 } 57 58 62 public ArooaHandler onStartChild(String uri, String tag, String qname, 63 Attributes attrs, 64 ArooaContext context) 65 throws SAXParseException { 66 Object object = context.get(ArooaConstants.CURRENTLY_CONFIGURING); 67 68 IntrospectionHelper ih = IntrospectionHelper.getHelper(object.getClass()); 69 return ih.provideHandler(object, tag, context); 70 } 71 72 76 public void onEndElement(String uri, String tag, ArooaContext context) { 77 DesignElementType object = (DesignElementType) context.get( 78 ArooaConstants.CURRENTLY_CONFIGURING); 79 DesignAdult parent = (DesignAdult) context.getParent().get( 80 ArooaConstants.CURRENTLY_CONFIGURING); 81 82 parent.addChild(object); 83 } 84 } 85 | Popular Tags |