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: 101   Methods: 5
NCLOC: 43   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 75% 71.4% 60% 70.4%
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.hivemind.impl.BaseLocatable;
 18   
 import org.apache.hivemind.internal.Module;
 19   
 import org.apache.hivemind.util.PropertyUtils;
 20   
 
 21   
 /**
 22   
  * Represents one facet of constructing a service implementation instance.
 23   
  * A facet is either a property to be set on the constructed instance,
 24   
  * or a parameter to the instance class' constructor. Facets are nested
 25   
  * properties within {@link org.apache.hivemind.service.impl.BuilderParameter},
 26   
  * and are used by {@link org.apache.hivemind.service.impl.BuilderFactory}.
 27   
  *
 28   
  * @author Howard Lewis Ship
 29   
  */
 30   
 public abstract class BuilderFacet extends BaseLocatable
 31   
 {
 32   
     private String _propertyName;
 33   
 
 34   
     /**
 35   
      * Implemented in subclasses to provide a specific value for the facet
 36   
      * (for use as a constructor parameter, or as a value to set a property to).
 37   
      * 
 38   
      * @param point the service extension point for which BuilderFactory is constructing
 39   
      * a core service implementation instance.
 40   
      * @param invokingModule the Module which invoked the BuilderFactory
 41   
      * @param targetType the desired property type (extracted from the property type
 42   
      * of the property to be updated, when a property is known)
 43   
      */
 44   
     public abstract Object getFacetValue(String serviceId, Module invokingModule, Class targetType);
 45   
 
 46  1259
     public String getPropertyName()
 47   
     {
 48  1259
         return _propertyName;
 49   
     }
 50   
 
 51  203
     public void setPropertyName(String string)
 52   
     {
 53  203
         _propertyName = string;
 54   
     }
 55   
 
 56  1259
     public void autowire(Object target, String serviceId, Module invokingModule)
 57   
     {
 58  1259
         if (_propertyName != null)
 59  203
             return;
 60   
 
 61  1056
         String defaultPropertyName = getDefaultPropertyName();
 62   
 
 63  1056
         if (defaultPropertyName == null)
 64  0
             return;
 65   
 
 66  1056
         Class facetType = getFacetType();
 67   
 
 68  1056
         if (facetType == null)
 69  0
             return;
 70   
 
 71  1056
         if (PropertyUtils.isWritable(target, defaultPropertyName)
 72   
             && PropertyUtils.getPropertyType(target, defaultPropertyName).isAssignableFrom(
 73   
                 facetType))
 74  20
             PropertyUtils.write(
 75   
                 target,
 76   
                 defaultPropertyName,
 77   
                 getFacetValue(serviceId, invokingModule, facetType));
 78   
     }
 79   
     
 80   
     /**
 81   
      * Returns null. Subclasses can provide the default name for a property used
 82   
      * by {@link #autowire(Object)}.
 83   
      */
 84  0
     protected String getDefaultPropertyName()
 85   
     {
 86  0
         return null;
 87   
     }
 88   
 
 89   
     /**
 90   
      * Returns the type of property assigned by this facet, if known. Returns null
 91   
      * otherwise.  This implementation returns null.  Used by 
 92   
      * {@link #autowire(Object, String, Module)}.
 93   
      */
 94   
 
 95  0
     protected Class getFacetType()
 96   
     {
 97  0
         return null;
 98   
     }
 99   
 
 100   
 }
 101