AtomicParser.java
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one
00003  * or more contributor license agreements.  See the NOTICE file
00004  * distributed with this work for additional information
00005  * regarding copyright ownership.  The ASF licenses this file
00006  * to you under the Apache License, Version 2.0 (the
00007  * "License"); you may not use this file except in compliance
00008  * with the License.  You may obtain a copy of the License at
00009  *
00010  *   http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing,
00013  * software distributed under the License is distributed on an
00014  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00015  * KIND, either express or implied.  See the License for the
00016  * specific language governing permissions and limitations
00017  * under the License.    
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 }


rosjava_core
Author(s):
autogenerated on Wed Aug 26 2015 16:06:49