rleland     2002/12/21 21:31:15

  Modified:    src/share/org/apache/struts/action ActionServlet.java
               src/share/org/apache/struts/config ModuleConfig.java
               src/share/org/apache/struts/config/impl
                        ModuleConfigImpl.java
  Added:       src/share/org/apache/struts/config ModuleConfigFactory.java
               src/share/org/apache/struts/config/impl
                        DefaultModuleConfigFactory.java
  Log:
  Commit ModuleConfig factory methods
  
  Revision  Changes    Path
  1.137     +12 -7     
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.136
  retrieving revision 1.137
  diff -u -r1.136 -r1.137
  --- ActionServlet.java        18 Dec 2002 07:39:45 -0000      1.136
  +++ ActionServlet.java        22 Dec 2002 05:31:14 -0000      1.137
  @@ -105,6 +105,7 @@
   import org.apache.struts.config.MessageResourcesConfig;
   import org.apache.struts.config.ModuleConfig;
   import org.apache.struts.config.PlugInConfig;
  +import org.apache.struts.config.ModuleConfigFactory;
   import org.apache.struts.config.impl.ModuleConfigImpl;
   import org.apache.struts.util.GenericDataSource;
   import org.apache.struts.util.MessageResources;
  @@ -798,7 +799,8 @@
        */
       protected ApplicationConfig getApplicationConfig
           (HttpServletRequest request) {
  -        /* Since Struts 1.1 only has one implementation for
  +        /* FIXME for Struts 1.2
  +           Since Struts 1.1 only has one implementation for
              ModuleConfig casting is safe here. Used only for
              transition purposes !
           */
  @@ -874,7 +876,8 @@
        */
       protected ApplicationConfig initApplicationConfig
           (String prefix, String path) throws ServletException {
  -        /* Since Struts 1.1 only has one implementation for
  +        /* FIXME for Struts 1.2
  +           Since Struts 1.1 only has one implementation for
              ModuleConfig casting is safe here. Used only for
              transition purposes !
           */
  @@ -905,7 +908,9 @@
           String mapping = null;
           try {
               //@todo & FIXME replace with a FactoryMethod
  -            config = new ModuleConfigImpl(prefix);
  +            ModuleConfigFactory factoryObject =
  +                ModuleConfigFactory.createFactory();
  +            config = factoryObject.createModuleConfig(prefix);
   
               // Support for module-wide ActionMapping type override
               mapping = getServletConfig().getInitParameter("mapping");
  
  
  
  1.2       +20 -10    
jakarta-struts/src/share/org/apache/struts/config/ModuleConfig.java
  
  Index: ModuleConfig.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/ModuleConfig.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ModuleConfig.java 6 Nov 2002 04:48:29 -0000       1.1
  +++ ModuleConfig.java 22 Dec 2002 05:31:14 -0000      1.2
  @@ -62,8 +62,8 @@
   
   /**
    * <p>The collection of static configuration information that describes a
  - * Struts-based module.  Multiple modules are identified by a
  - * <em>prefix</em> at the beginning of the context
  + * Struts-based module.  Multiple modules are identified by
  + * a <em>prefix</em> at the beginning of the context
    * relative portion of the request URI.  If no module prefix can be
    * matched, the default configuration (with a prefix equal to a zero-length
    * string) is selected, which is elegantly backwards compatible with the
  @@ -87,6 +87,7 @@
       ControllerConfig getControllerConfig();
       /**
        * The controller configuration object for this module.
  +     * @param cc   The controller configuration object for this module.
        */
   
       void setControllerConfig(ControllerConfig cc);
  @@ -100,6 +101,13 @@
       String getPrefix();
   
       /**
  +     * The prefix of the context-relative portion of the request URI, used to
  +     * select this configuration versus others supported by the controller
  +     * servlet.  A configuration with a prefix of a zero-length String is the
  +     * default configuration for this web module.
  +     */
  +    public void setPrefix(String prefix);
  +    /**
        * The default class name to be used when creating action mapping
        * instances.
        */
  @@ -107,6 +115,8 @@
       /**
        * The default class name to be used when creating action mapping
        * instances.
  +     * @param actionMappingClass  default class name to be used when creating 
action mapping
  +     * instances.
        */
   
       void setActionMappingClass(String actionMappingClass);
  @@ -178,7 +188,7 @@
       void addMessageResourcesConfig(MessageResourcesConfig config);
   
       /**
  -     * Add a newly configured {@link PlugInConfig} instance to the set of
  +     * Add a newly configured {@link org.apache.struts.config.PlugInConfig} 
instance to the set of
        * plug-in Actions for this module.
        *
        * @param plugInConfig The new configuration instance to be added
  @@ -287,7 +297,7 @@
        *
        * @param config ActionConfig instance to be removed
        *
  -     * @exception IllegalStateException if this module configuration
  +     * @exception java.lang.IllegalStateException if this module configuration
        *  has been frozen
        */
       void removeActionConfig(ActionConfig config);
  @@ -297,7 +307,7 @@
        *
        * @param config ActionConfig instance to be removed
        *
  -     * @exception IllegalStateException if this module configuration
  +     * @exception java.lang.IllegalStateException if this module configuration
        *  has been frozen
        */
       void removeExceptionConfig(ExceptionConfig config);
  @@ -307,7 +317,7 @@
        *
        * @param config DataSourceConfig instance to be removed
        *
  -     * @exception IllegalStateException if this module configuration
  +     * @exception java.lang.IllegalStateException if this module configuration
        *  has been frozen
        */
       void removeDataSourceConfig(DataSourceConfig config);
  
  
  
  1.1                  
jakarta-struts/src/share/org/apache/struts/config/ModuleConfigFactory.java
  
  Index: ModuleConfigFactory.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/ModuleConfigFactory.java,v 
1.1 2002/12/22 05:31:14 rleland Exp $
   * $Revision: 1.1 $
   * $Date: 2002/12/22 05:31:14 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Struts", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.struts.config;
  
  import org.apache.struts.util.RequestUtils;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * A factory interface for creating {@link ModuleConfig}s.
   *
   * @author Robert Leland
   * @version $Revision: 1.1 $ $Date: 2002/12/22 05:31:14 $ 
   *
   * @see ModuleConfig
   */
  public abstract class ModuleConfigFactory {
      /**
       * Create and return a newly instansiated {@link ModuleConfig}.
       * This method must be implemented by concrete subclasses.
       *
       * @param prefix Module prefix for Configuration
       */
      public abstract ModuleConfig createModuleConfig(String prefix);
  
  
      // ------------------------------------------------------ Static Properties
      /**
       * The fully qualified class name that is used for
       * <code>ModuleConfigFactory</code> instances.
       * @return class name that is used for
       *   <code>ModuleConfigFactory</code> instances
       */
      public static String getFactoryClass() {
          return (ModuleConfigFactory.factoryClass);
      }
  
      /**
       * Set the fully qualified class name that is used for
       * <code>ModuleConfigFactory</code> instances.
       * @param factoryClass name that is used for
       *   <code>ModuleConfigFactory</code> instances
       */
      public static void setFactoryClass(String factoryClass) {
          ModuleConfigFactory.factoryClass = factoryClass;
          ModuleConfigFactory.clazz = null;
      }
  
      // --------------------------------------------------------- Static Methods
  
  
      /**
       * Create and return a <code>ModuleConfigFactory</code> instance of the
       * appropriate class, which can be used to create customized
       * <code>ModuleConfig</code> instances.  If no such factory can be
       * created, return <code>null</code> instead.
       */
      public static ModuleConfigFactory createFactory() {
  
          // Construct a new instance of the specified factory class
          try {
              if (clazz == null)
                  clazz = RequestUtils.applicationClass(factoryClass);
              ModuleConfigFactory factory =
                  (ModuleConfigFactory) clazz.newInstance();
              return (factory);
          } catch (Throwable t) {
              LOG.error("ModuleConfigFactory.createFactory", t);
              return (null);
          }
  
      }
  
  
      /**
       * The Java class to be used for
       * <code>ModuleConfigFactory</code> instances.
       */
      protected static transient Class clazz = null;
  
      /**
       * Commons Logging instance.
       */
      private static Log LOG = LogFactory.getLog(ModuleConfigFactory.class);
  
  
      /**
       * The fully qualified class name to be used for
       * <code>ModuleConfigFactory</code> instances.
       */
      protected static String factoryClass =
          "org.apache.struts.config.impl.DefaultModuleConfigFactory";
  
  
  }
  
  
  
  1.3       +96 -67    
jakarta-struts/src/share/org/apache/struts/config/impl/ModuleConfigImpl.java
  
  Index: ModuleConfigImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/impl/ModuleConfigImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ModuleConfigImpl.java     8 Dec 2002 02:09:45 -0000       1.2
  +++ ModuleConfigImpl.java     22 Dec 2002 05:31:14 -0000      1.3
  @@ -75,6 +75,7 @@
   import org.apache.struts.config.PlugInConfig;
   import org.apache.struts.config.MessageResourcesConfig;
   import org.apache.struts.config.ForwardConfig;
  +import org.apache.struts.config.ModuleConfigFactory;
   
   
   /**
  @@ -87,7 +88,6 @@
    * previous Struts behavior that only supported one module.</p>
    *
    *
  - * @todo Add factory methods to construct ModuleConfig objects.
    * @author Craig R. McClanahan
    * @version $Revision$ $Date$
    * @since Struts 1.1
  @@ -100,6 +100,16 @@
        * @param prefix Context-relative URI prefix for this module
        */
       public ModuleConfigImpl(String prefix) {
  +        this(null,prefix);
  +    }
  +
  +    /**
  +     * Construct an ModuleConfigImpl object according to the specified
  +     * parameter values.
  +     *
  +     * @param prefix Context-relative URI prefix for this module
  +     */
  +    public ModuleConfigImpl(ModuleConfigFactory factory,String prefix) {
   
           super();
           this.actionConfigs = new HashMap();
  @@ -112,6 +122,7 @@
           this.forwards = new HashMap();
           this.messageResources = new HashMap();
           this.plugIns = new ArrayList();
  +        this.factory = factory;
           this.prefix = prefix;
   
       }
  @@ -143,68 +154,6 @@
       }
   
   
  -    // ----------------------------------------------------- Instance Variables
  -
  -
  -    /**
  -     * The set of action configurations for this module, if any,
  -     * keyed by the <code>path</code> property.
  -     */
  -    protected HashMap actionConfigs = null;
  -    /**
  -     * The set of JDBC data source configurations for this
  -     * module, if any, keyed by the <code>key</code> property.
  -     */
  -    protected HashMap dataSources = null;
  -    /**
  -     * The set of exception handling configurations for this
  -     * module, if any, keyed by the <code>type</code> property.
  -     */
  -    protected HashMap exceptions = null;
  -    /**
  -     * The set of form bean configurations for this module, if any,
  -     * keyed by the <code>name</code> property.
  -     */
  -    protected HashMap formBeans = null;
  -    /**
  -     * The set of global forward configurations for this module, if any,
  -     * keyed by the <code>name</code> property.
  -     */
  -    protected HashMap forwards = null;
  -    /**
  -     * The set of message resources configurations for this
  -     * module, if any, keyed by the <code>key</code> property.
  -     */
  -    protected HashMap messageResources = null;
  -    /**
  -     * The set of configured plug-in Actions for this module,
  -     * if any, in the order they were declared and configured.
  -     */
  -    protected ArrayList plugIns = null;
  -    /**
  -     * Has this module been completely configured yet.  Once this flag
  -     * has been set, any attempt to modify the configuration will return an
  -     * IllegalStateException.
  -     */
  -    protected boolean configured = false;
  -    /**
  -     * The controller configuration object for this module.
  -     */
  -    protected ControllerConfig controllerConfig = null;
  -    /**
  -     * The prefix of the context-relative portion of the request URI, used to
  -     * select this configuration versus others supported by the controller
  -     * servlet.  A configuration with a prefix of a zero-length String is the
  -     * default configuration for this web module.
  -     */
  -    protected String prefix = null;
  -    /**
  -     * The default class name to be used when creating action mapping
  -     * instances.
  -     */
  -    protected String actionMappingClass =
  -            "org.apache.struts.action.ActionMapping";
  -
       // --------------------------------------------------------- Public Methods
   
       /**
  @@ -248,6 +197,20 @@
       }
   
       /**
  +     * The prefix of the context-relative portion of the request URI, used to
  +     * select this configuration versus others supported by the controller
  +     * servlet.  A configuration with a prefix of a zero-length String is the
  +     * default configuration for this web module.
  +     */
  +    public void setPrefix(String prefix) {
  +        if (configured) {
  +            throw new IllegalStateException("Configuration is frozen");
  +        }
  +        this.prefix = prefix;
  +    }
  +
  +
  +    /**
        * The default class name to be used when creating action mapping
        * instances.
        */
  @@ -698,6 +661,72 @@
   
   
       // ------------------------------------------------------ Protected Methods
  +
  +    // ----------------------------------------------------- Instance Variables
  +    // Instance Variables at end to make comparing Interface and implementation 
easier.
  +
  +    /**
  +     * The factory that created this class.
  +     */
  +    protected ModuleConfigFactory factory = null;
  +    /**
  +     * The set of action configurations for this module, if any,
  +     * keyed by the <code>path</code> property.
  +     */
  +    protected HashMap actionConfigs = null;
  +    /**
  +     * The set of JDBC data source configurations for this
  +     * module, if any, keyed by the <code>key</code> property.
  +     */
  +    protected HashMap dataSources = null;
  +    /**
  +     * The set of exception handling configurations for this
  +     * module, if any, keyed by the <code>type</code> property.
  +     */
  +    protected HashMap exceptions = null;
  +    /**
  +     * The set of form bean configurations for this module, if any,
  +     * keyed by the <code>name</code> property.
  +     */
  +    protected HashMap formBeans = null;
  +    /**
  +     * The set of global forward configurations for this module, if any,
  +     * keyed by the <code>name</code> property.
  +     */
  +    protected HashMap forwards = null;
  +    /**
  +     * The set of message resources configurations for this
  +     * module, if any, keyed by the <code>key</code> property.
  +     */
  +    protected HashMap messageResources = null;
  +    /**
  +     * The set of configured plug-in Actions for this module,
  +     * if any, in the order they were declared and configured.
  +     */
  +    protected ArrayList plugIns = null;
  +    /**
  +     * Has this module been completely configured yet.  Once this flag
  +     * has been set, any attempt to modify the configuration will return an
  +     * IllegalStateException.
  +     */
  +    protected boolean configured = false;
  +    /**
  +     * The controller configuration object for this module.
  +     */
  +    protected ControllerConfig controllerConfig = null;
  +    /**
  +     * The prefix of the context-relative portion of the request URI, used to
  +     * select this configuration versus others supported by the controller
  +     * servlet.  A configuration with a prefix of a zero-length String is the
  +     * default configuration for this web module.
  +     */
  +    protected String prefix = null;
  +    /**
  +     * The default class name to be used when creating action mapping
  +     * instances.
  +     */
  +    protected String actionMappingClass =
  +            "org.apache.struts.action.ActionMapping";
   
   
   }
  
  
  
  1.1                  
jakarta-struts/src/share/org/apache/struts/config/impl/DefaultModuleConfigFactory.java
  
  Index: DefaultModuleConfigFactory.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/impl/DefaultModuleConfigFactory.java,v
 1.1 2002/12/22 05:31:14 rleland Exp $
   * $Revision: 1.1 $
   * $Date: 2002/12/22 05:31:14 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Struts", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.struts.config.impl;
  
  import org.apache.struts.config.ModuleConfig;
  import org.apache.struts.config.ModuleConfigFactory;
  
  /**
   * A factory for creating {@link ModuleConfig} instances.
   *
   * @see ModuleConfig
   * @see ModuleConfigFactory
   *
   * @author Robert Leland
   * @version $Id: DefaultModuleConfigFactory.java,v 1.1 2002/12/22 05:31:14 rleland 
Exp $
   */
  public class DefaultModuleConfigFactory extends ModuleConfigFactory {
      // --------------------------------------------------------- Public Methods
  
      /**
       * Create and return a newly instansiated {@link ModuleConfig}.
       * This method must be implemented by concrete subclasses.
       *
       * @param prefix Module prefix for Configuration
       */
      public ModuleConfig createModuleConfig(String prefix) {
  
          return new ModuleConfigImpl(this, prefix);
  
      }
  
  
  
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to