Search in sources :

Example 11 with ModuleClassLoader

use of org.jboss.modules.ModuleClassLoader 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 12 with ModuleClassLoader

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

the class FieldInjectionTarget method getField.

private Field getField(final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
    final String name = getName();
    final String className = getClassName();
    final Module module = deploymentUnit.getAttachment(MODULE);
    final ModuleClassLoader classLoader = module.getClassLoader();
    final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(REFLECTION_INDEX);
    final ClassReflectionIndex classIndex;
    try {
        classIndex = reflectionIndex.getClassIndex(Class.forName(className, false, classLoader));
    } catch (ClassNotFoundException e) {
        throw new DeploymentUnitProcessingException(e);
    }
    final Field field = classIndex.getField(name);
    if (field == null) {
        throw EeLogger.ROOT_LOGGER.fieldNotFound(name);
    }
    return field;
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) Field(java.lang.reflect.Field) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) Module(org.jboss.modules.Module) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)

Aggregations

ModuleClassLoader (org.jboss.modules.ModuleClassLoader)12 Module (org.jboss.modules.Module)5 ArrayList (java.util.ArrayList)4 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)4 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)4 PersistenceProvider (javax.persistence.spi.PersistenceProvider)3 ModuleLoadException (org.jboss.modules.ModuleLoadException)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)2 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)2 ServicesAttachment (org.jboss.as.server.deployment.ServicesAttachment)2 ResourceListingUtils (org.jboss.as.test.shared.ResourceListingUtils)2 TldMetaData (org.jboss.metadata.web.spec.TldMetaData)2 PersistenceProviderAdaptor (org.jipijapa.plugin.spi.PersistenceProviderAdaptor)2 Field (java.lang.reflect.Field)1 URL (java.net.URL)1 Driver (java.sql.Driver)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1