All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.openejb.config.WebModule Maven / Gradle / Ivy

The newest version!
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.openejb.config;

import org.apache.openejb.jee.FacesConfig;
import org.apache.openejb.jee.TldTaglib;
import org.apache.openejb.jee.WebApp;
import org.apache.openejb.jee.Webservices;
import org.apache.openejb.loader.SystemInstance;
import org.apache.xbean.finder.IAnnotationFinder;

import java.io.File;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

/**
 * @version $Rev$ $Date$
 */
public class WebModule extends Module implements WsModule, RESTModule {

    private final ValidationContext validation;

    private WebApp webApp;
    private Webservices webservices;
    private String host;
    private String contextRoot;
    private final List taglibs = new ArrayList();
    private final Set watchedResources = new TreeSet();
    // List of all faces configuration files found in this web module
    private final List facesConfigs = new ArrayList();
    private IAnnotationFinder finder;
    private final Set restClasses = new TreeSet();
    private final Set ejbWebServices = new TreeSet();
    private final Set ejbRestServices = new TreeSet();
    private final Set jaxrsProviders = new TreeSet();
    private final Set restApplications = new TreeSet();
    private final Map> jsfAnnotatedClasses = new HashMap>();
    private final Map> webAnnotatedClasses = new HashMap>();

    private final ID id;

    // keep the list of filtered URL we got after applying include/exclude pattern (@See DeploymentsResolver.loadFromClasspath)
    private List urls;
    private List rarUrls;
    private List addedUrls;
    private List scannableUrls;

    public WebModule(final WebApp webApp, String contextRoot, final ClassLoader classLoader, final String jarLocation, final String moduleId) {
        this.webApp = webApp;

        final File file = jarLocation == null ? null : new File(jarLocation);
        this.id = new ID(null, webApp, moduleId, file, null, this);
        this.validation = new ValidationContext(this);

        if (contextRoot == null) {

            contextRoot = null != jarLocation ? jarLocation.substring(jarLocation.lastIndexOf(File.separator)) : ".";

            if (contextRoot.endsWith(".unpacked")) {
                contextRoot = contextRoot.substring(0, contextRoot.length() - ".unpacked".length());
            }
            if (contextRoot.endsWith(".war")) {
                contextRoot = contextRoot.substring(0, contextRoot.length() - ".war".length());
            }
        }

        while (contextRoot.startsWith("/")) {
            contextRoot = contextRoot.substring(1);
        }

        while (contextRoot.startsWith("\\")) {
            contextRoot = contextRoot.substring(1);
        }

        this.contextRoot = contextRoot;
        setClassLoader(classLoader);

        if (webApp != null) {
            webApp.setContextRoot(contextRoot);
        }

        host = SystemInstance.get().getProperty(id.getName() + ".host", null);
    }

    @Override
    public String getJarLocation() {
        return id.getLocation() != null ? id.getLocation().getAbsolutePath() : null;
    }

    @Override
    public String getModuleId() {
        return id.getName();
    }

    @Override
    public File getFile() {
        return id.getLocation();
    }

    @Override
    public URI getModuleUri() {
        return id.getUri();
    }

    public List getUrls() {
        return urls;
    }

    public void setUrls(final List urls) {
        this.urls = urls;
    }

    public IAnnotationFinder getFinder() {
        return finder;
    }

    public void setFinder(final IAnnotationFinder finder) {
        this.finder = finder;
    }

    @Override
    public ValidationContext getValidation() {
        return validation;
    }

    public WebApp getWebApp() {
        return webApp;
    }

    public void setWebApp(final WebApp webApp) {
        this.webApp = webApp;
        if (webApp != null) {
            webApp.setContextRoot(contextRoot);
        }
    }

    @Override
    public Webservices getWebservices() {
        return webservices;
    }

    @Override
    public void setWebservices(final Webservices webservices) {
        this.webservices = webservices;
    }

    public String getContextRoot() {
        return contextRoot;
    }

    public void setContextRoot(final String contextRoot) {
        if (webApp != null) {
            webApp.setContextRoot(contextRoot);
        }
        this.contextRoot = contextRoot;
    }

    public String getHost() {
        return host;
    }

    public void setHost(final String host) {
        this.host = host;
    }

    public List getTaglibs() {
        return taglibs;
    }

    @Override
    public Set getWatchedResources() {
        return watchedResources;
    }

    public List getFacesConfigs() {
        return facesConfigs;
    }

    @Override
    public String toString() {
        return "WebModule{" +
            "moduleId='" + id.getName() + '\'' +
            ", contextRoot='" + contextRoot + '\'' +
            '}';
    }

    @Override
    public Set getRestClasses() {
        return restClasses;
    }

    public Set getRestApplications() {
        return restApplications;
    }

    public Set getEjbWebServices() {
        return ejbWebServices;
    }

    public Set getEjbRestServices() {
        return ejbRestServices;
    }

    public List getScannableUrls() {
        if (scannableUrls == null) {
            return Collections.emptyList();
        }
        return scannableUrls;
    }

    public void setScannableUrls(final List scannableUrls) {
        this.scannableUrls = scannableUrls;
    }

    public Map> getJsfAnnotatedClasses() {
        return jsfAnnotatedClasses;
    }

    public Map> getWebAnnotatedClasses() {
        return webAnnotatedClasses;
    }

    public Set getJaxrsProviders() {
        return jaxrsProviders;
    }

    public List getRarUrls() {
        if (rarUrls == null) {
            return Collections.emptyList();
        }
        return rarUrls;
    }

    public void setRarUrls(final List rarUrls) {
        this.rarUrls = rarUrls;
    }

    public List getAddedUrls() {
        return addedUrls;
    }

    public void setAddedUrls(final List addedUrls) {
        this.addedUrls = addedUrls;
    }

    @Override
    public AppModule appModule() {
        return super.getAppModule();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy