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 InjectionSource getBindingSource( final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, String injectionTypeName, final EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException { PersistenceUnitMetadata pu = getPersistenceUnit(deploymentUnit, annotation, classDescription); if (pu == null) { return null; } String scopedPuName = pu.getScopedPersistenceUnitName(); ServiceName puServiceName = getPuServiceName(scopedPuName); if (isPersistenceContext(annotation)) { if (pu.getTransactionType() == PersistenceUnitTransactionType.RESOURCE_LOCAL) { classDescription.setInvalid(MESSAGES.cannotInjectResourceLocalEntityManager()); return null; } AnnotationValue pcType = annotation.value("type"); PersistenceContextType type = (pcType == null || PersistenceContextType.TRANSACTION.name().equals(pcType.asString())) ? PersistenceContextType.TRANSACTION : PersistenceContextType.EXTENDED; Map properties; AnnotationValue value = annotation.value("properties"); AnnotationInstance[] props = value != null ? value.asNestedArray() : null; if (props != null) { properties = new HashMap(); for (int source = 0; source < props.length; source++) { properties.put(props[source].value("name"), props[source].value("value")); } } else { properties = null; } return new PersistenceContextInjectionSource( type, properties, puServiceName, deploymentUnit, scopedPuName, injectionTypeName, pu); } else { return new PersistenceUnitInjectionSource( puServiceName, deploymentUnit, injectionTypeName, pu); } }
private PersistenceUnitMetadata getPersistenceUnit( final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException { final AnnotationValue puName = annotation.value("unitName"); String searchName = null; // note: a null searchName will match the first PU definition found if (puName != null) { searchName = puName.asString(); } PersistenceUnitMetadata pu = PersistenceUnitSearch.resolvePersistenceUnitSupplier(deploymentUnit, searchName); if (null == pu) { classDescription.setInvalid(MESSAGES.persistenceUnitNotFound(searchName, deploymentUnit)); return null; } return pu; }