Package wrappers.catalina

Source Code of wrappers.catalina.SlideHost

/*
* $Header: /home/cvs/jakarta-slide/src/wrappers/catalina/SlideHost.java,v 1.5 2001/09/24 08:17:09 remm Exp $
* $Revision: 1.5 $
* $Date: 2001/09/24 08:17:09 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation.  All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
*    notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
*    notice, this list of conditions and the following disclaimer in
*    the documentation and/or other materials provided with the
*    distribution.
*
* 3. The end-user documentation included with the redistribution, if
*    any, must include the following acknowlegement: 
*       "This product includes software developed by the
*        Apache Software Foundation (http://www.apache.org/)."
*    Alternately, this acknowlegement may appear in the software itself,
*    if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
*    Foundation" must not be used to endorse or promote products derived
*    from this software without prior written permission. For written
*    permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
*    nor may "Apache" appear in their names without prior written
*    permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation.  For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/


package wrappers.catalina;


import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.net.JarURLConnection;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.catalina.Container;
import org.apache.catalina.Context;
import org.apache.catalina.Deployer;
import org.apache.catalina.Globals;
import org.apache.catalina.HttpRequest;
import org.apache.catalina.Host;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Request;
import org.apache.catalina.Response;
import org.apache.catalina.core.DefaultContext;
import org.apache.catalina.core.StandardHost;
import org.apache.catalina.core.ApplicationContext;

import wrappers.jndi.SlideDirContext;

import org.apache.slide.common.EmbeddedDomain;
import org.apache.slide.common.NamespaceAccessToken;
import org.apache.slide.webdav.WebdavServlet;

/**
* Slide implementation of Host.
*
* @author Remy Maucherat
* @version $Revision: 1.5 $ $Date: 2001/09/24 08:17:09 $
*/

public class SlideHost
    extends StandardHost
    implements Deployer, Host {


    // ----------------------------------------------------------- Constructors


    /**
     * Create a new SlideHost component with the default basic Valve.
     */
    public SlideHost() {

  super();

    }


    // ----------------------------------------------------- Instance Variables


    /**
     * Slide domain.
     */
    EmbeddedDomain domain;


    // ------------------------------------------------------------- Properties


    /**
     * Domain setter.
     */
    public void setDomain(EmbeddedDomain domain) {
        this.domain = domain;
    }


    /**
     * Domain getter.
     */
    public EmbeddedDomain getDomain() {
        return domain;
    }


    // --------------------------------------------------------- Public Methods


    /**
     * Prepare for active use of the public methods of this Component.
     *
     * @exception IllegalStateException if this component has already been
     *  started
     * @exception LifecycleException if this component detects a fatal error
     *  that prevents it from being started
     */
    public synchronized void start() throws LifecycleException {
       
        String defaultNamespace = domain.getDefaultNamespace();
        boolean installDefault = true;
       
        try {
            File rootWar = new File("webapps/ROOT.war");
            if (rootWar.exists()) {
                install("", rootWar.toURL());
                installDefault = false;
            }
        } catch (IOException e) {
            // Can't happen
            e.printStackTrace();
        }
       
        Enumeration namespaceNames = domain.enumerateNamespaces();
        while (namespaceNames.hasMoreElements()) {
            String name = (String) namespaceNames.nextElement();
            try {
                install("/" + name, new URL("http", "slide", name));
                if (installDefault && (name.equals(defaultNamespace))) {
                    // Also install the deafult namespace as the root context
                    install("", new URL("http", "slide", name));
                }
            } catch (IOException e) {
                // Can't happen
                e.printStackTrace();
            }
        }
       
        super.start();
       
    }


    // ------------------------------------------------------- Deployer Methods


    /**
     * Install a Slide context.
     */
    public void install(String contextPath, URL war) throws IOException {

        // Validate the format and state of our arguments
        if (contextPath == null)
            throw new IllegalArgumentException
                (sm.getString("standardHost.pathRequired"));
        if (war == null)
            throw new IllegalArgumentException
                (sm.getString("standardHost.warRequired"));

        if (!(war.getProtocol().equals("http")
              && war.getHost().equals("slide"))) {
            super.install(contextPath, war);
            return;
        }

        // Prepare the local variables we will require
        String docBase = war.getFile();
        log(sm.getString("standardHost.installing", contextPath, war));

        // Install this new web application
        try {

            Class clazz = Class.forName(getContextClass());
            Context context = (Context) clazz.newInstance();
            context.setPath(contextPath);
            context.setDocBase(docBase);

            String namespaceName = contextPath;
            while (namespaceName.startsWith("/")) {
                namespaceName = namespaceName.substring(1);
            }
            if (namespaceName.equals("")) {
                namespaceName = domain.getDefaultNamespace();
            }

            NamespaceAccessToken accessToken =
                domain.getNamespaceToken(namespaceName);

            SlideRealm slideRealm = new SlideRealm();
            slideRealm.setAccessToken(accessToken);
            slideRealm.setNamespace(namespaceName);
            context.setRealm(slideRealm);

            context.getServletContext().setAttribute
                (WebdavServlet.ATTRIBUTE_NAME, accessToken);
            ((ApplicationContext) context.getServletContext())
                .setAttributeReadOnly(WebdavServlet.ATTRIBUTE_NAME);

            if (context instanceof Lifecycle) {
                clazz = Class.forName(getConfigClass());
                LifecycleListener listener =
                    (LifecycleListener) clazz.newInstance();
                ((Lifecycle) context).addLifecycleListener(listener);
            }
            addChild(context);

            SlideDirContext resources = new SlideDirContext();
            resources.setAccessToken(accessToken);
            resources.setNamespaceName(war.getFile());
            context.setResources(resources);

      fireContainerEvent(INSTALL_EVENT, context);

        } catch (Exception e) {
            log(sm.getString("standardHost.installError", contextPath), e);
            throw new IOException(e.toString());
        }

    }


}
TOP

Related Classes of wrappers.catalina.SlideHost

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.