1 56 package org.objectstyle.cayenne.util; 57 58 import org.xml.sax.Attributes ; 59 import org.xml.sax.ContentHandler ; 60 import org.xml.sax.SAXException ; 61 import org.xml.sax.XMLReader ; 62 import org.xml.sax.helpers.DefaultHandler ; 63 64 65 88 public class AbstractHandler extends DefaultHandler { 89 90 protected XMLReader parser; 91 92 95 protected ContentHandler parentHandler; 96 97 107 public AbstractHandler(XMLReader parser, ContentHandler parentHandler) { 108 this.parentHandler = parentHandler; 109 this.parser = parser; 110 111 parser.setContentHandler(this); 113 } 114 115 116 public XMLReader getParser() { 117 return parser; 118 } 119 120 121 128 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) 129 throws SAXException { 130 throw new SAXException (this.getClass().getName() + ": unexpected element \"" + localName + "\""); 131 } 132 133 145 public void characters(char[] buf, int start, int count) throws SAXException { 146 String s = new String (buf, start, count).trim(); 147 148 if (s.length() > 0) { 149 throw new SAXException (this.getClass().getName() + ": unexpected text \"" + s + "\""); 150 } 151 } 152 153 157 protected void finished() {} 158 159 160 167 public void endElement(String namespaceURI, String localName, String qName) 168 throws SAXException { 169 finished(); 170 parser.setContentHandler(parentHandler); 172 } 173 } 174 175 | Popular Tags |