Search in sources :

Example 1 with RemoteEnvironment

use of org.jboss.metadata.javaee.spec.RemoteEnvironment in project wildfly by wildfly.

the class PersistenceRefProcessor method getPersistenceContextRefs.

/**
 * 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 JpaLogger.ROOT_LOGGER.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<String, String> map = new HashMap<>();
                    if (properties != null) {
                        for (PropertyMetaData prop : properties) {
                            map.put(prop.getKey(), prop.getValue());
                        }
                    }
                    PersistenceContextType type = (puRef.getPersistenceContextType() == null || puRef.getPersistenceContextType() == PersistenceContextTypeDescription.TRANSACTION) ? PersistenceContextType.TRANSACTION : PersistenceContextType.EXTENDED;
                    SynchronizationType synchronizationType = (puRef.getPersistenceContextSynchronization() == null || PersistenceContextSynchronizationType.Synchronized.equals(puRef.getPersistenceContextSynchronization())) ? SynchronizationType.SYNCHRONIZED : SynchronizationType.UNSYNCHRONIZED;
                    InjectionSource pcBindingSource = this.getPersistenceContextBindingSource(deploymentUnit, persistenceUnitName, type, synchronizationType, map);
                    bindingConfiguration = new BindingConfiguration(name, pcBindingSource);
                }
                bindingConfigurations.add(bindingConfiguration);
            }
        }
    }
    return bindingConfigurations;
}
Also used : RemoteEnvironment(org.jboss.metadata.javaee.spec.RemoteEnvironment) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PersistenceContextType(javax.persistence.PersistenceContextType) PropertyMetaData(org.jboss.metadata.javaee.spec.PropertyMetaData) PropertiesMetaData(org.jboss.metadata.javaee.spec.PropertiesMetaData) PersistenceContextSynchronizationType(org.jboss.metadata.javaee.spec.PersistenceContextSynchronizationType) SynchronizationType(javax.persistence.SynchronizationType) PersistenceContextReferenceMetaData(org.jboss.metadata.javaee.spec.PersistenceContextReferenceMetaData) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) InjectionSource(org.jboss.as.ee.component.InjectionSource) PersistenceContextInjectionSource(org.jboss.as.jpa.injectors.PersistenceContextInjectionSource) PersistenceUnitInjectionSource(org.jboss.as.jpa.injectors.PersistenceUnitInjectionSource) RemoteEnvironment(org.jboss.metadata.javaee.spec.RemoteEnvironment) DeploymentDescriptorEnvironment(org.jboss.as.ee.component.DeploymentDescriptorEnvironment) Environment(org.jboss.metadata.javaee.spec.Environment) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) PersistenceContextReferencesMetaData(org.jboss.metadata.javaee.spec.PersistenceContextReferencesMetaData) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource)

Example 2 with RemoteEnvironment

use of org.jboss.metadata.javaee.spec.RemoteEnvironment in project wildfly by wildfly.

the class DescriptorEnvironmentLifecycleMethodProcessor method handleMethods.

public static void handleMethods(DeploymentDescriptorEnvironment env, EEModuleDescription eeModuleDescription, String defaultClassName) throws DeploymentUnitProcessingException {
    final RemoteEnvironment environment = env.getEnvironment();
    // post-construct(s) of the interceptor configured (if any) in the deployment descriptor
    LifecycleCallbacksMetaData postConstructs = environment.getPostConstructs();
    if (postConstructs != null) {
        for (LifecycleCallbackMetaData postConstruct : postConstructs) {
            String className = postConstruct.getClassName();
            if (className == null || className.isEmpty()) {
                if (defaultClassName == null) {
                    continue;
                } else {
                    className = defaultClassName;
                }
            }
            final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
            String methodName = postConstruct.getMethodName();
            MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName);
            builder.setPostConstruct(methodIdentifier);
            eeModuleDescription.addInterceptorMethodOverride(className, builder.build());
        }
    }
    // pre-destroy(s) of the interceptor configured (if any) in the deployment descriptor
    LifecycleCallbacksMetaData preDestroys = environment.getPreDestroys();
    if (preDestroys != null) {
        for (LifecycleCallbackMetaData preDestroy : preDestroys) {
            String className = preDestroy.getClassName();
            if (className == null || className.isEmpty()) {
                if (defaultClassName == null) {
                    continue;
                } else {
                    className = defaultClassName;
                }
            }
            final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
            String methodName = preDestroy.getMethodName();
            MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName);
            builder.setPreDestroy(methodIdentifier);
            eeModuleDescription.addInterceptorMethodOverride(className, builder.build());
        }
    }
}
Also used : RemoteEnvironment(org.jboss.metadata.javaee.spec.RemoteEnvironment) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) LifecycleCallbackMetaData(org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) LifecycleCallbacksMetaData(org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData)

Example 3 with RemoteEnvironment

use of org.jboss.metadata.javaee.spec.RemoteEnvironment in project wildfly by wildfly.

the class EjbRefProcessor method processDescriptorEntries.

/**
 * Resolves ejb-ref and ejb-local-ref elements
 *
 * @param deploymentUnit
 * @param environment               The environment to resolve the elements for
 * @param componentDescription
 *@param classLoader               The deployment class loader
 * @param deploymentReflectionIndex The reflection index
 * @param applicationClasses    @return The bindings for the environment entries
 */
protected List<BindingConfiguration> processDescriptorEntries(DeploymentUnit deploymentUnit, DeploymentDescriptorEnvironment environment, ResourceInjectionTarget resourceInjectionTarget, final ComponentDescription componentDescription, ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException {
    final RemoteEnvironment remoteEnvironment = environment.getEnvironment();
    List<BindingConfiguration> bindingDescriptions = new ArrayList<BindingConfiguration>();
    EJBReferencesMetaData ejbRefs = remoteEnvironment.getEjbReferences();
    if (ejbRefs != null) {
        for (EJBReferenceMetaData ejbRef : ejbRefs) {
            String name = ejbRef.getEjbRefName();
            String ejbName = ejbRef.getLink();
            String lookup = ejbRef.getLookupName() != null ? ejbRef.getLookupName() : ejbRef.getMappedName();
            String remoteInterface = ejbRef.getRemote();
            String home = ejbRef.getHome();
            Class<?> remoteInterfaceType = null;
            // if a home is specified this is the type that is bound
            if (!isEmpty(home)) {
                try {
                    remoteInterfaceType = ClassLoadingUtils.loadClass(home, deploymentUnit);
                } catch (ClassNotFoundException e) {
                    throw EjbLogger.ROOT_LOGGER.failedToLoadViewClass(e, home);
                }
            } else if (!isEmpty(remoteInterface)) {
                try {
                    remoteInterfaceType = ClassLoadingUtils.loadClass(remoteInterface, deploymentUnit);
                } catch (ClassNotFoundException e) {
                    throw EjbLogger.ROOT_LOGGER.failedToLoadViewClass(e, remoteInterface);
                }
            }
            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
            remoteInterfaceType = processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, ejbRef, remoteInterfaceType);
            final BindingConfiguration bindingConfiguration;
            EjbInjectionSource ejbInjectionSource = null;
            if (!isEmpty(lookup)) {
                if (!lookup.startsWith("java:")) {
                    bindingConfiguration = new BindingConfiguration(name, new EjbLookupInjectionSource(lookup, remoteInterfaceType));
                } else {
                    bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(lookup));
                }
            } else {
                if (remoteInterfaceType == null) {
                    throw EjbLogger.ROOT_LOGGER.couldNotDetermineEjbRefForInjectionTarget(name, resourceInjectionTarget);
                }
                if (!isEmpty(ejbName)) {
                    bindingConfiguration = new BindingConfiguration(name, ejbInjectionSource = new EjbInjectionSource(ejbName, remoteInterfaceType.getName(), name, deploymentUnit, appclient));
                } else {
                    bindingConfiguration = new BindingConfiguration(name, ejbInjectionSource = new EjbInjectionSource(remoteInterfaceType.getName(), name, deploymentUnit, appclient));
                }
            }
            if (ejbInjectionSource != null) {
                deploymentUnit.addToAttachmentList(EjbDeploymentAttachmentKeys.EJB_INJECTIONS, ejbInjectionSource);
            }
            bindingDescriptions.add(bindingConfiguration);
        }
    }
    if (remoteEnvironment instanceof Environment && !appclient) {
        EJBLocalReferencesMetaData ejbLocalRefs = ((Environment) remoteEnvironment).getEjbLocalReferences();
        if (ejbLocalRefs != null) {
            for (EJBLocalReferenceMetaData ejbRef : ejbLocalRefs) {
                String name = ejbRef.getEjbRefName();
                String ejbName = ejbRef.getLink();
                String lookup = ejbRef.getLookupName() != null ? ejbRef.getLookupName() : ejbRef.getMappedName();
                String localInterface = ejbRef.getLocal();
                String localHome = ejbRef.getLocalHome();
                Class<?> localInterfaceType = null;
                // if a home is specified this is the type that is bound
                if (!isEmpty(localHome)) {
                    try {
                        localInterfaceType = ClassLoadingUtils.loadClass(localHome, deploymentUnit);
                    } catch (ClassNotFoundException e) {
                        throw EjbLogger.ROOT_LOGGER.failedToLoadViewClass(e, localHome);
                    }
                } else if (!isEmpty(localInterface)) {
                    try {
                        localInterfaceType = ClassLoadingUtils.loadClass(localInterface, deploymentUnit);
                    } catch (ClassNotFoundException e) {
                        throw EjbLogger.ROOT_LOGGER.failedToLoadViewClass(e, localInterface);
                    }
                }
                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
                localInterfaceType = processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, ejbRef, localInterfaceType);
                if (localInterfaceType == null) {
                    throw EjbLogger.ROOT_LOGGER.couldNotDetermineEjbLocalRefForInjectionTarget(name, resourceInjectionTarget);
                }
                final BindingConfiguration bindingConfiguration;
                EjbInjectionSource ejbInjectionSource = null;
                if (!isEmpty(lookup)) {
                    if (!lookup.startsWith("java:")) {
                        bindingConfiguration = new BindingConfiguration(name, new EjbLookupInjectionSource(lookup, localInterfaceType));
                    } else {
                        bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(lookup));
                    }
                } else if (!isEmpty(ejbName)) {
                    bindingConfiguration = new BindingConfiguration(name, ejbInjectionSource = new EjbInjectionSource(ejbName, localInterfaceType.getName(), name, deploymentUnit, appclient));
                } else {
                    bindingConfiguration = new BindingConfiguration(name, ejbInjectionSource = new EjbInjectionSource(localInterfaceType.getName(), name, deploymentUnit, appclient));
                }
                if (ejbInjectionSource != null) {
                    deploymentUnit.addToAttachmentList(EjbDeploymentAttachmentKeys.EJB_INJECTIONS, ejbInjectionSource);
                }
                bindingDescriptions.add(bindingConfiguration);
            }
        }
    }
    return bindingDescriptions;
}
Also used : RemoteEnvironment(org.jboss.metadata.javaee.spec.RemoteEnvironment) EJBLocalReferenceMetaData(org.jboss.metadata.javaee.spec.EJBLocalReferenceMetaData) ArrayList(java.util.ArrayList) EJBReferenceMetaData(org.jboss.metadata.javaee.spec.EJBReferenceMetaData) Environment(org.jboss.metadata.javaee.spec.Environment) RemoteEnvironment(org.jboss.metadata.javaee.spec.RemoteEnvironment) DeploymentDescriptorEnvironment(org.jboss.as.ee.component.DeploymentDescriptorEnvironment) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) EJBReferencesMetaData(org.jboss.metadata.javaee.spec.EJBReferencesMetaData) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) EJBLocalReferencesMetaData(org.jboss.metadata.javaee.spec.EJBLocalReferencesMetaData)

Aggregations

RemoteEnvironment (org.jboss.metadata.javaee.spec.RemoteEnvironment)3 ArrayList (java.util.ArrayList)2 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)2 DeploymentDescriptorEnvironment (org.jboss.as.ee.component.DeploymentDescriptorEnvironment)2 LookupInjectionSource (org.jboss.as.ee.component.LookupInjectionSource)2 Environment (org.jboss.metadata.javaee.spec.Environment)2 HashMap (java.util.HashMap)1 PersistenceContextType (javax.persistence.PersistenceContextType)1 SynchronizationType (javax.persistence.SynchronizationType)1 InjectionSource (org.jboss.as.ee.component.InjectionSource)1 InterceptorClassDescription (org.jboss.as.ee.component.interceptors.InterceptorClassDescription)1 PersistenceContextInjectionSource (org.jboss.as.jpa.injectors.PersistenceContextInjectionSource)1 PersistenceUnitInjectionSource (org.jboss.as.jpa.injectors.PersistenceUnitInjectionSource)1 MethodIdentifier (org.jboss.invocation.proxy.MethodIdentifier)1 EJBLocalReferenceMetaData (org.jboss.metadata.javaee.spec.EJBLocalReferenceMetaData)1 EJBLocalReferencesMetaData (org.jboss.metadata.javaee.spec.EJBLocalReferencesMetaData)1 EJBReferenceMetaData (org.jboss.metadata.javaee.spec.EJBReferenceMetaData)1 EJBReferencesMetaData (org.jboss.metadata.javaee.spec.EJBReferencesMetaData)1 LifecycleCallbackMetaData (org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData)1 LifecycleCallbacksMetaData (org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData)1