1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
@Aspect
public class CarbonAutowiredAdvice {
private static final Log LOG = LogFactory.getLog(CarbonAutowiredAdvice.class);
@Around("execution(* org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(..)) " +
"&& args(descriptor,beanName)")
public Object carbonAutowired(ProceedingJoinPoint invocation,
DependencyDescriptor descriptor, String beanName)
throws Throwable {
Object result = null;
try {
result = invocation.proceed();
} catch (NoSuchBeanDefinitionException se) {
LOG.info("////////// attempt to inject Carbon component...");
try {
// retrouver l'interface visée
Class c = Class.forName(beanName);
assert c.isInterface();
// chercher le champ DEFAULT_COMPONENT_PATH
Field f = c.getField("DEFAULT_COMPONENT_PATH");
String componentPath = (String) f.get(null); //FIXME ok champs static ?
// retrouver le composant dans Carbon
result = Lookup.getInstance().fetchComponent(componentPath);
} catch (Exception ce) {
LOG.debug(ce);
throw se; // en cas d'échec, on se fait oublier
}
}
return result;
}
} |