Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 package org.apache.xmlrpc.parser;
00020
00021 import javax.xml.namespace.QName;
00022
00023 import org.xml.sax.Attributes;
00024 import org.xml.sax.SAXException;
00025 import org.xml.sax.SAXParseException;
00026
00027
00031 public abstract class AtomicParser extends TypeParserImpl {
00032 private int level;
00033 protected StringBuffer sb;
00034
00037 protected AtomicParser() {
00038 }
00039
00040 protected abstract void setResult(String pResult) throws SAXException;
00041
00042 public void startDocument() throws SAXException {
00043 level = 0;
00044 }
00045
00046 public void characters(char[] pChars, int pStart, int pLength) throws SAXException {
00047 if (sb == null) {
00048 if (!isEmpty(pChars, pStart, pLength)) {
00049 throw new SAXParseException("Unexpected non-whitespace characters",
00050 getDocumentLocator());
00051 }
00052 } else {
00053 sb.append(pChars, pStart, pLength);
00054 }
00055 }
00056
00057 public void endElement(String pURI, String pLocalName, String pQName) throws SAXException {
00058 if (--level == 0) {
00059 setResult(sb.toString());
00060 } else {
00061 throw new SAXParseException("Unexpected end tag in atomic element: "
00062 + new QName(pURI, pLocalName),
00063 getDocumentLocator());
00064 }
00065 }
00066
00067 public void startElement(String pURI, String pLocalName, String pQName, Attributes pAttrs) throws SAXException {
00068 if (level++ == 0) {
00069 sb = new StringBuffer();
00070 } else {
00071 throw new SAXParseException("Unexpected start tag in atomic element: "
00072 + new QName(pURI, pLocalName),
00073 getDocumentLocator());
00074 }
00075 }
00076 }