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.reflect.BeanUtilsHelper; 7 import org.oddjob.arooa.reflect.IntrospectionHelper; 8 import org.xml.sax.Attributes ; 9 import org.xml.sax.SAXParseException ; 10 11 18 19 public class DesignValueHandler extends ArooaHandler { 20 21 35 public void onStartElement(String uri, String tag, String qname, 36 Attributes attrs, 37 ArooaContext context) 38 throws SAXParseException { 39 40 Object valueObj = null; 41 42 Object parent = context.get(ArooaConstants.CURRENTLY_CONFIGURING); 43 IntrospectionHelper pih = IntrospectionHelper.getHelper(parent.getClass()); 44 Class attributeClass = pih.getAttributeType(tag); 45 try { 46 valueObj = attributeClass.newInstance(); 47 } catch (Exception e) { 48 throw new SAXParseException ("No way to create inline attribute class [" + attributeClass 49 + "] at element [" + qname + "]", context.getLocator()); 50 } 51 52 IntrospectionHelper ih = IntrospectionHelper.getHelper(valueObj.getClass()); 53 54 HandlerUtils.setAttributes(uri, attrs, valueObj); 55 56 context.set(ArooaConstants.CURRENTLY_CONFIGURING, valueObj); 57 } 58 59 71 public void characters(char[] buf, int start, int count, 72 ArooaContext context) 73 throws SAXParseException { 74 Object obj 75 = context.get(ArooaConstants.CURRENTLY_CONFIGURING); 76 IntrospectionHelper ih = IntrospectionHelper.getHelper(obj.getClass()); 77 ih.addText(obj, new String (buf, start, count)); 78 } 79 80 91 public ArooaHandler onStartChild(String uri, String tag, String qname, 92 Attributes attrs, 93 ArooaContext context) 94 throws SAXParseException { 95 Object object = context.get( 96 ArooaConstants.CURRENTLY_CONFIGURING); 97 98 IntrospectionHelper ih = IntrospectionHelper.getHelper(object.getClass()); 99 return ih.provideHandler(object, tag, context); 100 } 101 102 public void onEndElement(String uri, String tag, 103 ArooaContext context) { 104 105 Object valueObj = context.get( 106 ArooaConstants.CURRENTLY_CONFIGURING); 107 Object parent = context.getParent().get( 108 ArooaConstants.CURRENTLY_CONFIGURING); 109 110 BeanUtilsHelper.setProperty(parent, tag, valueObj); 111 112 } 113 } 114 115 | Popular Tags |