use of org.jboss.metadata.javaee.spec.ResourceEnvironmentReferencesMetaData in project wildfly by wildfly.
the class ResourceReferenceProcessor method getResourceEnvRefEntries.
private List<BindingConfiguration> getResourceEnvRefEntries(final DeploymentUnit deploymentUnit, final DeploymentDescriptorEnvironment environment, ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, ResourceInjectionTarget resourceInjectionTarget) throws DeploymentUnitProcessingException {
List<BindingConfiguration> bindings = new ArrayList<BindingConfiguration>();
final ResourceEnvironmentReferencesMetaData resourceEnvRefs = environment.getEnvironment().getResourceEnvironmentReferences();
final EEResourceReferenceProcessorRegistry registry = deploymentUnit.getAttachment(Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY);
if (resourceEnvRefs == null) {
return bindings;
}
for (ResourceEnvironmentReferenceMetaData resourceEnvRef : resourceEnvRefs) {
final String name;
if (resourceEnvRef.getName().startsWith("java:")) {
name = resourceEnvRef.getName();
} else {
name = environment.getDefaultContext() + resourceEnvRef.getName();
}
Class<?> classType = null;
if (resourceEnvRef.getType() != null) {
try {
classType = classLoader.loadClass(resourceEnvRef.getType());
} catch (ClassNotFoundException e) {
throw EeLogger.ROOT_LOGGER.cannotLoad(e, resourceEnvRef.getType());
}
}
// our injection (source) comes from the local (ENC) lookup, no matter what.
InjectionSource injectionSource = new LookupInjectionSource(name);
classType = processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, resourceEnvRef, classType);
if (!isEmpty(resourceEnvRef.getLookupName())) {
injectionSource = new LookupInjectionSource(resourceEnvRef.getLookupName(), classType != null && JAVAX_NAMING_CONTEXT.equals(classType.getName()));
} else {
if (classType == null) {
throw EeLogger.ROOT_LOGGER.cannotDetermineType(name);
}
//check if it is a well known type
final String lookup = ResourceInjectionAnnotationParsingProcessor.FIXED_LOCATIONS.get(classType.getName());
if (lookup != null) {
injectionSource = new LookupInjectionSource(lookup);
} else {
final EEResourceReferenceProcessor resourceReferenceProcessor = registry.getResourceReferenceProcessor(classType.getName());
if (resourceReferenceProcessor != null) {
injectionSource = resourceReferenceProcessor.getResourceReferenceBindingSource();
} else {
//TODO: how are we going to handle these? Previously they would have been handled by jboss-*.xml
if (resourceEnvRef.getResourceEnvRefName().startsWith("java:")) {
ROOT_LOGGER.cannotResolve("resource-env-ref", name);
continue;
} else {
injectionSource = new LookupInjectionSource("java:jboss/resources/" + resourceEnvRef.getResourceEnvRefName());
}
}
}
}
bindings.add(new BindingConfiguration(name, injectionSource));
}
return bindings;
}
Aggregations