Coverage Report - org.apache.xmlrpc.parser.AtomicParser
 
Classes in this File Line Coverage Branch Coverage Complexity
AtomicParser
59% 
75% 
2,167
 
 1  
 /*
 2  
  * Copyright 1999,2005 The Apache Software Foundation.
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.apache.xmlrpc.parser;
 17  
 
 18  
 import javax.xml.namespace.QName;
 19  
 
 20  
 import org.xml.sax.Attributes;
 21  
 import org.xml.sax.SAXException;
 22  
 import org.xml.sax.SAXParseException;
 23  
 
 24  
 
 25  
 /** Abstract base implementation of {@link org.apache.xmlrpc.parser.TypeParser}
 26  
  * for parsing an atomic value.
 27  
  */
 28  
 public abstract class AtomicParser extends TypeParserImpl {
 29  
         private int level;
 30  
         protected StringBuffer sb;
 31  
 
 32  
         /** Creates a new instance.
 33  
          */
 34  544
         protected AtomicParser() {
 35  544
         }
 36  
 
 37  
         protected abstract void setResult(String pResult) throws SAXException;
 38  
 
 39  
         public void startDocument() throws SAXException {
 40  544
                 level = 0;
 41  544
         }
 42  
 
 43  
         public void characters(char[] pChars, int pStart, int pLength) throws SAXException {
 44  520
                 if (sb == null) {
 45  0
                         if (!isEmpty(pChars, pStart, pLength)) {
 46  0
                                 throw new SAXParseException("Unexpected non-whitespace characters",
 47  0
                                                                                         getDocumentLocator());
 48  
                         }
 49  
                 } else {
 50  520
                         sb.append(pChars, pStart, pLength);
 51  
                 }
 52  520
         }
 53  
 
 54  
         public void endElement(String pURI, String pLocalName, String pQName) throws SAXException {
 55  544
                 if (--level == 0) {
 56  544
                         setResult(sb.toString());
 57  
                 } else {
 58  0
                         throw new SAXParseException("Unexpected end tag in atomic element: "
 59  0
                                                                                 + new QName(pURI, pLocalName),
 60  0
                                                                                 getDocumentLocator());
 61  
                 }
 62  544
         }
 63  
 
 64  
         public void startElement(String pURI, String pLocalName, String pQName, Attributes pAttrs) throws SAXException {
 65  544
                 if (level++ == 0) {
 66  544
                         sb = new StringBuffer();
 67  
                 } else {
 68  0
                         throw new SAXParseException("Unexpected start tag in atomic element: "
 69  0
                                                                                 + new QName(pURI, pLocalName),
 70  0
                                                                                 getDocumentLocator());
 71  
                 }
 72  544
         }
 73  
 }