1 package org.oddjob.arooa.handlers; 2 3 import org.oddjob.arooa.ArooaRuntime; 4 import org.oddjob.arooa.ArooaContext; 5 import org.oddjob.arooa.ArooaConstants; 6 import org.oddjob.arooa.Lifecycle; 7 import org.oddjob.arooa.registry.ComponentRegistry; 8 import org.xml.sax.Attributes ; 9 import org.xml.sax.SAXParseException ; 10 11 26 public class DocumentStartHandler extends TypicalElementHandler { 27 28 29 private final Object rootComponent; 30 37 public DocumentStartHandler(Object rootObject) { 38 if (rootObject == null) { 39 throw new NullPointerException ("Root Object can not be null!"); 40 } 41 this.rootComponent = rootObject; 42 } 43 44 55 public void onStartElement(String uri, String tag, String qname, 56 Attributes attrs, 57 ArooaContext context) 58 throws SAXParseException { 59 60 final ComponentRegistry cr = (ComponentRegistry) context.get( 61 ArooaConstants.COMPONENT_REGISTRY); 62 63 final ArooaRuntime wrapper = new ArooaRuntime(rootComponent, tag, context); 64 65 AttributeHelper ah = new AttributeHelper(uri, attrs); 66 ah.process(new AttributeHelper.Processor() { 67 public void process(String name, String value) { 68 if (name.equals("id") ) { 69 cr.register(value, rootComponent); 70 try { 71 wrapper.setAttribute(name, value); 72 } 73 catch (Exception e) { 74 } 78 } 79 else { 80 wrapper.setAttribute(name, value); 81 } 82 } 83 }); 84 85 context.set(ArooaConstants.CURRENTLY_CONFIGURING, wrapper); 86 87 if (!Lifecycle.setContext(rootComponent, context)) { 89 ArooaRuntime parentWrapper 90 = (ArooaRuntime) context.getParent().get( 91 ArooaConstants.CURRENTLY_CONFIGURING); 92 parentWrapper.link(wrapper); 93 } 94 } 95 96 103 public void onEndElement(String uri, String tag, ArooaContext context) { 104 Lifecycle.init(rootComponent); 105 } 106 107 } 108 109 | Popular Tags |