Clover coverage report - Code Coverage for hivemind release 1.0-rc-2
Coverage timestamp: Sat Sep 11 2004 09:09:48 EDT
file stats: LOC: 139   Methods: 10
NCLOC: 91   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
ReadAttributeRule.java 75% 100% 100% 97.3%
coverage coverage
 1   
 //  Copyright 2004 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // You may obtain a copy of the License at
 6   
 //
 7   
 //     http://www.apache.org/licenses/LICENSE-2.0
 8   
 //
 9   
 // Unless required by applicable law or agreed to in writing, software
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.hivemind.schema.rules;
 16   
 
 17   
 import org.apache.commons.logging.Log;
 18   
 import org.apache.commons.logging.LogFactory;
 19   
 import org.apache.hivemind.Element;
 20   
 import org.apache.hivemind.ErrorHandler;
 21   
 import org.apache.hivemind.Location;
 22   
 import org.apache.hivemind.schema.SchemaProcessor;
 23   
 import org.apache.hivemind.schema.Translator;
 24   
 import org.apache.hivemind.util.PropertyUtils;
 25   
 
 26   
 /**
 27   
  * Reads an attribute of an element and uses it to set a property of the top object
 28   
  * on the stack.  Created from the <code>&lt;read-attribute&gt;</code>
 29   
  * element.
 30   
  *
 31   
  * @author Howard Lewis Ship
 32   
  */
 33   
 public class ReadAttributeRule extends BaseRule
 34   
 {
 35   
 
 36   
     private static final Log LOG = LogFactory.getLog(ReadAttributeRule.class);
 37   
 
 38   
     private String _attributeName;
 39   
     private String _propertyName;
 40   
     private boolean _skipIfNull = true;
 41   
     private String _translator;
 42   
 
 43  2217
     public ReadAttributeRule()
 44   
     {
 45   
     }
 46   
 
 47  1364
     public ReadAttributeRule(
 48   
         String attributeName,
 49   
         String propertyName,
 50   
         String translator,
 51   
         Location location)
 52   
     {
 53  1364
         setLocation(location);
 54   
 
 55  1364
         _attributeName = attributeName;
 56  1364
         _propertyName = propertyName;
 57  1364
         _translator = translator;
 58   
     }
 59   
 
 60  8424
     public void begin(SchemaProcessor processor, Element element)
 61   
     {
 62  8424
         String rawValue = element.getAttributeValue(_attributeName);
 63   
 
 64  8424
         if (rawValue == null && _skipIfNull)
 65  3158
             return;
 66   
 
 67  5266
         String value = RuleUtils.processText(processor, element, rawValue);
 68   
 
 69  5266
         Object target = processor.peek();
 70   
 
 71  5266
         try
 72   
         {
 73  5266
             Translator t =
 74  5266
                 _translator == null
 75   
                     ? processor.getAttributeTranslator(_attributeName)
 76   
                     : processor.getTranslator(_translator);
 77   
 
 78  5266
             Class propertyType = PropertyUtils.getPropertyType(target, _propertyName);
 79   
 
 80  5266
             Object finalValue =
 81   
                 t.translate(
 82   
                     processor.getContributingModule(),
 83   
                     propertyType,
 84   
                     value,
 85   
                     element.getLocation());
 86   
 
 87  5261
             PropertyUtils.write(target, _propertyName, finalValue);
 88   
 
 89   
         }
 90   
         catch (Exception ex)
 91   
         {
 92  5
             ErrorHandler eh = processor.getContributingModule().getErrorHandler();
 93   
 
 94  5
             eh.error(
 95   
                 LOG,
 96   
                 RulesMessages.readAttributeFailure(_attributeName, element, processor, ex),
 97   
                 element.getLocation(),
 98   
                 ex);
 99   
         }
 100   
 
 101   
     }
 102   
 
 103  1
     public String getAttributeName()
 104   
     {
 105  1
         return _attributeName;
 106   
     }
 107   
 
 108  1
     public String getPropertyName()
 109   
     {
 110  1
         return _propertyName;
 111   
     }
 112   
 
 113  1
     public boolean getSkipIfNull()
 114   
     {
 115  1
         return _skipIfNull;
 116   
     }
 117   
 
 118  2217
     public void setAttributeName(String string)
 119   
     {
 120  2217
         _attributeName = string;
 121   
     }
 122   
 
 123  2217
     public void setPropertyName(String string)
 124   
     {
 125  2217
         _propertyName = string;
 126   
     }
 127   
 
 128  2216
     public void setSkipIfNull(boolean b)
 129   
     {
 130  2216
         _skipIfNull = b;
 131   
     }
 132   
 
 133  2216
     public void setTranslator(String string)
 134   
     {
 135  2216
         _translator = string;
 136   
     }
 137   
 
 138   
 }
 139