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: 122   Methods: 5
NCLOC: 47   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
BuilderFacet.java 80% 78.9% 60% 76.5%
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.service.impl;
 16   
 
 17   
 import org.apache.commons.logging.Log;
 18   
 import org.apache.hivemind.impl.BaseLocatable;
 19   
 import org.apache.hivemind.internal.Module;
 20   
 import org.apache.hivemind.util.PropertyUtils;
 21   
 
 22   
 /**
 23   
  * Represents one facet of constructing a service implementation instance.
 24   
  * A facet is either a property to be set on the constructed instance,
 25   
  * or a parameter to the instance class' constructor. Facets are nested
 26   
  * properties within {@link org.apache.hivemind.service.impl.BuilderParameter},
 27   
  * and are used by {@link org.apache.hivemind.service.impl.BuilderFactory}.
 28   
  *
 29   
  * @author Howard Lewis Ship
 30   
  */
 31   
 public abstract class BuilderFacet extends BaseLocatable
 32   
 {
 33   
     private String _propertyName;
 34   
 
 35   
     /**
 36   
      * Implemented in subclasses to provide a specific value for the facet
 37   
      * (for use as a constructor parameter, or as a value to set a property to).
 38   
      * 
 39   
      * @param point the service extension point for which BuilderFactory is constructing
 40   
      * a core service implementation instance.
 41   
      * @param invokingModule the Module which invoked the BuilderFactory
 42   
      * @param targetType the desired property type (extracted from the property type
 43   
      * of the property to be updated, when a property is known)
 44   
      */
 45   
     public abstract Object getFacetValue(String serviceId, Module invokingModule, Class targetType);
 46   
 
 47  1354
     public String getPropertyName()
 48   
     {
 49  1354
         return _propertyName;
 50   
     }
 51   
 
 52  216
     public void setPropertyName(String string)
 53   
     {
 54  216
         _propertyName = string;
 55   
     }
 56   
 
 57   
     /**
 58   
      * Attempts to autowire a property of the target.  This requires that
 59   
      * <ul>
 60   
      * <li>The facet type defines a default property name and facet type
 61   
      * <li>The facet instance does not have a specified property name
 62   
      * <li>The (default) property is writeable
 63   
      * <li>The (default) property is assignable from the facet type
 64   
      * </ul>
 65   
      * 
 66   
      * If all conditions are met, then the property is updated to the facet value, and
 67   
      * the property name is returned.  In all other cases, null is returned.
 68   
      */
 69  1354
     public String autowire(Object target, String serviceId, Module invokingModule, Log log)
 70   
     {
 71  1354
         if (_propertyName != null)
 72  216
             return null;
 73   
 
 74  1138
         String defaultPropertyName = getDefaultPropertyName();
 75   
 
 76  1138
         if (defaultPropertyName == null)
 77  0
             return null;
 78   
 
 79  1138
         Class facetType = getFacetType();
 80   
 
 81  1138
         if (facetType == null)
 82  0
             return null;
 83   
 
 84  1138
         if (PropertyUtils.isWritable(target, defaultPropertyName)
 85   
             && PropertyUtils.getPropertyType(target, defaultPropertyName).isAssignableFrom(facetType))
 86   
         {
 87   
 
 88  22
             Object facetValue = getFacetValue(serviceId, invokingModule, facetType);
 89   
 
 90  22
             PropertyUtils.write(target, defaultPropertyName, facetValue);
 91   
 
 92  22
             if (log.isDebugEnabled())
 93  2
                 log.debug("Autowired property " + defaultPropertyName + " to " + facetValue);
 94   
 
 95  22
             return defaultPropertyName;
 96   
         }
 97   
 
 98  1116
         return null;
 99   
     }
 100   
 
 101   
     /**
 102   
      * Returns null. Subclasses can provide the default name for a property used
 103   
      * by {@link #autowire(Object)}.
 104   
      */
 105  0
     protected String getDefaultPropertyName()
 106   
     {
 107  0
         return null;
 108   
     }
 109   
 
 110   
     /**
 111   
      * Returns the type of property assigned by this facet, if known. Returns null
 112   
      * otherwise.  This implementation returns null.  Used by 
 113   
      * {@link #autowire(Object, String, Module)}.
 114   
      */
 115   
 
 116  0
     protected Class getFacetType()
 117   
     {
 118  0
         return null;
 119   
     }
 120   
 
 121   
 }
 122