Clover coverage report - Code Coverage for hivemind release 1.1-alpha-1
Coverage timestamp: Tue Jan 18 2005 07:55:08 EST
file stats: LOC: 78   Methods: 4
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
BuilderPropertyFacet.java 100% 100% 100% 100%
coverage
 1   
 // Copyright 2004, 2005 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.ApplicationRuntimeException;
 18   
 import org.apache.hivemind.ServiceImplementationFactoryParameters;
 19   
 import org.apache.hivemind.schema.Translator;
 20   
 import org.apache.hivemind.util.ConstructorUtils;
 21   
 
 22   
 /**
 23   
  * Implementation of {@link org.apache.hivemind.service.impl.BuilderFacet}that stores a value. This
 24   
  * corresponds to the <set> type elements and all constructor parameter elements. The value is
 25   
  * not resolved until needed using a specified {@link Translator}.
 26   
  * 
 27   
  * @author Howard Lewis Ship
 28   
  */
 29   
 public class BuilderPropertyFacet extends BuilderFacet
 30   
 {
 31   
     private String _translatorName;
 32   
 
 33   
     private String _literalValue;
 34   
 
 35  377
     public Object getFacetValue(ServiceImplementationFactoryParameters factoryParameters,
 36   
             Class targetType)
 37   
     {
 38  377
         Translator translator = factoryParameters.getInvokingModule()
 39   
                 .getTranslator(_translatorName);
 40   
 
 41  377
         return translator.translate(
 42   
                 factoryParameters.getInvokingModule(),
 43   
                 targetType,
 44   
                 _literalValue,
 45   
                 getLocation());
 46   
     }
 47   
 
 48  19
     public boolean isAssignableToType(ServiceImplementationFactoryParameters factoryParameters,
 49   
             Class targetType)
 50   
     {
 51  19
         try
 52   
         {
 53   
             // TODO should Translator declare an analoguous isAssignableToType method?
 54  19
             Object facetValue = getFacetValue(factoryParameters, targetType);
 55   
 
 56  18
             if (facetValue == null)
 57  1
                 return !targetType.isPrimitive();
 58   
 
 59  17
             return ConstructorUtils.isCompatible(targetType, facetValue.getClass());
 60   
         }
 61   
         catch (ApplicationRuntimeException e)
 62   
         {
 63  1
             return false;
 64   
         }
 65   
     }
 66   
 
 67   
     /** @since 1.1 */
 68  358
     public void setTranslator(String translatorName)
 69   
     {
 70  358
         _translatorName = translatorName;
 71   
     }
 72   
 
 73  357
     public void setValue(String value)
 74   
     {
 75  357
         _literalValue = value;
 76   
     }
 77   
 
 78   
 }