You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by cr...@apache.org on 2002/01/13 05:21:18 UTC

cvs commit: jakarta-struts/src/share/org/apache/struts/config ApplicationConfig.java ControllerConfig.java

craigmcc    02/01/12 20:21:18

  Modified:    conf/share struts-config_1_1.dtd
               src/share/org/apache/struts/action ActionServlet.java
               src/share/org/apache/struts/config ApplicationConfig.java
                        ControllerConfig.java
  Log:
  There is no reason that all sub-applications should have to share a single
  RequestProcessor, so make it configurable on a per-sub-application basis.
  As a side effect, this simplifies the internal method signatures too,
  since there will be one RequestProcessor instance per sub-application.
  
  Revision  Changes    Path
  1.7       +6 -1      jakarta-struts/conf/share/struts-config_1_1.dtd
  
  Index: struts-config_1_1.dtd
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/conf/share/struts-config_1_1.dtd,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- struts-config_1_1.dtd	13 Jan 2002 00:25:35 -0000	1.6
  +++ struts-config_1_1.dtd	13 Jan 2002 04:21:18 -0000	1.7
  @@ -11,7 +11,7 @@
          "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
          "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
   
  -     $Id: struts-config_1_1.dtd,v 1.6 2002/01/13 00:25:35 craigmcc Exp $
  +     $Id: struts-config_1_1.dtd,v 1.7 2002/01/13 04:21:18 craigmcc Exp $
   -->
   
   
  @@ -422,6 +422,10 @@
                        HTTP headers for defeating caching to every response.
                        [false]
   
  +     processorClass  The fully qualified Java class name of the
  +                     RequestProcessor class to be used.
  +                     [org.apache.struts.action.RequestProcessor]
  +
        tempDir         Temporary working directory to use when processing
                        file uploads.  [Directory provided by servlet container]
   -->
  @@ -434,6 +438,7 @@
   <!ATTLIST controller     maxFileSize    CDATA           #IMPLIED>
   <!ATTLIST controller     multipartClass %ClassName;     #IMPLIED>
   <!ATTLIST controller     nocache        %Boolean;       #IMPLIED>
  +<!ATTLIST controller     processorClass %ClassName;     #IMPLIED>
   <!ATTLIST controller     tempDir        CDATA           #IMPLIED>
   
   
  
  
  
  1.84      +46 -46    jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java
  
  Index: ActionServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
  retrieving revision 1.83
  retrieving revision 1.84
  diff -u -r1.83 -r1.84
  --- ActionServlet.java	13 Jan 2002 00:25:35 -0000	1.83
  +++ ActionServlet.java	13 Jan 2002 04:21:18 -0000	1.84
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.83 2002/01/13 00:25:35 craigmcc Exp $
  - * $Revision: 1.83 $
  - * $Date: 2002/01/13 00:25:35 $
  + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.84 2002/01/13 04:21:18 craigmcc Exp $
  + * $Revision: 1.84 $
  + * $Date: 2002/01/13 04:21:18 $
    *
    * ====================================================================
    *
  @@ -254,9 +254,6 @@
    *     be returned.  [true]
    *     <em>DEPRECATED - Configure this using the "null" attribute of
    *     the &lt;message-resources&gt; element.</em></li>
  - * <li><strong>processor</strong> - The fully qualified Java class name of the
  - *     <code>RequestProcessor</code> implementation class to be used.
  - *     [org.apache.struts.action.RequestProcessor]</li>
    * <li><strong>tempDir</strong> - The temporary working directory to use when
    *     processing file uploads.  [The working directory provided to this web
    *     application as a servlet context attribute]
  @@ -268,7 +265,7 @@
    *
    * @author Craig R. McClanahan
    * @author Ted Husted
  - * @version $Revision: 1.83 $ $Date: 2002/01/13 00:25:35 $
  + * @version $Revision: 1.84 $ $Date: 2002/01/13 04:21:18 $
    */
   
   public class ActionServlet
  @@ -332,13 +329,6 @@
   
   
       /**
  -     * The Java class name of the RequestProcessor implementation to use.
  -     */
  -    protected String processorClass =
  -        "org.apache.struts.action.RequestProcessor";
  -
  -
  -    /**
        * The set of public identifiers, and corresponding resource names, for
        * the versions of the configuration file DTDs that we know about.  There
        * <strong>MUST</strong> be an even number of Strings in this list!
  @@ -389,7 +379,7 @@
           log(internal.getMessage("finalizing"));
   
           destroyDataSources();
  -        destroyProcessor();
  +        destroyApplications();
           destroyInternal();
   
           // FIXME - destroy ApplicationConfig and message resource instances
  @@ -409,7 +399,6 @@
           initInternal();
           initOther();
           initServlet();
  -        initProcessor();
   
           // Initialize sub-applications as needed
           ApplicationConfig ac = initApplicationConfig("", config);
  @@ -445,7 +434,9 @@
                 HttpServletResponse response)
           throws IOException, ServletException {
   
  -        processor.process(request, response);
  +        RequestUtils.selectApplication(request, getServletContext());
  +        getApplicationConfig(request).getProcessor().process
  +            (request, response);
   
       }
   
  @@ -463,7 +454,9 @@
                  HttpServletResponse response)
           throws IOException, ServletException {
   
  -        processor.process(request, response);
  +        RequestUtils.selectApplication(request, getServletContext());
  +        getApplicationConfig(request).getProcessor().process
  +            (request, response);
   
       }
   
  @@ -586,6 +579,28 @@
   
   
       /**
  +     * Gracefully terminate use of any sub-applications associated with this
  +     * application (if any).
  +     */
  +    protected void destroyApplications() {
  +
  +        Enumeration names = getServletContext().getAttributeNames();
  +        while (names.hasMoreElements()) {
  +            String name = (String) names.nextElement();
  +            Object value = getServletContext().getAttribute(name);
  +            if (value instanceof ApplicationConfig) {
  +                try {
  +                    ((ApplicationConfig) value).getProcessor().destroy();
  +                } catch (Throwable t) {
  +                    ;
  +                }
  +            }
  +        }
  +
  +    }
  +
  +
  +    /**
        * Gracefully release any configDigester instance that we have created.
        */
       protected void destroyConfigDigester() {
  @@ -636,12 +651,21 @@
   
   
       /**
  -     * <p>Gracefully terminate the RequestProcessor instance we were using.
  +     * Return the application configuration object for the currently selected
  +     * sub-application.
  +     *
  +     * @param request The servlet request we are processing
        */
  -    protected void destroyProcessor() {
  +    protected ApplicationConfig getApplicationConfig
  +        (HttpServletRequest request) {
   
  -        processor.destroy();
  -        processor = null;
  +        ApplicationConfig config = (ApplicationConfig)
  +            request.getAttribute(Action.APPLICATION_KEY);
  +        if (config == null) {
  +            config = (ApplicationConfig)
  +                getServletContext().getAttribute(Action.APPLICATION_KEY);
  +        }
  +        return (config);
   
       }
   
  @@ -922,10 +946,6 @@
           } catch (Throwable t) {
               detail = 0;
           }
  -        value = getServletConfig().getInitParameter("processor");
  -        if (value != null) {
  -            processorClass = value;
  -        }
           value = getServletConfig().getInitParameter("validating");
           if (value != null) {
               if (value.equalsIgnoreCase("true") ||
  @@ -933,26 +953,6 @@
                   validating = true;
               else
                   validating = false;
  -        }
  -
  -    }
  -
  -
  -    /**
  -     * Initialize the RequestProcessor instance we will be using.
  -     *
  -     * @exception ServletException if we cannot initialize a request processor
  -     */
  -    protected void initProcessor() throws ServletException {
  -
  -        try {
  -            Class clazz = Class.forName(processorClass);
  -            processor = (RequestProcessor) clazz.newInstance();
  -            processor.init(this);
  -        } catch (Throwable t) {
  -            log(internal.getMessage("initProcessor"), t);
  -            throw new UnavailableException
  -                (internal.getMessage("initProcessor"));
           }
   
       }
  
  
  
  1.6       +33 -4     jakarta-struts/src/share/org/apache/struts/config/ApplicationConfig.java
  
  Index: ApplicationConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/ApplicationConfig.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ApplicationConfig.java	13 Jan 2002 00:25:36 -0000	1.5
  +++ ApplicationConfig.java	13 Jan 2002 04:21:18 -0000	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/ApplicationConfig.java,v 1.5 2002/01/13 00:25:36 craigmcc Exp $
  - * $Revision: 1.5 $
  - * $Date: 2002/01/13 00:25:36 $
  + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/ApplicationConfig.java,v 1.6 2002/01/13 04:21:18 craigmcc Exp $
  + * $Revision: 1.6 $
  + * $Date: 2002/01/13 04:21:18 $
    *
    * ====================================================================
    *
  @@ -64,8 +64,11 @@
   
   
   import java.io.Serializable;
  +import javax.servlet.ServletException;
  +import javax.servlet.UnavailableException;
   import org.apache.commons.collections.FastHashMap;
   import org.apache.struts.action.ActionServlet;
  +import org.apache.struts.action.RequestProcessor;
    
   
   
  @@ -79,7 +82,7 @@
    * previous Struts behavior that only supported one application.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.5 $ $Date: 2002/01/13 00:25:36 $
  + * @version $Revision: 1.6 $ $Date: 2002/01/13 04:21:18 $
    * @since Struts 1.1
    */
   
  @@ -204,6 +207,32 @@
   
       public String getPrefix() {
           return (this.prefix);
  +    }
  +
  +
  +    /**
  +     * The initialized RequestProcessor instance to be used for processing
  +     * requests for this application.
  +     */
  +    protected RequestProcessor processor = null;
  +
  +    public synchronized RequestProcessor getProcessor()
  +        throws ServletException {
  +
  +        if (processor == null) {
  +            try {
  +                Class clazz =
  +                    Class.forName(getControllerConfig().getProcessorClass());
  +                processor = (RequestProcessor) clazz.newInstance();
  +                processor.init(servlet, this);
  +            } catch (Throwable t) {
  +                throw new UnavailableException
  +                    ("Cannot initialize RequestProcessor of class " +
  +                     getControllerConfig().getProcessorClass() + ": " + t);
  +            }
  +        }
  +        return (this.processor);
  +
       }
   
   
  
  
  
  1.3       +22 -4     jakarta-struts/src/share/org/apache/struts/config/ControllerConfig.java
  
  Index: ControllerConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/ControllerConfig.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ControllerConfig.java	13 Jan 2002 00:25:36 -0000	1.2
  +++ ControllerConfig.java	13 Jan 2002 04:21:18 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/ControllerConfig.java,v 1.2 2002/01/13 00:25:36 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/01/13 00:25:36 $
  + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/ControllerConfig.java,v 1.3 2002/01/13 04:21:18 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/01/13 04:21:18 $
    *
    * ====================================================================
    *
  @@ -72,7 +72,7 @@
    * configuration file.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2002/01/13 00:25:36 $
  + * @version $Revision: 1.3 $ $Date: 2002/01/13 04:21:18 $
    * @since Struts 1.1
    */
   
  @@ -183,6 +183,22 @@
   
   
       /**
  +     * The fully qualified class name of the RequestProcessor implementation
  +     * class to be used for this application.
  +     */
  +    protected String processorClass =
  +        "org.apache.struts.action.RequestProcessor";
  +
  +    public String getProcessorClass() {
  +        return (this.processorClass);
  +    }
  +
  +    public void setProcessorClass(String processorClass) {
  +        this.processorClass = processorClass;
  +    }
  +
  +
  +    /**
        * The temporary working directory to use for file uploads.
        */
       protected String tempDir = null;
  @@ -219,6 +235,8 @@
           }
           sb.append(",nocache=");
           sb.append(this.nocache);
  +        sb.append(",processorClass=");
  +        sb.append(this.processorClass);
           if (this.tempDir != null) {
               sb.append(",tempDir=");
               sb.append(this.tempDir);
  
  
  

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