1 58 package org.oddjob.arooa; 59 60 import java.util.Stack ; 61 62 import org.apache.log4j.Logger; 63 import org.xml.sax.Attributes ; 64 import org.xml.sax.Locator ; 65 import org.xml.sax.SAXException ; 66 import org.xml.sax.SAXParseException ; 67 import org.xml.sax.helpers.DefaultHandler ; 68 69 74 public class RootHandler extends DefaultHandler { 75 private static final Logger logger = Logger.getLogger(RootHandler.class); 76 77 private Stack antHandlers = new Stack (); 78 private ArooaHandler currentHandler = null; 79 private ArooaContext context; 80 81 87 public RootHandler(ArooaContext context, ArooaHandler rootHandler) { 88 currentHandler = rootHandler; 89 antHandlers.push(currentHandler); 90 this.context = context; 91 } 92 93 107 public void startElement(String uri, String tag, String qname, Attributes attrs) 108 throws SAXParseException { 109 ArooaHandler next 110 = currentHandler.onStartChild(uri, tag, qname, attrs, context); 111 if (next == null) { 112 throw new IllegalStateException ("Handler [" + currentHandler + "] did not return a child handler."); 113 } 114 antHandlers.push(currentHandler); 115 context = new ArooaContext(context); 116 currentHandler = next; 117 logger.debug("onStartElement(" + qname + "), handler [" + currentHandler + "]"); 118 currentHandler.onStartElement(uri, tag, qname, attrs, context); 119 } 120 121 127 public void setDocumentLocator(Locator locator) { 128 context.setLocator(locator); 129 } 130 131 145 public void endElement(String uri, String name, String qName) throws SAXException { 146 logger.debug("onEndElement(" + name + "), handler [" + currentHandler + "]"); 147 currentHandler.onEndElement(uri, name, context); 148 ArooaHandler prev = (ArooaHandler) antHandlers.pop(); 149 currentHandler = prev; 150 context = context.getParent(); 151 if (currentHandler != null) { 152 currentHandler.onEndChild(uri, name, qName, context); 153 } 154 } 155 156 164 public void characters(char[] buf, int start, int count) 165 throws SAXParseException { 166 currentHandler.characters(buf, start, count, context); 167 } 168 169 175 public void startPrefixMapping(String prefix, String uri) { 176 context.startPrefixMapping(prefix, uri); 177 } 178 179 184 public void endPrefixMapping(String prefix) { 185 context.endPrefixMapping(prefix); 186 } 187 } 188 | Popular Tags |