private BindingDescription processMethod( final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, final MethodInfo methodInfo, final AbstractComponentDescription componentDescription, final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final String methodName = methodInfo.name(); if (!methodName.startsWith("set") || methodInfo.args().length != 1) { throw new IllegalArgumentException( "injection target is invalid. Only setter methods are allowed: " + methodInfo); } final String contextNameSuffix = methodName.substring(3, 4).toLowerCase() + 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 DotName declaredType = methodInfo.returnType().name(); final DotName injectionType = declaredType == null || declaredType.toString().equals(Object.class.getName()) ? methodInfo.returnType().name() : declaredType; final BindingDescription bindingDescription = new BindingDescription(); bindingDescription.setDependency(true); bindingDescription.setBindingName(localContextName); final String injectionTypeName = injectionType.toString(); bindingDescription.setBindingType(injectionTypeName); ServiceName injectorName = getInjectorServiceName( deploymentUnit, annotation, componentDescription, phaseContext, methodName, injectionTypeName); bindingDescription.setReferenceSourceDescription( new ServiceBindingSourceDescription(injectorName)); // setup the injection target final InjectionTargetDescription targetDescription = new InjectionTargetDescription(); targetDescription.setName(methodName); targetDescription.setClassName(methodInfo.declaringClass().name().toString()); targetDescription.setType(InjectionTargetDescription.Type.METHOD); targetDescription.setValueClassName(injectionTypeName); bindingDescription.getInjectionTargetDescriptions().add(targetDescription); return bindingDescription; }
private void processPersistenceAnnotations( final DeploymentUnit deploymentUnit, final EEModuleDescription eeModuleDescription, List<AnnotationInstance> persistenceContexts, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException { for (AnnotationInstance annotation : persistenceContexts) { ClassInfo declaringClass = null; final AnnotationTarget annotationTarget = annotation.target(); if (annotationTarget instanceof FieldInfo) { FieldInfo fieldInfo = (FieldInfo) annotationTarget; declaringClass = fieldInfo.declaringClass(); EEModuleClassDescription eeModuleClassDescription = eeModuleDescription.addOrGetLocalClassDescription(declaringClass.name().toString()); this.processField(deploymentUnit, annotation, fieldInfo, eeModuleClassDescription); } else if (annotationTarget instanceof MethodInfo) { MethodInfo methodInfo = (MethodInfo) annotationTarget; declaringClass = methodInfo.declaringClass(); EEModuleClassDescription eeModuleClassDescription = eeModuleDescription.addOrGetLocalClassDescription(declaringClass.name().toString()); this.processMethod(deploymentUnit, annotation, methodInfo, eeModuleClassDescription); } else if (annotationTarget instanceof ClassInfo) { declaringClass = (ClassInfo) annotationTarget; EEModuleClassDescription eeModuleClassDescription = eeModuleDescription.addOrGetLocalClassDescription(declaringClass.name().toString()); this.processClass(deploymentUnit, annotation, eeModuleClassDescription); } } }
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( MESSAGES.setterMethodOnlyAnnotation(annotation.name().toString(), methodInfo)); return; } final String contextNameSuffix = methodName.substring(3, 4).toLowerCase() + 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); } }
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 MESSAGES.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); }
@Override public Collection<Annotation> getAnnotation(Class<?> annotationClass) { List<AnnotationInstance> instances = backingRepository.getAnnotations(DotName.createSimple(annotationClass.getName())); ArrayList<Annotation> annotations = new ArrayList<Annotation>(instances.size()); for (AnnotationInstance instance : instances) { AnnotationTarget target = instance.target(); Annotation annotation = null; if (target instanceof MethodInfo) { MethodInfo m = (MethodInfo) target; List<String> parameterTypes = new ArrayList<String>(m.args().length); for (Type type : m.args()) { parameterTypes.add(type.toString()); } String declaringClass = m.declaringClass().name().toString(); annotation = new AnnotationImpl( declaringClass, cl, parameterTypes, m.name(), true, false, annotationClass); } if (target instanceof FieldInfo) { FieldInfo f = (FieldInfo) target; String declaringClass = f.declaringClass().name().toString(); annotation = new AnnotationImpl(declaringClass, cl, null, f.name(), false, true, annotationClass); } if (target instanceof ClassInfo) { ClassInfo c = (ClassInfo) target; annotation = new AnnotationImpl(c.name().toString(), cl, null, null, false, false, annotationClass); } if (annotation != null) { annotations.add(annotation); } } annotations.trimToSize(); if (annotations.size() == 0) { return null; } else { return Collections.unmodifiableList(annotations); } }