1 15 package org.apache.hivemind.service.impl; 16 17 import org.apache.commons.logging.Log; 18 import org.apache.hivemind.ServiceImplementationFactoryParameters; 19 import org.apache.hivemind.impl.BaseLocatable; 20 import org.apache.hivemind.util.PropertyUtils; 21 22 31 public abstract class BuilderFacet extends BaseLocatable 32 { 33 private String _propertyName; 34 35 45 public abstract Object getFacetValue(ServiceImplementationFactoryParameters factoryParameters, 46 Class targetType); 47 48 public abstract boolean isAssignableToType( 49 ServiceImplementationFactoryParameters factoryParameters, Class targetType); 50 51 public String getPropertyName() 52 { 53 return _propertyName; 54 } 55 56 public void setPropertyName(String string) 57 { 58 _propertyName = string; 59 } 60 61 77 public String autowire(Object target, ServiceImplementationFactoryParameters factoryParameters) 78 { 79 if (_propertyName != null) 80 return null; 81 82 String defaultPropertyName = getDefaultPropertyName(); 83 84 if (defaultPropertyName == null) 85 return null; 86 87 if (!PropertyUtils.isWritable(target, defaultPropertyName)) 88 return null; 89 90 Class propertyType = PropertyUtils.getPropertyType(target, defaultPropertyName); 91 92 if (isAssignableToType(factoryParameters, propertyType)) 93 { 94 Object facetValue = getFacetValue(factoryParameters, propertyType); 95 96 PropertyUtils.write(target, defaultPropertyName, facetValue); 97 98 Log log = factoryParameters.getLog(); 99 100 if (log.isDebugEnabled()) 101 log.debug("Autowired property " + defaultPropertyName + " to " + facetValue); 102 103 return defaultPropertyName; 104 } 105 106 return null; 107 } 108 109 113 protected String getDefaultPropertyName() 114 { 115 return null; 116 } 117 118 119 public boolean canAutowireConstructorParameter() 120 { 121 return false; 122 } 123 124 } | Popular Tags |