use of org.jboss.as.ee.component.ComponentDescription in project wildfly by wildfly.
the class AbstractIntegrationProcessorJAXWS method createComponentDescription.
static ComponentDescription createComponentDescription(final DeploymentUnit unit, final String componentName, final String componentClassName, final String dependsOnEndpointClassName) {
final EEModuleDescription moduleDescription = getRequiredAttachment(unit, EE_MODULE_DESCRIPTION);
// JBoss WEB processors may install fake components for WS endpoints - removing them forcibly
moduleDescription.removeComponent(componentName, componentClassName);
// register WS component
ComponentDescription componentDescription = new WSComponentDescription(componentName, componentClassName, moduleDescription, unit.getServiceName());
moduleDescription.addComponent(componentDescription);
// register WS dependency
final ServiceName endpointServiceName = EndpointService.getServiceName(unit, dependsOnEndpointClassName);
componentDescription.addDependency(endpointServiceName, ServiceBuilder.DependencyType.REQUIRED);
return componentDescription;
}
use of org.jboss.as.ee.component.ComponentDescription in project wildfly by wildfly.
the class WSRefAnnotationProcessor method processRef.
private static void processRef(final DeploymentUnit unit, final String type, final WSRefAnnotationWrapper annotation, final ClassInfo classInfo, final InjectionTarget injectionTarget, final String bindingName) throws DeploymentUnitProcessingException {
final EEModuleDescription moduleDescription = unit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final AnnotatedElement target = createAnnotatedElement(unit, classInfo, injectionTarget);
final String componentClassName = classInfo.name().toString();
final Map<String, String> bindingMap = new HashMap<String, String>();
boolean isEJB = false;
for (final ComponentDescription componentDescription : moduleDescription.getComponentsByClassName(componentClassName)) {
if (componentDescription instanceof SessionBeanComponentDescription) {
isEJB = true;
bindingMap.put(componentDescription.getComponentName() + "/" + bindingName, bindingName);
}
}
if (!isEJB) {
bindingMap.put(bindingName, bindingName);
}
for (String refKey : bindingMap.keySet()) {
String refName = bindingMap.get(refKey);
ManagedReferenceFactory factory = WebServiceReferences.createWebServiceFactory(unit, type, annotation, target, refName, refKey);
final EEModuleClassDescription classDescription = moduleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
// Create the binding from whence our injection comes.
final InjectionSource serviceRefSource = new FixedInjectionSource(factory, factory);
final BindingConfiguration bindingConfiguration = new BindingConfiguration(refName, serviceRefSource);
classDescription.getBindingConfigurations().add(bindingConfiguration);
// our injection comes from the local lookup, no matter what.
final ResourceInjectionConfiguration injectionConfiguration = injectionTarget != null ? new ResourceInjectionConfiguration(injectionTarget, new LookupInjectionSource(refName)) : null;
if (injectionConfiguration != null) {
classDescription.addResourceInjection(injectionConfiguration);
}
}
}
use of org.jboss.as.ee.component.ComponentDescription in project wildfly by wildfly.
the class WeldComponentIntegrationProcessor method addWeldIntegration.
/**
* As the weld based instantiator needs access to the bean manager it is installed as a service.
*/
private void addWeldIntegration(final Iterable<ComponentIntegrator> componentIntegrators, final ComponentInterceptorSupport componentInterceptorSupport, final ServiceTarget target, final ComponentConfiguration configuration, final ComponentDescription description, final Class<?> componentClass, final String beanName, final ServiceName weldServiceName, final ServiceName weldStartService, final ServiceName beanManagerService, final Set<Class<?>> interceptorClasses, final ClassLoader classLoader, final String beanDeploymentArchiveId) {
final ServiceName serviceName = configuration.getComponentDescription().getServiceName().append("WeldInstantiator");
final WeldComponentService weldComponentService = new WeldComponentService(componentClass, beanName, interceptorClasses, classLoader, beanDeploymentArchiveId, description.isCDIInterceptorEnabled(), description, isComponentWithView(description, componentIntegrators));
final ServiceBuilder<WeldComponentService> builder = target.addService(serviceName, weldComponentService).addDependency(weldServiceName, WeldBootstrapService.class, weldComponentService.getWeldContainer()).addDependency(weldStartService);
configuration.setInstanceFactory(WeldManagedReferenceFactory.INSTANCE);
configuration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {
@Override
public void configureDependency(final ServiceBuilder<?> serviceBuilder, ComponentStartService service) throws DeploymentUnitProcessingException {
serviceBuilder.addDependency(serviceName);
}
});
boolean isComponentIntegrationPerformed = false;
for (ComponentIntegrator componentIntegrator : componentIntegrators) {
Supplier<ServiceName> bindingServiceNameSupplier = () -> {
if (componentInterceptorSupport == null) {
WeldLogger.DEPLOYMENT_LOGGER.componentInterceptorSupportNotAvailable(componentClass);
}
return addWeldInterceptorBindingService(target, configuration, componentClass, beanName, weldServiceName, weldStartService, beanDeploymentArchiveId, componentInterceptorSupport);
};
DefaultInterceptorIntegrationAction integrationAction = (bindingServiceName) -> {
if (componentInterceptorSupport == null) {
WeldLogger.DEPLOYMENT_LOGGER.componentInterceptorSupportNotAvailable(componentClass);
}
addJsr299BindingsCreateInterceptor(configuration, description, beanName, weldServiceName, builder, bindingServiceName, componentInterceptorSupport);
addCommonLifecycleInterceptionSupport(configuration, builder, bindingServiceName, beanManagerService, componentInterceptorSupport);
configuration.addComponentInterceptor(new UserInterceptorFactory(factory(InterceptionType.AROUND_INVOKE, builder, bindingServiceName, componentInterceptorSupport), factory(InterceptionType.AROUND_TIMEOUT, builder, bindingServiceName, componentInterceptorSupport)), InterceptorOrder.Component.CDI_INTERCEPTORS, false);
};
if (componentIntegrator.integrate(beanManagerService, configuration, description, builder, bindingServiceNameSupplier, integrationAction, componentInterceptorSupport)) {
isComponentIntegrationPerformed = true;
break;
}
}
if (!isComponentIntegrationPerformed) {
//otherwise they will be called twice
description.setIgnoreLifecycleInterceptors(true);
// for components with no view register interceptors that delegate to InjectionTarget lifecycle methods to trigger lifecycle interception
configuration.addPostConstructInterceptor(new ImmediateInterceptorFactory(new AbstractInjectionTargetDelegatingInterceptor() {
@Override
protected void run(Object instance) {
weldComponentService.getInjectionTarget().postConstruct(instance);
}
}), InterceptorOrder.ComponentPostConstruct.CDI_INTERCEPTORS);
configuration.addPreDestroyInterceptor(new ImmediateInterceptorFactory(new AbstractInjectionTargetDelegatingInterceptor() {
@Override
protected void run(Object instance) {
weldComponentService.getInjectionTarget().preDestroy(instance);
}
}), InterceptorOrder.ComponentPreDestroy.CDI_INTERCEPTORS);
}
builder.install();
configuration.addPostConstructInterceptor(new ImmediateInterceptorFactory(new WeldInjectionContextInterceptor(weldComponentService)), InterceptorOrder.ComponentPostConstruct.WELD_INJECTION_CONTEXT_INTERCEPTOR);
configuration.addPostConstructInterceptor(new ImmediateInterceptorFactory(new WeldInterceptorInjectionInterceptor(interceptorClasses)), InterceptorOrder.ComponentPostConstruct.INTERCEPTOR_WELD_INJECTION);
configuration.addPostConstructInterceptor(WeldInjectionInterceptor.FACTORY, InterceptorOrder.ComponentPostConstruct.COMPONENT_WELD_INJECTION);
}
use of org.jboss.as.ee.component.ComponentDescription in project wildfly by wildfly.
the class WeldImplicitDeploymentProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (WeldDeploymentMarker.isWeldDeployment(deploymentUnit)) {
return;
}
if (Utils.getRootDeploymentUnit(deploymentUnit).getAttachment(WeldConfiguration.ATTACHMENT_KEY).isRequireBeanDescriptor()) {
// if running in the require-bean-descriptor mode then bean archives are found by BeansXmlProcessor
return;
}
/*
* look for classes with bean defining annotations
*/
final Set<AnnotationType> beanDefiningAnnotations = new HashSet<>(getRootDeploymentUnit(deploymentUnit).getAttachment(WeldAttachments.BEAN_DEFINING_ANNOTATIONS));
final Map<ResourceRoot, Index> indexes = AnnotationIndexUtils.getAnnotationIndexes(deploymentUnit);
final ExplicitBeanArchiveMetadataContainer explicitBeanArchiveMetadata = deploymentUnit.getAttachment(ExplicitBeanArchiveMetadataContainer.ATTACHMENT_KEY);
final ResourceRoot classesRoot = deploymentUnit.getAttachment(WeldAttachments.CLASSES_RESOURCE_ROOT);
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
for (Entry<ResourceRoot, Index> entry : indexes.entrySet()) {
ResourceRoot resourceRoot = entry.getKey();
if (resourceRoot == classesRoot) {
// BDA for WEB-INF/classes is keyed under deploymentRoot in explicitBeanArchiveMetadata
resourceRoot = deploymentRoot;
}
/*
* Make sure bean defining annotations used in archives with bean-discovery-mode="none" are not considered here
* WFLY-4388
*/
if (explicitBeanArchiveMetadata != null && explicitBeanArchiveMetadata.getBeanArchiveMetadata().containsKey(resourceRoot)) {
continue;
}
for (final AnnotationType annotation : beanDefiningAnnotations) {
if (!entry.getValue().getAnnotations(annotation.getName()).isEmpty()) {
WeldDeploymentMarker.mark(deploymentUnit);
return;
}
}
}
/*
* look for session beans and managed beans
*/
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final Iterable<ImplicitBeanArchiveDetector> detectors = ServiceLoader.load(ImplicitBeanArchiveDetector.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldImplicitDeploymentProcessor.class));
for (ComponentDescription component : eeModuleDescription.getComponentDescriptions()) {
for (ImplicitBeanArchiveDetector detector : detectors) {
if (detector.isImplicitBeanArchiveRequired(component)) {
WeldDeploymentMarker.mark(deploymentUnit);
return;
}
}
}
}
use of org.jboss.as.ee.component.ComponentDescription in project wildfly by wildfly.
the class BeanArchiveProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
return;
}
WeldLogger.DEPLOYMENT_LOGGER.processingWeldDeployment(deploymentUnit.getName());
final Map<ResourceRoot, Index> indexes = AnnotationIndexUtils.getAnnotationIndexes(deploymentUnit);
final Map<ResourceRoot, BeanDeploymentArchiveImpl> bdaMap = new HashMap<ResourceRoot, BeanDeploymentArchiveImpl>();
final Components components = new Components(deploymentUnit, indexes);
final ResourceRootHandler handler = new ResourceRootHandler(deploymentUnit, components, indexes);
for (ResourceRoot resourceRoot : deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS)) {
if (ModuleRootMarker.isModuleRoot(resourceRoot) && !SubDeploymentMarker.isSubDeployment(resourceRoot)) {
if (isClassesRoot(resourceRoot)) {
// this is handled below
continue;
}
handler.handleResourceRoot(bdaMap, resourceRoot);
}
}
if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
handler.handleResourceRoot(bdaMap, handler.deploymentResourceRoot);
}
if (!bdaMap.containsKey(handler.deploymentResourceRoot)) {
// there is not root bda, let's create one
BeanDeploymentArchiveImpl bda = new BeanDeploymentArchiveImpl(Collections.<String>emptySet(), BeansXml.EMPTY_BEANS_XML, handler.module, getDeploymentUnitId(deploymentUnit), BeanArchiveType.SYNTHETIC, true);
WeldLogger.DEPLOYMENT_LOGGER.beanArchiveDiscovered(bda);
bdaMap.put(handler.deploymentResourceRoot, bda);
}
deploymentUnit.putAttachment(WeldAttachments.DEPLOYMENT_ROOT_BEAN_DEPLOYMENT_ARCHIVE, bdaMap.get(handler.deploymentResourceRoot));
/*
* Finish EE component processing
*/
for (Entry<ResourceRoot, Collection<ComponentDescription>> entry : components.componentDescriptions.entrySet()) {
BeanDeploymentArchiveImpl bda = bdaMap.get(entry.getKey());
String id = null;
if (bda != null) {
id = bda.getId();
} else {
id = deploymentUnit.getAttachment(WeldAttachments.DEPLOYMENT_ROOT_BEAN_DEPLOYMENT_ARCHIVE).getId();
}
for (ComponentDescription componentDescription : entry.getValue()) {
componentDescription.setBeanDeploymentArchiveId(id);
}
}
final BeanDeploymentModule bdm = new BeanDeploymentModule(handler.module.getIdentifier().toString(), deploymentUnit, bdaMap.values());
deploymentUnit.putAttachment(WeldAttachments.BEAN_DEPLOYMENT_MODULE, bdm);
}
Aggregations