1 package org.oddjob.ant; 2 3 import org.apache.tools.ant.IntrospectionHelper; 4 import org.apache.tools.ant.Project; 5 import org.oddjob.arooa.ArooaHandler; 6 import org.oddjob.arooa.ArooaContext; 7 import org.oddjob.arooa.ArooaConstants; 8 import org.xml.sax.Attributes ; 9 import org.xml.sax.SAXParseException ; 10 11 12 15 public class AntElementHandler extends ArooaHandler { 16 17 private final Project project; 18 19 22 public AntElementHandler(Project project) { 23 this.project = project; 24 } 25 26 44 public void onStartElement(String uri, String tag, String qname, 45 Attributes attrs, 46 ArooaContext context) 47 throws SAXParseException { 48 AntJobRtc parentWrapper 49 = (AntJobRtc) context.getParent().get( 50 ArooaConstants.CURRENTLY_CONFIGURING); 51 Object parent = parentWrapper.getWrappedObject(); 52 IntrospectionHelper ih = IntrospectionHelper.getHelper(parent.getClass()); 53 54 IntrospectionHelper.Creator creator = 55 ih.getElementCreator( 56 project, uri, parent, tag, null); 57 Object object = creator.create(); 58 59 AntJobRtc wrapper 60 = new AntJobRtc(project, object, tag); 61 62 for (int i = 0; i < attrs.getLength(); i++) { 63 String attrUri = attrs.getURI(i); 64 if (attrUri != null 65 && !attrUri.equals("") 66 && !attrUri.equals(uri)) { 67 continue; } 69 String name = attrs.getLocalName(i); 70 String value = attrs.getValue(i); 71 wrapper.setAttribute(name, value); 72 } 73 74 parentWrapper.addChild(wrapper); 75 context.set(ArooaConstants.CURRENTLY_CONFIGURING, wrapper); 76 } 77 78 90 public void characters(char[] buf, int start, int count, 91 ArooaContext context) 92 throws SAXParseException { 93 AntJobRtc wrapper 94 = (AntJobRtc) context.get( 95 ArooaConstants.CURRENTLY_CONFIGURING); 96 wrapper.addText(buf, start, count); 97 } 98 99 116 public ArooaHandler onStartChild(String uri, String tag, String qname, 117 Attributes attrs, 118 ArooaContext context) { 119 return this; 120 } 121 } 122 | Popular Tags |