Search in sources :

Example 6 with ListenerMetaData

use of org.jboss.metadata.web.spec.ListenerMetaData in project wildfly by wildfly.

the class ExternalTldParsingDeploymentProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
        // Skip non web deployments
        return;
    }
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null || warMetaData.getMergedJBossWebMetaData() == null) {
        return;
    }
    TldsMetaData tldsMetaData = deploymentUnit.getAttachment(TldsMetaData.ATTACHMENT_KEY);
    Map<String, TldMetaData> tlds = tldsMetaData.getTlds();
    Set<String> sharedTldUris = new HashSet<>();
    for (TldMetaData shared : tldsMetaData.getSharedTlds(deploymentUnit)) {
        sharedTldUris.add(shared.getUri());
    }
    Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    try {
        Iterator<Resource> resources = module.globResources("META-INF/**.tld");
        while (resources.hasNext()) {
            final Resource resource = resources.next();
            //waste time re-parsing them
            if (resource.getURL().toString().contains("com/sun/jsf-impl/main")) {
                continue;
            }
            if (resource.getName().startsWith("META-INF/")) {
                if (tlds.containsKey(resource.getName())) {
                    continue;
                }
                if (resource.getURL().getProtocol().equals("vfs")) {
                    continue;
                }
                final TldMetaData value = parseTLD(resource);
                if (sharedTldUris.contains(value.getUri())) {
                    //don't re-include shared TLD's
                    continue;
                }
                String key = "/" + resource.getName();
                if (!tlds.containsKey(key)) {
                    tlds.put(key, value);
                }
                if (!tlds.containsKey(value.getUri())) {
                    tlds.put(value.getUri(), value);
                }
                if (value.getListeners() != null) {
                    for (ListenerMetaData l : value.getListeners()) {
                        List<ListenerMetaData> listeners = warMetaData.getMergedJBossWebMetaData().getListeners();
                        if (listeners == null) {
                            warMetaData.getMergedJBossWebMetaData().setListeners(listeners = new ArrayList<ListenerMetaData>());
                        }
                        listeners.add(l);
                    }
                }
            }
        }
    } catch (ModuleLoadException e) {
        throw new DeploymentUnitProcessingException(e);
    }
}
Also used : TldMetaData(org.jboss.metadata.web.spec.TldMetaData) ModuleLoadException(org.jboss.modules.ModuleLoadException) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) WarMetaData(org.jboss.as.web.common.WarMetaData) Resource(org.jboss.modules.Resource) ArrayList(java.util.ArrayList) ListenerMetaData(org.jboss.metadata.web.spec.ListenerMetaData) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) HashSet(java.util.HashSet)

Aggregations

ListenerMetaData (org.jboss.metadata.web.spec.ListenerMetaData)6 ArrayList (java.util.ArrayList)5 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)4 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)4 WarMetaData (org.jboss.as.web.common.WarMetaData)4 ParamValueMetaData (org.jboss.metadata.javaee.spec.ParamValueMetaData)4 JBossWebMetaData (org.jboss.metadata.web.jboss.JBossWebMetaData)3 FilterMappingMetaData (org.jboss.metadata.web.spec.FilterMappingMetaData)3 FilterMetaData (org.jboss.metadata.web.spec.FilterMetaData)3 HashMap (java.util.HashMap)2 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)2 JBossServletMetaData (org.jboss.metadata.web.jboss.JBossServletMetaData)2 StartException (org.jboss.msc.service.StartException)2 VirtualFile (org.jboss.vfs.VirtualFile)2 HandlerWrapper (io.undertow.server.HandlerWrapper)1 HttpHandler (io.undertow.server.HttpHandler)1 PredicatedHandler (io.undertow.server.handlers.builder.PredicatedHandler)1 CachingResourceManager (io.undertow.server.handlers.resource.CachingResourceManager)1 FileResourceManager (io.undertow.server.handlers.resource.FileResourceManager)1 ResourceManager (io.undertow.server.handlers.resource.ResourceManager)1