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/15 21:22:20 UTC

cvs commit: jakarta-struts/src/share/org/apache/struts/config FormPropertyConfig.java ConfigRuleSet.java FormBeanConfig.java

craigmcc    02/01/15 12:22:20

  Modified:    conf/share struts-config_1_1.dtd
               src/share/org/apache/struts/config ConfigRuleSet.java
                        FormBeanConfig.java
  Added:       src/share/org/apache/struts/config FormPropertyConfig.java
  Log:
  Tighten up the definitions in the DTD, including using a new entity called
  "AttributeName" that will be used instead of BeanName for attributes that
  do not need to conform to Java variable name requirements.  (Suggested by
  Donnie Hale).
  
  Make the DTD and the Digester rules consistent with respect to when the
  "className" attribute is used to override the configuration bean
  implementation class, and when a nested <set-property> value is supported.
  
  Add support for a new <form-property> element that can be nested inside
  <form-bean>.  This will be used to add support for creating ActionForm beans
  without having to actually create all the classes individually.
  
  Revision  Changes    Path
  1.8       +67 -20    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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- struts-config_1_1.dtd	13 Jan 2002 04:21:18 -0000	1.7
  +++ struts-config_1_1.dtd	15 Jan 2002 20:22:20 -0000	1.8
  @@ -11,13 +11,19 @@
          "-//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.7 2002/01/13 04:21:18 craigmcc Exp $
  +     $Id: struts-config_1_1.dtd,v 1.8 2002/01/15 20:22:20 craigmcc Exp $
   -->
   
   
   <!-- ========== Defined Types ============================================= -->
   
   
  +<!-- An "AttributeName" is the identifier of a page, request, session, or
  +     application scope attribute.
  +-->
  +<!ENTITY % AttributeName "CDATA">
  +
  +
   <!-- A "BeanName" is the identifier of a JavaBean, such as a form bean,
        and also serves as the name of the corresponding scripting variable
        and the name of the JSP attribute under which the bean is accessed.
  @@ -98,6 +104,10 @@
        and made available as a servlet context attribute (i.e. application
        scope bean).  The following attributes are required:
   
  +     className       Implementation subclass of the standard configuration
  +                     bean, if you do not want to use the standard value.
  +                     [org.apache.struts.config.DataSourceConfig]
  +
        key             Servlet context attribute key under which this data
                        source will be stored.  Default is the value specified
                        by string constant Action.DATA_SOURCE_KEY.
  @@ -141,7 +151,8 @@
   -->
   <!ELEMENT data-source (set-property*)>
   <!ATTLIST data-source    id             ID              #IMPLIED>
  -<!ATTLIST data-source    key            %BeanName;      #IMPLIED>
  +<!ATTLIST data-source    className      %ClassName;     #IMPLIED>
  +<!ATTLIST data-source    key            %AttributeName; #IMPLIED>
   <!ATTLIST data-source    type           %ClassName;     #IMPLIED>
   <!-- All of the following attributes are deprecated.  Use a nested          -->
   <!-- set-property element to configure data source properties.              -->
  @@ -171,8 +182,13 @@
        occur during Action delegation and should be handled by the
        ActionServlet.
   
  +    className        Implementation subclass of the standard configuration
  +                     bean, if you do not want to use the standard value.
  +                     [org.apache.struts.config.ExceptionConfig]
  +
       handler          Fully qualified Java class name of the exception handler
                        which should handle this exception.
  +                     [org.apache.struts.action.ExceptionHandler]
   
       key              Message resources key specifying the error message
                        associated with this exception.
  @@ -189,7 +205,8 @@
   -->
   <!ELEMENT exception (icon?, display-name?, description?, set-property*)>
   <!ATTLIST exception      id             ID              #IMPLIED>
  -<!ATTLIST exception      handler        %ClassName;     "org.apache.struts.action.ExceptionHandler">
  +<!ATTLIST exception      className      %ClassName;     #IMPLIED>
  +<!ATTLIST exception      handler        %ClassName;     #IMPLIED>
   <!ATTLIST exception      key            CDATA           #IMPLIED>
   <!ATTLIST exception      path           %RequestPath;   #IMPLIED>
   <!ATTLIST exception      scope          CDATA           #IMPLIED>
  @@ -209,17 +226,16 @@
   -->
   <!ELEMENT form-beans (form-bean*)>
   <!ATTLIST form-beans     id             ID              #IMPLIED>
  -<!ATTLIST form-beans     type           %ClassName;     "org.apache.struts.action.ActionFormBean">
  +<!ATTLIST form-beans     type           %ClassName;     #IMPLIED>
   
   
   <!-- The "form-bean" element describes a particular form bean, which is a
        JavaBean that implements the org.apache.struts.action.ActionForm
        class.  The following attributes are defined:
   
  -     className       Fully qualified Java class name of the ActionFormBean
  -                     implementation class to use.  Defaults to the value
  -                     configured as the "formBean" initialization parameter
  -                     to the Struts controller servlet.
  +     className       Implementation subclass of the standard configuration
  +                     bean, if you do not want to use the standard value.
  +                     [org.apache.struts.config.FormBeanConfig]
   
        name            Unique identifier of this bean, used to reference it
                        in corresponding action mappings.
  @@ -227,13 +243,36 @@
        type            Fully qualified Java class name of the implementation
                        class to be used or generated
   -->
  -<!ELEMENT form-bean (icon?, display-name?, description?, set-property*)>
  +<!ELEMENT form-bean (icon?, display-name?, description?, set-property*, form-property*)>
   <!ATTLIST form-bean      id             ID              #IMPLIED>
   <!ATTLIST form-bean      className      %ClassName;     #IMPLIED>
   <!ATTLIST form-bean      name           %BeanName;      #REQUIRED>
   <!ATTLIST form-bean      type           %ClassName;     #REQUIRED>
   
   
  +<!-- The "form-property" element describes a particular JavaBean property of a
  +     form bean.  It is utilized only when the "type" of the surrounding
  +     "form-bean" element is "org.apache.struts.action.DynaActionForm" (or
  +     a subclass of that class), and thus supports dynamic properties.  The
  +     following attributes are defined:
  +
  +     className       Implementation subclass of the standard configuration
  +                     bean, if you do not want to use the standard value.
  +                     [org.apache.struts.config.FormPropertyConfig]
  +
  +     name            JavaBeans property name of the property being described
  +                     by this element.
  +
  +     type            Fully qualified Java class name of the implementation
  +                     class of this bean property, optionally followed by "[]"
  +                     to indicate that this property is indexed.
  +-->
  +<!ELEMENT form-property  (set-property*)>
  +<!ATTLIST form-property  className      %ClassName;     #IMPLIED>
  +<!ATTLIST form-property  name           %PropName;      #REQUIRED>
  +<!ATTLIST form-property  type           %ClassName;     #REQUIRED>
  +
  +
   <!-- The "global-forwards" element configures the global mappings of logical
        names (used within the application) to mappable resources (identified
        by application-relative URI paths).  A global "forward" with a particular
  @@ -250,17 +289,16 @@
   -->
   <!ELEMENT global-forwards (forward*)>
   <!ATTLIST global-forwards id            ID              #IMPLIED>
  -<!ATTLIST global-forwards type          %ClassName;     "org.apache.struts.action.ActionForward">
  +<!ATTLIST global-forwards type          %ClassName;     #IMPLIED>
   
   
   <!-- The "forward" element describes a mapping of a logical name (used within
        the application) to a mappable resource identified by an
        application-relative URI path.  The following attributes are defined:
   
  -     className       Fully qualified Java class name of the ActionForward
  -                     implementation class to use.  Defaults to the value
  -                     configured as the "forward" initialization parameter
  -                     to the Struts controller servlet.
  +     className       Implementation subclass of the standard configuration
  +                     bean, if you do not want to use the standard value.
  +                     [org.apache.struts.action.ActionForward]
   
       contextRelative  Set to "true" if the path should be considered relative
                        to the entire web application, rather than prefixed with
  @@ -301,7 +339,7 @@
   -->
   <!ELEMENT action-mappings (action*)>
   <!ATTLIST action-mappings id             ID              #IMPLIED>
  -<!ATTLIST action-mappings type           %ClassName;     "org.apache.struts.action.ActionMapping">
  +<!ATTLIST action-mappings type           %ClassName;     #IMPLIED>
   
   
   <!-- The "action" element describes a mapping from a request paths to the
  @@ -313,10 +351,9 @@
                        than the bean's specified "name".  Optional if
                        "name" is specified, else not allowed.
   
  -     className       Fully qualified Java class name of the ActionMapping
  -                     implementation class to use.  Defaults to the value
  -                     configured as the "mapping" initialization parameter
  -                     to the Struts controller servlet.
  +     className       Implementation subclass of the standard configuration
  +                     bean, if you do not want to use the standard value.
  +                     [org.apache.struts.action.ActionMapping]
   
        forward         Application-relative path of the servlet or JSP resource
                        that will process this request, instead of instantiating
  @@ -400,6 +437,10 @@
        bufferSize      The size of the input buffer used when processing
                        file uploads.  [4096]
   
  +     className       Implementation subclass of the standard configuration
  +                     bean, if you do not want to use the standard value.
  +                     [org.apache.struts.config.ControllerConfig]
  +
        contentType     Default content type (and optional character encoding)
                        to be set on each response.  May be overridden by a
                        forwarded-to servlet or JSP page.  [text/html]
  @@ -429,9 +470,10 @@
        tempDir         Temporary working directory to use when processing
                        file uploads.  [Directory provided by servlet container]
   -->
  -<!ELEMENT controller     EMPTY>
  +<!ELEMENT controller     (set-property*)>
   <!ATTLIST controller     id             ID              #IMPLIED>
   <!ATTLIST controller     bufferSize     %Integer;       #IMPLIED>
  +<!ATTLIST controller     className      %ClassName;     #IMPLIED>
   <!ATTLIST controller     contentType    CDATA           #IMPLIED>
   <!ATTLIST controller     debug          %Integer;       #IMPLIED>  
   <!ATTLIST controller     locale         %Boolean;       #IMPLIED>
  @@ -446,6 +488,10 @@
        MessageResources containing the messages for this application.  The
        following attributes are defined:
   
  +     className       Implementation subclass of the standard configuration
  +                     bean, if you do not want to use the standard value.
  +                     [org.apache.struts.config.MessageResourcesConfig]
  +
        factory         Fully qualified Java class name of the
                        MessageResourcesFactory class we should use, if any.
                        By default, this is set to
  @@ -460,6 +506,7 @@
   -->
   <!ELEMENT message-resources EMPTY>
   <!ATTLIST message-resources id          ID              #IMPLIED>
  +<!ATTLIST message-resources className   %ClassName;     #IMPLIED>
   <!ATTLIST message-resources factory     %ClassName;     #IMPLIED>
   <!ATTLIST message-resources null        %Boolean;       #IMPLIED>
   <!ATTLIST message-resources parameter   CDATA           #REQUIRED>
  
  
  
  1.4       +15 -4     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ConfigRuleSet.java	13 Jan 2002 00:25:36 -0000	1.3
  +++ ConfigRuleSet.java	15 Jan 2002 20:22:20 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/ConfigRuleSet.java,v 1.3 2002/01/13 00:25:36 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/01/13 00:25:36 $
  + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/ConfigRuleSet.java,v 1.4 2002/01/15 20:22:20 craigmcc Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/01/15 20:22:20 $
    *
    * ====================================================================
    *
  @@ -72,7 +72,7 @@
    * configuration file (<code>struts-config.xml</code>).</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.3 $ $Date: 2002/01/13 00:25:36 $
  + * @version $Revision: 1.4 $ $Date: 2002/01/15 20:22:20 $
    * @since Struts 1.1
    */
   
  @@ -183,6 +183,17 @@
               ("struts-config/form-beans/form-bean",
                "addFormBeanConfig",
                "org.apache.struts.config.FormBeanConfig");
  +
  +        digester.addObjectCreate
  +            ("struts-config/form-beans/form-bean/form-property",
  +             "org.apache.struts.config.FormPropertyConfig",
  +             "className");
  +        digester.addSetProperties
  +            ("struts-config/form-beans/form-bean/form-property");
  +
  +        digester.addSetProperty
  +            ("struts-config/form-beans/form-bean/form-property/set-property",
  +             "property", "value");
   
           digester.addSetProperty
               ("struts-config/form-beans/form-bean/set-property",
  
  
  
  1.2       +67 -5     jakarta-struts/src/share/org/apache/struts/config/FormBeanConfig.java
  
  Index: FormBeanConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/FormBeanConfig.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FormBeanConfig.java	26 Dec 2001 19:16:25 -0000	1.1
  +++ FormBeanConfig.java	15 Jan 2002 20:22:20 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/FormBeanConfig.java,v 1.1 2001/12/26 19:16:25 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/12/26 19:16:25 $
  + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/FormBeanConfig.java,v 1.2 2002/01/15 20:22:20 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/01/15 20:22:20 $
    *
    * ====================================================================
    *
  @@ -64,6 +64,7 @@
   
   
   import java.io.Serializable;
  +import org.apache.commons.collections.FastHashMap;
   
   
   /**
  @@ -72,11 +73,21 @@
    * configuration file.<p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2001/12/26 19:16:25 $
  + * @version $Revision: 1.2 $ $Date: 2002/01/15 20:22:20 $
    * @since Struts 1.1
    */
   
  -public class FormBeanConfig {
  +public class FormBeanConfig implements Serializable {
  +
  +
  +    // ----------------------------------------------------- Instance Variables
  +
  +
  +    /**
  +     * The set of FormProperty elements defining dynamic form properties for
  +     * this form bean, keyed by property name.
  +     */
  +    protected FastHashMap formProperties = new FastHashMap();
   
   
       // ------------------------------------------------------------- Properties
  @@ -115,6 +126,57 @@
   
   
       // --------------------------------------------------------- Public Methods
  +
  +
  +    /**
  +     * Add a new <code>FormPropertyConfig</code> instance to the set associated
  +     * with this application.
  +     *
  +     * @param config The new configuration instance to be added
  +     */
  +    public void addFormPropertyConfig(FormPropertyConfig config) {
  +
  +        formProperties.put(config.getName(), config);
  +
  +    }
  +
  +
  +    /**
  +     * Return the form property configuration for the specified property
  +     * name, if any; otherwise return <code>null</code>.
  +     *
  +     * @param name Form property name to find a configuration for
  +     */
  +    public FormPropertyConfig findFormPropertyConfig(String name) {
  +
  +        return ((FormPropertyConfig) formProperties.get(name));
  +
  +    }
  +
  +
  +    /**
  +     * Return the form property configurations for this application.  If there
  +     * are none, a zero-length array is returned.
  +     */
  +    public FormPropertyConfig[] findFormPropertyConfigs() {
  +
  +        FormPropertyConfig results[] =
  +            new FormPropertyConfig[formProperties.size()];
  +        return ((FormPropertyConfig[]) formProperties.values().toArray(results));
  +
  +    }
  +
  +
  +    /**
  +     * Remove the specified form property configuration instance.
  +     *
  +     * @param config FormPropertyConfig instance to be removed
  +     */
  +    public void removeFormPropertyConfig(FormPropertyConfig config) {
  +
  +        formProperties.remove(config.getName());
  +
  +    }
   
   
       /**
  
  
  
  1.1                  jakarta-struts/src/share/org/apache/struts/config/FormPropertyConfig.java
  
  Index: FormPropertyConfig.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/config/FormPropertyConfig.java,v 1.1 2002/01/15 20:22:20 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2002/01/15 20:22:20 $
   *
   * ====================================================================
   *
   * 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 apache@apache.org.
   *
   * 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;
  
  
  /**
   * <p>A JavaBean representing the configuration information of a
   * <code>&lt;form-property&gt;</code> element in a Struts application
   * configuration file.<p>
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2002/01/15 20:22:20 $
   * @since Struts 1.1
   */
  
  public class FormPropertyConfig implements Serializable {
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * The JavaBean property name of the property described by this element.
       */
      protected String name = null;
  
      public String getName() {
          return (this.name);
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
  
      /**
       * The fully qualified Java class name of the implementation class
       * of this bean property, optionally followed by <code>[]</code> to
       * indicate that the property is indexed.
       */
      protected String type = null;
  
      public String getType() {
          return (this.type);
      }
  
      public void setType(String type) {
          this.type = type;
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Return a String representation of this object.
       */
      public String toString() {
  
          StringBuffer sb = new StringBuffer("FormPropertyConfig[");
          sb.append("name=");
          sb.append(this.name);
          sb.append(",type=");
          sb.append(this.type);
          sb.append("]");
          return (sb.toString());
  
      }
  
  
  }
  
  
  

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