Clover coverage report - Code Coverage for hivemind release 1.0-beta-2
Coverage timestamp: Sun Aug 1 2004 14:03:45 EDT
file stats: LOC: 128   Methods: 7
NCLOC: 75   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
PropertyAdaptor.java 100% 100% 100% 100%
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.util;
 16   
 
 17   
 import java.lang.reflect.Method;
 18   
 
 19   
 import org.apache.hivemind.ApplicationRuntimeException;
 20   
 
 21   
 /**
 22   
  * Used to manage dynamic access to a property of a specific class.
 23   
  *
 24   
  * @author Howard Lewis Ship
 25   
  */
 26   
 class PropertyAdaptor
 27   
 {
 28   
     private String _propertyName;
 29   
     private Class _propertyType;
 30   
     private Method _readMethod;
 31   
 
 32   
     private Method _writeMethod;
 33   
 
 34  204
     PropertyAdaptor(String propertyName, Class propertyType, Method readMethod, Method writeMethod)
 35   
     {
 36  204
         _propertyName = propertyName;
 37  204
         _propertyType = propertyType;
 38  204
         _readMethod = readMethod;
 39  204
         _writeMethod = writeMethod;
 40   
     }
 41   
 
 42  350
     public String getPropertyName()
 43   
     {
 44  350
         return _propertyName;
 45   
     }
 46   
     
 47  3852
     public Class getPropertyType()
 48   
     {
 49  3852
         return _propertyType;
 50   
     }
 51   
 
 52   
     /**
 53   
      * Updates the property of the target object.
 54   
      * 
 55   
      * @param target the object to update
 56   
      * @param value the value to be stored into the target object property
 57   
      */
 58  3797
     public void write(Object target, Object value)
 59   
     {
 60  3797
         if (_writeMethod == null)
 61  1
             throw new ApplicationRuntimeException(
 62   
                 UtilMessages.noPropertyWriter(_propertyName, target),
 63   
                 target,
 64   
                 null,
 65   
                 null);
 66   
 
 67  3796
         try
 68   
         {
 69  3796
             _writeMethod.invoke(target, new Object[] { value });
 70   
 
 71   
         }
 72   
         catch (Exception ex)
 73   
         {
 74  2
             throw new ApplicationRuntimeException(
 75   
                 UtilMessages.writeFailure(_propertyName, target, ex),
 76   
                 target,
 77   
                 null,
 78   
                 ex);
 79   
         }
 80   
     }
 81   
 
 82   
     /**
 83   
      * Returns true if there's a write method for the property.
 84   
      */
 85  614
     public boolean isWritable()
 86   
     {
 87  614
         return _writeMethod != null;
 88   
     }
 89   
 
 90   
     /**
 91   
      * Reads the property of the target object.
 92   
      * 
 93   
      * @param target the object to read a property from
 94   
      */
 95  8
     public Object read(Object target)
 96   
     {
 97  8
         if (_readMethod == null)
 98  1
             throw new ApplicationRuntimeException(
 99   
                 UtilMessages.noReader(_propertyName, target),
 100   
                 target,
 101   
                 null,
 102   
                 null);
 103   
 
 104  7
         try
 105   
         {
 106  7
             return _readMethod.invoke(target, null);
 107   
 
 108   
         }
 109   
         catch (Exception ex)
 110   
         {
 111  1
             throw new ApplicationRuntimeException(
 112   
                 UtilMessages.readFailure(_propertyName, target, ex),
 113   
                 target,
 114   
                 null,
 115   
                 ex);
 116   
         }
 117   
     }
 118   
 
 119   
     /**
 120   
      * Returns true if there's a read method for the property.
 121   
      */
 122   
 
 123  6
     public boolean isReadable()
 124   
     {
 125  6
         return _readMethod != null;
 126   
     }
 127   
 }
 128