tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core StandardContext.java
Date Wed, 12 Mar 2003 06:24:15 GMT
costin      2003/03/11 22:24:15

  Modified:    catalina/src/share/org/apache/catalina/core
                        StandardContext.java
  Log:
  - forgive duplicated start()
  
  - remove unused imports ( thanks Idea )
  
  - Add support for a "defaultWebXml" configuration option. It adds a bit
  more flexibility ( you could configure different defaults for different sets of webapps
)
  and reduces the dependency on catalina.base env.
  
  - stop using catalina.base if engine.baseDir is set - we should do a grep and
  make sure catalina.base system property is never used ( otherwise it's almost
  impossible to support the original goal of multiple engines in a vm )
  
  - few fixes in jmx registration. Create a host automatically if none set
  ( using the hostname from the jsr77 name of the context )
  
  - implement destroy for jmx deregistration
  
  - moved methods from mbeans - so all the JMX model is in StandardContext, we
  can remove the extra wrapper
  
  Revision  Changes    Path
  1.25      +89 -36    jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardContext.java
  
  Index: StandardContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardContext.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- StandardContext.java	11 Mar 2003 19:39:06 -0000	1.24
  +++ StandardContext.java	12 Mar 2003 06:24:15 -0000	1.25
  @@ -1,7 +1,4 @@
   /*
  - * $Header$
  - * $Revision$
  - * $Date$
    *
    * ====================================================================
    *
  @@ -92,23 +89,7 @@
   import org.apache.naming.resources.ProxyDirContext;
   import org.apache.naming.resources.WARDirContext;
   import org.apache.naming.resources.DirContextURLStreamHandler;
  -import org.apache.catalina.Container;
  -import org.apache.catalina.ContainerListener;
  -import org.apache.catalina.Context;
  -import org.apache.catalina.Host;
  -import org.apache.catalina.Globals;
  -import org.apache.catalina.InstanceListener;
  -import org.apache.catalina.Lifecycle;
  -import org.apache.catalina.LifecycleEvent;
  -import org.apache.catalina.LifecycleException;
  -import org.apache.catalina.LifecycleListener;
  -import org.apache.catalina.Loader;
  -import org.apache.catalina.Mapper;
  -import org.apache.catalina.Pipeline;
  -import org.apache.catalina.Request;
  -import org.apache.catalina.Response;
  -import org.apache.catalina.Valve;
  -import org.apache.catalina.Wrapper;
  +import org.apache.catalina.*;
   import org.apache.catalina.startup.ContextConfig;
   import org.apache.catalina.startup.TldConfig;
   import org.apache.catalina.mbeans.MBeanUtils;
  @@ -263,6 +244,10 @@
        */
       private String displayName = null;
   
  +    /** Override the default web xml location. ContextConfig is not configurable
  +     * so the setter is not used.
  +     */
  +    private String defaultWebXml;
   
       /**
        * The distributable flag for this web application.
  @@ -765,6 +750,22 @@
   
       }
   
  +    public String getDefaultWebXml() {
  +        return defaultWebXml;
  +    }
  +
  +    /** Set the location of the default web xml that will be used.
  +     * If not absolute, it'll be made relative to the engine's base dir
  +     * ( which defaults to catalina.base system property ).
  +     *
  +     * XXX If a file is not found - we can attempt a getResource()
  +     *
  +     * @param defaultWebXml
  +     */
  +    public void setDefaultWebXml(String defaultWebXml) {
  +        this.defaultWebXml = defaultWebXml;
  +    }
  +
       public long getStartupTime() {
           return startupTime;
       }
  @@ -3726,9 +3727,10 @@
        */
       public synchronized void start() throws LifecycleException {
   
  -        if (started)
  -            throw new LifecycleException
  -                (sm.getString("containerBase.alreadyStarted", logName()));
  +        if (started) {
  +            log.info(sm.getString("containerBase.alreadyStarted", logName()));
  +            return;
  +        }
   
           String logName="tomcat." + getParent().getName() + "." +
                   ("".equals(getName()) ? "ROOT" : getName()) + ".Context";
  @@ -4156,9 +4158,12 @@
        * entire servlet container (i.e. the Engine container if present).
        */
       protected File engineBase() {
  -
  -        return (new File(System.getProperty("catalina.base")));
  -
  +        String base=System.getProperty("catalina.base");
  +        if( base == null ) {
  +            StandardEngine eng=(StandardEngine)this.getParent().getParent();
  +            base=eng.getBaseDir();
  +        }
  +        return (new File(base));
       }
   
   
  @@ -4373,7 +4378,7 @@
           // Create this directory if necessary
           File dir = new File(workDir);
           if (!dir.isAbsolute()) {
  -            File catalinaHome = new File(System.getProperty("catalina.base"));
  +            File catalinaHome = engineBase();
               String catalinaHomePath = null;
               try {
                   catalinaHomePath = catalinaHome.getCanonicalPath();
  @@ -4661,7 +4666,7 @@
       private void registerJMX() {
           String onameStr=null;
           try {
  -            if( oname==null || oname.getKeyProperty("WebModule")==null ) {
  +            if( oname==null || oname.getKeyProperty("j2eeType")==null ) {
                   ContainerBase ctx=(ContainerBase)parent;
                   String pathName=getName();
                   String hostName=getParent().getName();
  @@ -4671,11 +4676,16 @@
                   onameStr="j2eeType=WebModule,name=" + name +
                           ctx.getJSR77Suffix();
                   if( log.isDebugEnabled())
  -                    log.debug("Registering " + onameStr );
  +                    log.debug("Registering " + onameStr + " for " + oname);
   
  -                Registry.getRegistry().registerComponent(this,
  -                        ctx.getDomain(),
  -                        "StandardContext", onameStr);
  +                ObjectName oname=new ObjectName(ctx.getDomain()+ ":" + onameStr);
  +                log.debug("Checking for " + oname );
  +                if(! Registry.getRegistry().getMBeanServer().isRegistered(oname))
  +                {
  +                    Registry.getRegistry().registerComponent(this,
  +                            ctx.getDomain(),
  +                            "StandardContext", onameStr);
  +                }
               }
               for( Iterator it=wrappers.iterator(); it.hasNext() ; ) {
                   StandardWrapper wrapper=(StandardWrapper)it.next();
  @@ -4683,8 +4693,8 @@
                   wrapper.registerJMX( this );
               }
           } catch( Exception ex ) {
  -            log.info("Error registering context with jmx " + this + " " +
  -                    onameStr + " " + ex.toString() );
  +            log.info("Error registering ctx with jmx " + this + " " +
  +                    onameStr + " " + ex.toString(), ex );
           }
       }
   
  @@ -4711,7 +4721,7 @@
           return name;
       }
   
  -    public void preDeregister() {
  +    public void preDeregister() throws Exception {
           if( started ) {
               try {
                   stop();
  @@ -4751,6 +4761,13 @@
                   "type=Host,host=" + hostName + ",service=Tomcat-Standalone");
           log.info("Adding to " + parentName );
   
  +        if( ! mserver.isRegistered(parentName)) {
  +            log.info("No host, creating one ");
  +            StandardHost host=new StandardHost();
  +            host.setName(hostName);
  +            Registry.getRegistry().registerComponent(host, parentName, null);
  +            mserver.invoke(parentName, "init", new Object[] {}, new String[] {} );
  +        }
           ContextConfig config = new ContextConfig();
           this.addLifecycleListener(config);
   
  @@ -4758,4 +4775,40 @@
                   new String[] {"org.apache.catalina.Container"});
   
       }
  +
  +    public void destroy() throws Exception {
  +        if( started ) {
  +            stop();
  +        }
  +        parent.removeChild(this);
  +    }
  +
  +    public void create() throws Exception{
  +        init();
  +    }
  +
  +    // ------------------------------------------------------------- Attributes
  +
  +
  +    /**
  +     * Return the naming resources associated with this web application.
  +     */
  +    public javax.naming.directory.DirContext getStaticResources() {
  +
  +        return getResources();
  +
  +    }
  +
  +
  +    /**
  +     * Return the naming resources associated with this web application.
  +     */
  +    public String[] getWelcomeFiles() {
  +
  +        return findWelcomeFiles();
  +
  +    }
  +
  +
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message