Search in sources :

Example 76 with Module

use of org.jboss.modules.Module in project wildfly by wildfly.

the class PersistenceProviderAdaptorLoader method loadPersistenceAdapterModule.

/**
     * Loads the persistence provider adapter
     *
     * @param adapterModule may specify the adapter module name (can be null to use noop provider)
     * @return the persistence provider adaptor for the provider class
     * @throws ModuleLoadException
     */
public static PersistenceProviderAdaptor loadPersistenceAdapterModule(final String adapterModule, final Platform platform, JtaManagerImpl manager) throws ModuleLoadException {
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    if (adapterModule == null) {
        return noopAdaptor;
    }
    PersistenceProviderAdaptor persistenceProviderAdaptor = null;
    Module module = moduleLoader.loadModule(ModuleIdentifier.fromString(adapterModule));
    final ServiceLoader<PersistenceProviderAdaptor> serviceLoader = module.loadService(PersistenceProviderAdaptor.class);
    if (serviceLoader != null) {
        for (PersistenceProviderAdaptor adaptor : serviceLoader) {
            if (persistenceProviderAdaptor != null) {
                throw JpaLogger.ROOT_LOGGER.multipleAdapters(adapterModule);
            }
            persistenceProviderAdaptor = adaptor;
            ROOT_LOGGER.debugf("loaded persistence provider adapter %s", adapterModule);
        }
        if (persistenceProviderAdaptor != null) {
            persistenceProviderAdaptor.injectJtaManager(manager);
            persistenceProviderAdaptor.injectPlatform(platform);
        }
    }
    return persistenceProviderAdaptor;
}
Also used : ModuleLoader(org.jboss.modules.ModuleLoader) Module(org.jboss.modules.Module) PersistenceProviderAdaptor(org.jipijapa.plugin.spi.PersistenceProviderAdaptor)

Example 77 with Module

use of org.jboss.modules.Module in project wildfly by wildfly.

the class PersistenceProviderHandler method deploy.

public static void deploy(final DeploymentPhaseContext phaseContext, final Platform platform) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    final ServicesAttachment servicesAttachment = deploymentUnit.getAttachment(Attachments.SERVICES);
    if (module != null && servicesAttachment != null) {
        final ModuleClassLoader deploymentModuleClassLoader = module.getClassLoader();
        PersistenceProvider provider;
        // collect list of persistence providers packaged with the application
        final List<String> providerNames = servicesAttachment.getServiceImplementations(PERSISTENCE_PROVIDER_CLASSNAME);
        List<PersistenceProvider> providerList = new ArrayList<PersistenceProvider>();
        for (String providerName : providerNames) {
            try {
                final Class<? extends PersistenceProvider> providerClass = deploymentModuleClassLoader.loadClass(providerName).asSubclass(PersistenceProvider.class);
                final Constructor<? extends PersistenceProvider> constructor = providerClass.getConstructor();
                provider = constructor.newInstance();
                providerList.add(provider);
                JpaLogger.ROOT_LOGGER.tracef("deployment %s is using its own copy of %s", deploymentUnit.getName(), providerName);
            } catch (Exception e) {
                throw JpaLogger.ROOT_LOGGER.cannotDeployApp(e, providerName);
            }
        }
        if (providerList.size() > 0) {
            final String adapterClass = deploymentUnit.getAttachment(JpaAttachments.ADAPTOR_CLASS_NAME);
            PersistenceProviderAdaptor adaptor;
            if (adapterClass != null) {
                try {
                    adaptor = (PersistenceProviderAdaptor) deploymentModuleClassLoader.loadClass(adapterClass).newInstance();
                    adaptor.injectJtaManager(new JtaManagerImpl(deploymentUnit.getAttachment(JpaAttachments.TRANSACTION_MANAGER), deploymentUnit.getAttachment(JpaAttachments.TRANSACTION_SYNCHRONIZATION_REGISTRY)));
                    adaptor.injectPlatform(platform);
                    ArrayList<PersistenceProviderAdaptor> adaptorList = new ArrayList<>();
                    adaptorList.add(adaptor);
                    PersistenceProviderDeploymentHolder.savePersistenceProviderInDeploymentUnit(deploymentUnit, providerList, adaptorList);
                } catch (InstantiationException e) {
                    throw JpaLogger.ROOT_LOGGER.cannotCreateAdapter(e, adapterClass);
                } catch (IllegalAccessException e) {
                    throw JpaLogger.ROOT_LOGGER.cannotCreateAdapter(e, adapterClass);
                } catch (ClassNotFoundException e) {
                    throw JpaLogger.ROOT_LOGGER.cannotCreateAdapter(e, adapterClass);
                }
            } else {
                // register the provider (no adapter specified)
                PersistenceProviderDeploymentHolder.savePersistenceProviderInDeploymentUnit(deploymentUnit, providerList, null);
            }
        }
    }
}
Also used : ServicesAttachment(org.jboss.as.server.deployment.ServicesAttachment) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) PersistenceProvider(javax.persistence.spi.PersistenceProvider) ArrayList(java.util.ArrayList) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) JtaManagerImpl(org.jboss.as.jpa.transaction.JtaManagerImpl) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) PersistenceProviderAdaptor(org.jipijapa.plugin.spi.PersistenceProviderAdaptor)

Example 78 with Module

use of org.jboss.modules.Module in project wildfly by wildfly.

the class JPADependencyProcessor method addHibernate3AdaptorToDeployment.

private void addHibernate3AdaptorToDeployment(final ModuleLoader moduleLoader, final DeploymentUnit deploymentUnit) {
    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    try {
        final Module module = moduleLoader.loadModule(HIBERNATE_3_PROVIDER);
        //use a trick to get to the root of the class loader
        final URL url = module.getClassLoader().getResource(HIBERNATE3_PROVIDER_ADAPTOR.replace('.', '/') + ".class");
        final URLConnection connection = url.openConnection();
        if (!(connection instanceof JarURLConnection)) {
            throw JpaLogger.ROOT_LOGGER.invalidUrlConnection("hibernate 3", connection);
        }
        final JarFile jarFile = ((JarURLConnection) connection).getJarFile();
        moduleSpecification.addResourceLoader(ResourceLoaderSpec.createResourceLoaderSpec(ResourceLoaders.createJarResourceLoader("hibernate3integration", jarFile)));
        // hack in the dependencies which are part of hibernate3integration
        // TODO:  do this automatically (adding dependencies found in HIBERNATE_3_PROVIDER).
        addDependency(moduleSpecification, moduleLoader, deploymentUnit, JBOSS_AS_NAMING_ID, JBOSS_JANDEX_ID);
    } catch (ModuleLoadException e) {
        throw JpaLogger.ROOT_LOGGER.cannotLoadModule(e, HIBERNATE_3_PROVIDER, "hibernate 3");
    } catch (MalformedURLException e) {
        throw JpaLogger.ROOT_LOGGER.cannotAddIntegration(e, "hibernate 3");
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) MalformedURLException(java.net.MalformedURLException) JarURLConnection(java.net.JarURLConnection) ModuleSpecification(org.jboss.as.server.deployment.module.ModuleSpecification) IOException(java.io.IOException) Module(org.jboss.modules.Module) JarFile(java.util.jar.JarFile) URL(java.net.URL) URLConnection(java.net.URLConnection) JarURLConnection(java.net.JarURLConnection)

Example 79 with Module

use of org.jboss.modules.Module in project wildfly by wildfly.

the class JSFManagedBeanProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final CompositeIndex index = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    final EEApplicationClasses applicationClassesDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    if (index == null) {
        return;
    }
    if (module == null) {
        return;
    }
    if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
        return;
    }
    final Set<String> managedBeanClasses = new HashSet<String>();
    handleAnnotations(index, managedBeanClasses);
    processXmlManagedBeans(deploymentUnit, managedBeanClasses);
    for (String managedBean : managedBeanClasses) {
        //fail due to missing managed beans
        try {
            final Class<?> componentClass = module.getClassLoader().loadClass(managedBean);
            componentClass.getConstructor();
        } catch (ClassNotFoundException e) {
            JSFLogger.ROOT_LOGGER.managedBeanLoadFail(managedBean);
            continue;
        } catch (NoSuchMethodException e) {
            JSFLogger.ROOT_LOGGER.managedBeanNoDefaultConstructor(managedBean);
            continue;
        }
        installManagedBeanComponent(managedBean, moduleDescription, deploymentUnit, applicationClassesDescription);
    }
}
Also used : EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) HashSet(java.util.HashSet)

Example 80 with Module

use of org.jboss.modules.Module in project wildfly by wildfly.

the class PersistenceProviderLoader method loadProviderModuleByName.

/**
     * Loads the specified JPA persistence provider module
     *
     * @param moduleName is the static module to be loaded
     * @throws ModuleLoadException
     * @return list of persistence providers in specified module
     *
     * Note: side effect of saving loaded persistence providers to static api in javax.persistence.spi.PersistenceProvider.
     */
public static List<PersistenceProvider> loadProviderModuleByName(String moduleName) throws ModuleLoadException {
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    Module module = moduleLoader.loadModule(ModuleIdentifier.fromString(moduleName));
    final ServiceLoader<PersistenceProvider> serviceLoader = module.loadService(PersistenceProvider.class);
    List<PersistenceProvider> result = new ArrayList<>();
    if (serviceLoader != null) {
        for (PersistenceProvider provider1 : serviceLoader) {
            // persistence provider jar may contain multiple provider service implementations
            // save each provider
            PersistenceProviderResolverImpl.getInstance().addPersistenceProvider(provider1);
            result.add(provider1);
        }
    }
    return result;
}
Also used : ModuleLoader(org.jboss.modules.ModuleLoader) PersistenceProvider(javax.persistence.spi.PersistenceProvider) ArrayList(java.util.ArrayList) Module(org.jboss.modules.Module)

Aggregations

Module (org.jboss.modules.Module)100 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)58 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)28 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)27 ServiceName (org.jboss.msc.service.ServiceName)21 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)19 HashMap (java.util.HashMap)17 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)17 ServiceTarget (org.jboss.msc.service.ServiceTarget)17 HashSet (java.util.HashSet)16 ArrayList (java.util.ArrayList)13 ModuleLoadException (org.jboss.modules.ModuleLoadException)11 ModuleIdentifier (org.jboss.modules.ModuleIdentifier)10 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)9 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)8 Method (java.lang.reflect.Method)7 Map (java.util.Map)7 IOException (java.io.IOException)6 InterceptorDescription (org.jboss.as.ee.component.InterceptorDescription)6 ContextNames (org.jboss.as.naming.deployment.ContextNames)6