2009/04/15 - Apache HiveMind has been retired.

For more information, please explore the Attic.

Clover coverage report - Code Coverage for hivemind release 1.2.1
Coverage timestamp: Fri Feb 10 2006 16:33:43 PST
file stats: LOC: 90   Methods: 4
NCLOC: 46   Classes: 1
 
 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 java.util.HashMap;
 18    import java.util.Map;
 19   
 20    import org.apache.hivemind.Location;
 21    import org.apache.hivemind.ServiceImplementationFactoryParameters;
 22    import org.apache.hivemind.internal.Module;
 23    import org.apache.hivemind.schema.Translator;
 24    import org.apache.hivemind.util.ConstructorUtils;
 25   
 26    /**
 27    * Implementation of {@link org.apache.hivemind.service.impl.BuilderFacet} that stores a value. This
 28    * corresponds to the <set> type elements and all constructor parameter elements. The value is
 29    * not resolved until needed using a specified {@link Translator}.
 30    *
 31    * @author Howard Lewis Ship
 32    */
 33    public class BuilderPropertyFacet extends BuilderFacet
 34    {
 35    private String _translatorName;
 36   
 37    private String _literalValue;
 38   
 39    /**
 40    * Cache for translated values to prevent calling
 41    * {@link Translator#translate(Module, Class, String, Location)} twice.
 42    */
 43    private Map _valuesCache = new HashMap();
 44   
 45  446 public Object getFacetValue(ServiceImplementationFactoryParameters factoryParameters,
 46    Class targetType)
 47    {
 48  446 Object result = _valuesCache.get(targetType);
 49   
 50  446 if (result == null)
 51    {
 52  437 Translator translator = factoryParameters.getInvokingModule().getTranslator(
 53    _translatorName);
 54   
 55  437 result = translator.translate(
 56    factoryParameters.getInvokingModule(),
 57    targetType,
 58    _literalValue,
 59    getLocation());
 60   
 61  435 _valuesCache.put(targetType, result);
 62    }
 63   
 64  444 return result;
 65    }
 66   
 67  21 public boolean isAssignableToType(ServiceImplementationFactoryParameters factoryParameters,
 68    Class targetType)
 69    {
 70    // TODO should Translator declare an analoguous isAssignableToType method?
 71  21 Object facetValue = getFacetValue(factoryParameters, targetType);
 72   
 73  20 if (facetValue == null)
 74  1 return !targetType.isPrimitive();
 75   
 76  19 return ConstructorUtils.isCompatible(targetType, facetValue.getClass());
 77    }
 78   
 79    /** @since 1.1 */
 80  426 public void setTranslator(String translatorName)
 81    {
 82  426 _translatorName = translatorName;
 83    }
 84   
 85  425 public void setValue(String value)
 86    {
 87  425 _literalValue = value;
 88    }
 89   
 90    }