Clover coverage report - Code Coverage for hivemind release 1.0-beta-1
Coverage timestamp: Sat Jul 3 2004 09:41:37 EDT
file stats: LOC: 135   Methods: 10
NCLOC: 87   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.HiveMind;
 22   
 import org.apache.hivemind.Location;
 23   
 import org.apache.hivemind.schema.SchemaProcessor;
 24   
 import org.apache.hivemind.schema.Translator;
 25   
 import org.apache.hivemind.util.PropertyUtils;
 26   
 
 27   
 /**
 28   
  * Reads an attribute of an element and uses it to set a property of the top object
 29   
  * on the stack.  Created from the <code>&lt;read-attribute&gt;</code>
 30   
  * element.
 31   
  *
 32   
  * @author Howard Lewis Ship
 33   
  */
 34   
 public class ReadAttributeRule extends BaseRule
 35   
 {
 36   
 
 37   
     private static final Log LOG = LogFactory.getLog(ReadAttributeRule.class);
 38   
 
 39   
     private String _attributeName;
 40   
     private String _propertyName;
 41   
     private boolean _skipIfNull = true;
 42   
     private String _translator;
 43   
 
 44  1567
     public ReadAttributeRule()
 45   
     {
 46   
     }
 47   
 
 48  878
     public ReadAttributeRule(
 49   
         String attributeName,
 50   
         String propertyName,
 51   
         String translator,
 52   
         Location location)
 53   
     {
 54  878
         setLocation(location);
 55   
 
 56  878
         _attributeName = attributeName;
 57  878
         _propertyName = propertyName;
 58  878
         _translator = translator;
 59   
     }
 60   
 
 61  4486
     public void begin(SchemaProcessor processor, Element element)
 62   
     {
 63  4486
         String rawValue = element.getAttributeValue(_attributeName);
 64   
 
 65  4486
         if (rawValue == null && _skipIfNull)
 66  1270
             return;
 67   
 
 68  3216
         String value = RuleUtils.processText(processor, element, rawValue);
 69   
 
 70  3216
         Object target = processor.peek();
 71   
 
 72  3216
         try
 73   
         {
 74  3216
             Translator t =
 75  3216
                 _translator == null
 76   
                     ? processor.getAttributeTranslator(_attributeName)
 77   
                     : processor.getTranslator(_translator);
 78   
 
 79  3216
             Class propertyType = PropertyUtils.getPropertyType(target, _propertyName);
 80   
 
 81  3216
             Object finalValue = t.translate(processor.getContributingModule(), propertyType, value);
 82   
 
 83  3211
             PropertyUtils.write(target, _propertyName, finalValue);
 84   
 
 85   
         }
 86   
         catch (Exception ex)
 87   
         {
 88  5
             ErrorHandler eh = processor.getContributingModule().getErrorHandler();
 89   
 
 90  5
             eh.error(
 91   
                 LOG,
 92   
                 RulesMessages.readAttributeFailure(_attributeName, element, processor, ex),
 93   
                 element.getLocation(),
 94   
                 ex);
 95   
         }
 96   
 
 97   
     }
 98   
 
 99  1
     public String getAttributeName()
 100   
     {
 101  1
         return _attributeName;
 102   
     }
 103   
 
 104  1
     public String getPropertyName()
 105   
     {
 106  1
         return _propertyName;
 107   
     }
 108   
 
 109  1
     public boolean getSkipIfNull()
 110   
     {
 111  1
         return _skipIfNull;
 112   
     }
 113   
 
 114  1567
     public void setAttributeName(String string)
 115   
     {
 116  1567
         _attributeName = string;
 117   
     }
 118   
 
 119  1567
     public void setPropertyName(String string)
 120   
     {
 121  1567
         _propertyName = string;
 122   
     }
 123   
 
 124  1566
     public void setSkipIfNull(boolean b)
 125   
     {
 126  1566
         _skipIfNull = b;
 127   
     }
 128   
 
 129  1566
     public void setTranslator(String string)
 130   
     {
 131  1566
         _translator = string;
 132   
     }
 133   
 
 134   
 }
 135