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: 126   Methods: 7
NCLOC: 60   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
ClassAdaptor.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.beans.PropertyDescriptor;
 18   
 import java.util.HashMap;
 19   
 import java.util.Map;
 20   
 
 21   
 import org.apache.hivemind.ApplicationRuntimeException;
 22   
 
 23   
 /**
 24   
  * Provides access to an object (of a particular class) as a set of individual property
 25   
  * that may be read or updated.
 26   
  * 
 27   
  * @author Howard Lewis Ship
 28   
  */
 29   
 class ClassAdaptor
 30   
 {
 31   
     private final Map _propertyAdaptorMap = new HashMap();
 32   
 
 33  184
     public ClassAdaptor(PropertyDescriptor[] properties)
 34   
     {
 35  184
         for (int i = 0; i < properties.length; i++)
 36   
         {
 37  679
             PropertyDescriptor d = properties[i];
 38   
 
 39  679
             String name = d.getName();
 40   
 
 41  679
             _propertyAdaptorMap.put(
 42   
                 name,
 43   
                 new PropertyAdaptor(
 44   
                     name,
 45   
                     d.getPropertyType(),
 46   
                     d.getReadMethod(),
 47   
                     d.getWriteMethod()));
 48   
         }
 49   
     }
 50   
 
 51   
     /**
 52   
      * Updates the property of the target object.
 53   
      * 
 54   
      * @param target the object to update
 55   
      * @param value the value to be stored into the target object property
 56   
      */
 57  3509
     public void write(Object target, String propertyName, Object value)
 58   
     {
 59  3509
         PropertyAdaptor a = getAdaptor(target, propertyName);
 60   
 
 61  3509
         a.write(target, value);
 62   
     }
 63   
 
 64   
     /**
 65   
      * Reads the property of the target object.
 66   
      * 
 67   
      * @param target the object to read
 68   
      * @param propertyName the name of the property to read
 69   
      */
 70  8
     public Object read(Object target, String propertyName)
 71   
     {
 72  8
         PropertyAdaptor a = getAdaptor(target, propertyName);
 73   
 
 74  7
         return a.read(target);
 75   
     }
 76   
 
 77   
     /**
 78   
      * Returns the type of the named property.
 79   
      * 
 80   
      * @param target the object to examine
 81   
      * @param propertyName the name of the property to check
 82   
      */
 83  3459
     public Class getPropertyType(Object target, String propertyName)
 84   
     {
 85  3459
         PropertyAdaptor a = getAdaptor(target, propertyName);
 86   
 
 87  3458
         return a.getPropertyType();
 88   
     }
 89   
 
 90   
     /**
 91   
      * Returns true if the named property exists and is readable.
 92   
      */
 93   
 
 94  4
     public boolean isReadable(String propertyName)
 95   
     {
 96  4
         PropertyAdaptor result = (PropertyAdaptor) _propertyAdaptorMap.get(propertyName);
 97   
 
 98  4
         return result != null && result.isReadable();
 99   
     }
 100   
 
 101   
     /**
 102   
      * Returns true if the named property exists and is writable.
 103   
      */
 104   
 
 105  1060
     public boolean isWritable(String propertyName)
 106   
     {
 107  1060
         PropertyAdaptor result = (PropertyAdaptor) _propertyAdaptorMap.get(propertyName);
 108   
 
 109  1060
         return result != null && result.isWritable();
 110   
     }
 111   
 
 112  6976
     private PropertyAdaptor getAdaptor(Object target, String propertyName)
 113   
     {
 114  6976
         PropertyAdaptor result = (PropertyAdaptor) _propertyAdaptorMap.get(propertyName);
 115   
 
 116  6976
         if (result == null)
 117  2
             throw new ApplicationRuntimeException(
 118   
                 UtilMessages.noSuchProperty(target, propertyName),
 119   
                 target,
 120   
                 null,
 121   
                 null);
 122   
 
 123  6974
         return result;
 124   
     }
 125   
 }
 126