use of org.jboss.as.ee.component.ResourceInjectionTarget in project wildfly by wildfly.
the class AbstractDeploymentDescriptorBindingsProcessor method processInjectionTargets.
/**
* Processes the injection targets of a resource binding
*
*
* @param injectionSource The injection source for the injection target
* @param classLoader The module class loader
* @param deploymentReflectionIndex The deployment reflection index
* @param entry The resource with injection targets
* @param classType The expected type of the injection point, may be null if this is to be inferred from the injection target
* @return The actual class type of the injection point
* @throws DeploymentUnitProcessingException
* If the injection points could not be resolved
*/
protected Class<?> processInjectionTargets(final ResourceInjectionTarget resourceInjectionTarget, InjectionSource injectionSource, ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, ResourceInjectionMetaData entry, Class<?> classType) throws DeploymentUnitProcessingException {
if (entry.getInjectionTargets() != null) {
for (ResourceInjectionTargetMetaData injectionTarget : entry.getInjectionTargets()) {
final String injectionTargetClassName = injectionTarget.getInjectionTargetClass();
final String injectionTargetName = injectionTarget.getInjectionTargetName();
final AccessibleObject fieldOrMethod = getInjectionTarget(injectionTargetClassName, injectionTargetName, classLoader, deploymentReflectionIndex);
final Class<?> injectionTargetType = fieldOrMethod instanceof Field ? ((Field) fieldOrMethod).getType() : ((Method) fieldOrMethod).getParameterTypes()[0];
final String memberName = fieldOrMethod instanceof Field ? ((Field) fieldOrMethod).getName() : ((Method) fieldOrMethod).getName();
if (classType != null) {
if (!injectionTargetType.isAssignableFrom(classType)) {
boolean ok = false;
if (classType.isPrimitive()) {
if (BOXED_TYPES.get(classType).equals(injectionTargetType)) {
ok = true;
}
} else if (injectionTargetType.isPrimitive()) {
if (BOXED_TYPES.get(injectionTargetType).equals(classType)) {
ok = true;
}
}
if (!ok) {
throw EeLogger.ROOT_LOGGER.invalidInjectionTarget(injectionTarget.getInjectionTargetName(), injectionTarget.getInjectionTargetClass(), classType);
}
classType = injectionTargetType;
}
} else {
classType = injectionTargetType;
}
final InjectionTarget injectionTargetDescription = fieldOrMethod instanceof Field ? new FieldInjectionTarget(injectionTargetClassName, memberName, classType.getName()) : new MethodInjectionTarget(injectionTargetClassName, memberName, classType.getName());
final ResourceInjectionConfiguration injectionConfiguration = new ResourceInjectionConfiguration(injectionTargetDescription, injectionSource);
resourceInjectionTarget.addResourceInjection(injectionConfiguration);
}
}
return classType;
}
Aggregations