1 package org.oddjob.arooa.handlers; 2 3 import org.oddjob.arooa.ArooaHandler; 4 import org.oddjob.arooa.ArooaContext; 5 import org.oddjob.arooa.ArooaConstants; 6 import org.oddjob.arooa.ArooaRuntime; 7 import org.oddjob.arooa.PropertyProxyResolver; 8 import org.oddjob.arooa.SimpleObjectFactory; 9 import org.xml.sax.Attributes ; 10 import org.xml.sax.SAXParseException ; 11 12 30 31 public class NestedPropertyHandler extends TypicalElementHandler { 32 33 47 public void onStartElement(String uri, String tag, String qname, 48 Attributes attrs, 49 ArooaContext context) 50 throws SAXParseException { 51 Object valueObj = null; 52 AttributeHelper ah = new AttributeHelper(uri, attrs); 53 54 String className = ah.remove("class"); 55 if (className != null) { 57 try { 58 valueObj = SimpleObjectFactory.createObjectFromClass(className); 59 } 60 catch (Exception e) { 61 throw new SAXParseException ("Could not create object of class" 62 + className + " for type \"" + tag + "\" (" 63 + e.getMessage() + ")", context.getLocator(), e); 64 } 65 } 66 67 ArooaRuntime parentWrapper = 68 (ArooaRuntime) context.get( 69 ArooaConstants.CURRENTLY_CONFIGURING); 70 Object parent = parentWrapper.getWrappedObject(); 71 72 if (valueObj == null) { 73 PropertyProxyResolver pr = (PropertyProxyResolver) context.get(ArooaConstants.PROPERTY_PROXY_RESOLVER); 74 if (pr == null) { 75 throw new IllegalStateException ("PropertyProxyResolver is missing!"); 76 } 77 try { 78 valueObj = pr.proxyFor(parent, tag); 79 } catch (Exception e) { 80 throw new SAXParseException ("Failed to create value for \"" + qname 81 + "\" (" + e.getMessage() + ")", context.getLocator(), e); 82 } 83 } 84 if (valueObj == null) { 85 throw new SAXParseException ("There is no way to configure the attribute \"" + qname 86 + "\" as an inline element.", context.getLocator()); 87 } 88 89 final ArooaRuntime wrapper = new ArooaRuntime(valueObj, tag, context); 90 ah.process(new AttributeHelper.Processor() { 91 public void process(String name, String value) { 92 wrapper.setAttribute(name, value); 93 } 94 }); 95 96 parentWrapper.setAttribute( 97 (String )context.getParent().get(ArooaConstants.ELEMENT_NAME), wrapper); 98 99 context.set(ArooaConstants.CURRENTLY_CONFIGURING, wrapper); 100 } 101 102 103 } 104 105 | Popular Tags |