1 19 20 package org.apache.cayenne.conf; 21 22 import org.xml.sax.Attributes ; 23 import org.xml.sax.ContentHandler ; 24 import org.xml.sax.SAXException ; 25 import org.xml.sax.XMLReader ; 26 import org.xml.sax.helpers.DefaultHandler ; 27 28 39 class AbstractHandler extends DefaultHandler { 40 41 42 protected XMLReader parser; 43 44 48 protected ContentHandler parentHandler; 49 50 57 public AbstractHandler(XMLReader parser, ContentHandler parentHandler) { 58 this.parentHandler = parentHandler; 59 this.parser = parser; 60 61 parser.setContentHandler(this); 63 } 64 65 66 public XMLReader getParser() { 67 return parser; 68 } 69 70 76 public void startElement( 77 String namespaceURI, 78 String localName, 79 String qName, 80 Attributes atts) throws SAXException { 81 throw new SAXException (this.getClass().getName() 82 + ": unexpected element \"" 83 + localName 84 + "\""); 85 } 86 87 97 public void characters(char[] buf, int start, int count) throws SAXException { 98 String s = new String (buf, start, count).trim(); 99 100 if (s.length() > 0) { 101 throw new SAXException (this.getClass().getName() 102 + ": unexpected text \"" 103 + s 104 + "\""); 105 } 106 } 107 108 111 protected void finished() { 112 } 113 114 120 public void endElement(String namespaceURI, String localName, String qName) 121 throws SAXException { 122 finished(); 123 parser.setContentHandler(parentHandler); 125 } 126 } 127 | Popular Tags |