craigmcc    02/03/22 17:14:04

  Modified:    src/share/org/apache/struts/action Action.java
                        ActionServlet.java
               src/share/org/apache/struts/config ApplicationConfig.java
                        ConfigRuleSet.java
  Added:       src/share/org/apache/struts/config PlugInConfig.java
  Log:
  Revise the way that PlugIn instances are initialized so that the config
  information is maintained separately, and is therefore Serializable.
  
  Revision  Changes    Path
  1.38      +14 -4     jakarta-struts/src/share/org/apache/struts/action/Action.java
  
  Index: Action.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/Action.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- Action.java       22 Mar 2002 23:47:18 -0000      1.37
  +++ Action.java       23 Mar 2002 01:14:04 -0000      1.38
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/Action.java,v 1.37 
2002/03/22 23:47:18 craigmcc Exp $
  - * $Revision: 1.37 $
  - * $Date: 2002/03/22 23:47:18 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/Action.java,v 1.38 
2002/03/23 01:14:04 craigmcc Exp $
  + * $Revision: 1.38 $
  + * $Date: 2002/03/23 01:14:04 $
    *
    * ====================================================================
    *
  @@ -109,7 +109,7 @@
    * by this Action.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.37 $ $Date: 2002/03/22 23:47:18 $
  + * @version $Revision: 1.38 $ $Date: 2002/03/23 01:14:04 $
    */
   
   public class Action {
  @@ -255,6 +255,16 @@
        */
       public static final String MULTIPART_KEY =
           "org.apache.struts.action.mapping.multipartclass";
  +
  +
  +    /**
  +     * <p>The base of the context attributes key under which an array of
  +     * <code>PlugIn</code> instances will be stored.  This
  +     * will be suffixed with the actual application prefix (including the
  +     * leading "/" character) to form the actual attributes key.</p>
  +     */
  +    public static final String PLUG_INS_KEY =
  +        "org.apache.struts.action.PLUG_INS";
   
   
       /**
  
  
  
  1.99      +27 -10    
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.98
  retrieving revision 1.99
  diff -u -r1.98 -r1.99
  --- ActionServlet.java        22 Mar 2002 23:47:18 -0000      1.98
  +++ ActionServlet.java        23 Mar 2002 01:14:04 -0000      1.99
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.98 
2002/03/22 23:47:18 craigmcc Exp $
  - * $Revision: 1.98 $
  - * $Date: 2002/03/22 23:47:18 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.99 
2002/03/23 01:14:04 craigmcc Exp $
  + * $Revision: 1.99 $
  + * $Date: 2002/03/23 01:14:04 $
    *
    * ====================================================================
    *
  @@ -96,6 +96,7 @@
   import org.apache.struts.config.FormBeanConfig;
   import org.apache.struts.config.ForwardConfig;
   import org.apache.struts.config.MessageResourcesConfig;
  +import org.apache.struts.config.PlugInConfig;
   import org.apache.struts.taglib.html.Constants;
   import org.apache.struts.upload.MultipartRequestWrapper;
   import org.apache.struts.util.GenericDataSource;
  @@ -269,7 +270,7 @@
    *
    * @author Craig R. McClanahan
    * @author Ted Husted
  - * @version $Revision: 1.98 $ $Date: 2002/03/22 23:47:18 $
  + * @version $Revision: 1.99 $ $Date: 2002/03/23 01:14:04 $
    */
   
   public class ActionServlet
  @@ -655,10 +656,14 @@
                   } catch (Throwable t) {
                       ;
                   }
  -                PlugIn plugIns[] = config.findPlugIns();
  -                for (int i = 0; i < plugIns.length; i++) {
  -                    int j = plugIns.length - (i + 1);
  -                    plugIns[j].destroy();
  +                PlugIn plugIns[] = (PlugIn[])
  +                    getServletContext().getAttribute
  +                    (Action.PLUG_INS_KEY + config.getPrefix());
  +                if (plugIns != null) {
  +                    for (int i = 0; i < plugIns.length; i++) {
  +                        int j = plugIns.length - (i + 1);
  +                        plugIns[j].destroy();
  +                    }
                   }
               }
           }
  @@ -912,10 +917,22 @@
                   "' plug ins");
           }
   
  -        PlugIn plugIns[] = config.findPlugIns();
  +        PlugInConfig plugInConfigs[] = config.findPlugInConfigs();
  +        PlugIn plugIns[] = new PlugIn[plugInConfigs.length];
           for (int i = 0; i < plugIns.length; i++) {
  -            plugIns[i].init(this, config);
  +            try {
  +                plugIns[i] = (PlugIn)
  +                    RequestUtils.applicationInstance
  +                    (plugInConfigs[i].getClassName());;
  +                plugIns[i].init(this, config);
  +            } catch (Exception e) {
  +                throw new UnavailableException
  +                    (internal.getMessage("plugIn.init",
  +                                         plugInConfigs[i].getClassName()));
  +            }
           }
  +        getServletContext().setAttribute
  +            (Action.PLUG_INS_KEY + config.getPrefix(), plugIns);
   
   
       }
  
  
  
  1.14      +16 -12    
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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ApplicationConfig.java    22 Mar 2002 23:47:18 -0000      1.13
  +++ ApplicationConfig.java    23 Mar 2002 01:14:04 -0000      1.14
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/ApplicationConfig.java,v 
1.13 2002/03/22 23:47:18 craigmcc Exp $
  - * $Revision: 1.13 $
  - * $Date: 2002/03/22 23:47:18 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/ApplicationConfig.java,v 
1.14 2002/03/23 01:14:04 craigmcc Exp $
  + * $Revision: 1.14 $
  + * $Date: 2002/03/23 01:14:04 $
    *
    * ====================================================================
    *
  @@ -68,7 +68,6 @@
   import java.util.HashMap;
   import javax.servlet.ServletException;
   import javax.servlet.UnavailableException;
  -import org.apache.struts.action.PlugIn;
    
   
   
  @@ -82,7 +81,7 @@
    * previous Struts behavior that only supported one application.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.13 $ $Date: 2002/03/22 23:47:18 $
  + * @version $Revision: 1.14 $ $Date: 2002/03/23 01:14:04 $
    * @since Struts 1.1
    */
   
  @@ -341,17 +340,17 @@
   
   
       /**
  -     * Add a newly configured {@link PlugIn} instance to the set of
  +     * Add a newly configured {@link PlugInConfig} instance to the set of
        * plug in modules for this application.
        *
  -     * @param plugIn The new configured plugIn module
  +     * @param plugInConfig The new configuration instance to be added
        */
  -    public void addPlugIn(PlugIn plugIn) {
  +    public void addPlugInConfig(PlugInConfig plugInConfig) {
   
           if (configured) {
               throw new IllegalStateException("Configuration is frozen");
           }
  -        plugIns.add(plugIn);
  +        plugIns.add(plugInConfig);
   
       }
   
  @@ -512,10 +511,10 @@
        * Return the configured plug in modules for this application.  If there
        * are none, a zero-length array is returned.
        */
  -    public PlugIn[] findPlugIns() {
  +    public PlugInConfig[] findPlugInConfigs() {
   
  -        PlugIn results[] = new PlugIn[plugIns.size()];
  -        return ((PlugIn[]) plugIns.toArray(results));
  +        PlugInConfig results[] = new PlugInConfig[plugIns.size()];
  +        return ((PlugInConfig[]) plugIns.toArray(results));
   
       }
   
  @@ -559,6 +558,11 @@
           MessageResourcesConfig[] mrconfigs = findMessageResourcesConfigs();
           for (int i = 0; i < mrconfigs.length; i++) {
               mrconfigs[i].freeze();
  +        }
  +
  +        PlugInConfig[] piconfigs = findPlugInConfigs();
  +        for (int i = 0; i < piconfigs.length; i++) {
  +            piconfigs[i].freeze();
           }
   
       }
  
  
  
  1.11      +29 -10    
jakarta-struts/src/share/org/apache/struts/config/ConfigRuleSet.java
  
  Index: ConfigRuleSet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/ConfigRuleSet.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ConfigRuleSet.java        10 Mar 2002 01:23:30 -0000      1.10
  +++ ConfigRuleSet.java        23 Mar 2002 01:14:04 -0000      1.11
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/ConfigRuleSet.java,v 1.10 
2002/03/10 01:23:30 craigmcc Exp $
  - * $Revision: 1.10 $
  - * $Date: 2002/03/10 01:23:30 $
  + * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/ConfigRuleSet.java,v 1.11 
2002/03/23 01:14:04 craigmcc Exp $
  + * $Revision: 1.11 $
  + * $Date: 2002/03/23 01:14:04 $
    *
    * ====================================================================
    *
  @@ -76,7 +76,7 @@
    * configuration file (<code>struts-config.xml</code>).</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.10 $ $Date: 2002/03/10 01:23:30 $
  + * @version $Revision: 1.11 $ $Date: 2002/03/23 01:14:04 $
    * @since Struts 1.1
    */
   
  @@ -257,18 +257,17 @@
   
           digester.addObjectCreate
               ("struts-config/plug-in",
  -             null, // Class name MUST be specified in the element
  -             "className");
  +             "org.apache.struts.config.PlugInConfig");
           digester.addSetProperties
               ("struts-config/plug-in");
           digester.addSetNext
               ("struts-config/plug-in",
  -             "addPlugIn",
  -             "org.apache.struts.action.PlugIn");
  +             "addPlugInConfig",
  +             "org.apache.struts.config.PlugInConfig");
   
  -        digester.addSetProperty
  +        digester.addRule
               ("struts-config/plug-in/set-property",
  -             "property", "value");
  +             new PlugInSetPropertyRule(digester));
   
       }
   
  @@ -291,6 +290,26 @@
           DataSourceConfig dsc = (DataSourceConfig) digester.peek();
           dsc.addProperty(attributes.getValue("property"),
                           attributes.getValue("value"));
  +    }
  +
  +}
  +
  +
  +/**
  + * Class that records the name and value of a configuration property to be
  + * used in configuring a <code>PlugIn</code> instance when instantiated.
  + */
  +
  +final class PlugInSetPropertyRule extends Rule {
  +
  +    public PlugInSetPropertyRule(Digester digester) {
  +        super(digester);
  +    }
  +
  +    public void begin(Attributes attributes) throws Exception {
  +        PlugInConfig plugInConfig = (PlugInConfig) digester.peek();
  +        plugInConfig.addProperty(attributes.getValue("property"),
  +                                 attributes.getValue("value"));
       }
   
   }
  
  
  
  1.1                  
jakarta-struts/src/share/org/apache/struts/config/PlugInConfig.java
  
  Index: PlugInConfig.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/PlugInConfig.java,v 1.1 
2002/03/23 01:14:04 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2002/03/23 01:14:04 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-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 java.io.Serializable;
  import java.util.HashMap;
  import java.util.Map;
  
  
  /**
   * <p>A JavaBean representing the configuration information of a
   * <code>&lt;plug-in&gt;</code> element in a Struts application
   * configuration file.</p>
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2002/03/23 01:14:04 $
   * @since Struts 1.1
   */
  
  public class PlugInConfig implements Serializable {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * Has this component been completely configured?
       */
      protected boolean configured = false;
  
  
      /**
       * A <code>Map</code> of the name-value pairs that will be used to
       * configure the property values of a <code>PlugIn</code> instance.
       */
      protected Map properties = new HashMap();
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * The fully qualified Java class name of the <code>PlugIn</code>
       * implementation class being configured.
       */
      protected String className = null;
  
      public String getClassName() {
          return (this.className);
      }
  
      public void setClassName(String className) {
          this.className = className;
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Add a new property name and value to the set that will be used to
       * configure the <code>PlugIn</code> instance.
       *
       * @param name Property name
       * @param value Property value
       */
      public void addProperty(String name, String value) {
  
          if (configured) {
              throw new IllegalStateException("Configuration is frozen");
          }
          properties.put(name, value);
  
      }
  
  
      /**
       * Freeze the configuration of this component.
       */
      public void freeze() {
  
          configured = true;
  
      }
  
  
      /**
       * Return the properties that will be used to configure a
       * <code>PlugIn</code> instance.
       */
      public Map getProperties() {
  
          return (properties);
  
      }
  
  
  }
  
  
  

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

Reply via email to