1 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.TranslatorManager; 23 import org.apache.hivemind.internal.Module; 24 import org.apache.hivemind.schema.Translator; 25 import org.apache.hivemind.util.ConstructorUtils; 26 27 34 public class BuilderPropertyFacet extends BuilderFacet 35 { 36 private String _translatorName; 37 38 private String _literalValue; 39 40 44 private Map _valuesCache = new HashMap (); 45 46 public Object getFacetValue(ServiceImplementationFactoryParameters factoryParameters, 47 Class targetType) 48 { 49 Object result = _valuesCache.get(targetType); 50 51 if (result == null) 52 { 53 TranslatorManager translatorManager = (TranslatorManager) factoryParameters.getInvokingModule().getService(TranslatorManager.class); 54 Translator translator = translatorManager.getTranslator(_translatorName); 55 56 result = translator.translate( 57 factoryParameters.getInvokingModule(), 58 targetType, 59 _literalValue, 60 getLocation()); 61 62 _valuesCache.put(targetType, result); 63 } 64 65 return result; 66 } 67 68 public boolean isAssignableToType(ServiceImplementationFactoryParameters factoryParameters, 69 Class targetType) 70 { 71 Object facetValue = getFacetValue(factoryParameters, targetType); 73 74 if (facetValue == null) 75 return !targetType.isPrimitive(); 76 77 return ConstructorUtils.isCompatible(targetType, facetValue.getClass()); 78 } 79 80 81 public void setTranslator(String translatorName) 82 { 83 _translatorName = translatorName; 84 } 85 86 public void setValue(String value) 87 { 88 _literalValue = value; 89 } 90 91 } | Popular Tags |