You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ha...@apache.org on 2002/09/29 13:38:43 UTC

cvs commit: jakarta-avalon-apps/sevak/src/demo/java/org/apache/avalon/apps/sevak/demo MultihostSevakTest.java

hammant     2002/09/29 04:38:43

  Modified:    sevak    build.xml
               sevak/src/demo/conf catalina-assembly.xml
                        catalina-config.xml catalina-environment.xml
               sevak/src/java/org/apache/avalon/apps/sevak Sevak.java
               sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina
                        CatalinaLogger.java CatalinaSevak.java
                        CustomWebappLoader.java
               sevak/src/java/org/apache/avalon/apps/sevak/blocks/jetty
                        JettySevak.java
               sevak/src/java/org/apache/avalon/apps/sevak/blocks/jo
                        JoAvalonLogListener.java JoException.java
                        JoSevak.java
  Added:       sevak    ant.properties.sample
               sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina
                        CatalinaSevakBootstrap.java
                        CatalinaSevakClassLoaderFactory.java
                        CatalinaSevakServer.java
                        CatalinaSevakShutdownHook.java
                        ParentClassLoaderRule.java
               sevak/src/demo/java/org/apache/avalon/apps/sevak/demo
                        MultihostSevakTest.java
  Log:
  More work on Sevak.  99% submitted by Daniel Krieg
  
  Revision  Changes    Path
  1.14      +0 -52     jakarta-avalon-apps/sevak/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/sevak/build.xml,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- build.xml	22 Sep 2002 21:39:12 -0000	1.13
  +++ build.xml	29 Sep 2002 11:38:42 -0000	1.14
  @@ -276,58 +276,6 @@
   
     </target>
   
  -  <target name="compile-demo" depends="compile" description="Compiles the Demo Block">
  -    <delete dir="${build.demoClasses}"/>
  -    <delete dir="${build.demoXdoclet}"/>
  -
  - 
  -    <mkdir dir="${build.demoClasses}"/>
  -    <javac srcdir="${java.demo.dir}"
  -            destdir="${build.demoClasses}"
  -            debug="${build.debug}"
  -            optimize="${build.optimize}"
  -            deprecation="${build.deprecation}">
  -       <classpath refid="test.class.path" />
  -       <include name="**"/>
  -    </javac>
  -  </target>
  -
  -  <target name="phoenix-demo-xdoclet" depends="compile-demo" >
  -   
  -    <mkdir dir="${build.demoXdoclet}"/>
  -  
  -    <taskdef name="phoenix-blocks"
  -             classname="org.apache.avalon.phoenix.tools.xdoclet.PhoenixXDoclet"
  -             classpathref="test.class.path"/>
  -
  -    <phoenix-blocks
  -        destdir="${build.demoXdoclet}"
  -        classpathref="test.class.path">
  -      <fileset dir="${java.demo.dir}">
  -        <include name="**/*.java" />
  -      </fileset>
  -      <blockinfo/>
  -      <manifest manifestFile="manifest.mf" />
  -    </phoenix-blocks>
  -
  -  </target>
  -
  -  <target name="demo-jar" depends="phoenix-demo-xdoclet" description="Makes a jar file out of the Demo classes">
  - 
  -    <mkdir dir="${build.lib}"/>
  -    
  -    <jar jarfile="${build.lib}/sevak-demo.jar"
  -         manifest="${build.demoXdoclet}/manifest.mf">
  -      <fileset dir="${build.demoClasses}">
  -        <include name="org/apache/avalon/apps/sevak/**"/>
  -      </fileset>
  -     <fileset dir="${build.demoXdoclet}">
  -        <include name="org/apache/avalon/apps/sevak/**/*.xinfo"/>
  -      </fileset>
  -    </jar>
  -    
  -  </target>
  -
     <!-- Jars project for Merlin -->
     <target name="merlin" depends="compile" >
   
  
  
  
  1.1                  jakarta-avalon-apps/sevak/ant.properties.sample
  
  Index: ant.properties.sample
  ===================================================================
  # -----------------------------------------------------------------------------
  # Component ant.properties.sample
  #
  # This is an example "ant.properties" file, used to customize the building of
  # the component for your local environment.  It defines the location of all
  # external modules that this component depend on.  Copy this file to
  # "ant.properties" in the source directory, and customize it as needed.
  #
  # The ant.properties values in this directory apply only to this component.
  # It is overridden by ../ant.properties and ~/build.properties
  # It overrides all default.properties files and ~/.ant.properties
  #
  # $Id: ant.properties.sample,v 1.1 2002/09/29 11:38:42 hammant Exp $
  # -----------------------------------------------------------------------------
  
  # ----- Compile Control Flags -----
  build.debug=on
  build.optimize=off
  build.deprecation=off
  
  # --------------------------------------------------
  #                REQUIRED LIBRARIES
  # --------------------------------------------------
  
  
  # ----- Checkstyle, version 2.3 -----
  # Uncomment the 'do.checkstyle' flag property to enable checkstyle
  do.checkstyle=
  checkstyle.home=../../checkstyle-2.3
  checkstyle.lib=${checkstyle.home}
  checkstyle.jar=${checkstyle.lib}/checkstyle-all-2.3.jar
  
  
  
  
  
  1.2       +5 -4      jakarta-avalon-apps/sevak/src/demo/conf/catalina-assembly.xml
  
  Index: catalina-assembly.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/sevak/src/demo/conf/catalina-assembly.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- catalina-assembly.xml	22 Sep 2002 09:35:01 -0000	1.1
  +++ catalina-assembly.xml	29 Sep 2002 11:38:42 -0000	1.2
  @@ -3,8 +3,9 @@
                     "http://jakarta.apache.org/phoenix/assembly_1_0.dtd">
   
   <assembly>
  -  <block class="org.apache.avalon.apps.sevak.blocks.catalina.CatalinaSevak" name="sevak"/>
  -  <block class="org.apache.avalon.apps.sevak.demo.SevakTest" name="sevakTest">
  -	<provide name="sevak" role="org.apache.avalon.apps.sevak.Sevak"/>
  -  </block>
  +    <block class="org.apache.avalon.apps.sevak.blocks.catalina.CatalinaSevakBootstrap" name="catalina"/>
  +    
  +    <block class="org.apache.avalon.apps.sevak.demo.MultihostSevakTest" name="multihost-sevak-test">
  +        <provide name="catalina" role="org.apache.avalon.apps.sevak.MultihostSevak"/>
  +    </block>
   </assembly>
  
  
  
  1.2       +7 -26     jakarta-avalon-apps/sevak/src/demo/conf/catalina-config.xml
  
  Index: catalina-config.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/sevak/src/demo/conf/catalina-config.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- catalina-config.xml	22 Sep 2002 09:35:01 -0000	1.1
  +++ catalina-config.xml	29 Sep 2002 11:38:42 -0000	1.2
  @@ -7,31 +7,12 @@
   -->
   <config>
   
  -  <sevak>
  -      <port>8080</port>
  -      <bind>127.0.0.1</bind>
  -  </sevak>
  -  <sevakTest>
  -	  <!-- 
  -	   * The Web Application's within the src/conf/webapps 
  -	   * is added into the Sevak Demo Block SAR file under
  -	   * webapps/ folder  within it.
  -	   * -->
  -	   
  -	  <Context docBase="/" path="webapps/ROOT"/>	  
  -	  
  -	  <!-- 	  
  -	    <Context docBase="/examples" path="webapps/examples"/>
  -	    <Context docBase="/manager" path="webapps/manager"/>	  
  -	  -->
  -	  
  -	  
  -	  <Context docBase="/tomcat-docs" path="webapps/tomcat-docs"/>
  -	  
  -	  <!--
  -	    <Context docBase="/webdav" path="webapps/webdav"/>	  
  -	  -->
  -	  
  -  </sevakTest>
  +    <catalina>
  +        <use-naming>true</use-naming>
  +        <config-file>conf/server-noexamples.xml.config</config-file>
  +    </catalina>
  +    <multihost-sevak-test>
  +      <Context docBase="/multihost-sevak" path="/local/test.war"/>
  +    </multihost-sevak-test>
   
   </config>
  
  
  
  1.2       +1 -5      jakarta-avalon-apps/sevak/src/demo/conf/catalina-environment.xml
  
  Index: catalina-environment.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/sevak/src/demo/conf/catalina-environment.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- catalina-environment.xml	22 Sep 2002 09:35:01 -0000	1.1
  +++ catalina-environment.xml	29 Sep 2002 11:38:42 -0000	1.2
  @@ -11,13 +11,9 @@
   
         <category name="" target="default"
                   priority="DEBUG" />
  -      <category name="objectstorage" target="objectstorage-target"
  -                priority="DEBUG" />
   
         <log-target name="default"
  -                  location="/logs/avalon-demo.log" />
  -      <log-target name="objectstorage-target"
  -                  location="/logs/objectstorage.log" />
  +                  location="/logs/multihost-sevak-demo.log" />
       </logs>
   
       <policy>
  
  
  
  1.2       +6 -0      jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/Sevak.java
  
  Index: Sevak.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/Sevak.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Sevak.java	28 Jun 2002 05:02:42 -0000	1.1
  +++ Sevak.java	29 Sep 2002 11:38:42 -0000	1.2
  @@ -20,6 +20,12 @@
       String ROLE = Sevak.class.getName();
   
       /**
  +     * A constant for localhost
  +     */
  +    String LOCALHOST = "localhost";
  +
  +
  +    /**
        * Deploy the given Web Application
        * @param context Context for the the webapp
        * @param pathToWebAppFolder path can be a war-archive or exploded directory
  
  
  
  1.2       +42 -42    jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina/CatalinaLogger.java
  
  Index: CatalinaLogger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina/CatalinaLogger.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CatalinaLogger.java	22 Sep 2002 09:35:01 -0000	1.1
  +++ CatalinaLogger.java	29 Sep 2002 11:38:42 -0000	1.2
  @@ -102,7 +102,7 @@
       /**
        * Writes the specified message to a servlet log file, usually an event
        * log.  The name and type of the servlet log is specific to the
  -     * servlet container.
  +     * servlet m_container.
        *
        * @param msg A <code>String</code> specifying the message to be written
        *  to the log file
  @@ -139,22 +139,22 @@
       /**
        * The Container with which this Logger has been associated.
        */
  -    protected Container container = null;
  +    private Container m_container = null;
   
       /**
        * The debugging detail level for this component.
        */
  -    protected int debug = 0;
  +    private int m_debug = 0;
   
       /**
  -     * The property change support for this component.
  +     * The property change m_support for this component.
        */
  -    protected PropertyChangeSupport support = new PropertyChangeSupport(this);
  +    private PropertyChangeSupport m_support = new PropertyChangeSupport(this);
   
       /**
  -     * The verbosity level for above which log messages may be filtered.
  +     * The m_verbosity level for above which log messages may be filtered.
        */
  -    protected int verbosity = ERROR;
  +    private int m_verbosity = ERROR;
   
       /**
        * @see org.apache.catalina.Logger#getContainer()
  @@ -164,12 +164,12 @@
   
       /**
        * Return the Container with which this Logger has been associated.
  -     * @return Container Return the container
  +     * @return Container Return the m_container
        */
       public Container getContainer()
       {
   
  -        return (container);
  +        return (m_container);
   
       }
   
  @@ -181,20 +181,20 @@
       public void setContainer(Container container)
       {
   
  -        Container oldContainer = this.container;
  -        this.container = container;
  -        support.firePropertyChange("container", oldContainer, this.container);
  +        Container oldContainer = this.m_container;
  +        this.m_container = container;
  +        m_support.firePropertyChange("m_container", oldContainer, this.m_container);
   
       }
   
       /**
        * Return the debugging detail level for this component.
  -     * @return int 
  +     * @return int
        */
       public int getDebug()
       {
   
  -        return (this.debug);
  +        return (this.m_debug);
   
       }
   
  @@ -206,7 +206,7 @@
       public void setDebug(int debug)
       {
   
  -        this.debug = debug;
  +        this.m_debug = debug;
   
       }
   
  @@ -214,7 +214,7 @@
        * Return descriptive information about this Logger implementation and
        * the corresponding version number, in the format
        * <code>&lt;description&gt;/&lt;version&gt;</code>.
  -     * @return String 
  +     * @return String
        */
       public String getInfo()
       {
  @@ -224,58 +224,58 @@
       }
   
       /**
  -     * Return the verbosity level of this logger.  Messages logged with a
  -     * higher verbosity than this level will be silently ignored.
  +     * Return the m_verbosity level of this logger.  Messages logged with a
  +     * higher m_verbosity than this level will be silently ignored.
        * @return int
        */
       public int getVerbosity()
       {
   
  -        return (this.verbosity);
  +        return (this.m_verbosity);
   
       }
   
       /**
  -     * Set the verbosity level of this logger.  Messages logged with a
  -     * higher verbosity than this level will be silently ignored.
  +     * Set the m_verbosity level of this logger.  Messages logged with a
  +     * higher m_verbosity than this level will be silently ignored.
        *
  -     * @param verbosity The new verbosity level
  +     * @param verbosity The new m_verbosity level
        */
       public void setVerbosity(int verbosity)
       {
   
  -        this.verbosity = verbosity;
  +        this.m_verbosity = verbosity;
   
       }
   
       /**
  -     * Set the verbosity level of this logger.  Messages logged with a
  -     * higher verbosity than this level will be silently ignored.
  +     * Set the m_verbosity level of this logger.  Messages logged with a
  +     * higher m_verbosity than this level will be silently ignored.
        *
  -     * @param verbosity The new verbosity level, as a string
  +     * @param verbosity The new m_verbosity level, as a string
        */
       public void setVerbosityLevel(String verbosity)
       {
   
           if ("FATAL".equalsIgnoreCase(verbosity))
           {
  -            this.verbosity = FATAL;
  +            this.m_verbosity = FATAL;
           }
           else if ("ERROR".equalsIgnoreCase(verbosity))
           {
  -            this.verbosity = ERROR;
  +            this.m_verbosity = ERROR;
           }
           else if ("WARNING".equalsIgnoreCase(verbosity))
           {
  -            this.verbosity = WARNING;
  +            this.m_verbosity = WARNING;
           }
           else if ("INFORMATION".equalsIgnoreCase(verbosity))
           {
  -            this.verbosity = INFORMATION;
  +            this.m_verbosity = INFORMATION;
           }
           else if ("DEBUG".equalsIgnoreCase(verbosity))
           {
  -            this.verbosity = DEBUG;
  +            this.m_verbosity = DEBUG;
           }
   
       }
  @@ -290,7 +290,7 @@
       public void addPropertyChangeListener(PropertyChangeListener listener)
       {
   
  -        support.addPropertyChangeListener(listener);
  +        m_support.addPropertyChangeListener(listener);
   
       }
   
  @@ -315,7 +315,7 @@
       /**
        * Writes an explanatory message and a stack trace for a given
        * <code>Throwable</code> exception to the servlet log file.  The name
  -     * and type of the servlet log file is specific to the servlet container,
  +     * and type of the servlet log file is specific to the servlet m_container,
        * usually an event log.  This message will be logged unconditionally.
        *
        * @param msg A <code>String</code> that describes the error or
  @@ -349,7 +349,7 @@
   
       /**
        * Writes the specified message to the servlet log file, usually an event
  -     * log, if the logger is set to a verbosity level equal to or higher than
  +     * log, if the logger is set to a m_verbosity level equal to or higher than
        * the specified value for this message.
        *
        * @param message A <code>String</code> specifying the message to be
  @@ -359,16 +359,16 @@
       public void log(String message, int verbosity)
       {
   
  -        if (this.verbosity >= verbosity)
  -		{
  +        if (this.m_verbosity >= verbosity)
  +        {
               log(message);
  -		}
  +        }
   
       }
   
       /**
        * Writes the specified message and exception to the servlet log file,
  -     * usually an event log, if the logger is set to a verbosity level equal
  +     * usually an event log, if the logger is set to a m_verbosity level equal
        * to or higher than the specified value for this message.
        *
        * @param message A <code>String</code> that describes the error or
  @@ -379,10 +379,10 @@
       public void log(String message, Throwable throwable, int verbosity)
       {
   
  -        if (this.verbosity >= verbosity)
  -		{
  +        if (this.m_verbosity >= verbosity)
  +        {
               log(message, throwable);
  -		}
  +        }
   
       }
   
  @@ -394,7 +394,7 @@
       public void removePropertyChangeListener(PropertyChangeListener listener)
       {
   
  -        support.removePropertyChangeListener(listener);
  +        m_support.removePropertyChangeListener(listener);
   
       }
   
  
  
  
  1.2       +350 -264  jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina/CatalinaSevak.java
  
  Index: CatalinaSevak.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina/CatalinaSevak.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CatalinaSevak.java	22 Sep 2002 09:35:01 -0000	1.1
  +++ CatalinaSevak.java	29 Sep 2002 11:38:42 -0000	1.2
  @@ -7,345 +7,431 @@
    */
   package org.apache.avalon.apps.sevak.blocks.catalina;
   
  -import java.io.File;
  -import java.io.FileOutputStream;
  -import java.io.InputStream;
  +import java.security.Security;
   
  -import org.apache.avalon.apps.sevak.Sevak;
  -import org.apache.avalon.apps.sevak.SevakException;
  -import org.apache.avalon.framework.activity.Startable;
  -import org.apache.avalon.framework.activity.Initializable;
  -import org.apache.avalon.framework.configuration.Configurable;
  -import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.avalon.framework.context.Context;
  -import org.apache.avalon.framework.context.Contextualizable;
  -import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -import org.apache.avalon.framework.service.ServiceException;
  -import org.apache.avalon.framework.service.ServiceManager;
  -import org.apache.avalon.framework.service.Serviceable;
  -import org.apache.catalina.Engine;
  -import org.apache.catalina.Host;
  +import org.apache.catalina.Container;
   import org.apache.catalina.Lifecycle;
   import org.apache.catalina.LifecycleException;
  -import org.apache.catalina.Loader;
  -import org.apache.catalina.DefaultContext;
  -import org.apache.catalina.core.StandardContext;
  -import org.apache.catalina.startup.ContextConfig;
  -import org.apache.catalina.startup.Embedded;
  -import org.apache.coyote.tomcat4.CoyoteConnector;
  +import org.apache.catalina.Server;
  +import org.apache.catalina.Service;
  +import org.apache.catalina.Deployer;
  +import org.apache.catalina.startup.ContextRuleSet;
  +import org.apache.catalina.startup.EngineRuleSet;
  +import org.apache.catalina.startup.HostRuleSet;
  +import org.apache.catalina.startup.NamingRuleSet;
  +
  +import org.apache.commons.digester.Digester;
  +
  +import org.xml.sax.InputSource;
  +
  +import java.io.File;
  +import java.io.FileInputStream;
   
   /**
  - * @phoenix:block
  - * @phoenix:service name="org.apache.avalon.apps.sevak.Sevak"
  - *
  - * Tomcat Wrapper.
  - *
  + * Tomcat Wrapper.  This is the true CatalinaSevak service.  It must be dynamically loaded
  + * through a bootstrap approach because it directly manipulates Tomcat libraries.  The bootstrap
  + * abstraction layer separates Tomcat from Phoenix, thus allowing them to coexist.  This class
  + * contains a Tomcat-specific ClassLoader i.e. org.apache.catalina.loader.StandardClassLoader that
  + * handles the true bootstrapping of Tomcat.
    *
    * @see <a href="http://jakarta.apache.org/tomcat">Tomcat Project Page</a>
    *
  - * @author  Vinay Chandran<vi...@yahoo.com>
  - * @version 1.0
  + * @author  Daniel Krieg<dk...@kc.rr.com>
  + * @version $Revision$ $Date$
    */
   public class CatalinaSevak
  -    extends AbstractLogEnabled
  -    implements Contextualizable, Configurable, Initializable, Startable, Sevak
   {
  -    //private BlockContext m_context;
  -    private Context m_context;
  -    private Configuration m_configuration;
  -    private Engine m_engine = null;
  -    private Embedded m_embedded = null;
  -    private Host m_tomcatHost = null;
  -    private Loader m_catalinaCustomClassLoader = null;
  -    private int m_port;
  -    private String m_host = null;
  -
  -   /**
  -    * The thread that monitors stop requests from the container.
  -    */
  -    private Thread m_thread;
  -
  -   /**
  -    * A flag used to trigger stop.
  -    */
  -    private boolean CONTINUE = false;
  -
  -   /**
  -    * The period to sleep before checking for a stop request.
  -    */
  -    private int SLEEP_INTERVAL = 1000;
  -
  +    private ClassLoader m_parentLoader = ClassLoader.getSystemClassLoader();
  +    private Server m_server = null;
  +    private String m_configFile;
  +    private boolean m_useNaming = true;
   
       /**
  -     * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
  +     * Set the parent classloader
  +     * @param parentLoader the parent classloader
        */
  -
  -    public void contextualize(final Context context)
  +    public void setParentClassLoader(ClassLoader parentLoader)
       {
  -        getLogger().info("Sevak.contextualize()");
  -        //m_context = (BlockContext) context;
  -        m_context = (Context) context;
  +        m_parentLoader = parentLoader;
       }
   
       /**
  -     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
  +     * set the configuration file
  +     * @param configFile the config file
        */
  -
  -    public void configure(final Configuration configuration)
  -        throws ConfigurationException
  +    public void setConfigFile(String configFile)
       {
  -
  -        m_configuration = configuration;
  -
  +        m_configFile = configFile;
       }
   
       /**
  -     * @see org.apache.avalon.framework.activity.Initializable#initialize()
  +     * Set the use naming
  +     * @param useNaming the use naming
        */
  -
  -    public void initialize() throws Exception
  +    public void setUseNaming(boolean useNaming)
       {
  -        getLogger().info("Sevak.initialize()");
  -
  -        //create the Logger
  -        CatalinaLogger catalinaLogger = new CatalinaLogger();
  -        catalinaLogger.enableLogging( getLogger().getChildLogger("catalina") );
  -
  -        //create the Custom ClassLoader
  -        m_catalinaCustomClassLoader =
  -            new CustomWebappLoader(this.getClass().getClassLoader());
  -
  -        //read the configuration properties
  -        String catalinaHome =
  -            m_configuration.getChild("catalina.home").getValue(null);
  -        if (catalinaHome == null)
  -        {
  -            catalinaHome = ((File)m_context.get("app.home")).getAbsolutePath();
  -
  -            File confDir=new File( (File) m_context.get("app.home"),"conf");
  -            confDir.mkdir();
  -            getLogger().info("Created conf/ folder");
  -            InputStream in= CatalinaSevak.class.getResourceAsStream("default-web.xml");
  -            FileOutputStream fos =
  -                        new FileOutputStream(new File(confDir,"web.xml").getAbsolutePath());
  -            byte[] bytes= new byte[512];
  -            int read=0;
  -            while((read=in.read(bytes))!=-1)
  -            {
  -                fos.write(bytes,0,read);
  -            }
  -            fos.close();
  -            in.close();
  -        }
  -        /*
  -         * TODO : Hack Tomcat to be able to run without the catalina.home property set
  -        {
  -            System.out.println(
  -                "catalina.home property Not Found. Using : "
  -                    + m_context.get("app.home"));
  -            catalinaHome = ((File)m_context.get("app.home")).getAbsolutePath();
  -        }
  -        */
  -        m_port = m_configuration.getChild("port").getValueAsInteger(8080);
  -        m_host = m_configuration.getChild("bind").getValue("localhost");
  -
  -        //set the catalina home directory
  -        System.setProperty("catalina.home", new File(catalinaHome).getAbsolutePath());
  -        // Create an Embedded Tomcat server
  -        m_embedded = new Embedded();
  -        m_embedded.setDebug(0);
  -        m_embedded.setLogger(catalinaLogger);
  -
  -        //Create Tomcat Engine
  -        m_engine = m_embedded.createEngine();
  -        m_engine.setDefaultHost("localhost");
  -
  -        // Create Tomcat Host
  -        m_tomcatHost = m_embedded.createHost("localhost", "webapps");
  -        m_engine.addChild(m_tomcatHost);
  -
  -        // Create HTTP Coyote Connector
  -        CoyoteConnector coyoteConnector = new CoyoteConnector();
  -        coyoteConnector.setPort(8080);
  -        coyoteConnector.setMinProcessors(5);
  -        coyoteConnector.setMaxProcessors(75);
  -        coyoteConnector.setEnableLookups(true);
  -        coyoteConnector.setAcceptCount(10);
  -        coyoteConnector.setDebug(0);
  -        coyoteConnector.setConnectionTimeout(20000);
  -        coyoteConnector.setUseURIValidationHack(false);
  -
  -        m_embedded.addEngine(m_engine);
  -        m_embedded.addConnector(coyoteConnector);
  -        getLogger().debug( "initialization complete" );
  -    }
  -
  -    //=======================================================================
  -    // Startable
  -    //=======================================================================
  +        m_useNaming = useNaming;
  +    }
   
  -   /**
  -    */
  -    public void start() throws Exception
  +    /**
  +     * Set the server
  +     * @param server the server
  +     */
  +    public void setServer(Server server)
       {
  -        getLogger().debug( "starting" );
  -        m_thread = new Thread(
  -          new Runnable() {
  -            public void run()
  -            {
  -                while( CONTINUE )
  -                {
  -                    try
  -                    {
  -                        Thread.currentThread().sleep( SLEEP_INTERVAL );
  -                    }
  -                    catch( Throwable e )
  -                    {
  -                    }
  -                }
  -            }
  -          }
  -        );
  +        this.m_server = server;
  +    }
   
  -        //START  Tomcat Instance
  +    /**
  +     * Initialize
  +     * @throws Exception if a problem
  +     */
  +    public void initialize() throws Exception
  +    {
  +        Digester digester = createStartDigester();
  +        File file = getConfigFile();
           try
           {
  -            getLogger().debug("starting Tomcat on home: " + System.getProperty("catalina.home"));
  -            m_embedded.start();
  -            getLogger().debug("Tomcat started");
  +            InputSource is =
  +                    new InputSource("file://" + file.getAbsolutePath());
  +            FileInputStream fis = new FileInputStream(file);
  +            is.setByteStream(fis);
  +            digester.push(this);
  +            digester.parse(is);
  +            fis.close();
           }
  -        catch (LifecycleException le)
  +        catch (Exception e)
           {
  -            le.printStackTrace();
  -            throw new ConfigurationException("[FATAL] Could Not START Tomcat  ");
  +            e.printStackTrace();
  +            return;
           }
   
  -        CONTINUE = true;
  -        m_thread.start();
  -        getLogger().debug( "started" );
  -    }
  -
  -   /**
  -    * Request to stop the service from the container.
  -    */
  -    public void stop()
  -    {
  -        getLogger().debug( "stopping" );
  -        CONTINUE = false;
  -        try
  +        if (!m_useNaming)
           {
  -            m_thread.join();
  -            m_embedded.stop();
  +            System.setProperty("catalina.useNaming", "false");
           }
  -        catch( Throwable e )
  +        else
           {
  -            getLogger().warn("Unexpected error while reqesting stop.", e );
  +            System.setProperty("catalina.useNaming", "true");
  +            String value = "org.apache.naming";
  +            String oldValue =
  +                    System.getProperty(javax.naming.Context.URL_PKG_PREFIXES);
  +            if (oldValue != null)
  +            {
  +                value = value + ":" + oldValue;
  +            }
  +            System.setProperty(javax.naming.Context.URL_PKG_PREFIXES, value);
  +            value = System.getProperty
  +                    (javax.naming.Context.INITIAL_CONTEXT_FACTORY);
  +            if (value == null)
  +            {
  +                System.setProperty
  +                        (javax.naming.Context.INITIAL_CONTEXT_FACTORY,
  +                                "org.apache.naming.java.javaURLContextFactory");
  +            }
           }
  -    }
   
  +        if (System.getSecurityManager() != null)
  +        {
  +            String access = Security.getProperty("package.access");
  +            if (access != null && access.length() > 0)
  +            {
  +                access += ",";
  +            }
  +            else
  +            {
  +                access = "sun.,";
  +            }
  +            Security.setProperty("package.access",
  +                    access + "org.apache.catalina.,org.apache.jasper.");
  +            String definition = Security.getProperty("package.definition");
  +            if (definition != null && definition.length() > 0)
  +            {
  +                definition += ",";
  +            }
  +            else
  +            {
  +                definition = "sun.,";
  +            }
  +            Security.setProperty("package.definition",
  +                    // FIX ME package "javax." was removed to prevent HotSpot
  +                    // fatal internal errors
  +                    definition + "java.,org.apache.catalina.,org.apache.jasper.");
  +        }
  +
  +        if (m_server instanceof Lifecycle)
  +        {
  +            m_server.initialize();
  +        }
  +//        Service[] services = m_server.findServices();
  +//        for( int i = 0; i < services.length; i++ ) {
  +//            Service service = services[ i ];
  +//            System.out.println( service.getName() + ": " + service.getInfo() );
  +//
  +//            Container container = service.getContainer();
  +//            System.out.println( container.getName() + ": " + container.getInfo() );
  +//            Container[] children = container.findChildren();
  +//            for( int j = 0; j < children.length; j++ ) {
  +//                Container child = children[ j ];
  +//                System.out.println( "    Child: " + child.getName() + ": " + child.getInfo() );
  +//            }
  +//            System.out.println();
  +//        }
  +        System.out.println("CatalinaSevak Server initialized");
  +    }
   
       /**
  -     * Deploy the given Web Application
  -     * @param context Context for the the webapp
  -     * @param dirToWebAppFolder path can be a war-archive or exploded directory
  -     * @throws org.apache.avalon.apps.sevak.SevakException Thrown when the context already exists
  +     * Start the server
  +     * @throws Exception if a problem
        */
  -    public void deploy(String context, File dirToWebAppFolder)
  -        throws SevakException
  +    public void start() throws Exception
       {
  -        if (!dirToWebAppFolder.exists())
  -        {
  -            throw new SevakException(
  -                "Path not Found[" + dirToWebAppFolder + "]");
  -        }
  -        try
  +        if (m_server instanceof Lifecycle)
           {
  -            if (context == null)
  +            try
               {
  -                throw new SevakException("Invalid Context[" + context + "]");
  +                ((Lifecycle) m_server).start();
  +                m_server.await();
               }
  -            if (context.equals("/"))
  +            catch (LifecycleException e)
               {
  -                context = "";
  +                System.out.println("Catalina.start: " + e);
  +                e.printStackTrace(System.out);
  +                if (e.getThrowable() != null)
  +                {
  +                    System.out.println("----- Root Cause -----");
  +                    e.getThrowable().printStackTrace(System.out);
  +                }
               }
  -            if (dirToWebAppFolder == null)
  +            catch (Throwable throwable)
               {
  -                throw new SevakException(
  -                    "Invalid WAR [" + dirToWebAppFolder + "]");
  +                throwable.printStackTrace();
               }
  -            //now deploy ....
  -            org.apache.catalina.Context catalinaContext =
  -                (org.apache.catalina.Context) m_tomcatHost.findChild(context);
  -            if (catalinaContext != null)
  +        }
  +        else
  +        {
  +            throw new Exception("Unable to start CatalinSevak Server: "
  +                    + m_server.getClass().getName());
  +        }
  +    }
  +
  +    /**
  +     * Stop the server
  +     * @throws Exception if a problem
  +     */
  +    public void stop() throws Exception
  +    {
  +        if (m_server instanceof Lifecycle)
  +        {
  +            try
               {
  -                throw new Exception("Context " + context + " Already Exists!");
  +                ((Lifecycle) m_server).stop();
  +            }
  +            catch (LifecycleException e)
  +            {
  +                System.out.println("Catalina.stop: " + e);
  +                e.printStackTrace(System.out);
  +                if (e.getThrowable() != null)
  +                {
  +                    System.out.println("----- Root Cause -----");
  +                    e.getThrowable().printStackTrace(System.out);
  +                }
               }
  -            catalinaContext =
  -                createContext(context, dirToWebAppFolder.getAbsolutePath());
  -            m_tomcatHost.addChild(catalinaContext);
  -            // TODO - get this whole beast working!!!!
  -            //m_tomcatHost.setRealm(new org.apache.catalina.realm.MemoryRealm());
  -            System.out.println("Deployed [" + context + "] Context");
           }
  -        catch (Exception catalinaException)
  +        else
           {
  +            throw new Exception("Unable to start CatalinSevak Server: "
  +                    + m_server.getClass().getName());
  +        }
  +    }
   
  -            throw new SevakException(
  -                "Catalina Internal Error",
  -                catalinaException);
  +    /**
  +     * Deploy a webapp
  +     * @param host the host
  +     * @param context the server context
  +     * @param pathToWebAppFolder the path to the war file
  +     * @throws Exception if aproblem
  +     */
  +    public void deploy(String host, String context, File pathToWebAppFolder) throws Exception
  +    {
  +        Service[] services = m_server.findServices();
  +        Container child = null;
  +        found_host: {
  +            for (int i = 0; i < services.length; i++)
  +            {
  +                Service service = services[i];
  +                Container[] children = service.getContainer().findChildren();
  +                for (int j = 0; j < children.length; j++)
  +                {
  +                    child = children[j];
  +                    if (child.getName().equals(host))
  +                    {
  +                        break found_host;
  +                    }
  +                }
  +            }
  +        }
  +        if (child == null)
  +        {
  +            throw new IllegalArgumentException(host + ": no such host.");
  +        }
  +        if (!(child instanceof Deployer))
  +        {
  +            throw new Exception(host + ": not able to deploy " + context);
           }
   
  +        final Deployer deployer = (Deployer) child;
  +        if (deployer.findDeployedApp(context) != null)
  +        {
  +            throw new Exception(context + " already deployed to host " + host);
  +        }
  +        deployer.install(context, pathToWebAppFolder.toURL());
  +        deployer.start(context);
       }
   
       /**
  -     * Undeploy the given WebApp 
  -     * @param context Webapp context
  -     * @throws org.apache.avalon.apps.sevak.SevakException Thrown when context does NOT exist
  +     * Undeploy a web app
  +     * @param host the host
  +     * @param context the context
  +     * @throws Exception if a problem
        */
  -    public void undeploy(String context) throws SevakException
  +    public void undeploy(String host, String context) throws Exception
       {
  -        if (context == null)
  +        Service[] services = m_server.findServices();
  +        Container child = null;
  +        found_host: {
  +            for (int i = 0; i < services.length; i++)
  +            {
  +                Service service = services[i];
  +                Container[] children = service.getContainer().findChildren();
  +                for (int j = 0; j < children.length; j++)
  +                {
  +                    child = children[j];
  +                    if (child.getName().equals(host))
  +                    {
  +                        break found_host;
  +                    }
  +                }
  +            }
  +        }
  +        if (child == null)
           {
  -            throw new SevakException("Invalid Context[" + context + "]");
  +            throw new IllegalArgumentException(host + ": no such host.");
           }
  -        if (context.equals("/"))
  +        if (!(child instanceof Deployer))
           {
  -            context = "";
  +            throw new Exception(host + ": not able to undeploy " + context);
           }
  -        org.apache.catalina.Context catalinaContext =
  -            (org.apache.catalina.Context) m_tomcatHost.findChild(context);
  -        if (catalinaContext == null)
  +        final Deployer deployer = (Deployer) child;
  +        if (deployer.findDeployedApp(context) == null)
           {
  -            throw new SevakException("Context " + context + " does NOT Exist");
  +            throw new Exception(context + " does not exist in host " + host);
           }
  -        m_tomcatHost.removeChild(catalinaContext);
  +        deployer.start(context);
  +        deployer.remove(context);
       }
  +
       /**
  -     * Create a StandardContext 
  -     * @param path
  -     * @param docBase
  -     * @return Context
  +     * Create a digester to start with
  +     * @return the digester
        */
  -
  -    private org.apache.catalina.Context createContext(
  -        String path,
  -        String docBase)
  +    protected Digester createStartDigester()
       {
  +        Digester digester = new Digester();
  +        digester.setValidating(false);
   
  -        StandardContext context = new StandardContext();
  -
  -        context.setDebug(0);
  -        context.setDocBase(docBase);
  -        context.setPath(path);
  -        context.setLoader(m_catalinaCustomClassLoader);
  +        digester.addObjectCreate("Server",
  +                "org.apache.avalon.apps.sevak.blocks.catalina.CatalinaSevakServer");
  +        digester.addSetProperties("Server");
  +        digester.addSetNext("Server",
  +                "setServer",
  +                "org.apache.catalina.Server");
  +
  +        digester.addObjectCreate("Server/GlobalNamingResources",
  +                "org.apache.catalina.deploy.NamingResources");
  +        digester.addSetProperties("Server/GlobalNamingResources");
  +        digester.addSetNext("Server/GlobalNamingResources",
  +                "setGlobalNamingResources",
  +                "org.apache.catalina.deploy.NamingResources");
  +
  +        digester.addObjectCreate("Server/Listener",
  +                null, // MUST be specified in the element
  +                "className");
  +        digester.addSetProperties("Server/Listener");
  +        digester.addSetNext("Server/Listener",
  +                "addLifecycleListener",
  +                "org.apache.catalina.LifecycleListener");
  +
  +        digester.addObjectCreate("Server/Service",
  +                "org.apache.catalina.core.StandardService",
  +                "className");
  +        digester.addSetProperties("Server/Service");
  +        digester.addSetNext("Server/Service",
  +                "addService",
  +                "org.apache.catalina.Service");
  +
  +        digester.addObjectCreate("Server/Service/Listener",
  +                null, // MUST be specified in the element
  +                "className");
  +        digester.addSetProperties("Server/Service/Listener");
  +        digester.addSetNext("Server/Service/Listener",
  +                "addLifecycleListener",
  +                "org.apache.catalina.LifecycleListener");
  +
  +        digester.addObjectCreate("Server/Service/Connector",
  +                "org.apache.catalina.connector.http.HttpConnector",
  +                "className");
  +        digester.addSetProperties("Server/Service/Connector");
  +        digester.addSetNext("Server/Service/Connector",
  +                "addConnector",
  +                "org.apache.catalina.Connector");
  +
  +        digester.addObjectCreate("Server/Service/Connector/Factory",
  +                "org.apache.catalina.net.DefaultServerSocketFactory",
  +                "className");
  +        digester.addSetProperties("Server/Service/Connector/Factory");
  +        digester.addSetNext("Server/Service/Connector/Factory",
  +                "setFactory",
  +                "org.apache.catalina.net.ServerSocketFactory");
  +
  +        digester.addObjectCreate("Server/Service/Connector/Listener",
  +                null, // MUST be specified in the element
  +                "className");
  +        digester.addSetProperties("Server/Service/Connector/Listener");
  +        digester.addSetNext("Server/Service/Connector/Listener",
  +                "addLifecycleListener",
  +                "org.apache.catalina.LifecycleListener");
  +
  +        digester.addRuleSet(new NamingRuleSet("Server/GlobalNamingResources/"));
  +        digester.addRuleSet(new EngineRuleSet("Server/Service/"));
  +        digester.addRuleSet(new HostRuleSet("Server/Service/Engine/"));
  +        digester.addRuleSet(new ContextRuleSet("Server/Service/Engine/Default"));
  +        digester.addRuleSet(new NamingRuleSet("Server/Service/Engine/DefaultContext/"));
  +        digester.addRuleSet(new ContextRuleSet("Server/Service/Engine/Host/Default"));
  +        digester.addRuleSet(new NamingRuleSet("Server/Service/Engine/Host/DefaultContext/"));
  +        digester.addRuleSet(new ContextRuleSet("Server/Service/Engine/Host/"));
  +        digester.addRuleSet(new NamingRuleSet("Server/Service/Engine/Host/Context/"));
  +
  +        digester.addRule("Server/Service/Engine",
  +                new ParentClassLoaderRule(digester,
  +                        m_parentLoader));
  +        return (digester);
  +    }
   
  -        ContextConfig config = new ContextConfig();
  -        config.setDebug(0);
  -        ((Lifecycle) context).addLifecycleListener(config);
  +    /**
  +     * get the config file
  +     * @return the File
  +     */
  +    protected File getConfigFile()
  +    {
   
  -        return (context);
  +        File file = new File(m_configFile);
  +        if (!file.isAbsolute())
  +        {
  +            file = new File(System.getProperty("catalina.base"), m_configFile);
  +        }
  +        return (file);
   
       }
  -
   }
  +
  
  
  
  1.2       +7 -7      jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina/CustomWebappLoader.java
  
  Index: CustomWebappLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina/CustomWebappLoader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CustomWebappLoader.java	22 Sep 2002 09:35:01 -0000	1.1
  +++ CustomWebappLoader.java	29 Sep 2002 11:38:42 -0000	1.2
  @@ -14,7 +14,7 @@
    * Tomcat ClassLoader Hack to make Catalina run over Avalon/Phoenix .
    *
    * @author  Vinay Chandran<vi...@yahoo.com>
  - * @version 1.0
  + * @version $Revision$ $Date$
    */
   
   public class CustomWebappLoader extends WebappLoader
  @@ -23,13 +23,13 @@
       private boolean m_started = false;
   
       /**
  -      * Start this component, initializing our associated class loader.
  -      *
  -      * @exception org.apache.catalina.LifecycleException if a lifecycle error occurs
  -      */
  +     * Start this component, initializing our associated class loader.
  +     *
  +     * @exception LifecycleException if a lifecycle error occurs
  +     */
       public void start() throws LifecycleException
       {
  -        //Prevent the LifecycleException by preventing any further calls made 
  +        //Prevent the LifecycleException by preventing any further calls made
           // to the base implementation to ' start' again
           if (m_started)
           {
  @@ -41,7 +41,7 @@
       }
   
       /**
  -     *  Constructor 
  +     *  Constructor
        * @param classLoader ClassLoader
        */
       public CustomWebappLoader(ClassLoader classLoader)
  
  
  
  1.1                  jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina/CatalinaSevakBootstrap.java
  
  Index: CatalinaSevakBootstrap.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.apps.sevak.blocks.catalina;
  
  import java.lang.reflect.Method;
  import org.apache.avalon.apps.sevak.Sevak;
  import org.apache.avalon.apps.sevak.SevakException;
  import org.apache.avalon.apps.sevak.MultihostSevak;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.activity.Startable;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  
  import java.io.File;
  
  /**
   * @phoenix:block
   * @phoenix:service name="org.apache.avalon.apps.sevak.MultihostSevak"
   *
   * Catalina Sevak Bootstrapper.  This class will bootstrap all Tomcat libraries dynamically.
   * It also acts as a Wrapper around the CatalinaSevak class which directly utilizes Tomcat
   * libraries and therefore cannot be loaded directly by Phoenix without creating hard linkages
   * between the two.
   *
   * Catalina Sevak provides the true service by directly manipulating Tomcat classes.  All Catalina
   * Sevak clients will call to the CatalinaSevakBootstrap which will delegate the true work to
   * CatalinaSevak.
   *
   * This bootstrap approach allows Tomcat to be embedded into Phoenix directly and administrated
   * as a standard installation while providing the ability for other Phoenix services to deploy
   * and undeploy Web Applications.
   *
   *
   * @see <a href="http://jakarta.apache.org/tomcat">Tomcat Project Page</a>
   *
   * @author  Daniel Krieg<dk...@kc.rr.com>
   * @version $Revision: 1.1 $ $Date: 2002/09/29 11:38:42 $
   */
  public class CatalinaSevakBootstrap
          extends AbstractLogEnabled
          implements Contextualizable, Configurable, Initializable, Startable, Sevak, MultihostSevak
  {
      private Context m_context;
      private Configuration m_configuration;
      private Object m_sevak;
      private String m_catalinaHome;
      private String m_catalinaBase;
      private boolean m_useNaming;
      private String m_configFile;
  
      /**
       * Contextualize
       * @param context the context
       * @throws ContextException if a problem
       */
      public void contextualize(Context context) throws ContextException
      {
          getLogger().debug("CatalinaSevakBootstrap.contextualize()");
          m_context = context;
      }
  
      /**
       * Configure block
       * @param configuration the configuration
       * @throws ConfigurationException if a problem
       */
      public void configure(Configuration configuration) throws ConfigurationException
      {
          getLogger().debug("CatalinaSevakBootstrap.configure()");
          m_configuration = configuration;
  
          m_catalinaHome = m_configuration.getChild("catalina-home").getValue("default");
          m_catalinaBase = m_configuration.getChild("catalina-base").getValue("default");
          m_configFile = m_configuration.getChild("config-file").getValue("conf/server.xml");
          m_useNaming = m_configuration.getChild("use-naming").getValueAsBoolean(true);
  
          setCatalinaHome();
          setCatalinaBase();
          getLogger().debug("Catalina Home: " + getCatalinaHome());
          getLogger().debug("Catalina Base: " + getCatalinaBase());
      }
  
      /**
       * Initialize
       * @throws Exception if a problem
       */
      public void initialize() throws Exception
      {
          getLogger().debug("CatalinaSevakBootstrap.initialize()");
          CatalinaSevakClassLoaderFactory catalinaSevakClassLoaderFactory
                  = new CatalinaSevakClassLoaderFactory();
          catalinaSevakClassLoaderFactory.enableLogging(getLogger());
  
          // Construct the class loaders we will need
          ClassLoader bootstrapLoader = null;
          ClassLoader commonLoader = null;
          ClassLoader sevakLoader = null;
          ClassLoader sharedLoader = null;
          File[] unpacked = new File[1];
          File[] packed = new File[1];
          File[] packed2 = new File[2];
  
          //  load bootstrap classes
          packed[0] = new File(getCatalinaHome(), "bin");
          bootstrapLoader = catalinaSevakClassLoaderFactory.createClassLoader(null, packed, null);
          getLogger().debug("Loaded bin dir...");
  
          //  load common directory
          unpacked[0] = new File(getCatalinaHome(), "common" + File.separator + "classes");
          packed2[0] = new File(getCatalinaHome(), "common" + File.separator + "endorsed");
          packed2[1] = new File(getCatalinaHome(), "common" + File.separator + "lib");
          commonLoader = catalinaSevakClassLoaderFactory.createClassLoader(unpacked, packed2,
                  bootstrapLoader);
          getLogger().debug("Loaded common dir...");
  
          //  load server directory
          unpacked[0] = new File(getCatalinaHome(), "server" + File.separator + "classes");
          packed2[0] = new File(getCatalinaHome(), "server" + File.separator + "lib");
          packed2[1] = new File(getStartupDir());
          sevakLoader = catalinaSevakClassLoaderFactory.createClassLoader(unpacked, packed2,
                  commonLoader);
          getLogger().debug("Loaded server dir...");
          getLogger().debug("Loaded startup dir..." + packed2[1].getAbsoluteFile());
  
          //  load shared directory
          unpacked[0] = new File(getCatalinaBase(), "shared" + File.separator + "classes");
          packed[0] = new File(getCatalinaBase(), "shared" + File.separator + "lib");
          sharedLoader = catalinaSevakClassLoaderFactory.createClassLoader(unpacked, packed,
                  commonLoader);
          getLogger().debug("Loaded shared dir...");
  
          // Load our startup class and run its lifecycle
          Thread.currentThread().setContextClassLoader(commonLoader);
          catalinaSevakClassLoaderFactory.securityClassLoad(commonLoader);
  
          // Instantiate a startup class instance
          getLogger().debug("Loading startup class");
          Class startupClass =
                  sevakLoader.loadClass("org.apache.avalon.apps.sevak.blocks.catalina.CatalinaSevak");
          getLogger().debug("Startup class loaded: " + startupClass);
          m_sevak = startupClass.newInstance();
  
          // Set the shared extensions class loader
          Class paramTypes[] = new Class[1];
          Object paramValues[] = new Object[1];
          getLogger().debug("Setting startup class properties");
  
          String methodName = "setParentClassLoader";
          paramTypes[0] = Class.forName("java.lang.ClassLoader");
          paramValues[0] = commonLoader;
          Method method = m_sevak.getClass().getMethod(methodName, paramTypes);
          method.invoke(m_sevak, paramValues);
  
          methodName = "setUseNaming";
          paramTypes[0] = Boolean.TYPE;
          paramValues[0] = (m_useNaming) ? Boolean.TRUE : Boolean.FALSE;
          method = m_sevak.getClass().getMethod(methodName, paramTypes);
          method.invoke(m_sevak, paramValues);
  
          methodName = "setConfigFile";
          paramTypes[0] = String.class;
          paramValues[0] = m_configFile;
          method = m_sevak.getClass().getMethod(methodName, paramTypes);
          method.invoke(m_sevak, paramValues);
  
          methodName = "initialize";
          method = m_sevak.getClass().getMethod(methodName, null);
          method.invoke(m_sevak, null);
  
          getLogger().debug("CatalinaSevakBootstrap complete.");
      }
  
      /**
       * Start the server
       * @throws Exception if aproblem
       */
      public void start() throws Exception
      {
          getLogger().debug("CatalinaSevakBootstrap.start()");
          m_sevak.getClass().getMethod("start", null).invoke(m_sevak, null);
      }
  
      /**
       * Stop the server
       * @throws Exception if a problem
       */
      public void stop() throws Exception
      {
          getLogger().debug("CatalinaSevakBootstrap.stop()");
          m_sevak.getClass().getMethod("stop", null).invoke(m_sevak, null);
      }
  
      /**
       * Deploy the a webapp
       * @param context the context to use
       * @param pathToWebAppFolder the path to the war file
       * @throws SevakException if a problem
       */
      public void deploy(String context, File pathToWebAppFolder) throws SevakException
      {
          getLogger().debug("CatalinaSevakBootstrap.deploy()");
          deploy(LOCALHOST, context, pathToWebAppFolder);
      }
  
      /**
       * Undeploy a webapp
       * @param context the context
       * @throws SevakException if a problem
       */
      public void undeploy(String context) throws SevakException
      {
          getLogger().debug("CatalinaSevakBootstrap.undeploy()");
          undeploy(LOCALHOST, context);
      }
  
      /**
       * Deploy a webapp
       * @param host the host to bind to
       * @param context the context to use
       * @param pathToWebAppFolder the path to the web app
       * @throws SevakException if a problem
       */
      public void deploy(String host, String context, File pathToWebAppFolder) throws SevakException
      {
          Class[] paramTypes = {String.class, String.class, File.class};
          Object[] paramValues = {host, context, pathToWebAppFolder};
          try
          {
              m_sevak.getClass().getMethod("deploy", paramTypes).invoke(m_sevak, paramValues);
          }
          catch (Exception e)
          {
              throw new SevakException("Unable to deploy", e);
          }
      }
  
      /**
       * Undeploy a webapp
       * @param host The host to bind to
       * @param context the context for teh webapp
       * @throws SevakException if a problem
       */
      public void undeploy(String host, String context) throws SevakException
      {
          Class[] paramTypes = {String.class, String.class};
          Object[] paramValues = {host, context};
          try
          {
              m_sevak.getClass().getMethod("undeploy", paramTypes).invoke(m_sevak, paramValues);
          }
          catch (Exception e)
          {
              throw new SevakException("Unable to undeploy", e);
          }
      }
  
  
      /**
       * Set the base for catalina
       * This a bit dirty for Phoenix but necessary
       */
      private void setCatalinaBase()
      {
          if (m_catalinaBase.equals("default"))
          {
              System.setProperty("catalina.base", getCatalinaHome());
          }
          else if (m_catalinaBase.equals("user.dir"))
          {
              System.setProperty("catalina.base", System.getProperty("user.dir"));
          }
          else
          {
              System.setProperty("catalina.base", m_catalinaBase);
          }
      }
  
      /**
       * Get the Base for Catalina.
       * @return Catalina's base.
       */
      private String getCatalinaBase()
      {
          if (System.getProperty("catalina.base") == null)
          {
              setCatalinaBase();
          }
          return System.getProperty("catalina.base");
      }
  
      /**
       * Set the home for catalina
       * This a bit dirty for Phoenix but necessary
       */
      private void setCatalinaHome()
      {
          if (m_catalinaHome.equals("default"))
          {
              System.setProperty("catalina.home", System.getProperty("phoenix.home")
                      + File.separator + "catalina");
          }
          else
          {
              System.setProperty("catalina.home", m_catalinaHome);
          }
      }
  
      /**
       * Get the Home for Catalina.
       * @return Catalina's home.
       */
      private String getCatalinaHome()
      {
          if (System.getProperty("catalina.home") == null)
          {
              setCatalinaHome();
          }
          return System.getProperty("catalina.home");
      }
  
      /**
       * Get the directory that this was started in
       * @return The directory that jar file for this block was started in.
       */
      private String getStartupDir()
      {
          String startup = this.getClass().getClassLoader()
                  .getResource("org/apache/avalon/apps/sevak/blocks/catalina/CatalinaSevak.class")
                  .toExternalForm();
          startup = startup.substring("jar:file:/".length(), startup.indexOf("!"));
          getLogger().debug("Start up JAR " + startup);
          return new File(startup).getParent();
      }
  }
  
  
  
  1.1                  jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina/CatalinaSevakClassLoaderFactory.java
  
  Index: CatalinaSevakClassLoaderFactory.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.apps.sevak.blocks.catalina;
  
  
  import java.lang.reflect.Method;
  
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.CascadingRuntimeException;
  
  import java.io.File;
  import java.io.IOException;
  
  import java.net.URL;
  import java.net.URLClassLoader;
  
  import java.util.ArrayList;
  
  /**
   * Catalina Sevak Class Loader Factory.
   *
   * This class dynamically loads the org.apache.catalina.loader.StandardClassLoader class used within
   * catalina for bootstrapping.
   *
   *
   * @see <a href="http://jakarta.apache.org/tomcat">Tomcat Project Page</a>
   *
   * @author  Daniel Krieg<dk...@kc.rr.com>
   * @version $Revision: 1.1 $ $Date: 2002/09/29 11:38:42 $
   */
  public final class CatalinaSevakClassLoaderFactory extends AbstractLogEnabled
  {
  
      /**
       * Create a ClassLoader for Catalina
       * @param unpacked unpacked files
       * @param packed packed files
       * @param parent the parent classloader
       * @return The classloader
       * @throws IOException if a problem
       * @throws ClassNotFoundException if a problem
       */
      public ClassLoader createClassLoader(File unpacked[], File packed[], ClassLoader parent)
              throws IOException, ClassNotFoundException
      {
          getLogger().debug("Creating new class loader");
  
          // Construct the "class path" for this class loader
          ArrayList stringList = new ArrayList();
          ArrayList urlList = new ArrayList();
  
          // Add unpacked directories
          if (unpacked != null)
          {
              for (int i = 0; i < unpacked.length; i++)
              {
                  File file = unpacked[i];
                  if (!file.isDirectory() || !file.exists() || !file.canRead())
                  {
                      continue;
                  }
                  getLogger().debug("  Including directory " + file.getAbsolutePath());
                  URL url = new URL("file", null,
                          file.getCanonicalPath() + File.separator);
                  stringList.add(url.toString());
                  urlList.add(url);
              }
          }
  
          // Add packed directory JAR files
          if (packed != null)
          {
              for (int i = 0; i < packed.length; i++)
              {
                  File directory = packed[i];
                  if (!directory.isDirectory()
                          || !directory.exists()
                          || !directory.canRead())
                  {
                      continue;
                  }
                  String filenames[] = directory.list();
                  for (int j = 0; j < filenames.length; j++)
                  {
                      String filename = filenames[j].toLowerCase();
                      if (!filename.endsWith(".jar"))
                      {
                          continue;
                      }
                      File file = new File(directory, filenames[j]);
                      getLogger().debug(("  Including jar file " + file.getAbsolutePath()));
                      URL url = new URL("file", null,
                              file.getCanonicalPath());
                      stringList.add(url.toString());
                      urlList.add(url);
                  }
              }
          }
  
          // Construct the class loader itself
          String[] stringArray = (String[]) stringList.toArray(new String[stringList.size()]);
          URL[] urlArray = (URL[]) urlList.toArray(new URL[urlList.size()]);
          Class loaderClass = (parent == null)
                  ? URLClassLoader.newInstance(urlArray)
                      .loadClass("org.apache.catalina.loader.StandardClassLoader")
                  : URLClassLoader.newInstance(urlArray, parent)
                      .loadClass("org.apache.catalina.loader.StandardClassLoader");
  
          getLogger().debug(loaderClass.getName() + " successfully loaded.");
          Object loader = null;
  
          if (parent == null)
          {
              try
              {
                  loader = loaderClass.getConstructor(new Class[]{stringArray.getClass()})
                          .newInstance(new Object[]{stringArray});
              }
              catch (Exception e)
              {
                  throw new CascadingRuntimeException("Some problem constructing using reflection",e);
              }
          }
          else
          {
              try
              {
                  loader = loaderClass.getConstructor(new Class[]{stringArray.getClass(),
                          ClassLoader.class}).newInstance(new Object[]{stringArray, parent});
              }
              catch (Exception e)
              {
                  throw new CascadingRuntimeException("Some problem constructing using reflection",e);
              }
          }
  
          getLogger().debug("Setting loader to delegate=true");
          try
          {
              Method delegating = loader.getClass().getMethod("setDelegate",
                      new Class[]{Boolean.TYPE});
              delegating.invoke(loader, new Object[]{Boolean.TRUE});
          }
          catch (Exception e)
          {
              throw new CascadingRuntimeException("Some problem invoking methods using reflection",e);
          }
          getLogger().debug("Class Loader Intance: " + loader);
  
          getLogger().debug("ClassLoader creation completed...");
          return (ClassLoader) loader;
  
      }
  
      /**
       * Load some securty stuff for Catalina.
       * @param loader the loader
       * @throws Exception if a problem
       */
      public void securityClassLoad(ClassLoader loader) throws Exception
      {
  
          if (System.getSecurityManager() == null)
          {
              return;
          }
  
          String basePackage = "org.apache.catalina.";
          loader.loadClass
                  (basePackage
                  + "core.ApplicationContext$PrivilegedGetRequestDispatcher");
          loader.loadClass
                  (basePackage
                  + "core.ApplicationContext$PrivilegedGetResource");
          loader.loadClass
                  (basePackage
                  + "core.ApplicationContext$PrivilegedGetResourcePaths");
          loader.loadClass
                  (basePackage
                  + "core.ApplicationContext$PrivilegedLogMessage");
          loader.loadClass
                  (basePackage
                  + "core.ApplicationContext$PrivilegedLogException");
          loader.loadClass
                  (basePackage
                  + "core.ApplicationContext$PrivilegedLogThrowable");
          loader.loadClass
                  (basePackage
                  + "core.ApplicationDispatcher$PrivilegedForward");
          loader.loadClass
                  (basePackage
                  + "core.ApplicationDispatcher$PrivilegedInclude");
          loader.loadClass
                  (basePackage
                  + "core.ContainerBase$PrivilegedAddChild");
          loader.loadClass
                  (basePackage
                  + "connector.HttpRequestBase$PrivilegedGetSession");
          loader.loadClass
                  (basePackage
                  + "connector.HttpResponseBase$PrivilegedFlushBuffer");
          loader.loadClass
                  (basePackage
                  + "loader.WebappClassLoader$PrivilegedFindResource");
          loader.loadClass
                  (basePackage + "session.StandardSession");
          loader.loadClass
                  (basePackage + "util.CookieTools");
          loader.loadClass
                  (basePackage + "util.URL");
          loader.loadClass(basePackage + "util.Enumerator");
          loader.loadClass("javax.servlet.http.Cookie");
  
      }
  }
  
  
  
  1.1                  jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina/CatalinaSevakServer.java
  
  Index: CatalinaSevakServer.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.apps.sevak.blocks.catalina;
  
  import org.apache.catalina.Deployer;
  import org.apache.catalina.Lifecycle;
  import org.apache.catalina.LifecycleException;
  import org.apache.catalina.LifecycleListener;
  import org.apache.catalina.Server;
  import org.apache.catalina.Service;
  import org.apache.catalina.deploy.NamingResources;
  import org.apache.catalina.util.LifecycleSupport;
  
  /**
   * Catalina Sevak Server
   *
   * @author  Daniel Krieg<dk...@kc.rr.com>
   * @version $Revision: 1.1 $ $Date: 2002/09/29 11:38:42 $
   */
  public class CatalinaSevakServer implements Server, Lifecycle, Runnable
  {
      private static final String C_INFO = CatalinaSevakServer.class.getName();
      private LifecycleSupport m_lifecycleSupport = new LifecycleSupport(this);
      private String m_shutdown = "SHUTDOWN";
      private Service[] m_services = new Service[0];
      private int m_port = 8005;
      private boolean m_initialized = false;
      private boolean m_started = false;
      private NamingResources m_globalNamingResources;
      private boolean m_serving = false;
  
      /**
       * As per runnable
       */
      public void run()
      {
          while (m_serving)
          {
              try
              {
                  Thread.sleep(3 * 1000); // Three seconds
              }
              catch (InterruptedException e)
              {
                  System.out.println("CatalinaSevakServer.run: " + e);
              }
          }
      }
  
      /**
       * Await
       */
      public void await()
      {
          Thread t = new Thread(this);
          t.start();
      }
  
      /**
       * Start
       * @throws LifecycleException if a problem
       */
      public void start() throws LifecycleException
      {
          if (m_started)
          {
              throw new LifecycleException("This server has already been started");
          }
  
          m_lifecycleSupport.fireLifecycleEvent(BEFORE_START_EVENT, null);
          m_lifecycleSupport.fireLifecycleEvent(START_EVENT, null);
          m_started = true;
  
          synchronized (m_services)
          {
              for (int i = 0; i < m_services.length; i++)
              {
                  if (m_services[i] instanceof Lifecycle)
                  {
                      ((Lifecycle) m_services[i]).start();
                  }
              }
          }
  
          m_lifecycleSupport.fireLifecycleEvent(AFTER_START_EVENT, null);
      }
  
      /**
       * Stop
       * @throws LifecycleException if a problem
       */
      public void stop() throws LifecycleException
      {
          if (!m_started)
          {
              throw new LifecycleException("This server has not yet been started");
          }
  
          m_lifecycleSupport.fireLifecycleEvent(BEFORE_STOP_EVENT, null);
          m_lifecycleSupport.fireLifecycleEvent(STOP_EVENT, null);
          m_started = false;
  
          for (int i = 0; i < m_services.length; i++)
          {
              if (m_services[i] instanceof Lifecycle)
              {
                  ((Lifecycle) m_services[i]).stop();
              }
          }
  
          m_lifecycleSupport.fireLifecycleEvent(AFTER_STOP_EVENT, null);
      }
  
      /**
       * Initialize
       * @throws LifecycleException if a problem
       */
      public void initialize() throws LifecycleException
      {
          if (m_initialized)
          {
              throw new LifecycleException("This server has already been initialized");
          }
          m_initialized = true;
  
          for (int i = 0; i < m_services.length; i++)
          {
              m_services[i].initialize();
          }
      }
  
      /**
       * Get the GlobalNamingReources
       * @return the naming resources
       */
      public NamingResources getGlobalNamingResources()
      {
          return m_globalNamingResources;
      }
  
      /**
       * Set the global naming resources
       * @param globalNamingResources the global naming resources.
       */
      public void setGlobalNamingResources(NamingResources globalNamingResources)
      {
          m_globalNamingResources = globalNamingResources;
          m_globalNamingResources.setContainer(this);
      }
  
      /**
       * Add the service
       * @param service the service
       */
      public void addService(final Service service)
      {
          service.setServer(this);
  
          synchronized (m_services)
          {
              Service[] services = new Service[m_services.length + 1];
              System.arraycopy(m_services, 0, services, 0, m_services.length);
              services[m_services.length] = service;
              m_services = services;
  
              if (m_initialized)
              {
                  try
                  {
                      service.initialize();
                  }
                  catch (LifecycleException e)
                  {
                      e.printStackTrace(System.err);
                  }
              }
  
              if (m_started && (service instanceof Lifecycle))
              {
                  try
                  {
                      ((Lifecycle) service).start();
                  }
                  catch (LifecycleException e)
                  {
                      // nothing?
                  }
              }
          }
      }
  
      /**
       * Find a service
       * @param name the service name
       * @return the service
       */
      public Service findService(String name)
      {
  
          if (name == null)
          {
              return (null);
          }
          synchronized (m_services)
          {
              for (int i = 0; i < m_services.length; i++)
              {
                  if (name.equals(m_services[i].getName()))
                  {
                      return (m_services[i]);
                  }
              }
          }
          return (null);
  
      }
  
      /**
       * Find all services
       * @return the services
       */
      public Service[] findServices()
      {
  
          return (m_services);
  
      }
  
      /**
       * Remove a service
       * @param service the service
       */
      public void removeService(Service service)
      {
          synchronized (m_services)
          {
              int j = -1;
              for (int i = 0; i < m_services.length; i++)
              {
                  if (service == m_services[i])
                  {
                      j = i;
                      break;
                  }
              }
              if (j < 0)
              {
                  return;
              }
              if (m_services[j] instanceof Lifecycle)
              {
                  try
                  {
                      ((Lifecycle) m_services[j]).stop();
                  }
                  catch (LifecycleException e)
                  {
                      // nothing?
                  }
              }
              int k = 0;
              Service results[] = new Service[m_services.length - 1];
              for (int i = 0; i < m_services.length; i++)
              {
                  if (i != j)
                  {
                      results[k++] = m_services[i];
                  }
              }
              m_services = results;
          }
      }
  
      /**
       * Get the port
       * @return the port
       */
      public int getPort()
      {
          return m_port;
      }
  
      /**
       * Set the port
       * @param port the port
       */
      public void setPort(int port)
      {
          m_port = port;
      }
  
      /**
       * Get info
       * @return info
       */
      public String getInfo()
      {
          return C_INFO;
      }
  
      /**
       * Get shutdown property
       * @return the shutdown property
       */
      public String getShutdown()
      {
          return m_shutdown;
      }
  
      /**
       * Set the shutdown property
       * @param shutdown the shutdown property
       */
      public void setShutdown(String shutdown)
      {
          m_shutdown = shutdown;
      }
  
      /**
       * Add a lifecycle listener
       * @param listener the listener
       */
      public void addLifecycleListener(LifecycleListener listener)
      {
          m_lifecycleSupport.addLifecycleListener(listener);
      }
  
      /**
       * Find lifecycle listeners.
       * @return the LifeCycle listeners
       */
      public LifecycleListener[] findLifecycleListeners()
      {
          return m_lifecycleSupport.findLifecycleListeners();
      }
  
      /**
       * Remove lifecycle listeners.
       * @param listener the listener
       */
      public void removeLifecycleListener(LifecycleListener listener)
      {
          m_lifecycleSupport.removeLifecycleListener(listener);
      }
  
      /**
       * A string rep of this instance
       * @return the string
       */
      public String toString()
      {
          StringBuffer sb = new StringBuffer("CatalinaSevakServer[");
          sb.append(getPort());
          sb.append("]");
          return (sb.toString());
      }
  
      /**
       * Get the deployer
       * @return the deployer
       */
      public Deployer getDeployer()
      {
          return null;
      }
  }
  
  
  
  1.1                  jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina/CatalinaSevakShutdownHook.java
  
  Index: CatalinaSevakShutdownHook.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.apps.sevak.blocks.catalina;
  
  import org.apache.catalina.Lifecycle;
  import org.apache.catalina.LifecycleException;
  import org.apache.catalina.Server;
  
  /**
   * Catalina SevakShutdownHook
   *
   * @author  Daniel Krieg<dk...@kc.rr.com>
   * @version $Revision: 1.1 $ $Date: 2002/09/29 11:38:42 $
   */
  public class CatalinaSevakShutdownHook extends Thread
  {
  
      private Server m_server;
  
      /**
       * Construct a shutdown hook.
       * @param server the server
       */
      public CatalinaSevakShutdownHook(Server server)
      {
          super("CatalinaSevakShutdownHook");
          m_server =server;
      }
  
      /**
       * Run as per Runnable.
       */
      public void run()
      {
          if (m_server != null)
          {
              try
              {
                  ((Lifecycle) m_server).stop();
              }
              catch (LifecycleException e)
              {
                  System.out.println("Catalina.stop: " + e);
                  e.printStackTrace(System.out);
                  if (e.getThrowable() != null)
                  {
                      System.out.println("----- Root Cause -----");
                      e.getThrowable().printStackTrace(System.out);
                  }
              }
          }
      }
  
  }
  
  
  
  1.1                  jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/catalina/ParentClassLoaderRule.java
  
  Index: ParentClassLoaderRule.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.apps.sevak.blocks.catalina;
  
  import org.apache.catalina.Container;
  import org.apache.commons.digester.Digester;
  import org.apache.commons.digester.Rule;
  
  import org.xml.sax.Attributes;
  
  /**
   * A Parent Classloader Rule for Catalina
   *
   * @author  Daniel Krieg<dk...@kc.rr.com>
   * @version $Revision: 1.1 $ $Date: 2002/09/29 11:38:42 $
   */
  public class ParentClassLoaderRule extends Rule
  {
      private ClassLoader m_parentClassLoader = null;
  
      /**
       * Construct a ParentClassLoaderRule
       * @param digester The Digester
       * @param parentClassLoader The parent ClassLoader
       */
      public ParentClassLoaderRule(Digester digester, ClassLoader parentClassLoader)
      {
          super(digester);
          this.m_parentClassLoader = parentClassLoader;
      }
  
      /**
       * Begin operation
       * @param attributes the attributes
       * @throws Exception if an Exception
       */
      public void begin(Attributes attributes) throws Exception
      {
          Container top = (Container) digester.peek();
          top.setParentClassLoader(m_parentClassLoader);
      }
  }
  
  
  
  1.2       +6 -12     jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/jetty/JettySevak.java
  
  Index: JettySevak.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/jetty/JettySevak.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JettySevak.java	22 Sep 2002 21:39:12 -0000	1.1
  +++ JettySevak.java	29 Sep 2002 11:38:43 -0000	1.2
  @@ -45,7 +45,7 @@
   
       private Server m_server;
       private String m_hostName;
  -    private HashMap webapps = new HashMap();
  +    private HashMap m_webapps = new HashMap();
   
   
       public JettySevak()
  @@ -87,19 +87,13 @@
           }
       }
   
  -    //----------------------------------------------------------------------------
  -    // 'deploy' interface
  -    //----------------------------------------------------------------------------
  -    /**
  -     * @param context context path
  -     * @param pathToWebAppFolder
  -     */
       public void deploy(String context, File pathToWebAppFolder) throws SevakException
       {
           try
           {
  -            WebApplicationContext ctx = m_server.addWebApplication(m_hostName, context, pathToWebAppFolder.getAbsolutePath());
  -            webapps.put(context,ctx);
  +            WebApplicationContext ctx = m_server.addWebApplication(m_hostName, context,
  +                    pathToWebAppFolder.getAbsolutePath());
  +            m_webapps.put(context,ctx);
           }
           catch (IOException ioe)
           {
  @@ -110,9 +104,9 @@
   
       public void undeploy(String context) throws SevakException
       {
  -        WebApplicationContext ctx = (WebApplicationContext) webapps.get(context);
  +        WebApplicationContext ctx = (WebApplicationContext) m_webapps.get(context);
           ctx.destroy();
  -        webapps.remove(context);
  +        m_webapps.remove(context);
       }
   
   
  
  
  
  1.2       +106 -58   jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/jo/JoAvalonLogListener.java
  
  Index: JoAvalonLogListener.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/jo/JoAvalonLogListener.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JoAvalonLogListener.java	22 Sep 2002 09:35:01 -0000	1.1
  +++ JoAvalonLogListener.java	29 Sep 2002 11:38:43 -0000	1.2
  @@ -1,27 +1,12 @@
   /*
  -License $Id$
  -
  -Copyright (c) 2001-2002 tagtraum industries.
  -
  -LGPL
  -====
  -
  -jo! is free software; you can redistribute it and/or
  -modify it under the terms of the GNU Lesser General Public
  -License as published by the Free Software Foundation; either
  -version 2.1 of the License, or (at your option) any later version.
  -
  -jo! is distributed in the hope that it will be useful,
  -but WITHOUT ANY WARRANTY; without even the implied warranty of
  -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  -Lesser General Public License for more details.
  -
  -You should have received a copy of the GNU Lesser General Public
  -License along with this library; if not, write to the Free Software
  -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  -
  -For LGPL see <http://www.fsf.org/copyleft/lesser.txt>
  + * Copyright (C) The Apache Software Foundation. All rights reserved.
  + *
  + * This software is published under the terms of the Apache Software License
  + * version 1.1, a copy of which has been included with this distribution in
  + * the LICENSE file.
  + */
   
  +/*
   
   Sun license
   ===========
  @@ -87,13 +72,7 @@
      Commerce Department's Table of Denial Orders.
   
   
  -Feedback
  -========
  -
  -We encourage your feedback and suggestions and want to use your feedback to
  -improve the Software. Send all such feedback to:
  -<fe...@tagtraum.com>
  -/*
  + *
    * Copyright (C) The Apache Software Foundation. All rights reserved.
    *
    * This software is published under the terms of the Apache Software License
  @@ -114,55 +93,124 @@
    * @author <a href="mailto:hs@tagtraum.com">Hendrik Schreiber</a>
    * @version $Revision$
    */
  -public class JoAvalonLogListener implements I_LogEventListener {
  +public class JoAvalonLogListener implements I_LogEventListener
  +{
   
  -    private String name;
  -    private Logger logger;
  +    private String m_name;
  +    private Logger m_logger;
   
  -    public JoAvalonLogListener(String name, Logger logger) {
  -        this.name = name;        // source
  -        this.logger = logger;
  +    /**
  +     * Construct a log listener
  +     * @param name the name of the log
  +     * @param logger the logger
  +     */
  +    public JoAvalonLogListener(String name, Logger logger)
  +    {
  +        this.m_name = name;        // source
  +        this.m_logger = logger;
           Log.getLog(name).addI_LogEventListener(this);
       }
   
  -    public void handleLogEvent(LogEvent le) {
  -        switch (le.getLevel()) {
  +    /**
  +     * Handle a log event
  +     * @param le the log event
  +     */
  +    public void handleLogEvent(LogEvent le)
  +    {
  +        switch (le.getLevel())
  +        {
               case C_Log.NOLOG:
                   break;
               case C_Log.ERROR:
  -                if (le.getMessage() != null && le.getThrowable() != null) logger.error(le.getMessage(), le.getThrowable());
  -                else if (le.getMessage() != null) logger.error(le.getMessage());
  -                else if (le.getThrowable() != null) logger.error(le.getThrowable().toString(), le.getThrowable());
  +                if (le.getMessage() != null && le.getThrowable() != null)
  +                {
  +                    m_logger.error(le.getMessage(), le.getThrowable());
  +                }
  +                else if (le.getMessage() != null)
  +                {
  +                    m_logger.error(le.getMessage());
  +                }
  +                else if (le.getThrowable() != null)
  +                {
  +                    m_logger.error(le.getThrowable().toString(), le.getThrowable());
  +                }
                   break;
               case C_Log.MODULE:
  -                if (le.getMessage() != null && le.getThrowable() != null) logger.info(le.getMessage(), le.getThrowable());
  -                else if (le.getMessage() != null) logger.info(le.getMessage());
  -                else if (le.getThrowable() != null) logger.info(le.getThrowable().toString(), le.getThrowable());
  +                if (le.getMessage() != null && le.getThrowable() != null)
  +                {
  +                    m_logger.info(le.getMessage(), le.getThrowable());
  +                }
  +                else if (le.getMessage() != null)
  +                {
  +                    m_logger.info(le.getMessage());
  +                }
  +                else if (le.getThrowable() != null)
  +                {
  +                    m_logger.info(le.getThrowable().toString(), le.getThrowable());
  +                }
                   break;
               default:
  -                if (le.getMessage() != null && le.getThrowable() != null) logger.debug(le.getMessage(), le.getThrowable());
  -                else if (le.getMessage() != null) logger.debug(le.getMessage());
  -                else if (le.getThrowable() != null) logger.debug(le.getThrowable().toString(), le.getThrowable());
  +                if (le.getMessage() != null && le.getThrowable() != null)
  +                {
  +                    m_logger.debug(le.getMessage(), le.getThrowable());
  +                }
  +                else if (le.getMessage() != null)
  +                {
  +                    m_logger.debug(le.getMessage());
  +                }
  +                else if (le.getThrowable() != null)
  +                {
  +                    m_logger.debug(le.getThrowable().toString(), le.getThrowable());
  +                }
           }
       }
   
  -    public String getName() {
  -        return name;
  +    /**
  +     * Get the log name
  +     * @return the log name
  +     */
  +    public String getName()
  +    {
  +        return m_name;
       }
   
  -    public Logger getLogger() {
  -        return logger;
  +    /**
  +     * Get the logger
  +     * @return the logger
  +     */
  +    public Logger getLogger()
  +    {
  +        return m_logger;
       }
   
  -    public int hashCode() {
  -        return name.hashCode() ^ logger.hashCode();
  +    /**
  +     * Makea hash code
  +     * @return the hash
  +     */
  +    public int hashCode()
  +    {
  +        return m_name.hashCode() ^ m_logger.hashCode();
       }
   
  -    public boolean equals(Object obj) {
  -        if (obj == null) return false;
  -        if (obj == this) return true;
  -        if (obj.getClass() == getClass()) {
  -            return logger.equals(((JoAvalonLogListener)obj).getLogger()) && name.equals(((JoAvalonLogListener)obj).getName());
  +    /**
  +     * Implement and equality test
  +     * @param obj to test against
  +     * @return equals or not.
  +     */
  +    public boolean equals(Object obj)
  +    {
  +        if (obj == null)
  +        {
  +            return false;
  +        }
  +        if (obj == this)
  +        {
  +            return true;
  +        }
  +        if (obj.getClass() == getClass())
  +        {
  +            return m_logger.equals(((JoAvalonLogListener) obj).getLogger())
  +                    && m_name.equals(((JoAvalonLogListener) obj).getName());
           }
           return false;
       }
  
  
  
  1.2       +23 -33    jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/jo/JoException.java
  
  Index: JoException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/jo/JoException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JoException.java	22 Sep 2002 09:35:01 -0000	1.1
  +++ JoException.java	29 Sep 2002 11:38:43 -0000	1.2
  @@ -7,8 +7,7 @@
    */
   package org.apache.avalon.apps.sevak.blocks.jo;
   
  -import java.io.PrintStream;
  -import java.io.PrintWriter;
  +import org.apache.avalon.framework.CascadingException;
   
   /**
    *
  @@ -17,36 +16,27 @@
    * @author <a href="mailto:hs@tagtraum.com">Hendrik Schreiber</a>
    * @version $Id$
    */
  -public class JoException extends Exception {
  -   private Exception nestedException;
  -   public JoException(String s) {
  -      super(s);
  -   }
  -   public JoException(Exception nestedException) {
  -      super(nestedException.toString());
  -      setNestedException(nestedException);
  -   }
  +public class JoException extends CascadingException
  +{
   
  -   public Exception getNestedException() {
  -      return nestedException;
  -   }
  +    /**
  +     * Construct a Jo Exception
  +     * @param message the message
  +     */
  +    public JoException(String message)
  +    {
  +        super(message);
  +
  +    }
  +
  +    /**
  +     * Construct a Jo Exception
  +     * @param message the message*
  +     * @param nestedException a nested exception
  +     */
  +    public JoException(String message, Exception nestedException)
  +    {
  +        super(message, nestedException);
  +    }
   
  -   private void setNestedException(Exception nestedException) {
  -      this.nestedException = nestedException;
  -   }
  -
  -   public void printStackTrace() {
  -      if (nestedException != null) nestedException.printStackTrace();
  -      super.printStackTrace();
  -   }
  -
  -   public void printStackTrace(PrintStream s) {
  -      if (nestedException != null) nestedException.printStackTrace(s);
  -      super.printStackTrace(s);
  -   }
  -
  -   public void printStackTrace(PrintWriter s) {
  -      if (nestedException != null) nestedException.printStackTrace(s);
  -      super.printStackTrace(s);
  -   }
   }
  
  
  
  1.3       +54 -13    jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/jo/JoSevak.java
  
  Index: JoSevak.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/sevak/src/java/org/apache/avalon/apps/sevak/blocks/jo/JoSevak.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JoSevak.java	22 Sep 2002 21:39:12 -0000	1.2
  +++ JoSevak.java	29 Sep 2002 11:38:43 -0000	1.3
  @@ -63,26 +63,43 @@
       private BlockContext m_context;
       private String m_hostName;
   
  +    /**
  +     * Constrct a Sevak instance that wraps Jo!
  +     */
       public JoSevak()
       {
           m_log = com.tagtraum.framework.log.Log.getLog("Jo");
       }
   
  +    /**
  +     * Contextualize the block
  +     * @param context the context
  +     */
       public void contextualize(final Context context)
       {
           this.m_context = (BlockContext) context;
       }
   
  +    /**
  +     * Configure the block
  +     * @param configuration the configuration
  +     * @throws ConfigurationException If an error during configuration
  +     */
       public void configure(final Configuration configuration) throws ConfigurationException
       {
           m_hostName = configuration.getChild("hostname").getValue("localhost");
       }
   
   
  +    /**
  +     * Initialize the block
  +     * @throws Exception if a problem during initialization
  +     */
       public void initialize() throws Exception
       {
   
  -        m_buildURL = URLHelper.make(((BlockContext) m_context).getBaseDirectory().toString() + "/etc/");
  +        m_buildURL = URLHelper.make(((BlockContext) m_context).getBaseDirectory().toString()
  +                + "/etc/");
   
           JoServletService._setJoHome(((BlockContext) m_context).getBaseDirectory());
           // ugly hack...
  @@ -95,11 +112,19 @@
           m_joServletService = (I_JoServletService) m_builder.build();
       }
   
  +    /**
  +     * Start the server
  +     * @throws Exception if a problem
  +     */
       public final void start() throws Exception
       {
           m_joServletService.start();
       }
   
  +    /**
  +     * Stop the server
  +     * @throws Exception if a problem
  +     */
       public void stop() throws Exception
       {
           try
  @@ -114,16 +139,15 @@
           catch (ServerException e)
           {
               m_log.log(e, C_Log.ERROR);
  -            getLogger().error("Error uring stopping of Jo!",e);
  +            getLogger().error("Error uring stopping of Jo!", e);
           }
       }
   
  -    //----------------------------------------------------------------------------
  -    // 'deploy' interface
  -    //----------------------------------------------------------------------------
       /**
  -     * @param context context path
  -     * @param pathToWebAppFolder
  +     * Deploy the server
  +     * @param context the context
  +     * @param pathToWebAppFolder the path to the web app
  +     * @throws SevakException if a problem deploying
        */
       public void deploy(String context, File pathToWebAppFolder) throws SevakException
       {
  @@ -134,7 +158,10 @@
               warUrl = pathToWebAppFolder.toURL().toString();
               // now build the servletcontext
               I_JoHost host = m_joServletService.getHost(m_hostName);
  -            if (host == null) throw new JoException("Host '" + m_hostName + "' does not exist.");
  +            if (host == null)
  +            {
  +                throw new JoException("Host '" + m_hostName + "' does not exist.");
  +            }
               I_JoHostBuilder builder = (I_JoHostBuilder) host.getBuilder();
   
               /*
  @@ -151,11 +178,15 @@
               m_log.log("WARUrl: " + warUrl);
               if (host.getNamedServletContextPeer(context) != null)
               {
  -                throw new JoException("Webapp " + context + " is already deployed. You need to undeploy it in order to deploy a different WAR with the same name.");
  +                throw new JoException("Webapp " + context + " is already deployed. You need to"
  +                    + " undeploy it in order to deploy a different WAR with the same name.");
               }
               I_JoServletContextPeer peer = builder.buildWebApp(host, null, context, warUrl, context);
               // now start the webapp
  -            if (peer == null) throw new JoException("Failed to built webapp. Please check logs.");
  +            if (peer == null)
  +            {
  +                throw new JoException("Failed to built webapp. Please check logs.");
  +            }
               peer.start();
               m_log.log("Successfully deployed " + warUrl + " to " + context);
           }
  @@ -163,7 +194,8 @@
           {
               m_log.log("Problem deploying " + warUrl + " to " + context, C_Log.ERROR);
               m_log.log(je, C_Log.ERROR);
  -            throw new SevakException("Jo could not deploy " + warUrl + " to " + context + ": " + je.getMessage());
  +            throw new SevakException("Jo could not deploy " + warUrl + " to " + context + ": "
  +                    + je.getMessage());
           }
           catch (BuildException be)
           {
  @@ -173,16 +205,25 @@
           }
           catch (MalformedURLException mufe)
           {
  -            m_log.log("Problem deploying " + warUrl + " to " + context + " as URL cannot be made from path", C_Log.ERROR);
  +            m_log.log("Problem deploying " + warUrl + " to " + context
  +                    + " as URL cannot be made from path", C_Log.ERROR);
               m_log.log(mufe, C_Log.ERROR);
               throw new SevakException("Jo could not build deployment : " + mufe.getMessage());
           }
       }
   
  +    /**
  +     * Undeploy a webapp
  +     * @param context The context for the webapp
  +     * @throws SevakException If a problem during operation
  +     */
       public void undeploy(String context) throws SevakException
       {
           I_JoHost host = m_joServletService.getHost(m_hostName);
  -        if (host == null) throw new SevakException("Host '" + m_hostName + "' does not exist.");
  +        if (host == null)
  +        {
  +            throw new SevakException("Host '" + m_hostName + "' does not exist.");
  +        }
           try
           {
               host.removeServletContextPeer(context);
  
  
  
  1.1                  jakarta-avalon-apps/sevak/src/demo/java/org/apache/avalon/apps/sevak/demo/MultihostSevakTest.java
  
  Index: MultihostSevakTest.java
  ===================================================================
  package org.apache.avalon.apps.sevak.demo;
  
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.service.Serviceable;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.apps.sevak.MultihostSevak;
  import org.apache.avalon.phoenix.BlockContext;
  
  import java.io.File;
  
  /**
   * @phoenix:block
   *
   * Test Sevak (Tomcat wrapper).
   *
   * @author  Daniel Krieg<dk...@kc.rr.com>
   * @version 1.0
   */
  public class MultihostSevakTest extends AbstractLogEnabled
          implements Contextualizable, Serviceable, Configurable, Initializable {
  
      private BlockContext m_context;
      private Configuration m_configuration;
      private MultihostSevak m_mulihostSevak;
  
      public void contextualize( Context context ) throws ContextException {
          getLogger().info( "MultihostSevakTest.contextualize" );
          m_context = (BlockContext) context;
      }
  
      public void configure( Configuration configuration ) throws ConfigurationException {
          getLogger().info( "MultihostSevakTest.configure" );
          m_configuration = configuration;
      }
  
      /**
       * @see org.apache.avalon.framework.service.Serviceable
       * @phoenix:dependency name="org.apache.avalon.apps.sevak.MultihostSevak"
       */
      public void service( ServiceManager serviceManager ) throws ServiceException {
          getLogger().info( "MultihostSevakTest.service" );
          m_mulihostSevak = (MultihostSevak) serviceManager.lookup( MultihostSevak.ROLE );
      }
  
      public void initialize() throws Exception {
          getLogger().info( "MultihostSevakTest.initialize" );
          Configuration[] contexts = m_configuration.getChildren( "Context" );
          for( int i = 0; i < contexts.length; i++ ) {
              String ctx = contexts[ i ].getAttribute( "docBase" );
              String ctxPath = contexts[ i ].getAttribute( "path" );
              ctxPath = ctxPath.replace( '/', File.separatorChar );
              ctxPath = ctxPath.replace( '\\', File.separatorChar );
              String ctxFullPath = m_context.getBaseDirectory().getAbsolutePath() + File.separatorChar + ctxPath;
              //System.out.println("Ctx = " + ctx + ", path = " + ctxFullPath);
              m_mulihostSevak.deploy( "loclhost", ctx, new File( ctxFullPath ) );
          }
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>