1 15 package org.apache.hivemind.service.impl; 16 17 import org.apache.commons.logging.Log; 18 import org.apache.commons.logging.LogFactory; 19 import org.apache.hivemind.internal.RegistryInfrastructure; 20 import org.apache.hivemind.service.AutowiringStrategy; 21 import org.apache.hivemind.util.PropertyUtils; 22 23 29 public class AutowiringByTypeStrategy implements AutowiringStrategy 30 { 31 private static final Log LOG = LogFactory.getLog(AutowiringByTypeStrategy.class); 32 33 public boolean autowireProperty(RegistryInfrastructure registry, Object target, String propertyName) 34 { 35 Class propertyType = PropertyUtils.getPropertyType(target, propertyName); 36 37 if (registry.containsService(propertyType, null)) 39 { 40 Object collaboratingService = registry.getService(propertyType, null); 41 PropertyUtils.write(target, propertyName, collaboratingService); 42 43 if (LOG.isDebugEnabled()) 44 { 45 LOG.debug("Autowired property " + propertyName + " by type to " + collaboratingService); 46 } 47 return true; 48 } else { 49 return false; 50 } 51 } 52 53 } 54 | Popular Tags |