Search in sources :

Example 1 with Module

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

the class PersistenceProviderHandler method allDeploymentModuleClassLoaders.

/**
     * returns the toplevel deployment module classloader and all subdeployment classloaders
     *
     * @param deploymentUnit
     * @return
     */
private static Set<ClassLoader> allDeploymentModuleClassLoaders(DeploymentUnit deploymentUnit) {
    Set<ClassLoader> deploymentClassLoaders = new HashSet<ClassLoader>();
    final DeploymentUnit topDeploymentUnit = DeploymentUtils.getTopDeploymentUnit(deploymentUnit);
    final Module toplevelModule = topDeploymentUnit.getAttachment(Attachments.MODULE);
    if (toplevelModule != null) {
        deploymentClassLoaders.add(toplevelModule.getClassLoader());
        final List<DeploymentUnit> subDeployments = topDeploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS);
        for (DeploymentUnit subDeploymentUnit : subDeployments) {
            final Module subDeploymentModule = subDeploymentUnit.getAttachment(Attachments.MODULE);
            if (subDeploymentModule != null) {
                deploymentClassLoaders.add(subDeploymentModule.getClassLoader());
            }
        }
    }
    return deploymentClassLoaders;
}
Also used : ModuleClassLoader(org.jboss.modules.ModuleClassLoader) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) HashSet(java.util.HashSet)

Example 2 with Module

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

the class NamingBindingAdd method createObjectFactory.

private ObjectFactory createObjectFactory(OperationContext context, ModelNode model) throws OperationFailedException {
    final ModuleIdentifier moduleID = ModuleIdentifier.fromString(NamingBindingResourceDefinition.MODULE.resolveModelAttribute(context, model).asString());
    final String className = NamingBindingResourceDefinition.CLASS.resolveModelAttribute(context, model).asString();
    final Module module;
    try {
        module = Module.getBootModuleLoader().loadModule(moduleID);
    } catch (ModuleLoadException e) {
        throw NamingLogger.ROOT_LOGGER.couldNotLoadModule(moduleID);
    }
    final ObjectFactory objectFactoryClassInstance;
    final ClassLoader cl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
    try {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
        final Class<?> clazz = module.getClassLoader().loadClass(className);
        objectFactoryClassInstance = (ObjectFactory) clazz.newInstance();
    } catch (ClassNotFoundException e) {
        throw NamingLogger.ROOT_LOGGER.couldNotLoadClassFromModule(className, moduleID);
    } catch (InstantiationException e) {
        throw NamingLogger.ROOT_LOGGER.couldNotInstantiateClassInstanceFromModule(className, moduleID);
    } catch (IllegalAccessException e) {
        throw NamingLogger.ROOT_LOGGER.couldNotInstantiateClassInstanceFromModule(className, moduleID);
    } catch (ClassCastException e) {
        throw NamingLogger.ROOT_LOGGER.notAnInstanceOfObjectFactory(className, moduleID);
    } finally {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(cl);
    }
    return objectFactoryClassInstance;
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ObjectFactory(javax.naming.spi.ObjectFactory) ExternalContextObjectFactory(org.jboss.as.naming.ExternalContextObjectFactory) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) Module(org.jboss.modules.Module)

Example 3 with Module

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

the class ParsedKernelDeploymentProcessor method deploy.

/**
     * Process a deployment for KernelDeployment configuration.
     * Will install a {@code POJO} for each configured bean.
     *
     * @param phaseContext the deployment unit context
     * @throws DeploymentUnitProcessingException
     *
     */
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit unit = phaseContext.getDeploymentUnit();
    final List<KernelDeploymentXmlDescriptor> kdXmlDescriptors = unit.getAttachment(KernelDeploymentXmlDescriptor.ATTACHMENT_KEY);
    if (kdXmlDescriptors == null || kdXmlDescriptors.isEmpty())
        return;
    final Module module = unit.getAttachment(Attachments.MODULE);
    if (module == null)
        throw PojoLogger.ROOT_LOGGER.noModuleFound(unit);
    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    final DeploymentReflectionIndex index = unit.getAttachment(Attachments.REFLECTION_INDEX);
    if (index == null)
        throw PojoLogger.ROOT_LOGGER.missingReflectionIndex(unit);
    for (KernelDeploymentXmlDescriptor kdXmlDescriptor : kdXmlDescriptors) {
        final List<BeanMetaDataConfig> beanConfigs = kdXmlDescriptor.getBeans();
        for (final BeanMetaDataConfig beanConfig : beanConfigs) {
            describeBean(module, serviceTarget, index, beanConfig);
        }
    // TODO -- KD::classloader, KD::aliases
    }
}
Also used : BeanMetaDataConfig(org.jboss.as.pojo.descriptor.BeanMetaDataConfig) ServiceTarget(org.jboss.msc.service.ServiceTarget) KernelDeploymentXmlDescriptor(org.jboss.as.pojo.descriptor.KernelDeploymentXmlDescriptor) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)

Example 4 with Module

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

the class BaseBeanFactory method create.

@SuppressWarnings("unchecked")
public Object create() throws Throwable {
    Module module = bmd.getModule().getInjectedModule().getValue();
    Class<?> beanClass = module.getClassLoader().loadClass(bmd.getBeanClass());
    DeploymentReflectionIndex index = DeploymentReflectionIndex.create();
    BeanInfo beanInfo = new DefaultBeanInfo(index, beanClass);
    Object result = BeanUtils.instantiateBean(bmd, beanInfo, index, module);
    BeanUtils.configure(bmd, beanInfo, module, result, false);
    BeanUtils.dispatchLifecycleJoinpoint(beanInfo, result, bmd.getCreate(), "create");
    BeanUtils.dispatchLifecycleJoinpoint(beanInfo, result, bmd.getStart(), "start");
    return result;
}
Also used : DefaultBeanInfo(org.jboss.as.pojo.service.DefaultBeanInfo) BeanInfo(org.jboss.as.pojo.service.BeanInfo) DefaultBeanInfo(org.jboss.as.pojo.service.DefaultBeanInfo) Module(org.jboss.modules.Module) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)

Example 5 with Module

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

the class SecurityActions method getModuleClassLoader.

static ModuleClassLoader getModuleClassLoader(final String moduleSpec) throws ModuleLoadException {
    ModuleLoader loader = Module.getCallerModuleLoader();
    final Module module = loader.loadModule(ModuleIdentifier.fromString(moduleSpec));
    GetModuleClassLoaderAction action = new GetModuleClassLoaderAction(module);
    return WildFlySecurityManager.isChecking() ? doPrivileged(action) : action.run();
}
Also used : ModuleLoader(org.jboss.modules.ModuleLoader) GetModuleClassLoaderAction(org.wildfly.security.manager.action.GetModuleClassLoaderAction) 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