Exemplo n.º 1
0
  @Override
  protected List<BindingConfiguration> processDescriptorEntries(
      final DeploymentUnit unit,
      final DeploymentDescriptorEnvironment environment,
      final EEModuleDescription moduleDescription,
      final ComponentDescription componentDescription,
      final ClassLoader classLoader,
      final DeploymentReflectionIndex deploymentReflectionIndex,
      final EEApplicationClasses applicationClasses)
      throws DeploymentUnitProcessingException {
    final ServiceReferencesMetaData serviceRefsMD =
        environment.getEnvironment().getServiceReferences();
    if (serviceRefsMD == null) {
      return Collections.<BindingConfiguration>emptyList();
    }

    final List<BindingConfiguration> bindingDescriptions = new LinkedList<BindingConfiguration>();
    for (final ServiceReferenceMetaData serviceRefMD : serviceRefsMD) {
      final UnifiedServiceRefMetaData serviceRefUMDM = getServiceRef(unit, serviceRefMD);
      final WSRefValueSource valueSource = new WSRefValueSource(serviceRefUMDM);
      final BindingConfiguration bindingConfiguration =
          new BindingConfiguration(serviceRefUMDM.getServiceRefName(), valueSource);
      bindingDescriptions.add(bindingConfiguration);
      final String serviceRefTypeName = serviceRefUMDM.getServiceRefType();
      final Class<?> serviceRefType = getClass(classLoader, serviceRefTypeName);
      processInjectionTargets(
          moduleDescription,
          componentDescription,
          applicationClasses,
          valueSource,
          classLoader,
          deploymentReflectionIndex,
          serviceRefMD,
          serviceRefType);
    }
    return bindingDescriptions;
  }
Exemplo n.º 2
0
  /**
   * Resolves persistence-unit-ref
   *
   * @param environment The environment to resolve the elements for
   * @param classLoader The deployment class loader
   * @param deploymentReflectionIndex The reflection index
   * @return The bindings for the environment entries
   */
  private List<BindingConfiguration> getPersistenceContextRefs(
      DeploymentUnit deploymentUnit,
      DeploymentDescriptorEnvironment environment,
      ClassLoader classLoader,
      DeploymentReflectionIndex deploymentReflectionIndex,
      ResourceInjectionTarget resourceInjectionTarget)
      throws DeploymentUnitProcessingException {

    List<BindingConfiguration> bindingConfigurations = new ArrayList<BindingConfiguration>();
    final RemoteEnvironment remoteEnvironment = environment.getEnvironment();
    if (remoteEnvironment == null) {
      return bindingConfigurations;
    }

    if (remoteEnvironment instanceof Environment) {
      PersistenceContextReferencesMetaData persistenceUnitRefs =
          ((Environment) remoteEnvironment).getPersistenceContextRefs();

      if (persistenceUnitRefs != null) {
        for (PersistenceContextReferenceMetaData puRef : persistenceUnitRefs) {
          String name = puRef.getName();
          String persistenceUnitName = puRef.getPersistenceUnitName();
          String lookup = puRef.getLookupName();

          if (!isEmpty(lookup) && !isEmpty(persistenceUnitName)) {
            throw MESSAGES.cannotSpecifyBoth(
                "<lookup-name>",
                lookup,
                "persistence-unit-name",
                persistenceUnitName,
                "<persistence-context-ref/>",
                resourceInjectionTarget);
          }
          if (!name.startsWith("java:")) {
            name = environment.getDefaultContext() + name;
          }

          // our injection (source) comes from the local (ENC) lookup, no matter what.
          LookupInjectionSource injectionSource = new LookupInjectionSource(name);
          // add any injection targets
          processInjectionTargets(
              resourceInjectionTarget,
              injectionSource,
              classLoader,
              deploymentReflectionIndex,
              puRef,
              EntityManager.class);

          BindingConfiguration bindingConfiguration = null;
          if (!isEmpty(lookup)) {
            bindingConfiguration =
                new BindingConfiguration(name, new LookupInjectionSource(lookup));
          } else {
            PropertiesMetaData properties = puRef.getProperties();
            Map map = new HashMap();
            if (properties != null) {
              for (PropertyMetaData prop : properties) {
                map.put(prop.getKey(), prop.getValue());
              }
            }
            PersistenceContextType type =
                puRef.getPersistenceContextType() == null
                    ? PersistenceContextType.TRANSACTION
                    : puRef.getPersistenceContextType();
            InjectionSource pcBindingSource =
                this.getPersistenceContextBindingSource(
                    deploymentUnit, persistenceUnitName, type, map);
            bindingConfiguration = new BindingConfiguration(name, pcBindingSource);
          }
          bindingConfigurations.add(bindingConfiguration);
        }
      }
    }
    return bindingConfigurations;
  }
Exemplo n.º 3
0
  /**
   * Resolves persistence-unit-ref
   *
   * @param environment The environment to resolve the elements for
   * @param classLoader The deployment class loader
   * @param deploymentReflectionIndex The reflection index
   * @return The bindings for the environment entries
   */
  private List<BindingConfiguration> getPersistenceUnitRefs(
      DeploymentUnit deploymentUnit,
      DeploymentDescriptorEnvironment environment,
      ClassLoader classLoader,
      DeploymentReflectionIndex deploymentReflectionIndex,
      ResourceInjectionTarget resourceInjectionTarget)
      throws DeploymentUnitProcessingException {

    final List<BindingConfiguration> bindingConfigurations = new ArrayList<BindingConfiguration>();
    if (environment.getEnvironment() == null) {
      return bindingConfigurations;
    }
    PersistenceUnitReferencesMetaData persistenceUnitRefs =
        environment.getEnvironment().getPersistenceUnitRefs();

    if (persistenceUnitRefs != null) {
      if (persistenceUnitRefs.size() > 0) {
        JPADeploymentMarker.mark(deploymentUnit);
      }
      for (PersistenceUnitReferenceMetaData puRef : persistenceUnitRefs) {
        String name = puRef.getName();
        String persistenceUnitName = puRef.getPersistenceUnitName();
        String lookup = puRef.getLookupName();

        if (!isEmpty(lookup) && !isEmpty(persistenceUnitName)) {
          throw MESSAGES.cannotSpecifyBoth(
              "<lookup-name>",
              lookup,
              "persistence-unit-name",
              persistenceUnitName,
              "<persistence-unit-ref/>",
              resourceInjectionTarget);
        }
        if (!name.startsWith("java:")) {
          name = environment.getDefaultContext() + name;
        }

        // our injection (source) comes from the local (ENC) lookup, no matter what.
        LookupInjectionSource injectionSource = new LookupInjectionSource(name);

        // add any injection targets
        processInjectionTargets(
            resourceInjectionTarget,
            injectionSource,
            classLoader,
            deploymentReflectionIndex,
            puRef,
            EntityManagerFactory.class);

        BindingConfiguration bindingConfiguration = null;
        if (!isEmpty(lookup)) {
          bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(lookup));
        } else {
          InjectionSource puBindingSource =
              this.getPersistenceUnitBindingSource(deploymentUnit, persistenceUnitName);
          bindingConfiguration = new BindingConfiguration(name, puBindingSource);
        }
        bindingConfigurations.add(bindingConfiguration);
      }
    }
    return bindingConfigurations;
  }