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