Coverage Report - org.apache.commons.betwixt.digester.ConfigRule

Classes in this File Line Coverage Branch Coverage Complexity
ConfigRule
82% 
100% 
2.333

 1  
 /*
 2  
  * Copyright 2004 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.commons.betwixt.digester;
 17  
 
 18  
 
 19  
 import org.apache.commons.logging.Log;
 20  
 import org.apache.commons.logging.LogFactory;
 21  
 import org.xml.sax.Attributes;
 22  
 import org.xml.sax.SAXException;
 23  
 
 24  
 /**
 25  
  * Digester Rule to process config elements.
 26  
  * @since 0.7
 27  
  * @author Brian Pugh
 28  
  */
 29  175
 public class ConfigRule extends RuleSupport {
 30  
     /** Logger. */
 31  175
     private static final Log log = LogFactory.getLog(ConfigRule.class);
 32  
 
 33  
     /** Base constructor. */
 34  415
     public ConfigRule() {
 35  415
     }
 36  
     // Rule interface
 37  
     //-------------------------------------------------------------------------
 38  
     /**
 39  
      * Process the beginning of this element.
 40  
      *
 41  
      * @param attributes The attribute list of this element
 42  
      * @throws org.xml.sax.SAXException if the primitiveTypes attribute contains an invalid value
 43  
      */
 44  
     public void begin(Attributes attributes) throws SAXException {
 45  415
         String value = attributes.getValue("primitiveTypes");
 46  415
         if (value != null) {
 47  65
             if (value.equalsIgnoreCase("element")) {
 48  0
                         getXMLInfoDigester().setAttributesForPrimitives(false);
 49  
             
 50  65
             } else if (value.equalsIgnoreCase("attribute")) {
 51  65
                 getXMLInfoDigester().setAttributesForPrimitives(true);
 52  
             } else {
 53  0
                 throw new SAXException(
 54  0
                         "Invalid value inside element <betwixt-config> for attribute 'primitiveTypes'."
 55  
                         + " Value should be 'element' or 'attribute'");
 56  
             }
 57  
         }
 58  415
         MultiMappingBeanInfoDigester digester = (MultiMappingBeanInfoDigester) getDigester();
 59  415
         getDigester().push(digester.getBeanInfoMap());
 60  415
     }
 61  
     /**
 62  
      * Process the end of this element.
 63  
      */
 64  
     public void end() {
 65  415
         Object top = getDigester().pop();
 66  415
     }
 67  
 
 68  
 
 69  
 }