use of org.jboss.as.ee.component.MethodInjectionTarget in project wildfly by wildfly.
the class ResourceInjectionAnnotationParsingProcessor method processMethodResource.
protected void processMethodResource(final DeploymentPhaseContext phaseContext, final MethodInfo methodInfo, final String name, final String type, final EEModuleClassDescription classDescription, final AnnotationInstance annotation, final EEModuleDescription eeModuleDescription, final Module module, final EEApplicationClasses applicationClasses, final PropertyReplacer replacer) throws DeploymentUnitProcessingException {
final String methodName = methodInfo.name();
if (!methodName.startsWith("set") || methodInfo.args().length != 1) {
throw EeLogger.ROOT_LOGGER.setterMethodOnly("@Resource", methodInfo);
}
final String contextNameSuffix = methodName.substring(3, 4).toLowerCase(Locale.ENGLISH) + methodName.substring(4);
final String localContextName = isEmpty(name) ? methodInfo.declaringClass().name().toString() + "/" + contextNameSuffix : name;
final String injectionType = isEmpty(type) || type.equals(Object.class.getName()) ? methodInfo.args()[0].name().toString() : type;
final InjectionTarget targetDescription = new MethodInjectionTarget(methodInfo.declaringClass().name().toString(), methodName, methodInfo.args()[0].name().toString());
process(phaseContext, classDescription, annotation, injectionType, localContextName, targetDescription, eeModuleDescription, module, applicationClasses, replacer);
}
use of org.jboss.as.ee.component.MethodInjectionTarget 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;
}
use of org.jboss.as.ee.component.MethodInjectionTarget in project wildfly by wildfly.
the class JPAAnnotationProcessor method processMethod.
private void processMethod(final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, final MethodInfo methodInfo, final EEModuleClassDescription eeModuleClassDescription) throws DeploymentUnitProcessingException {
final String methodName = methodInfo.name();
if (!methodName.startsWith("set") || methodInfo.args().length != 1) {
eeModuleClassDescription.setInvalid(JpaLogger.ROOT_LOGGER.setterMethodOnlyAnnotation(annotation.name().toString(), methodInfo));
return;
}
final String contextNameSuffix = methodName.substring(3, 4).toLowerCase(Locale.ENGLISH) + methodName.substring(4);
final AnnotationValue declaredNameValue = annotation.value("name");
final String declaredName = declaredNameValue != null ? declaredNameValue.asString() : null;
final String localContextName;
if (declaredName == null || declaredName.isEmpty()) {
localContextName = methodInfo.declaringClass().name().toString() + "/" + contextNameSuffix;
} else {
localContextName = declaredName;
}
final String injectionType = methodInfo.args()[0].name().toString();
final InjectionSource bindingSource = this.getBindingSource(deploymentUnit, annotation, injectionType, eeModuleClassDescription);
if (bindingSource != null) {
final BindingConfiguration bindingConfiguration = new BindingConfiguration(localContextName, bindingSource);
eeModuleClassDescription.getBindingConfigurations().add(bindingConfiguration);
// setup the injection configuration
final InjectionTarget injectionTarget = new MethodInjectionTarget(methodInfo.declaringClass().name().toString(), methodName, methodInfo.args()[0].name().toString());
// source is always local ENC jndi name
final InjectionSource injectionSource = new LookupInjectionSource(localContextName);
final ResourceInjectionConfiguration injectionConfiguration = new ResourceInjectionConfiguration(injectionTarget, injectionSource);
eeModuleClassDescription.addResourceInjection(injectionConfiguration);
}
}
use of org.jboss.as.ee.component.MethodInjectionTarget in project wildfly by wildfly.
the class EjbResourceInjectionAnnotationProcessor method processMethod.
private void processMethod(final DeploymentUnit deploymentUnit, final EJBResourceWrapper annotation, final MethodInfo methodInfo, final EEModuleDescription eeModuleDescription) {
final String methodName = methodInfo.name();
if (!methodName.startsWith("set") || methodInfo.args().length != 1) {
throw EjbLogger.ROOT_LOGGER.onlySetterMethodsAllowedToHaveEJBAnnotation(methodInfo);
}
final String methodParamType = methodInfo.args()[0].name().toString();
final InjectionTarget targetDescription = new MethodInjectionTarget(methodInfo.declaringClass().name().toString(), methodName, methodParamType);
final String localContextName = isEmpty(annotation.name()) ? methodInfo.declaringClass().name().toString() + "/" + methodName.substring(3, 4).toLowerCase(Locale.ENGLISH) + methodName.substring(4) : annotation.name();
final String beanInterfaceType = isEmpty(annotation.beanInterface()) || annotation.beanInterface().equals(Object.class.getName()) ? methodParamType : annotation.beanInterface();
process(deploymentUnit, beanInterfaceType, annotation.beanName(), annotation.lookup(), methodInfo.declaringClass(), targetDescription, localContextName, eeModuleDescription);
}
use of org.jboss.as.ee.component.MethodInjectionTarget in project wildfly by wildfly.
the class WSRefAnnotationProcessor method processMethodRef.
private static void processMethodRef(final DeploymentUnit unit, final WSRefAnnotationWrapper annotation, final MethodInfo methodInfo) throws DeploymentUnitProcessingException {
final String methodName = methodInfo.name();
if (!methodName.startsWith("set") || methodInfo.args().length != 1) {
throw WSLogger.ROOT_LOGGER.invalidServiceRefSetterMethodName(methodInfo);
}
final String injectionType = isEmpty(annotation.type()) || annotation.type().equals(Object.class.getName()) ? methodInfo.args()[0].name().toString() : annotation.type();
final InjectionTarget injectionTarget = new MethodInjectionTarget(methodInfo.declaringClass().name().toString(), methodName, injectionType);
final String bindingName = isEmpty(annotation.name()) ? methodInfo.declaringClass().name().toString() + "/" + methodName.substring(3, 4).toLowerCase(Locale.ENGLISH) + methodName.substring(4) : annotation.name();
processRef(unit, injectionType, annotation, methodInfo.declaringClass(), injectionTarget, bindingName);
}
Aggregations