You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by hu...@apache.org on 2005/09/12 01:55:16 UTC

svn commit: r280217 - in /struts/core/trunk/src/java/org/apache/struts/chain/contexts: ActionContext.java ActionContextBase.java ContextWrapper.java MockActionContext.java ServletActionContext.java WebActionContext.java

Author: husted
Date: Sun Sep 11 16:55:11 2005
New Revision: 280217

URL: http://svn.apache.org/viewcvs?rev=280217&view=rev
Log:
JavaDoc changes only. No significant code changes, only some renaming of non-public members and parameters to simplify documentation.

Modified:
    struts/core/trunk/src/java/org/apache/struts/chain/contexts/ActionContext.java
    struts/core/trunk/src/java/org/apache/struts/chain/contexts/ActionContextBase.java
    struts/core/trunk/src/java/org/apache/struts/chain/contexts/ContextWrapper.java
    struts/core/trunk/src/java/org/apache/struts/chain/contexts/MockActionContext.java
    struts/core/trunk/src/java/org/apache/struts/chain/contexts/ServletActionContext.java
    struts/core/trunk/src/java/org/apache/struts/chain/contexts/WebActionContext.java

Modified: struts/core/trunk/src/java/org/apache/struts/chain/contexts/ActionContext.java
URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/java/org/apache/struts/chain/contexts/ActionContext.java?rev=280217&r1=280216&r2=280217&view=diff
==============================================================================
--- struts/core/trunk/src/java/org/apache/struts/chain/contexts/ActionContext.java (original)
+++ struts/core/trunk/src/java/org/apache/struts/chain/contexts/ActionContext.java Sun Sep 11 16:55:11 2005
@@ -365,7 +365,7 @@
 
     /**
      * <p>
-     * Indicate whether a transaction token for the context is valid.
+     * Indicate whether a transaction token for this context is valid.
      * </p>
      * <p>
      * A typical implementation will place a transaction token in the
@@ -379,63 +379,54 @@
 
 
     /**
-     * <p>Return <code>true</code> if there is a transaction token stored in
-     * the user's current session, and the value submitted as a request
-     * parameter with this action matches it. Returns <code>false</code>.</p>
-     * <ul>
-     * <li>No session associated with this request</li>
-     * <li>No transaction token saved in the session</li>
-     * <li>No transaction token included as a request parameter</li>
-     * <li>The included transaction token value does not match the
-     *     transaction token in the user's session</li>
-     * </ul>
-     *
-     * @param request The servlet request we are processing
-     * @param reset Should we reset the token after checking it?
+     * <p>
+     * Indicate whether a transaction token is stored in the "session"
+     * scope for this context, optionally clearing the token,
+     * so that the next check would return false.
+     * </p>
+     * @param reset On true, clear the transactional token
      */
     boolean isTokenValid(boolean reset);
 
 
     /**
-     * <p>Reset the saved transaction token in the user's session. This
-     * indicates that transactional token checking will not be needed
-     * on the next request that is submitted.</p>
-     *
-     * @param request The servlet request we are processing
+     * <p>
+     * Clear any transactional token stored in the "session" scope for
+     * this context, so that the next check would return false.
+     * </p>
      */
     void resetToken();
 
 
-
     /**
-     * <p>Save a new transaction token in the user's current session, creating
-     * a new session if necessary.</p>
-     *
-     * @param request The servlet request we are processing
+     * <p>
+     * Save a new transaction token in the "session" scope for this context,
+     * creating new resources, if needed.
+     * </p>
      */
     void saveToken();
 
 
-
-
-
     // -------------------------------
     // Cancel Processing
     // -------------------------------
 
     /**
-     * <p>Returns <code>Boolean.TRUE</code> if the current form's cancel button was
-     * pressed. Rather than evaluating any system state,
-     * this simply reflects the value of the <code>cancelled</code> property,
-     * assuming it was set elsewhere by some other process.</p>
-     *
-     * @see org.apache.struts.taglib.html.CancelTag
+     * <p>
+     * Indicate if the "cancel event" state is set for for this context,
+     * </p>
+     * @see ActionContextBase.CANCEL_KEY
      */
     Boolean getCancelled();
 
     /**
-     * <p>Indicate that the current form was detected to be cancelled.</p>
-     * @param cancelled
+     * <p>
+     * Set the "cancel event" state for this context.
+     * </p>
+     * <p>
+     * @see ActionContextBase.CANCEL_KEY
+     * @param cancelled On true, set the cancel event state to true.
+     * On false, set the cancel event state to false.
      */
     void setCancelled(Boolean cancelled);
 
@@ -446,26 +437,20 @@
 
     /**
      * <p>Return the default message resources for the current module.</p>
-     *
      */
     MessageResources getMessageResources();
 
     /**
      * <p>Set the default message resources for the current module.</p>
-     *
-     * @return the default message resources for the current module.
      */
     void setMessageResources(MessageResources resources);
 
 
     /**
      * <p>Return the specified message resources for the current module.</p>
-     *
-     * @param request The servlet request we are processing
      * @param key The key specified in the
      *  <code>&lt;message-resources&gt;</code> element for the
      *  requested bundle
-     *
      */
     MessageResources getMessageResources(String key);
 
@@ -475,7 +460,6 @@
 
     /**
      * <p>Return the user's currently selected Locale.</p>
-     *
      */
     Locale getLocale();
 
@@ -483,7 +467,6 @@
 
     /**
      * <p>Set the user's currently selected <code>Locale</code>.</p>
-     *
      * @param locale The user's selected Locale to be set, or null
      *  to select the server's default Locale
      */

Modified: struts/core/trunk/src/java/org/apache/struts/chain/contexts/ActionContextBase.java
URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/java/org/apache/struts/chain/contexts/ActionContextBase.java?rev=280217&r1=280216&r2=280217&view=diff
==============================================================================
--- struts/core/trunk/src/java/org/apache/struts/chain/contexts/ActionContextBase.java (original)
+++ struts/core/trunk/src/java/org/apache/struts/chain/contexts/ActionContextBase.java Sun Sep 11 16:55:11 2005
@@ -37,56 +37,125 @@
 
 
 /**
- * <p>Title: struts</p>
- * <p>Description: The core of the Struts framework is a flexible control layer based on standard technologies like Java Servlets, JavaBeans, ResourceBundles, and Extensible Markup Language (XML), as well as various Jakarta Commons packages. Struts encourages application architectures based on the Model 2 approach, a variation of the classic Model-View-Controller (MVC) design paradigm. Struts provides its own Controller component and integrates with other technologies to provide the Model and the View. For the Model, Struts can interact with any standard data access technology, including Enterprise Java Beans, JDBC, and Object Relational Bridge. For the View, Struts works well with JavaServer Pages, including JSTL and JSF, as well as Velocity Templates, XSLT, and other presentation systems. The Struts framework provides the invisible underpinnings every professional web application needs to survive. Struts helps you create an extensible development environment for your appli
 cation, based on published standards and proven design patterns.</p>
- * <p>Copyright: Copyright (c) 2000-2004 The Apache Software Foundation - All Rights Reserved.</p>
- * <p>Company: The Apache Software Foundation</p>
- * @version 1.2.5
+ * <p>
+ * Provide an abstract but semi-complete implementation of ActionContext
+ * to serve as the base for concrete implementations.
+ * </p>
+ * <p>
+ * The abstract methods to implement are the accessors for the named states,
+ * <code>getApplicationScope</code>,
+ * <code>getRequestScope</code>, and
+ * <code>getSessionScope</code>.
+ * </p>
  */
-
 public abstract class ActionContextBase extends ContextWrapper implements ActionContext {
 
-
+    /**
+     * @see Constants.ACTION_KEY
+     */
     public static final String ACTION_KEY = Constants.ACTION_KEY;
 
+    /**
+     * @see
+     */
     public static final String ACTION_CONFIG_KEY = Constants.ACTION_CONFIG_KEY;
 
+    /**
+     * @see Constants.ACTION_FORM_KEY
+     */
     public static final String ACTION_FORM_KEY = Constants.ACTION_FORM_KEY;
 
+    /**
+     * @see Constants.FORWARD_CONFIG_KEY
+     */
     public static final String FORWARD_CONFIG_KEY = Constants.FORWARD_CONFIG_KEY;
 
+    /**
+     * @see Constants.MODULE_CONFIG_KEY
+     */
     public static final String MODULE_CONFIG_KEY = Constants.MODULE_CONFIG_KEY;
 
+    /**
+     * @see Constants.EXCEPTION_KEY
+     */
     public static final String EXCEPTION_KEY = Constants.EXCEPTION_KEY;
 
+    /**
+     * <p>
+     * Provide the default context attribute under which to store
+     * the ActionMessage cache for errors.
+     * </p>
+     */
     public static final String ERROR_ACTION_MESSAGES_KEY = "errors";
 
+    /**
+     * <p>
+     * Provide the default context attribute under which to store
+     * the ActionMessage cache.
+     * </p>
+     */
     public static final String MESSAGE_ACTION_MESSAGES_KEY = "messages";
 
+    /**
+     * @see Constants.MESSAGE_RESOURCES_KEY
+     */
     public static final String MESSAGE_RESOURCES_KEY = Constants.MESSAGE_RESOURCES_KEY;
 
+    /**
+     * @see Constants.INCLUDE_KEY
+     */
     public static final String INCLUDE_KEY = Constants.INCLUDE_KEY;
 
+    /**
+     * @see Constants.LOCALE_KEY
+     */
     public static final String LOCALE_KEY = Constants.LOCALE_KEY;
 
+    /**
+     * @see Constants.CANCEL_KEY
+     */
     public static final String CANCEL_KEY = Constants.CANCEL_KEY;
 
+    /**
+     * @see Constants.VALID_KEY
+     */
     public static final String VALID_KEY = Constants.VALID_KEY;
 
+    /**
+     * Provide the default context attribute under which to store
+     * the transaction token key.
+     */
     public static final String TRANSACTION_TOKEN_KEY = "TRANSACTION_TOKEN_KEY";
 
+    /**
+     * Provide the default context attribute under which to store
+     * the token key.
+     */
     public static final String TOKEN_KEY = "TOKEN_KEY";
 
+    /**
+     * Store the TokenProcessor instance for this Context.
+     */
     protected TokenProcessor token = null;
 
+    /**
+     * Store the Log instance for this Context.
+     */
     private Log logger = null;
 
+    /**
+     * Instantiate ActionContextBase, wrapping the given Context.
+     * @param context Context to wrap
+     */
     public ActionContextBase(Context context) {
         super(context);
         token = TokenProcessor.getInstance();
         logger = LogFactory.getLog(this.getClass());
     }
 
+    /**
+     * Instantiate ActionContextBase, wrapping a default ContextBase instance.
+     */
     public ActionContextBase() {
         this(new ContextBase());
     }
@@ -97,7 +166,7 @@
 
     public void release() {
         this.token = null;
-     };
+     }
 
     public abstract Map getApplicationScope();
 
@@ -213,10 +282,18 @@
         this.saveActionMessages(MESSAGE_ACTION_MESSAGES_KEY, messages);
     }
 
-    // do we want to add this to the public API?
-    public void addActionMessages(String key, ActionMessages msgs) {
+    // ISSUE: do we want to add this to the public API?
+
+    /**
+     * <p>
+     * Add the given messages to a cache stored in this Context, under key.
+     * </p>
+     * @param key The attribute name for the message cache
+     * @param messages The ActionMessages to add
+     */
+    public void addActionMessages(String key, ActionMessages messages) {
 
-        if (msgs == null) {
+        if (messages == null) {
             // bad programmer! *slap*
             return;
         }
@@ -227,30 +304,43 @@
             requestMessages = new ActionMessages();
         }
         // add incoming messages
-        requestMessages.add(msgs);
+        requestMessages.add(messages);
 
         // if still empty, just wipe it out from the request
         this.remove(key);
 
-        // Save the messages
+        // save the messages
         this.saveActionMessages(key, requestMessages);
     }
 
-    // do we want to add this to the public API?
-    public void saveActionMessages(String key, ActionMessages msgs) {
-        if ((msgs == null) || msgs.isEmpty()) {
+    // ISSUE: do we want to add this to the public API?
+
+    /**
+     * <p>
+     * Save the given ActionMessages this Context under key,
+     * clearing the attribute if the messages are empty or null.
+     * </p>
+     * @param key The attribute name for the message cache
+     * @param messages The ActionMessages to add
+     */
+    public void saveActionMessages(String key, ActionMessages messages) {
+        if ((messages == null) || messages.isEmpty()) {
             this.remove(key);
             return;
         }
-        this.put(key, msgs);
+        this.put(key, messages);
     }
 
 
+    // ISSUE: Should we deprecate this method, since it is misleading?
+    // Do we need it for backward compatability?
+
     /**
-     * ActionContextBase only has one scope, so this method delegates
-     * to saveMessages(messages).
-     * @param scope
-     * @param messages
+     * <p>
+     * Adapt a legacy form of SaveMessages to the ActionContext API
+     * by storing the ActoinMessages under the default scope.
+     * @param scope The scope for the internal cache
+     * @param messages ActionMesssages to cache
      */
     public void saveMessages(String scope, ActionMessages messages) {
         this.saveMessages(messages);
@@ -261,10 +351,12 @@
     // Token Processing
     // -------------------------------
 
-    /** @todo Is there a problem trying to map this method from Action
-     * to ActionContext when we aren't necessarily sure how token
-     * processing maps into a context with an ill-defined "session"?
-     * There's no getToken() method, but maybe there should be. */
+    // ISSUE: Should there be a getToken method?
+    // Is there a problem trying to map this method from Action
+    // to ActionContext when we aren't necessarily sure how token
+    // processing maps into a context with an ill-defined "session"?
+    // There's no getToken() method, but maybe there should be. *
+
     public void saveToken() {
         String token = this.generateToken();
         this.put(TRANSACTION_TOKEN_KEY, token);
@@ -275,10 +367,12 @@
 
     }
 
+    // ISSUE: The original implementation was based on the HttpSession identifier;
+    // what would be a way to do that without depending on the Servlet API?
+    // REPLY: uuid's
+    // http://java.sun.com/products/jini/2.0/doc/specs/api/net/jini/id/Uuid.html
+
     protected String getTokenGeneratorId() {
-        /** @todo The original implementation was based on the HttpSession identifier;
-         what would be a way to do that without depending on the Servlet API?
-         */
         return "";
 
     }
@@ -316,6 +410,7 @@
     // -------------------------------
     // Cancel Processing
     // -------------------------------
+
     public Boolean getCancelled() {
         return (Boolean) this.get(CANCEL_KEY);
     }
@@ -327,6 +422,7 @@
     // -------------------------------
     // MessageResources Processing
     // -------------------------------
+
     public void setMessageResources(MessageResources messageResources) {
         this.put(MESSAGE_RESOURCES_KEY, messageResources);
     }
@@ -342,6 +438,7 @@
     // -------------------------------
     // Locale Processing
     // -------------------------------
+
     public void setLocale(Locale locale) {
         this.put(LOCALE_KEY, locale);
     }
@@ -355,71 +452,98 @@
     // Convenience Methods: these are not part of the formal ActionContext API,
     // but are likely to be commonly useful.
     // -------------------------------
+
     /**
-     * <p>Return the currently configured commons-logging <code>Log</code> instance.</p>
-     * @return
+     * <p>
+     * Provide the currently configured commons-logging <code>Log</code>
+     * instance.
+     * </p>
+     * @return Log instance for this context
      */
     public Log getLogger() {
         return this.logger;
     }
 
     /**
-     * <p>Set the commons-logging <code>Log</code> instance which should be used to log messages.
-     * This is initialized at instantiation time but may be overridden.  Be advised not to set the value
-     * to null, as <code>ActionContextBase</code> uses the logger for some of its own operations.</p>
+     * <p>
+     * Set the commons-logging <code>Log</code> instance which should be
+     * used to log messages.
+     * This is initialized at instantiation time but may be overridden.
+     * Be advised not to set the value to null,
+     * as <code>ActionContextBase</code> uses the logger for some of its own
+     * operations.
+     * </p>
      */
     public void setLogger(Log logger) {
         this.logger = logger;
     }
 
     /**
-     * Using this <code>ActionContext</code>'s default <code>ModuleConfig</code>, return an existing
-     * <code>ActionForm</code> in the specified scope, or create a new one and add it to the specified scope.
-     * @param formName
-     * @param scopeName
-     * @return
+     * <p>
+     * Using this <code>ActionContext</code>'s default
+     * <code>ModuleConfig</code>, return an existing
+     * <code>ActionForm</code> in the specified scope,
+     * or create a new one and add it to the specified scope.
+     * </p>
+     * @param formName The name attribute of our ActionForm
+     * @param scopeName The scope identier (request, session)
+     * @return The ActionForm for this request
      * @throws IllegalAccessException
      * @throws InstantiationException
-     * @see findOrCreateActionForm(String, String, ModuleConfig)
+     * @see this.findOrCreateActionForm(String, String, ModuleConfig)
      */
-    public ActionForm findOrCreateActionForm(String formName, String scopeName) throws IllegalAccessException, InstantiationException {
-        return this.findOrCreateActionForm(formName, scopeName, this.getModuleConfig());
+    public ActionForm findOrCreateActionForm(String formName,
+                                             String scopeName) throws
+            IllegalAccessException, InstantiationException {
+        return this.findOrCreateActionForm(formName, scopeName,
+                this.getModuleConfig());
     }
 
     /**
-     * <p>In the context of the given <code>ModuleConfig</code> and this <code>ActionContext</code>,
-     * look for an existing <code>ActionForm</code> in the specified scope.  If one is found, return
-     * it; otherwise, create a new instance, add it to that scope, and then return it.</p>
-     * @param formName
-     * @param scopeName
-     * @return
-     * @throws IllegalAccessException
-     * @throws InstantiationException
+     * <p>
+     * In the context of the given <code>ModuleConfig</code>
+     * and this <code>ActionContext</code>,
+     * look for an existing <code>ActionForm</code> in the specified scope.
+     * If one is found, return it;
+     * otherwise, create a new instance, add it to that scope,
+     * and then return it.
+     * </p>
+     * @param formName The name attribute of our ActionForm
+     * @param scopeName The scope identier (request, session)
+     * @return The ActionForm for this request
+     * @throws IllegalAccessException If object cannot be created
+     * @throws InstantiationException If object cannot be created
+     * @throws IllegalArgumentException If form config is missing from module
+     * or scopeName is invalid
      */
-    public ActionForm findOrCreateActionForm(String formName, String scopeName, ModuleConfig moduleConfig) throws IllegalAccessException, InstantiationException {
+    public ActionForm findOrCreateActionForm(String formName, String
+            scopeName, ModuleConfig moduleConfig) throws
+            IllegalAccessException, InstantiationException {
         Map scope = this.getScope(scopeName);
 
-        ActionForm instance = null;
-        FormBeanConfig formBeanConfig = moduleConfig.findFormBeanConfig(formName);
+        ActionForm instance;
+        FormBeanConfig formBeanConfig =
+                moduleConfig.findFormBeanConfig(formName);
 
         if (formBeanConfig == null) {
-            throw new IllegalArgumentException("No form config found under " + formName + " in module " + moduleConfig.getPrefix() );
+            throw new IllegalArgumentException("No form config found under " +
+                    formName + " in module " + moduleConfig.getPrefix() );
         }
 
         instance = (ActionForm) scope.get(formName);
-        // Can we recycle the existing instance (if any)?
+        // ISSUE: Can we recycle the existing instance (if any)?
         if (instance != null) {
-            getLogger().trace("Found an instance in scope " + scopeName + "; test for reusability");
+            getLogger().trace("Found an instance in scope " + scopeName +
+                    "; test for reusability");
             if (formBeanConfig.canReuse(instance)) {
                 return instance;
             }
         }
 
         ActionForm form = formBeanConfig.createActionForm(this);
+        // ISSUE: Should we check this call to put?
         scope.put(formName, form);
         return form;
     }
-
-
 
 }

Modified: struts/core/trunk/src/java/org/apache/struts/chain/contexts/ContextWrapper.java
URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/java/org/apache/struts/chain/contexts/ContextWrapper.java?rev=280217&r1=280216&r2=280217&view=diff
==============================================================================
--- struts/core/trunk/src/java/org/apache/struts/chain/contexts/ContextWrapper.java (original)
+++ struts/core/trunk/src/java/org/apache/struts/chain/contexts/ContextWrapper.java Sun Sep 11 16:55:11 2005
@@ -23,22 +23,41 @@
 import java.util.Map;
 
 /**
- * <code>ContextWrapper</code> is meant as a base class for any Context Implementation which
- * is primarily intended for use in a subchain.  Classes which extend <code>ContextWrapper</code>
- * may implement typesafe property methods which also leave their values in the underlying context.
+ * <p>
+ * Provide a base class for any Context Implementation which is primarily
+ * intended for use in a subchain.
+ * </p>
+ * <p>
+ * Classes which extend <code>ContextWrapper</code> may implement typesafe
+ * property methods which also leave their values in the underlying context.
+ * </p>
  */
 public class ContextWrapper implements Context {
 
+    /**
+     * <p>
+     * Instantiate object as a composite around the given Context.
+     * </p>
+     * @param context Context instance to wrap
+     */
     public ContextWrapper(Context context) {
         this.base = context;
     }
 
     private Context base;
 
+    /**
+     * Provide the underlying Context for this composite.
+     * @return The undelrying Context
+     */
     protected Context getBaseContext() {
         return this.base;
     }
 
+    // -------------------------------
+    // Map interface methods
+    // -------------------------------
+
     public Set entrySet() {
         return this.base.entrySet();
     }
@@ -56,6 +75,7 @@
     }
 
     public void putAll(Map map) {
+        // ISSUE: Should we check this call to putAll?
         this.base.putAll(map);
     }
 
@@ -64,6 +84,7 @@
     }
 
     public Object put(Object key, Object value) {
+        // ISSUE: Should we check this call to put?
         return this.base.put(key, value);
     }
 

Modified: struts/core/trunk/src/java/org/apache/struts/chain/contexts/MockActionContext.java
URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/java/org/apache/struts/chain/contexts/MockActionContext.java?rev=280217&r1=280216&r2=280217&view=diff
==============================================================================
--- struts/core/trunk/src/java/org/apache/struts/chain/contexts/MockActionContext.java (original)
+++ struts/core/trunk/src/java/org/apache/struts/chain/contexts/MockActionContext.java Sun Sep 11 16:55:11 2005
@@ -20,11 +20,15 @@
 import java.util.HashMap;
 import java.util.Map;
 
+//  ISSUE: Are there any useful "assert" type methods we could add to this?
+
 /**
- * Implementation of <code>ActionContext</code> which begins with empty maps for
- * <code>applicationScope</code>, <code>sessionScope</code>, <code>requestScope</code>,
+ * <p>
+ * Implement <code>ActionContext</code> with empty maps for
+ * <code>applicationScope</code>, <code>sessionScope</code>,
+ * <code>requestScope</code>,
  * and <code>parameterMap</code> properties.
- * :TODO Are there any useful "assert" type methods we could add to this?
+ * </p>
  */
 public class MockActionContext extends ActionContextBase {
     private Map applicationScope = new HashMap();

Modified: struts/core/trunk/src/java/org/apache/struts/chain/contexts/ServletActionContext.java
URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/java/org/apache/struts/chain/contexts/ServletActionContext.java?rev=280217&r1=280216&r2=280217&view=diff
==============================================================================
--- struts/core/trunk/src/java/org/apache/struts/chain/contexts/ServletActionContext.java (original)
+++ struts/core/trunk/src/java/org/apache/struts/chain/contexts/ServletActionContext.java Sun Sep 11 16:55:11 2005
@@ -1,196 +1,266 @@
-/*
- * $Id$
- *
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.struts.chain.contexts;
-
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.chain.web.servlet.ServletWebContext;
-import org.apache.struts.Globals;
-import org.apache.struts.action.ActionMessages;
-import org.apache.struts.action.ActionServlet;
-import org.apache.struts.chain.Constants;
-import org.apache.struts.config.ActionConfig;
-import org.apache.struts.util.MessageResources;
-
-/**
- * Implement ActionContext interface while making Servlet API-specific
- * values available.
- */
-public class ServletActionContext extends WebActionContext {
-
-    public ServletActionContext(ServletWebContext context) {
-        super(context);
-    }
-
-    public ServletActionContext(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
-        this(new ServletWebContext(context, request, response));
-    }
-
-    protected ServletWebContext swcontext() {
-        return (ServletWebContext) this.getBaseContext();
-    }
-
-    public void release() {
-        this.swcontext().release();
-        super.release();
-    }
-
-    // -------------------------------
-    // Servlet specific properties
-    // -------------------------------
-    public ServletContext getContext() {
-        return swcontext().getContext();
-    }
-
-    public HttpServletRequest getRequest() {
-        return swcontext().getRequest();
-    }
-
-    public HttpServletResponse getResponse() {
-        return swcontext().getResponse();
-    }
-
-    public ActionServlet getActionServlet() {
-        return (ActionServlet) this.get(Constants.ACTION_SERVLET_KEY);
-    }
-
-    public void setActionServlet(ActionServlet servlet) {
-        this.put(Constants.ACTION_SERVLET_KEY, servlet);
-    }
-
-    // -------------------------------
-    // Servlet specific modifications to base properties.
-    // -------------------------------
-    public void setActionConfig(ActionConfig actionConfig) {
-        super.setActionConfig(actionConfig);
-        this.getRequestScope().put(Globals.MAPPING_KEY, actionConfig);
-    }
-
-    public MessageResources getMessageResources() {
-        return ((MessageResources) getRequest().getAttribute(Globals.MESSAGES_KEY));
-
-    }
-
-    public MessageResources getMessageResources(String key) {
-        // Identify the current module
-        ServletContext context = getActionServlet().getServletContext();
-
-        // Return the requested message resources instance
-        /** @todo This method would probably be better handled by a "Struts"
-         * object which encapsulated the servler (Application) scope. */
-        return (MessageResources) context.getAttribute(key + getModuleConfig().getPrefix());
-
-    }
-
-    public void setMessageResources(MessageResources resources) {
-        super.setMessageResources(resources);
-        this.getRequest().setAttribute(Globals.MESSAGES_KEY, resources);
-    }
-
-    public void setMessageResources(String key, MessageResources resources) {
-        this.getRequest().setAttribute(key + getModuleConfig().getPrefix(), resources);
-    }
-
-    // -------------------------------
-    // ActionMessage Processing
-    // -------------------------------
-    public void saveErrors(ActionMessages errors) {
-
-        // Remove any error messages attribute if none are required
-        if ((errors == null) || errors.isEmpty()) {
-            getRequest().removeAttribute(Globals.ERROR_KEY);
-            return;
-        }
-
-        // Save the error messages we need
-        getRequest().setAttribute(Globals.ERROR_KEY, errors);
-
-    }
-
-    public void saveMessages(ActionMessages messages) {
-
-        if ((messages == null) || messages.isEmpty()) {
-            getRequest().removeAttribute(Globals.MESSAGE_KEY);
-            return;
-        }
-        getRequest().setAttribute(Globals.MESSAGE_KEY, messages);
-    }
-
-    public void addMessages(ActionMessages messages) {
-
+/*
+ * $Id$
+ *
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.struts.chain.contexts;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.chain.web.servlet.ServletWebContext;
+import org.apache.struts.Globals;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.action.ActionServlet;
+import org.apache.struts.chain.Constants;
+import org.apache.struts.config.ActionConfig;
+import org.apache.struts.util.MessageResources;
+
+/**
+ * <p>
+ * Implement ActionContext interface while making Servlet API-specific
+ * values available.
+ * </p>
+ */
+public class ServletActionContext extends WebActionContext {
+
+    /**
+     * <p>
+     * Instantiate this composite by wrapping a ServletWebContext.
+     * </p>
+     * @param context The ServletWebContext to wrap
+     */
+    public ServletActionContext(ServletWebContext context) {
+        super(context);
+    }
+
+    /**
+     * <p>
+     * Instantiate this Context for a given ServletContext,
+     * HttpServletRequest, and HttpServletResponse.
+     * </p>
+     * @param context The instant ServletContext
+     * @param request The instant HttpServletRequest
+     * @param response The instant HttpServletResponse
+     */
+    public ServletActionContext(ServletContext context,
+                                HttpServletRequest request,
+                                HttpServletResponse response) {
+        this(new ServletWebContext(context, request, response));
+    }
+
+    /**
+     * <p>
+     * Provide the ServletWebContext for this composite.
+     * </p>
+     * @return Our ServletWebContext
+     */
+    protected ServletWebContext servletWebContext() {
+        return (ServletWebContext) this.getBaseContext();
+    }
+
+    public void release() {
+        this.servletWebContext().release();
+        super.release();
+    }
+
+    // -------------------------------
+    // Servlet specific properties
+    // -------------------------------
+
+    /**
+     * <p>
+     * Return the ServletContext for this context.
+     * </p>
+     * @return Our ServletContext
+     */
+    public ServletContext getContext() {
+        return servletWebContext().getContext();
+    }
+
+    /**
+     * <p>
+     * Return the HttpServletRequest for this context.
+     * </p>
+     * @return Our HttpServletRequest
+     */
+    public HttpServletRequest getRequest() {
+        return servletWebContext().getRequest();
+    }
+
+    /**
+     * <p>
+     * Return the HttpServletResponse for this context.
+     * </p>
+     * @return Our HttpServletResponse
+     */
+    public HttpServletResponse getResponse() {
+        return servletWebContext().getResponse();
+    }
+
+    /**
+     * <p>
+     * Return the ActionServlet for this context.
+     * </p>
+     * @return Our ActionServlet
+     */
+    public ActionServlet getActionServlet() {
+        return (ActionServlet) this.get(Constants.ACTION_SERVLET_KEY);
+    }
+
+    /**
+     * <p>
+     * Set the ActionServlet instance for this context.
+     * </p>
+     * @param servlet Our ActionServlet instance
+     */
+    public void setActionServlet(ActionServlet servlet) {
+        this.put(Constants.ACTION_SERVLET_KEY, servlet);
+    }
+
+    // -------------------------------
+    // Servlet specific modifications to base properties.
+    // -------------------------------
+
+    public void setActionConfig(ActionConfig actionConfig) {
+        super.setActionConfig(actionConfig);
+        this.getRequestScope().put(Globals.MAPPING_KEY, actionConfig);
+        // ISSUE: Should we check this call to put?
+    }
+
+    public MessageResources getMessageResources() {
+        return ((MessageResources)
+                getRequest().getAttribute(Globals.MESSAGES_KEY));
+
+    }
+
+    // ISSUE: This method would probably be better handled by a "Struts"
+    // object which encapsulated the servler (Application) scope.
+
+    public MessageResources getMessageResources(String key) {
+        // Identify the current module
+        ServletContext context = getActionServlet().getServletContext();
+        // Return the requested message resources instance
+        return (MessageResources) context.getAttribute(key +
+                getModuleConfig().getPrefix());
+    }
+
+    public void setMessageResources(MessageResources resources) {
+        super.setMessageResources(resources);
+        this.getRequest().setAttribute(Globals.MESSAGES_KEY, resources);
+    }
+
+    /**
+     * <p>
+     * Store the mesasage resources for the current module under the given
+     * request attribute key.
+     * </p>
+     * @param key Request attribute key
+     * @param resources Message resouces to store
+     */
+    public void setMessageResources(String key, MessageResources resources) {
+        this.getRequest().setAttribute(key + getModuleConfig().getPrefix(),
+                resources);
+    }
+
+    // -------------------------------
+    // ActionMessage Processing
+    // -------------------------------
+
+    public void saveErrors(ActionMessages errors) {
+        // Remove any error messages attribute if none are required
+        if ((errors == null) || errors.isEmpty()) {
+            getRequest().removeAttribute(Globals.ERROR_KEY);
+            return;
+        }
+        // Save the error messages we need
+        getRequest().setAttribute(Globals.ERROR_KEY, errors);
+
+    }
+
+    public void saveMessages(ActionMessages messages) {
+
+        if ((messages == null) || messages.isEmpty()) {
+            getRequest().removeAttribute(Globals.MESSAGE_KEY);
+            return;
+        }
+        getRequest().setAttribute(Globals.MESSAGE_KEY, messages);
+    }
+
+    public void addMessages(ActionMessages messages) {
+
             if (messages == null) {
                 return;
-            }
-
-            ActionMessages requestMessages = getMessages();
-            if (requestMessages == null) {
-                    requestMessages = new ActionMessages();
-            }
-            requestMessages.add(messages);
-            saveMessages(requestMessages);
-    }
-
-
-    public void addErrors(ActionMessages errors) {
-
+            }
+
+            ActionMessages requestMessages = getMessages();
+            if (requestMessages == null) {
+                    requestMessages = new ActionMessages();
+            }
+            requestMessages.add(messages);
+            saveMessages(requestMessages);
+    }
+
+
+    public void addErrors(ActionMessages errors) {
+
             if (errors == null) {
                 return;
-            }
-
-            ActionMessages requestErrors = getErrors();
-            if (requestErrors == null) {
-                    requestErrors = new ActionMessages();
-            }
-            requestErrors.add(errors);
-            saveErrors(requestErrors);
-    }
-
-    public ActionMessages getErrors() {
-        return (ActionMessages) this.getRequest().getAttribute(Globals.ERROR_KEY);
-    }
-
-    public ActionMessages getMessages() {
-        return (ActionMessages) this.getRequest().getAttribute(Globals.MESSAGE_KEY);
-    }
-
-    // -------------------------------
-    // Token Processing
-    // Implementing the servlet-aware versions by using the TokenProcessor class
-    // directly should ensure greater compatibility.
-    // -------------------------------
-
-    public void saveToken() {
-        token.saveToken(getRequest());
-    }
-
-    public String generateToken() {
-        return token.generateToken(getRequest());
-
-    }
-
-    public boolean isTokenValid(boolean reset) {
-        return token.isTokenValid(getRequest(), reset);
-    }
-
-    public void resetToken() {
-        token.resetToken(getRequest());
-    }
-
+            }
+
+            ActionMessages requestErrors = getErrors();
+            if (requestErrors == null) {
+                    requestErrors = new ActionMessages();
+            }
+            requestErrors.add(errors);
+            saveErrors(requestErrors);
+    }
+
+    public ActionMessages getErrors() {
+        return (ActionMessages)
+                this.getRequest().getAttribute(Globals.ERROR_KEY);
+    }
+
+    public ActionMessages getMessages() {
+        return (ActionMessages)
+                this.getRequest().getAttribute(Globals.MESSAGE_KEY);
+    }
+
+    // -------------------------------
+    // Token Processing
+    // Implementing the servlet-aware versions by using the
+    // TokenProcessor class
+    // directly should ensure greater compatibility.
+    // -------------------------------
+
+    public void saveToken() {
+        token.saveToken(getRequest());
+    }
+
+    public String generateToken() {
+        return token.generateToken(getRequest());
+
+    }
+
+    public boolean isTokenValid(boolean reset) {
+        return token.isTokenValid(getRequest(), reset);
+    }
+
+    public void resetToken() {
+        token.resetToken(getRequest());
+    }
+
 }

Modified: struts/core/trunk/src/java/org/apache/struts/chain/contexts/WebActionContext.java
URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/java/org/apache/struts/chain/contexts/WebActionContext.java?rev=280217&r1=280216&r2=280217&view=diff
==============================================================================
--- struts/core/trunk/src/java/org/apache/struts/chain/contexts/WebActionContext.java (original)
+++ struts/core/trunk/src/java/org/apache/struts/chain/contexts/WebActionContext.java Sun Sep 11 16:55:11 2005
@@ -25,16 +25,27 @@
 import org.apache.struts.config.ModuleConfig;
 
 /**
- * Subclass of ActionContextBase which is understood to be wrapping
+ * <p>
+ * Provide a Subclass of ActionContextBase which is understood to be wrapping
  * an instance of <code>org.apache.commons.chain.web.WebContext</code>.
+ * </p>
  */
 public class WebActionContext extends ActionContextBase {
 
+    /**
+     * Instantiate this composite by wrapping an instance of WebContext.
+     * @param context The WebContext to wrap
+     */
     public WebActionContext(WebContext context) {
         super(context);
     }
 
-    protected WebContext wcontext() {
+
+    /**
+     * Provide the wrapped WebContext for this composite.
+     * @return The wrapped WebContext
+     */
+    protected WebContext webContext() {
         return (WebContext) this.getBaseContext();
     }
 
@@ -42,70 +53,98 @@
         super.release();
     }
 
-    public Map getApplicationScope() {
-        return wcontext().getApplicationScope();
-    }
+    // -------------------------------
+    // WebContext property wrappers
+    // -------------------------------
 
+    /**
+     * <p>
+     * Return an immutable Map that maps header names to the first
+     * (or only) header value (as a String).
+     * </p>
+     * @return  A immutable Map of web request header names
+     */
     public Map getHeader() {
-        return wcontext().getHeader();
+        return webContext().getHeader();
     }
 
+    /**
+     * <p>
+     * Return an immutable Map that maps header names to the set of all
+     * values specified in the request (as a String array).
+     * Header names must be matched in a case-insensitive manner.
+     * </p>
+      * @return An immutable Map of web request header values
+     */
     public Map getHeaderValues() {
-        return wcontext().getHeaderValues();
+        return webContext().getHeaderValues();
     }
 
+    /***
+     * <p>
+     * Return an immutable Map that maps context application initialization
+     * parameters to their values.
+     * </p>
+     * @return An immutable Map of web context initialization parameters
+     */
     public Map getInitParam() {
-        return wcontext().getInitParam();
+        return webContext().getInitParam();
     }
 
     /**
-     * Return a map whose keys are <code>String</code> request parameter names and whose values
-     * are <code>String</code> values.  For parameters which were submitted with more than one value,
-     * only one value will be returned, as if one called <code>ServletRequest.getParameter(String)</code>
-     * @return
+     * <p>
+     * Return a map whose keys are <code>String</code> request parameter names
+     * and whose values are <code>String</code> values.
+     * </p>
+     * <p>
+     * For parameters which were submitted with more than one value,
+     * only one value will be returned, as if one called
+     * <code>ServletRequest.getParameter(String)</code>
+     * </p>
+     * @return A map of web request parameters
      */
     public Map getParam() {
-        return wcontext().getParam();
+        return webContext().getParam();
     }
 
     /**
-     * Return a map whose keys are <code>String</code> request parameter names and whose values
-     * are <code>String[]</code> values.
-     * @return
+     * <p>
+     * Return a map whose keys are <code>String</code> request parameter names
+     * and whose values are <code>String[]</code> values.
+     * </p>
+     * @return A map of web request parameter values (as an array)
      */
     public Map getParamValues() {
-        return wcontext().getParamValues();
+        return webContext().getParamValues();
+    }
+
+    public Map getApplicationScope() {
+        return webContext().getApplicationScope();
     }
 
     public Map getRequestScope() {
-        return wcontext().getRequestScope();
+        return webContext().getRequestScope();
     }
 
-    /**
-     * <p>Return the map returned by our nested <code>WebContext</code>'s
-     * <code>getParamValues()</code> method. </p>
-     */
     public Map getParameterMap() {
         return getParamValues();
     }
 
     public Map getSessionScope() {
-        return wcontext().getSessionScope();
+        return webContext().getSessionScope();
     }
 
-    /*
-     * @todo AbstractSelectModule set the precedent of doing this at the "web context" level
-     * instead of the ServletWebContext level.  Consider whether that's how we want to do it
-     * universally for other manipulations of the RequestScope or not...
-     */
+    // ISSUE: AbstractSelectModule set the precedent of doing this at the
+    // "web context" level instead of the ServletWebContext level.
+    // Consider whether that's how we want to do it universally for other
+    // manipulations of the RequestScope or not...
+
     public void setModuleConfig(ModuleConfig moduleConfig) {
         super.setModuleConfig(moduleConfig);
         this.getRequestScope().put(Globals.MODULE_KEY, moduleConfig);
     }
 
-    /*
-     *  (non-Javadoc)
-     * Should thi
+    /**
      * @see org.apache.struts.chain.contexts.ActionContext#getModuleConfig()
      */
     public ModuleConfig getModuleConfig() {
@@ -116,11 +155,10 @@
         return mc;
     }
 
-    /*
-     * @todo AbstractSelectModule set the precedent of doing this at the "web context" level
-     * instead of the ServletWebContext level.  Consider whether that's how we want to do it
-     * universally for other manipulations of the RequestScope or not...
-     */
+    // ISSUE:  AbstractSelectModule set the precedent of doing this at the "web context" level
+    // instead of the ServletWebContext level.  Consider whether that's how we want to do it
+    // universally for other manipulations of the RequestScope or not...
+
     public void setCancelled(Boolean cancelled) {
         super.setCancelled(cancelled);
         // historic semantics of "isCancelled" are to consider any non-null
@@ -133,12 +171,11 @@
 
     }
 
-
     public Boolean getCancelled() {
-        Boolean c = super.getCancelled();
-        if (c == null) {
-            c = (Boolean) this.getRequestScope().get(Globals.CANCEL_KEY);
+        Boolean cancelled = super.getCancelled();
+        if (cancelled == null) {
+            cancelled = (Boolean) this.getRequestScope().get(Globals.CANCEL_KEY);
         }
-        return c;
+        return cancelled;
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org