Coverage Report - org.apache.commons.configuration.BaseConfigurationXMLReader
 
Classes in this File Line Coverage Branch Coverage Complexity
BaseConfigurationXMLReader
100%
13/13
N/A
1,125
BaseConfigurationXMLReader$SAXConverter
100%
7/7
100%
2/2
1,125
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *     http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 package org.apache.commons.configuration;
 19  
 
 20  
 /**
 21  
  * <p>A specialized SAX2 XML parser that processes configuration objects.</p>
 22  
  *
 23  
  * <p>This class mimics to be a SAX compliant XML parser. It is able to iterate
 24  
  * over the keys in a configuration object and to generate corresponding SAX
 25  
  * events. By registering a {@code ContentHandler} at an instance
 26  
  * it is possible to perform XML processing on a configuration object.</p>
 27  
  *
 28  
  * @author <a
 29  
  * href="http://commons.apache.org/configuration/team-list.html">Commons
 30  
  * Configuration team</a>
 31  
  * @version $Id: BaseConfigurationXMLReader.java 1206765 2011-11-27 16:46:11Z oheger $
 32  
  */
 33  
 public class BaseConfigurationXMLReader extends ConfigurationXMLReader
 34  
 {
 35  
     /** Stores the actual configuration.*/
 36  
     private Configuration config;
 37  
 
 38  
     /**
 39  
      * Creates a new instance of {@code BaseConfigurationXMLReader}.
 40  
      */
 41  
     public BaseConfigurationXMLReader()
 42  
     {
 43  6
         super();
 44  6
     }
 45  
 
 46  
     /**
 47  
      * Creates a new instance of {@code BaseConfigurationXMLReader} and
 48  
      * sets the configuration object to be parsed.
 49  
      *
 50  
      * @param conf the configuration to be parsed
 51  
      */
 52  
     public BaseConfigurationXMLReader(Configuration conf)
 53  
     {
 54  5
         this();
 55  5
         setConfiguration(conf);
 56  5
     }
 57  
 
 58  
     /**
 59  
      * Returns the actual configuration to be processed.
 60  
      *
 61  
      * @return the actual configuration
 62  
      */
 63  
     public Configuration getConfiguration()
 64  
     {
 65  7
         return config;
 66  
     }
 67  
 
 68  
     /**
 69  
      * Sets the configuration to be processed.
 70  
      *
 71  
      * @param conf the configuration
 72  
      */
 73  
     public void setConfiguration(Configuration conf)
 74  
     {
 75  5
         config = conf;
 76  5
     }
 77  
 
 78  
     /**
 79  
      * Returns the configuration to be processed.
 80  
      *
 81  
      * @return the actual configuration
 82  
      */
 83  
     @Override
 84  
     public Configuration getParsedConfiguration()
 85  
     {
 86  4
         return getConfiguration();
 87  
     }
 88  
 
 89  
     /**
 90  
      * The main SAX event generation method. This element uses an internal
 91  
      * {@code HierarchicalConfigurationConverter} object to iterate over
 92  
      * all keys in the actual configuration and to generate corresponding SAX
 93  
      * events.
 94  
      */
 95  
     @Override
 96  
     protected void processKeys()
 97  
     {
 98  3
         fireElementStart(getRootName(), null);
 99  3
         new SAXConverter().process(getConfiguration());
 100  3
         fireElementEnd(getRootName());
 101  3
     }
 102  
 
 103  
     /**
 104  
      * An internally used helper class to iterate over all configuration keys
 105  
      * ant to generate corresponding SAX events.
 106  
      *
 107  
      */
 108  3
     class SAXConverter extends HierarchicalConfigurationConverter
 109  
     {
 110  
         /**
 111  
          * Callback for the start of an element.
 112  
          *
 113  
          * @param name the element name
 114  
          * @param value the element value
 115  
          */
 116  
         @Override
 117  
         protected void elementStart(String name, Object value)
 118  
         {
 119  60
             fireElementStart(name, null);
 120  60
             if (value != null)
 121  
             {
 122  45
                 fireCharacters(value.toString());
 123  
             }
 124  60
         }
 125  
 
 126  
         /**
 127  
          * Callback for the end of an element.
 128  
          *
 129  
          * @param name the element name
 130  
          */
 131  
         @Override
 132  
         protected void elementEnd(String name)
 133  
         {
 134  60
             fireElementEnd(name);
 135  60
         }
 136  
     }
 137  
 }