Class annotatedClass = annotatedType.getJavaClass();
JndiNameEnvironment jndiNameEnvironment = (JndiNameEnvironment) bundleContext;
ServiceLocator serviceLocator = Globals.getDefaultHabitat();
InvocationManager invocationManager = serviceLocator.getService(InvocationManager.class);
ComponentEnvManager compEnvManager = serviceLocator.getService(ComponentEnvManager.class);
String componentId = compEnvManager.getComponentEnvId(jndiNameEnvironment);
String appName = bundleContext.getApplication().getAppName();
String moduleName = bundleContext.getModuleName();
ComponentInvocation componentInvocation = null;
InjectionInfo injectionInfo = jndiNameEnvironment.getInjectionInfoByClass(annotatedClass);
List<InjectionCapable> injectionResources = injectionInfo.getInjectionResources();
if ( injectionResources.size() > 0 ) {
}
boolean lookupsWillWork = true;
for (AnnotatedField<? super T> annotatedField : annotatedType.getFields()) {
if ( lookupsWillWork && annotatedField.isAnnotationPresent( Produces.class ) ) {
if ( componentInvocation == null ) {
componentInvocation = createComponentInvocation( componentId,
appName,
moduleName);
try {
invocationManager.preInvoke(componentInvocation);
} catch ( Exception preInvokeException ) {
lookupsWillWork = false;
}
}
if ( lookupsWillWork ) {
String lookupName = getLookupName( annotatedClass,
annotatedField,
injectionResources );
Object resource = getResource( lookupName );
if ( resource == null ) {
// we have to retry using the component environment name because it could be a env entry with a
// name specified in the annotation but getLookupName returned that instead of the
// field's component env entry name...convoluted but necessary
lookupName = getComponentEnvName( annotatedClass,
annotatedField.getJavaMember().getName(),
injectionResources );
resource = getResource( lookupName );
}
if ( resource != null ) {
validateResource( annotatedField, resource);
}
}
}
}
if ( componentInvocation != null ) {
try {
invocationManager.postInvoke(componentInvocation);
} catch ( Exception ignore ) {
}
}
}