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;
}
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);
}
}
}
}
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);
}
}
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);
}
}
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;
}
Aggregations