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 BindingDescription processField( final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, final FieldInfo fieldInfo, final AbstractComponentDescription componentDescription, final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final String fieldName = fieldInfo.name(); final AnnotationValue declaredNameValue = annotation.value("name"); final String declaredName = declaredNameValue != null ? declaredNameValue.asString() : null; final String localContextName; if (declaredName == null || declaredName.isEmpty()) { localContextName = "java:comp/env/persistence" + "/" + fieldName; } else { localContextName = declaredName; } // final AnnotationValue declaredTypeValue = annotation.value("type"); final DotName declaredType = fieldInfo.type().name(); final DotName injectionType = declaredType == null || declaredType.toString().equals(Object.class.getName()) ? fieldInfo.type().name() : declaredType; 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, fieldName, injectionTypeName); bindingDescription.setReferenceSourceDescription( new ServiceBindingSourceDescription(injectorName)); // setup the injection target final InjectionTargetDescription targetDescription = new InjectionTargetDescription(); targetDescription.setName(fieldName); targetDescription.setClassName(fieldInfo.declaringClass().name().toString()); targetDescription.setType(InjectionTargetDescription.Type.FIELD); targetDescription.setValueClassName(injectionTypeName); bindingDescription.getInjectionTargetDescriptions().add(targetDescription); return bindingDescription; }