Search in sources :

Example 1 with WebComponentDescription

use of org.jboss.as.web.common.WebComponentDescription in project wildfly by wildfly.

the class JSFComponentProcessor method install.

private void install(String type, String className, final EEModuleDescription moduleDescription, final Module module, final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClassesDescription) {
    final ComponentDescription componentDescription = new WebComponentDescription(type + "." + className, className, moduleDescription, deploymentUnit.getServiceName(), applicationClassesDescription);
    moduleDescription.addComponent(componentDescription);
    deploymentUnit.addToAttachmentList(WebComponentDescription.WEB_COMPONENTS, componentDescription.getStartServiceName());
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) WebComponentDescription(org.jboss.as.web.common.WebComponentDescription) WebComponentDescription(org.jboss.as.web.common.WebComponentDescription)

Example 2 with WebComponentDescription

use of org.jboss.as.web.common.WebComponentDescription in project wildfly by wildfly.

the class WebComponentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
        return;
    }
    final Map<String, ComponentDescription> componentByClass = new HashMap<String, ComponentDescription>();
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final EEApplicationClasses applicationClassesDescription = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final CompositeIndex compositeIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
    if (moduleDescription == null) {
        // not an EE deployment
        return;
    }
    for (ComponentDescription component : moduleDescription.getComponentDescriptions()) {
        componentByClass.put(component.getComponentClassName(), component);
    }
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    final TldsMetaData tldsMetaData = deploymentUnit.getAttachment(TldsMetaData.ATTACHMENT_KEY);
    final Set<String> classes = getAllComponentClasses(deploymentUnit, compositeIndex, warMetaData, tldsMetaData);
    for (String clazz : classes) {
        if (clazz == null || clazz.trim().isEmpty()) {
            continue;
        }
        ComponentDescription description = componentByClass.get(clazz);
        if (description != null) {
            // TODO: make sure the component is a managed bean
            if (!(description.getViews().size() == 1)) {
                throw UndertowLogger.ROOT_LOGGER.wrongComponentType(clazz);
            }
        } else {
            // we do not make the standard tags into components, as there is no need
            if (compositeIndex.getClassByName(DotName.createSimple(clazz)) == null) {
                boolean found = false;
                for (String pack : BUILTIN_TAGLIBS) {
                    if (clazz.startsWith(pack)) {
                        found = true;
                        break;
                    }
                }
                if (found) {
                    continue;
                }
            }
            description = new WebComponentDescription(clazz, clazz, moduleDescription, deploymentUnit.getServiceName(), applicationClassesDescription);
            moduleDescription.addComponent(description);
            deploymentUnit.addToAttachmentList(WebComponentDescription.WEB_COMPONENTS, description.getStartServiceName());
        }
    }
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) WebComponentDescription(org.jboss.as.web.common.WebComponentDescription) HashMap(java.util.HashMap) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) WarMetaData(org.jboss.as.web.common.WarMetaData) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) WebComponentDescription(org.jboss.as.web.common.WebComponentDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 3 with WebComponentDescription

use of org.jboss.as.web.common.WebComponentDescription in project wildfly by wildfly.

the class JSFManagedBeanProcessor method installManagedBeanComponent.

private void installManagedBeanComponent(String className, final EEModuleDescription moduleDescription, final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClassesDescription) {
    final ComponentDescription componentDescription = new WebComponentDescription(MANAGED_BEAN.toString() + "." + className, className, moduleDescription, deploymentUnit.getServiceName(), applicationClassesDescription);
    moduleDescription.addComponent(componentDescription);
    deploymentUnit.addToAttachmentList(WebComponentDescription.WEB_COMPONENTS, componentDescription.getStartServiceName());
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) WebComponentDescription(org.jboss.as.web.common.WebComponentDescription) WebComponentDescription(org.jboss.as.web.common.WebComponentDescription)

Example 4 with WebComponentDescription

use of org.jboss.as.web.common.WebComponentDescription in project camunda-bpm-platform by camunda.

the class ProcessApplicationProcessor method detectExistingComponent.

/**
 * Detect an existing {@link ProcessApplication} component.
 */
protected ComponentDescription detectExistingComponent(DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final EEApplicationClasses eeApplicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final CompositeIndex compositeIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    // extract deployment metadata
    List<AnnotationInstance> processApplicationAnnotations = null;
    List<AnnotationInstance> postDeployAnnnotations = null;
    List<AnnotationInstance> preUndeployAnnnotations = null;
    Set<ClassInfo> servletProcessApplications = null;
    if (compositeIndex != null) {
        processApplicationAnnotations = compositeIndex.getAnnotations(DotName.createSimple(ProcessApplication.class.getName()));
        postDeployAnnnotations = compositeIndex.getAnnotations(DotName.createSimple(PostDeploy.class.getName()));
        preUndeployAnnnotations = compositeIndex.getAnnotations(DotName.createSimple(PreUndeploy.class.getName()));
        servletProcessApplications = compositeIndex.getAllKnownSubclasses(DotName.createSimple(ServletProcessApplication.class.getName()));
    } else {
        return null;
    }
    if (processApplicationAnnotations.isEmpty()) {
        // no pa found, this is not a process application deployment.
        return null;
    } else if (processApplicationAnnotations.size() > 1) {
        // found multiple PAs -> unsupported.
        throw new DeploymentUnitProcessingException("Detected multiple classes annotated with @" + ProcessApplication.class.getSimpleName() + ". A deployment must only provide a single @" + ProcessApplication.class.getSimpleName() + " class.");
    } else {
        // found single PA
        AnnotationInstance annotationInstance = processApplicationAnnotations.get(0);
        ClassInfo paClassInfo = (ClassInfo) annotationInstance.target();
        String paClassName = paClassInfo.name().toString();
        ComponentDescription paComponent = null;
        // it can either be a Servlet Process Application or a Singleton Session Bean Component or
        if (servletProcessApplications.contains(paClassInfo)) {
            // Servlet Process Applications can only be deployed inside Web Applications
            if (warMetaData == null) {
                throw new DeploymentUnitProcessingException("@ProcessApplication class is a ServletProcessApplication but deployment is not a Web Application.");
            }
            // check whether it's already a servlet context listener:
            JBossWebMetaData mergedJBossWebMetaData = warMetaData.getMergedJBossWebMetaData();
            List<ListenerMetaData> listeners = mergedJBossWebMetaData.getListeners();
            if (listeners == null) {
                listeners = new ArrayList<ListenerMetaData>();
                mergedJBossWebMetaData.setListeners(listeners);
            }
            boolean isListener = false;
            for (ListenerMetaData listenerMetaData : listeners) {
                if (listenerMetaData.getListenerClass().equals(paClassInfo.name().toString())) {
                    isListener = true;
                }
            }
            if (!isListener) {
                // register as Servlet Context Listener
                ListenerMetaData listener = new ListenerMetaData();
                listener.setListenerClass(paClassName);
                listeners.add(listener);
                // synthesize WebComponent
                WebComponentDescription paWebComponent = new WebComponentDescription(paClassName, paClassName, eeModuleDescription, deploymentUnit.getServiceName(), eeApplicationClasses);
                eeModuleDescription.addComponent(paWebComponent);
                deploymentUnit.addToAttachmentList(WebComponentDescription.WEB_COMPONENTS, paWebComponent.getStartServiceName());
                paComponent = paWebComponent;
            } else {
                // lookup the existing component
                paComponent = eeModuleDescription.getComponentsByClassName(paClassName).get(0);
            }
        // deactivate sci
        } else {
            // if its not a ServletProcessApplication it must be a session bean component
            List<ComponentDescription> componentsByClassName = eeModuleDescription.getComponentsByClassName(paClassName);
            if (!componentsByClassName.isEmpty() && (componentsByClassName.get(0) instanceof SessionBeanComponentDescription)) {
                paComponent = componentsByClassName.get(0);
            } else {
                throw new DeploymentUnitProcessingException("Class " + paClassName + " is annotated with @" + ProcessApplication.class.getSimpleName() + " but is neither a ServletProcessApplication nor an EJB Session Bean Component.");
            }
        }
        if (!postDeployAnnnotations.isEmpty()) {
            if (postDeployAnnnotations.size() == 1) {
                ProcessApplicationAttachments.attachPostDeployDescription(deploymentUnit, postDeployAnnnotations.get(0));
            } else {
                throw new DeploymentUnitProcessingException("There can only be a single method annotated with @PostDeploy. Found [" + postDeployAnnnotations + "]");
            }
        }
        if (!preUndeployAnnnotations.isEmpty()) {
            if (preUndeployAnnnotations.size() == 1) {
                ProcessApplicationAttachments.attachPreUndeployDescription(deploymentUnit, preUndeployAnnnotations.get(0));
            } else {
                throw new DeploymentUnitProcessingException("There can only be a single method annotated with @PreUndeploy. Found [" + preUndeployAnnnotations + "]");
            }
        }
        return paComponent;
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) PostDeploy(org.camunda.bpm.application.PostDeploy) JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) WebComponentDescription(org.jboss.as.web.common.WebComponentDescription) ServletProcessApplication(org.camunda.bpm.application.impl.ServletProcessApplication) PreUndeploy(org.camunda.bpm.application.PreUndeploy) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) WarMetaData(org.jboss.as.web.common.WarMetaData) ArrayList(java.util.ArrayList) ServletProcessApplication(org.camunda.bpm.application.impl.ServletProcessApplication) ProcessApplication(org.camunda.bpm.application.ProcessApplication) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) WebComponentDescription(org.jboss.as.web.common.WebComponentDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) ListenerMetaData(org.jboss.metadata.web.spec.ListenerMetaData) ArrayList(java.util.ArrayList) List(java.util.List) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Example 5 with WebComponentDescription

use of org.jboss.as.web.common.WebComponentDescription in project wildfly by wildfly.

the class Utils method registerAsComponent.

public static void registerAsComponent(String listener, DeploymentUnit deploymentUnit) {
    final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final EEModuleDescription module = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final WebComponentDescription componentDescription = new WebComponentDescription(listener, listener, module, deploymentUnit.getServiceName(), applicationClasses);
    module.addComponent(componentDescription);
    deploymentUnit.addToAttachmentList(WebComponentDescription.WEB_COMPONENTS, componentDescription.getStartServiceName());
}
Also used : EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) WebComponentDescription(org.jboss.as.web.common.WebComponentDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses)

Aggregations

WebComponentDescription (org.jboss.as.web.common.WebComponentDescription)5 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)4 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)3 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)3 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)2 WarMetaData (org.jboss.as.web.common.WarMetaData)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 PostDeploy (org.camunda.bpm.application.PostDeploy)1 PreUndeploy (org.camunda.bpm.application.PreUndeploy)1 ProcessApplication (org.camunda.bpm.application.ProcessApplication)1 ServletProcessApplication (org.camunda.bpm.application.impl.ServletProcessApplication)1 SessionBeanComponentDescription (org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)1 AnnotationInstance (org.jboss.jandex.AnnotationInstance)1 ClassInfo (org.jboss.jandex.ClassInfo)1 JBossWebMetaData (org.jboss.metadata.web.jboss.JBossWebMetaData)1 ListenerMetaData (org.jboss.metadata.web.spec.ListenerMetaData)1