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: 88   Methods: 5
NCLOC: 51   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
SetPropertyRule.java 50% 80% 100% 81.8%
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.schema.SchemaProcessor;
 22   
 import org.apache.hivemind.schema.Translator;
 23   
 import org.apache.hivemind.util.PropertyUtils;
 24   
 
 25   
 /**
 26   
  * Used to set a property of an object to a literal value.
 27   
  *
 28   
  * @author Howard Lewis Ship
 29   
  */
 30   
 public class SetPropertyRule extends BaseRule
 31   
 {
 32   
     private static final Log LOG = LogFactory.getLog(SetPropertyRule.class);
 33   
 
 34   
     private String _propertyName;
 35   
     private String _value;
 36   
     private Translator _smartTranslator;
 37   
 
 38  4
     public void begin(SchemaProcessor processor, Element element)
 39   
     {
 40  4
         String value = RuleUtils.processText(processor, element, _value);
 41   
 
 42  4
         Object target = processor.peek();
 43   
 
 44  4
         try
 45   
         {
 46  4
             if (_smartTranslator == null)
 47  4
                 _smartTranslator = RuleUtils.getTranslator(processor, "smart");
 48   
 
 49  4
             Class propertyType = PropertyUtils.getPropertyType(target, _propertyName);
 50   
 
 51  4
             Object finalValue =
 52   
                 _smartTranslator.translate(processor.getContributingModule(), propertyType, value);
 53   
 
 54  4
             PropertyUtils.write(target, _propertyName, finalValue);
 55   
         }
 56   
         catch (Exception ex)
 57   
         {
 58  0
             ErrorHandler eh = processor.getContributingModule().getErrorHandler();
 59   
 
 60  0
             String message = RulesMessages.unableToSetProperty(_propertyName, target, ex);
 61   
 
 62  0
             eh.error(LOG, message, element.getLocation(), ex);
 63   
         }
 64   
 
 65   
     }
 66   
 
 67  159
     public void setPropertyName(String string)
 68   
     {
 69  159
         _propertyName = string;
 70   
     }
 71   
 
 72  159
     public void setValue(String string)
 73   
     {
 74  159
         _value = string;
 75   
     }
 76   
 
 77  1
     public String getPropertyName()
 78   
     {
 79  1
         return _propertyName;
 80   
     }
 81   
 
 82  1
     public String getValue()
 83   
     {
 84  1
         return _value;
 85   
     }
 86   
 
 87   
 }
 88