コード例 #1
0
  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);
      }
    }
  }
コード例 #2
0
  private void process(
      final DeploymentUnit deploymentUnit,
      final String beanInterface,
      final String beanName,
      final String lookup,
      final ClassInfo classInfo,
      final InjectionTarget targetDescription,
      final String localContextName,
      final EEModuleDescription eeModuleDescription) {

    if (!isEmpty(lookup) && !isEmpty(beanName)) {
      logger.debug(
          "Both beanName = "
              + beanName
              + " and lookup = "
              + lookup
              + " have been specified in @EJB annotation."
              + " lookup will be given preference. Class: "
              + classInfo.name());
    }

    final EEModuleClassDescription classDescription =
        eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());

    final InjectionSource valueSource;
    EjbInjectionSource ejbInjectionSource = null;
    // give preference to lookup
    if (!isEmpty(lookup)) {
      if (!lookup.startsWith("java:")) {
        valueSource =
            new EjbLookupInjectionSource(lookup, targetDescription.getDeclaredValueClassName());
      } else {
        valueSource = createLookup(lookup, appclient);
      }
    } else if (!isEmpty(beanName)) {
      valueSource =
          ejbInjectionSource =
              new EjbInjectionSource(
                  beanName, beanInterface, localContextName, deploymentUnit, appclient);
    } else {
      valueSource =
          ejbInjectionSource =
              new EjbInjectionSource(beanInterface, localContextName, deploymentUnit, appclient);
    }
    if (ejbInjectionSource != null) {
      deploymentUnit.addToAttachmentList(
          EjbDeploymentAttachmentKeys.EJB_INJECTIONS, ejbInjectionSource);
    }
    // our injection comes from the local lookup, no matter what.
    final ResourceInjectionConfiguration injectionConfiguration =
        targetDescription != null
            ? new ResourceInjectionConfiguration(
                targetDescription, createLookup(localContextName, appclient))
            : null;

    // Create the binding from whence our injection comes.
    final BindingConfiguration bindingConfiguration =
        new BindingConfiguration(localContextName, valueSource);

    classDescription.getBindingConfigurations().add(bindingConfiguration);
    if (injectionConfiguration != null) {
      classDescription.addResourceInjection(injectionConfiguration);
    }
  }