tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amy...@apache.org
Subject cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core StandardContext.java StandardHostDeployer.java StandardServer.java
Date Fri, 02 Aug 2002 01:37:43 GMT
amyroh      2002/08/01 18:37:43

  Modified:    catalina/src/share/org/apache/catalina Context.java
               catalina/src/share/org/apache/catalina/core
                        StandardContext.java StandardHostDeployer.java
                        StandardServer.java
  Log:
  Add install method where you can specify the configuration file to save the
  Context information.
  
  Revision  Changes    Path
  1.2       +20 -6     jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/Context.java
  
  Index: Context.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/Context.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Context.java	18 Jul 2002 16:47:37 -0000	1.1
  +++ Context.java	2 Aug 2002 01:37:42 -0000	1.2
  @@ -166,6 +166,20 @@
   
   
       /**
  +     * Return the path to a file to save this Context information.
  +     */
  +    public String getConfigFile();
  +
  +
  +    /**
  +     * Set the path to a file to save this Context information.
  +     *
  +     * @param configFile The path to a file to save this Context information.
  +     */
  +    public void setConfigFile(String configFile);
  +
  +
  +    /**
        * Return the "correctly configured" flag for this Context.
        */
       public boolean getConfigured();
  @@ -275,7 +289,7 @@
   
       /**
        * Set the naming resources for this web application.
  -     * 
  +     *
        * @param namingResources The new naming resources
        */
       public void setNamingResources(NamingResources namingResources);
  @@ -347,7 +361,7 @@
   
       /**
        * Set the privileged flag for this web application.
  -     * 
  +     *
        * @param privileged The new privileged flag
        */
       public void setPrivileged(boolean privileged);
  
  
  
  1.2       +39 -13    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StandardContext.java	18 Jul 2002 16:48:09 -0000	1.1
  +++ StandardContext.java	2 Aug 2002 01:37:43 -0000	1.2
  @@ -214,6 +214,12 @@
   
   
       /**
  +     * The path to a file to save this Context information.
  +     */
  +    private String configFile = null;
  +
  +
  +    /**
        * The "correctly configured" flag for this Context.
        */
       private boolean configured = false;
  @@ -378,7 +384,7 @@
        * Should the next call to <code>addWelcomeFile()</code> cause replacement
        * of any existing welcome files?  This will be set before processing the
        * web application's deployment descriptor, so that application specified
  -     * choices <strong>replace</strong>, rather than append to, those defined

  +     * choices <strong>replace</strong>, rather than append to, those defined
        * in the global descriptor.
        */
       private boolean replaceWelcomeFiles = false;
  @@ -618,6 +624,26 @@
   
       }
   
  +    /**
  +     * Return the path to a file to save this Context information.
  +     */
  +    public String getConfigFile() {
  +
  +        return (this.configFile);
  +
  +    }
  +
  +
  +    /**
  +     * Set the path to a file to save this Context information.
  +     *
  +     * @param configFile The path to a file to save this Context information.
  +     */
  +    public void setConfigFile(String configFile) {
  +
  +        this.configFile = configFile;
  +    }
  +
   
       /**
        * Return the "correctly configured" flag for this Context.
  @@ -864,7 +890,7 @@
   
       /**
        * Set the naming resources for this web application.
  -     * 
  +     *
        * @param namingResources The new naming resources
        */
       public void setNamingResources(NamingResources namingResources) {
  @@ -965,7 +991,7 @@
   
       /**
        * Set the privileged flag for this web application.
  -     * 
  +     *
        * @param privileged The new privileged flag
        */
       public void setPrivileged(boolean privileged) {
  @@ -3342,9 +3368,9 @@
                   ok = false;
               }
               if (ok) {
  -                DirContext dirContext = 
  +                DirContext dirContext =
                       ((ProxyDirContext) resources).getDirContext();
  -                if ((dirContext != null) 
  +                if ((dirContext != null)
                       && (dirContext instanceof BaseDirContext)) {
                       ((BaseDirContext) dirContext).allocate();
                   }
  @@ -3436,7 +3462,7 @@
                           ((Lifecycle) children[i]).start();
                   }
   
  -                // Start the Valves in our pipeline (including the basic), 
  +                // Start the Valves in our pipeline (including the basic),
                   // if any
                   if (pipeline instanceof Lifecycle)
                       ((Lifecycle) pipeline).start();
  @@ -3579,7 +3605,7 @@
                   if (resources instanceof Lifecycle) {
                       ((Lifecycle) resources).stop();
                   } else if (resources instanceof ProxyDirContext) {
  -                    DirContext dirContext = 
  +                    DirContext dirContext =
                           ((ProxyDirContext) resources).getDirContext();
                       if (dirContext != null) {
                           if (debug >= 1) {
  @@ -3719,12 +3745,12 @@
       /**
        * Bind current thread, both for CL purposes and for JNDI ENC support
        * during : startup, shutdown and realoading of the context.
  -     * 
  +     *
        * @return the previous context class loader
        */
       private ClassLoader bindThread() {
   
  -        ClassLoader oldContextClassLoader = 
  +        ClassLoader oldContextClassLoader =
               Thread.currentThread().getContextClassLoader();
   
           if (getResources() == null)
  
  
  
  1.3       +92 -4     jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardHostDeployer.java
  
  Index: StandardHostDeployer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardHostDeployer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StandardHostDeployer.java	1 Aug 2002 01:40:49 -0000	1.2
  +++ StandardHostDeployer.java	2 Aug 2002 01:37:43 -0000	1.3
  @@ -266,6 +266,94 @@
   
   
       /**
  +     * Install a new web application, whose web application archive is at the
  +     * specified URL, into this container with the specified context path.
  +     * A context path of "" (the empty string) should be used for the root
  +     * application for this container.  Otherwise, the context path must
  +     * start with a slash.
  +     * <p>
  +     * If this application is successfully installed, a ContainerEvent of type
  +     * <code>PRE_INSTALL_EVENT</code> will be sent to registered listeners
  +     * before the associated Context is started, and a ContainerEvent of type
  +     * <code>INSTALL_EVENT</code> will be sent to all registered listeners
  +     * after the associated Context is started, with the newly created
  +     * <code>Context</code> as an argument.
  +     *
  +     * @param contextPath The context path to which this application should
  +     *  be installed (must be unique)
  +     * @param war A URL of type "jar:" that points to a WAR file, or type
  +     *  "file:" that points to an unpacked directory structure containing
  +     *  the web application to be installed
  +     * @param configFile The path to a file to save the Context information.
  +     *  If configFile is null, the Context information is saved in server.xml;
  +     *  if it is NOT null, the Context information is saved in configFile.
  +     *
  +     * @exception IllegalArgumentException if the specified context path
  +     *  is malformed (it must be "" or start with a slash)
  +     * @exception IllegalStateException if the specified context path
  +     *  is already attached to an existing web application
  +     * @exception IOException if an input/output error was encountered
  +     *  during installation
  +     */
  +    public synchronized void install(String contextPath, URL war,
  +        String configFile) throws IOException {
  +
  +        // Validate the format and state of our arguments
  +        if (contextPath == null)
  +            throw new IllegalArgumentException
  +                (sm.getString("standardHost.pathRequired"));
  +        if (!contextPath.equals("") && !contextPath.startsWith("/"))
  +            throw new IllegalArgumentException
  +                (sm.getString("standardHost.pathFormat", contextPath));
  +        if (findDeployedApp(contextPath) != null)
  +            throw new IllegalStateException
  +                (sm.getString("standardHost.pathUsed", contextPath));
  +        if (war == null)
  +            throw new IllegalArgumentException
  +                (sm.getString("standardHost.warRequired"));
  +
  +        // Calculate the document base for the new web application
  +        host.log(sm.getString("standardHost.installing",
  +                              contextPath, war.toString()));
  +        String url = war.toString();
  +        String docBase = null;
  +        if (url.startsWith("jar:")) {
  +            url = url.substring(4, url.length() - 2);
  +        }
  +        if (url.startsWith("file://"))
  +            docBase = url.substring(7);
  +        else if (url.startsWith("file:"))
  +            docBase = url.substring(5);
  +        else
  +            throw new IllegalArgumentException
  +                (sm.getString("standardHost.warURL", url));
  +
  +        // Install the new web application
  +        try {
  +            Class clazz = Class.forName(host.getContextClass());
  +            Context context = (Context) clazz.newInstance();
  +            context.setPath(contextPath);
  +            context.setDocBase(docBase);
  +            context.setConfigFile(configFile);
  +            if (context instanceof Lifecycle) {
  +                clazz = Class.forName(host.getConfigClass());
  +                LifecycleListener listener =
  +                    (LifecycleListener) clazz.newInstance();
  +                ((Lifecycle) context).addLifecycleListener(listener);
  +            }
  +            host.fireContainerEvent(PRE_INSTALL_EVENT, context);
  +            host.addChild(context);
  +            host.fireContainerEvent(INSTALL_EVENT, context);
  +        } catch (Exception e) {
  +            host.log(sm.getString("standardHost.installError", contextPath),
  +                     e);
  +            throw new IOException(e.toString());
  +        }
  +
  +    }
  +
  +
  +    /**
        * <p>Install a new web application, whose context configuration file
        * (consisting of a <code>&lt;Context&gt;</code> element) and (optional)
        * web application archive are at the specified URLs.</p>
  
  
  
  1.2       +61 -19    jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardServer.java
  
  Index: StandardServer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardServer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StandardServer.java	18 Jul 2002 16:48:11 -0000	1.1
  +++ StandardServer.java	2 Aug 2002 01:37:43 -0000	1.2
  @@ -203,7 +203,7 @@
       /**
        * ServerLifecycleListener classname.
        */
  -    private static String SERVER_LISTENER_CLASS_NAME = 
  +    private static String SERVER_LISTENER_CLASS_NAME =
           "org.apache.catalina.mbeans.ServerLifecycleListener";
   
   
  @@ -382,7 +382,7 @@
   
       /**
        * Set the global naming resources.
  -     * 
  +     *
        * @param namingResources The new global naming resources
        */
       public void setGlobalNamingResources
  @@ -828,7 +828,7 @@
               }
           }
               return(filtered.toString());
  -    } 
  +    }
   
   
       /**
  @@ -1078,6 +1078,33 @@
       private void storeContext(PrintWriter writer, int indent,
                                 Context context) throws Exception {
   
  +        String configFile = context.getConfigFile();
  +
  +        if (configFile != null) {
  +
  +            File config = new File(configFile);
  +            if (!config.isAbsolute()) {
  +                config = new File(System.getProperty("catalina.base"),
  +                                        configFile);
  +            }
  +
  +            // Open an output writer for the new configuration file
  +            writer = null;
  +            try {
  +                writer = new PrintWriter(new FileWriter(config));
  +            } catch (IOException e) {
  +                if (writer != null) {
  +                    try {
  +                        writer.close();
  +                    } catch (Throwable t) {
  +                        ;
  +                    }
  +                }
  +                throw (e);
  +            }
  +
  +        }
  +
           // Store the beginning of this element
           for (int i = 0; i < indent; i++) {
               writer.print(' ');
  @@ -1156,7 +1183,7 @@
                   storeRealm(writer, indent + 2, realm);
               }
           }
  -        
  +
           // Store nested <Resources> element
           DirContext resources = context.getResources();
           if (resources != null) {
  @@ -1205,6 +1232,21 @@
           }
           writer.println("</Context>");
   
  +        if (configFile != null) {
  +
  +             // Flush and close the output file
  +            try {
  +                 writer.flush();
  +            } catch (Exception e) {
  +                 throw (e);
  +            }
  +            try {
  +                 writer.close();
  +            } catch (Exception e) {
  +                 throw (e);
  +            }
  +        }
  +
       }
   
   
  @@ -1304,7 +1346,7 @@
               }
           }
           */
  -        
  +
           // Store nested <Resources> element
           DirContext resources = dcontext.getResources();
           if (resources != null) {
  @@ -1474,7 +1516,7 @@
   
       }
   
  -    
  +
       /**
        * Store the specified Host properties.
        *
  @@ -1718,7 +1760,7 @@
       private void storeNamingResources(PrintWriter writer, int indent,
                                         NamingResources resources)
           throws Exception {
  -       
  +
           // Store nested <Ejb> elements
           ContextEjb[] ejbs = resources.findEjbs();
           if (ejbs.length > 0) {
  @@ -1731,7 +1773,7 @@
                   writer.println("/>");
               }
           }
  -                
  +
           // Store nested <Environment> elements
           ContextEnvironment[] envs = resources.findEnvironments();
           if (envs.length > 0) {
  @@ -1744,7 +1786,7 @@
                   writer.println("/>");
               }
           }
  -                
  +
           // Store nested <LocalEjb> elements
           ContextLocalEjb[] lejbs = resources.findLocalEjbs();
           if (lejbs.length > 0) {
  @@ -1757,7 +1799,7 @@
                   writer.println("/>");
               }
           }
  -                
  +
           // Store nested <Resource> elements
           ContextResource[] dresources = resources.findResources();
           for (int i = 0; i < dresources.length; i++) {
  @@ -1844,11 +1886,11 @@
               writer.print("<ResourceLink");
               storeAttributes(writer, false, resourceLinks[i]);
               writer.println("/>");
  -        }       
  +        }
   
       }
  -    
  -    
  +
  +
       /**
        * Store the specified Realm properties.
        *
  @@ -1946,7 +1988,7 @@
               }
               writer.println("</GlobalNamingResources>");
           }
  -        
  +
           // Store nested <Service> elements
           Service services[] = server.findServices();
           for (int i = 0; i < services.length; i++) {
  @@ -2137,7 +2179,7 @@
   
   
       /**
  -     * Get the lifecycle listeners associated with this lifecycle. If this 
  +     * Get the lifecycle listeners associated with this lifecycle. If this
        * Lifecycle has no listeners registered, a zero-length array is returned.
        */
       public LifecycleListener[] findLifecycleListeners() {
  
  
  

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


Mime
View raw message