}
if (isEmpty(lookup) && FIXED_LOCATIONS.containsKey(injectionType)) {
lookup = FIXED_LOCATIONS.get(injectionType);
}
InjectionSource valueSource = null;
final boolean isEnvEntryType = this.isEnvEntryType(injectionType, module);
final boolean isResourceRefType = RESOURCE_REF_ENTRIES.contains(injectionType);
boolean createBinding = true;
if (!isEmpty(lookup)) {
valueSource = new LookupInjectionSource(lookup);
} else if (isEnvEntryType) {
// if it's a env-entry type then we do *not* create a BindingConfiguration to bind to the ENC
// since the binding (value) for env-entry is always driven from a deployment descriptor.
// The deployment descriptor processing and subsequent binding in the ENC is taken care off by a
// different Deployment unit processor. If the value isn't specified in the deployment descriptor,
// then there will be no binding the ENC and that's what is expected by the Java EE 6 spec. Furthermore,
// if the @Resource is a env-entry binding then the injection target will be optional since in the absence of
// a env-entry-value, there won't be a binding and effectively no injection. This again is as expected by spec.
} else if (!isResourceRefType) {
final EEResourceReferenceProcessor resourceReferenceProcessor = EEResourceReferenceProcessorRegistry.getResourceReferenceProcessor(injectionType);
if (resourceReferenceProcessor == null) {
logger.warnf("Can't handle @Resource for ENC name: %s on class %s since it's missing a \"lookup\" (or \"mappedName\") value and isn't of any known type", localContextName, classDescription.getClassName());
return;
}
valueSource = resourceReferenceProcessor.getResourceReferenceBindingSource(phaseContext, eeModuleDescription, classDescription, injectionType, localContextName, targetDescription);
if (valueSource == null) {
logger.warnf("Could not find binding source for @Resource, for ENC name: %s on class %s " +
" of type: %s from resource reference processor: %s", localContextName, classDescription.getClassName(), injectionType, resourceReferenceProcessor);
return;
}
} else {
//handle resource reference types
createBinding = false;
valueSource = new LookupInjectionSource(localContextName);
}
final boolean createBindingFinal = createBinding;
// EE.5.2.4
// Each injection of an object corresponds to a JNDI lookup. Whether a new
// instance of the requested object is injected, or whether a shared instance is
// injected, is determined by the rules described above.
// Because of performance we allow any type of InjectionSource.
if (valueSource == null) {
// the ResourceInjectionConfiguration is created by LazyResourceInjection
LazyResourceInjection lazyResourceInjection = new LazyResourceInjection(targetDescription, localContextName , classDescription);
applicationClasses.addLazyResourceInjection(lazyResourceInjection);
} else {
// our injection comes from the local lookup, no matter what.
final InjectionSource injectionSource = new LookupInjectionSource(localContextName);
final ResourceInjectionConfiguration injectionConfiguration = targetDescription != null ?
new ResourceInjectionConfiguration(targetDescription, injectionSource) : null;
final BindingConfiguration bindingConfiguration = new BindingConfiguration(localContextName, valueSource);
// TODO: class hierarchies? shared bindings?