Search in sources :

Example 66 with Module

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

the class AbstractDeploymentModelBuilder method newDeployment.

/**
     * Creates new Web Service deployment.
     *
     * @param unit deployment unit
     * @return archive deployment
     */
private ArchiveDeployment newDeployment(final DeploymentUnit unit) {
    WSLogger.ROOT_LOGGER.tracef("Creating new unified WS deployment model for %s", unit);
    final ResourceRoot deploymentRoot = unit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    final VirtualFile root = deploymentRoot != null ? deploymentRoot.getRoot() : null;
    final ClassLoader classLoader;
    final Module module = unit.getAttachment(Attachments.MODULE);
    if (module == null) {
        classLoader = unit.getAttachment(CLASSLOADER_KEY);
        if (classLoader == null) {
            throw WSLogger.ROOT_LOGGER.classLoaderResolutionFailed(unit);
        }
    } else {
        classLoader = module.getClassLoader();
    }
    ArchiveDeployment parentDep = null;
    if (unit.getParent() != null) {
        final Module parentModule = unit.getParent().getAttachment(Attachments.MODULE);
        if (parentModule == null) {
            throw WSLogger.ROOT_LOGGER.classLoaderResolutionFailed(deploymentRoot);
        }
        WSLogger.ROOT_LOGGER.tracef("Creating new unified WS deployment model for %s", unit.getParent());
        parentDep = this.newDeployment(null, unit.getParent().getName(), parentModule.getClassLoader(), null);
    }
    final UnifiedVirtualFile uvf = root != null ? new VirtualFileAdaptor(root) : new ResourceLoaderAdapter(classLoader);
    final ArchiveDeployment dep = this.newDeployment(parentDep, unit.getName(), classLoader, uvf);
    //add an AnnotationInfo attachment that uses composite jandex index
    dep.addAttachment(AnnotationsInfo.class, new JandexAnnotationsInfo(unit));
    return dep;
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) UnifiedVirtualFile(org.jboss.wsf.spi.deployment.UnifiedVirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) ArchiveDeployment(org.jboss.wsf.spi.deployment.ArchiveDeployment) UnifiedVirtualFile(org.jboss.wsf.spi.deployment.UnifiedVirtualFile) VirtualFileAdaptor(org.jboss.as.webservices.util.VirtualFileAdaptor) ResourceLoaderAdapter(org.jboss.ws.common.ResourceLoaderAdapter) Module(org.jboss.modules.Module)

Example 67 with Module

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

the class AbstractProtocolConfigurationBuilder method createProtocol.

@SuppressWarnings("unchecked")
@Override
public final P createProtocol() {
    StringBuilder builder = new StringBuilder();
    if (this.moduleName.equals(AbstractProtocolResourceDefinition.Attribute.MODULE.getDefinition().getDefaultValue().asString()) && !this.name.startsWith(org.jgroups.conf.ProtocolConfiguration.protocol_prefix)) {
        builder.append(org.jgroups.conf.ProtocolConfiguration.protocol_prefix).append('.');
    }
    String className = builder.append(this.name).toString();
    try {
        Module module = this.loader.getValue().loadModule(this.moduleName);
        Class<? extends Protocol> protocolClass = module.getClassLoader().loadClass(className).asSubclass(Protocol.class);
        Protocol protocol = ProtocolFactory.newInstance(protocolClass);
        P result = (P) ProtocolFactory.TRANSFORMER.apply(protocol);
        Map<String, String> properties = new HashMap<>(this.defaults.getValue().getProperties(this.name));
        properties.putAll(this.properties);
        Configurator.resolveAndAssignFields(result, properties);
        Configurator.resolveAndInvokePropertyMethods(result, properties);
        this.accept(result);
        return result;
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : HashMap(java.util.HashMap) Module(org.jboss.modules.Module) Protocol(org.jgroups.stack.Protocol) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 68 with Module

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

the class ServerAdd method unwrapClass.

private static Class unwrapClass(ModelNode classModel) throws OperationFailedException {
    String className = classModel.get(NAME).asString();
    String moduleName = classModel.get(MODULE).asString();
    try {
        ModuleIdentifier moduleID = ModuleIdentifier.fromString(moduleName);
        Module module = Module.getCallerModuleLoader().loadModule(moduleID);
        Class<?> clazz = module.getClassLoader().loadClass(className);
        return clazz;
    } catch (Exception e) {
        throw MessagingLogger.ROOT_LOGGER.unableToLoadClassFromModule(className, moduleName);
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) Module(org.jboss.modules.Module) IOException(java.io.IOException) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 69 with Module

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

the class ServiceLoaderTestCase method decorateWithServiceLoader.

@Test
public void decorateWithServiceLoader() {
    Module module = Module.forClass(TestService.class);
    ServiceLoader<TestService> loader = module.loadService(TestService.class);
    String s = "Hello";
    for (TestService service : loader) {
        s = service.decorate(s);
    }
    Assert.assertEquals("#TestService#Hello", s);
}
Also used : Module(org.jboss.modules.Module) Test(org.junit.Test)

Example 70 with Module

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

the class WeldComponentIntegrationProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!WeldDeploymentMarker.isWeldDeployment(deploymentUnit)) {
        return;
    }
    final DeploymentUnit topLevelDeployment = getRootDeploymentUnit(deploymentUnit);
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    final ServiceName weldBootstrapService = topLevelDeployment.getServiceName().append(WeldBootstrapService.SERVICE_NAME);
    final ServiceName weldStartService = topLevelDeployment.getServiceName().append(WeldStartService.SERVICE_NAME);
    final ServiceName beanManagerService = ServiceNames.beanManagerServiceName(deploymentUnit);
    final Iterable<ComponentIntegrator> componentIntegrators = ServiceLoader.load(ComponentIntegrator.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldComponentIntegrationProcessor.class));
    final ComponentInterceptorSupport componentInterceptorSupport = ServiceLoaders.loadSingle(ComponentInterceptorSupport.class, WeldComponentIntegrationProcessor.class).orElse(null);
    WeldClassIntrospector.install(deploymentUnit, phaseContext.getServiceTarget());
    eeModuleDescription.setDefaultClassIntrospectorServiceName(WeldClassIntrospector.serviceName(deploymentUnit));
    for (ComponentDescription component : eeModuleDescription.getComponentDescriptions()) {
        final String beanName;
        if (isBeanNameRequired(component, componentIntegrators)) {
            beanName = component.getComponentName();
        } else {
            beanName = null;
        }
        component.getConfigurators().add((context, description, configuration) -> {
            //add interceptor to activate the request scope if required
            final EjbRequestScopeActivationInterceptor.Factory requestFactory = new EjbRequestScopeActivationInterceptor.Factory(beanManagerService);
            for (ViewConfiguration view : configuration.getViews()) {
                view.addViewInterceptor(requestFactory, InterceptorOrder.View.CDI_REQUEST_SCOPE);
            }
            configuration.addTimeoutViewInterceptor(requestFactory, InterceptorOrder.View.CDI_REQUEST_SCOPE);
        });
        component.getConfigurators().addFirst(new ComponentConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
                final Class<?> componentClass = configuration.getComponentClass();
                final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
                final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
                final ModuleClassLoader classLoader = module.getClassLoader();
                //get the interceptors so they can be injected as well
                final Set<Class<?>> interceptorClasses = new HashSet<Class<?>>();
                for (InterceptorDescription interceptorDescription : description.getAllInterceptors()) {
                    try {
                        interceptorClasses.add(ClassLoadingUtils.loadClass(interceptorDescription.getInterceptorClassName(), module));
                    } catch (ClassNotFoundException e) {
                        throw WeldLogger.ROOT_LOGGER.couldNotLoadInterceptorClass(interceptorDescription.getInterceptorClassName(), e);
                    }
                }
                addWeldIntegration(componentIntegrators, componentInterceptorSupport, context.getServiceTarget(), configuration, description, componentClass, beanName, weldBootstrapService, weldStartService, beanManagerService, interceptorClasses, classLoader, description.getBeanDeploymentArchiveId());
            }
        });
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) Set(java.util.Set) HashSet(java.util.HashSet) ComponentConfigurator(org.jboss.as.ee.component.ComponentConfigurator) UserInterceptorFactory(org.jboss.as.ee.component.interceptors.UserInterceptorFactory) WeldManagedReferenceFactory(org.jboss.as.weld.injection.WeldManagedReferenceFactory) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) InterceptorDescription(org.jboss.as.ee.component.InterceptorDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ComponentIntegrator(org.jboss.as.weld.spi.ComponentIntegrator) ComponentInterceptorSupport(org.jboss.as.weld.spi.ComponentInterceptorSupport) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ServiceName(org.jboss.msc.service.ServiceName) EjbRequestScopeActivationInterceptor(org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) Utils.getRootDeploymentUnit(org.jboss.as.weld.util.Utils.getRootDeploymentUnit)

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