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 2006/01/21 01:21:00 UTC
svn commit: r370938 [9/50] - in /struts: action/trunk/
action/trunk/conf/java/ action/trunk/src/java/org/apache/struts/
action/trunk/src/java/org/apache/struts/action/
action/trunk/src/java/org/apache/struts/chain/
action/trunk/src/java/org/apache/stru...
Modified: struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/SetContentType.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/SetContentType.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/SetContentType.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/SetContentType.java Fri Jan 20 16:19:02 2006
@@ -13,38 +13,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.struts.chain.commands.servlet;
-
-import javax.servlet.http.HttpServletResponse;
-
import org.apache.struts.chain.commands.AbstractSetContentType;
import org.apache.struts.chain.contexts.ActionContext;
import org.apache.struts.chain.contexts.ServletActionContext;
+import javax.servlet.http.HttpServletResponse;
/**
* <p>Check to see if the content type is set, and if so, set it for this
* response.</p>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-06-04 10:58:46 -0400 (Sat, 04 Jun 2005)
+ * $
*/
-
public class SetContentType extends AbstractSetContentType {
-
-
// ------------------------------------------------------- Protected Methods
-
-
protected void setContentType(ActionContext context, String contentType) {
-
ServletActionContext swcontext = (ServletActionContext) context;
HttpServletResponse response = swcontext.getResponse();
response.setContentType(contentType);
-
}
-
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/SetOriginalURI.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/SetOriginalURI.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/SetOriginalURI.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/SetOriginalURI.java Fri Jan 20 16:19:02 2006
@@ -1,51 +1,40 @@
-/*
- * Copyright 2003,2004 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.commands.servlet;
-
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.struts.Globals;
-import org.apache.struts.chain.commands.AbstractSetOriginalURI;
-import org.apache.struts.chain.contexts.ActionContext;
-import org.apache.struts.chain.contexts.ServletActionContext;
-
-
-/**
- * <p>Set the servlet path.</p>
- *
- * @version $Rev: 179995 $ $Date: 2005-06-04 07:58:46 -0700 (Sat, 04 Jun 2005) $
- */
-
-public class SetOriginalURI extends AbstractSetOriginalURI {
-
-
- // ------------------------------------------------------- Protected Methods
-
-
- protected void setOriginalURI(ActionContext context) {
-
- ServletActionContext swcontext = (ServletActionContext) context;
- HttpServletRequest request = swcontext.getRequest();
-
- request.setAttribute(
- Globals.ORIGINAL_URI_KEY, request.getServletPath());
-
- }
-
-
-}
+/*
+ * Copyright 2003,2004 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.commands.servlet;
+
+import org.apache.struts.Globals;
+import org.apache.struts.chain.commands.AbstractSetOriginalURI;
+import org.apache.struts.chain.contexts.ActionContext;
+import org.apache.struts.chain.contexts.ServletActionContext;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * <p>Set the servlet path.</p>
+ *
+ * @version $Rev: 179995 $ $Date: 2005-06-04 07:58:46 -0700 (Sat, 04 Jun 2005)
+ * $
+ */
+public class SetOriginalURI extends AbstractSetOriginalURI {
+ // ------------------------------------------------------- Protected Methods
+ protected void setOriginalURI(ActionContext context) {
+ ServletActionContext swcontext = (ServletActionContext) context;
+ HttpServletRequest request = swcontext.getRequest();
+
+ request.setAttribute(Globals.ORIGINAL_URI_KEY,
+ request.getServletPath());
+ }
+}
Modified: struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/ValidateActionForm.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/ValidateActionForm.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/ValidateActionForm.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/chain/commands/servlet/ValidateActionForm.java Fri Jan 20 16:19:02 2006
@@ -13,10 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.struts.chain.commands.servlet;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionErrors;
@@ -27,56 +25,48 @@
import org.apache.struts.chain.contexts.ServletActionContext;
import org.apache.struts.config.ActionConfig;
-
/**
* <p>Validate the properties of the form bean for this request. If there are
* any validation errors, execute the child commands in our chain; otherwise,
* proceed normally. Also, if any errors are found and the request is a
* multipart request, rollback the <code>MultipartRequestHandler</code>.</p>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-06-04 10:58:46 -0400 (Sat, 04 Jun 2005)
+ * $
*/
-
public class ValidateActionForm extends AbstractValidateActionForm {
-
// ------------------------------------------------------ Instance Variables
-
-
private static final Log log =
- LogFactory.getLog(ValidateActionForm.class);
-
+ LogFactory.getLog(ValidateActionForm.class);
// ------------------------------------------------------- Protected Methods
-
/**
* <p>Call the <code>validate()</code> method of the specified form bean,
* and return the resulting <code>ActionErrors</code> object.</p>
*
- * @param context The context for this request
+ * @param context The context for this request
* @param actionForm The form bean for this request
*/
protected ActionErrors validate(ActionContext context,
ActionConfig actionConfig,
ActionForm actionForm) {
-
ServletActionContext saContext = (ServletActionContext) context;
- ActionErrors errors = (actionForm.validate((ActionMapping) actionConfig,
- saContext.getRequest()));
+ ActionErrors errors =
+ (actionForm.validate((ActionMapping) actionConfig,
+ saContext.getRequest()));
// Special handling for multipart request
- if (errors != null && !errors.isEmpty()) {
+ if ((errors != null) && !errors.isEmpty()) {
if (actionForm.getMultipartRequestHandler() != null) {
if (log.isTraceEnabled()) {
log.trace(" Rolling back multipart request");
}
+
actionForm.getMultipartRequestHandler().rollback();
}
}
return errors;
-
}
-
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/chain/commands/util/ClassUtils.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/chain/commands/util/ClassUtils.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/chain/commands/util/ClassUtils.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/chain/commands/util/ClassUtils.java Fri Jan 20 16:19:02 2006
@@ -13,69 +13,56 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.struts.chain.commands.util;
+
/**
* <p>Utility methods to load application classes and create instances.</p>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-11-12 13:01:44 -0500 (Sat, 12 Nov 2005)
+ * $
*/
-
public final class ClassUtils {
-
-
// ---------------------------------------------------------- Static Methods
-
/**
* <p>Return the <code>Class</code> object for the specified fully
* qualified class name, from this web application's class loader.
*
* @param className Fully qualified class name
- *
- * @exception ClassNotFoundException if the specified class cannot
- * be loaded
+ * @throws ClassNotFoundException if the specified class cannot be loaded
*/
public static Class getApplicationClass(String className)
- throws ClassNotFoundException {
-
+ throws ClassNotFoundException {
if (className == null) {
throw new NullPointerException(
"getApplicationClass called with null className");
}
ClassLoader classLoader =
- Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().getContextClassLoader();
+
if (classLoader == null) {
classLoader = ClassUtils.class.getClassLoader();
}
- return (classLoader.loadClass(className));
+ return (classLoader.loadClass(className));
}
-
/**
* <p>Return a new instance of the specified fully qualified class name,
* after loading the class (if necessary) from this web application's
* class loader.</p>
*
* @param className Fully qualified class name
- *
- * @exception ClassNotFoundException if the specified class cannot
- * be loaded
- * @exception IllegalAccessException if this class is not concrete
- * @exception InstantiationException if this class has no zero-arguments
- * constructor
+ * @throws ClassNotFoundException if the specified class cannot be loaded
+ * @throws IllegalAccessException if this class is not concrete
+ * @throws InstantiationException if this class has no zero-arguments
+ * constructor
*/
public static Object getApplicationInstance(String className)
- throws ClassNotFoundException, IllegalAccessException,
- InstantiationException {
-
+ throws ClassNotFoundException, IllegalAccessException,
+ InstantiationException {
return (getApplicationClass(className).newInstance());
-
}
-
-
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/chain/contexts/ActionContext.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/chain/contexts/ActionContext.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/chain/contexts/ActionContext.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/chain/contexts/ActionContext.java Fri Jan 20 16:19:02 2006
@@ -1,474 +1,427 @@
-/*
- * $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 java.util.Locale;
-import java.util.Map;
-
-import org.apache.commons.chain.Context;
-import org.apache.struts.action.ActionMessages;
-import org.apache.struts.util.MessageResources;
-import org.apache.struts.action.ActionForm;
-import org.apache.struts.config.ActionConfig;
-import org.apache.struts.config.ForwardConfig;
-import org.apache.struts.config.ModuleConfig;
-import org.apache.struts.action.Action;
-
-
-/**
- * <p>An ActionContext represents a view of a commons-chain
- * <code>Context</code> which encapsulates access to request
- * and session-scoped resources and services</p>
- */
-public interface ActionContext extends Context {
-
- public static final String APPLICATION_SCOPE = "application";
-
- public static final String SESSION_SCOPE = "session";
-
- public static final String REQUEST_SCOPE = "request";
-
- // -------------------------------
- // General Application Support
- // -------------------------------
- /**
- * Signal to the instance that it will not be used any more,
- * so that any resources which should be cleaned up can be cleaned up.
- */
- void release();
-
- /**
- * <p>Return a <code>Map</code> of Application scoped values.</p>
- *
- * <p>This is implemented in analogy with the Application scope in
- * the Servlet API, but it seems reasonable to expect that any
- * Struts implementation will have an equivalent concept.</p>
- *
- * <p>The ultimate meaning of "application scope" is an implementation
- * detail left unspecified by Struts.</p>
- * @return A Map of "application scope" attributes.
- */
- Map getApplicationScope();
-
- /**
- * <p>Return a <code>Map</code> of Session scoped values. A session
- * is understood as a sequence of requests made by the same user.</p>
- *
- * <p>This is implemented in analogy with the Session scope in
- * the Servlet API, but it seems reasonable to expect that any
- * Struts implementation will have an equivalent concept.</p>
- *
- * <p>The ultimate meaning of "session scope" is an implementation detail
- * left unspecified by Struts.</p>
- * @return A Map of "session scope" attributes.
- */
- Map getSessionScope();
-
- /**
- * <p>Return a <code>Map</code> of request scoped values. A
- * request is understood as the fundamental motivation for any
- * particular instance of an <code>ActionContext</code>.</p>
- *
- * <p>This is implemented in analogy with the Request Context in
- * the Servlet API, but it seems reasonable to expect that any
- * Struts implementation will have an equivalent concept.</p>
- *
- * <p>The ultimate meaning of "request scope" is an implementation detail
- * left unspecified by Struts.</p>
- * @return a Map of "request scope" attributes.
- */
- Map getRequestScope();
-
- /**
- * Return the Map representing the scope identified by
- * <code>scopeName</code>.
- * Implementations should support at minimum the names associated with
- * the constants
- * <code>APPLICATION_SCOPE</code>, <code>SESSION_SCOPE</code>, and
- * <code>REQUEST_SCOPE</code>, but are permitted to support others
- * as well.
- * @param scopeName A token identifying a scope, including but not
- * limited to <code>APPLICATION_SCOPE</code>, <code>SESSION_SCOPE</code>,
- * <code>REQUEST_SCOPE</code>.
- * @return A Map of attributes for the specified scope.
- */
- Map getScope(String scopeName);
-
- /**
- * <p>Return a <code>Map</code> of parameters submitted by the user
- * as part of this request. The keys to this map will be request
- * parameter names (of type <code>String</code>), and the values will be
- * <code>String[]</code>.</p>
- *
- * <p>This is implemented in analogy with the Request parameters of
- * the Servlet API, but it seems reasonable to expect that any
- * Struts implementation will have an equivalent concept.</p>
- * @return A map of the request parameter attributes
- */
- Map getParameterMap();
-
- // -------------------------------
- // General Struts properties
- // -------------------------------
-
- /**
- * <p>
- * Set the action which has been identified to be executed as part
- * of processing this request.
- * </p>
- * @param action
- */
- void setAction(Action action);
-
- /**
- *<p>
- * Get the action which has been identified to be executed as part
- * of processing this request.
- * </p>
- * @return The action to be executed with this request
- */
- Action getAction();
-
- /**
- * <p>
- * Set the ActionForm instance which will carry any data submitted
- * as part of this request.
- * </p>
- * @param form The ActionForm instance to use with this request
- */
- void setActionForm(ActionForm form);
-
- /**
- * <p>
- * Get the ActionForm instance which will carry any data submitted as
- * part of this request.
- * </p>
- * @return The ActionForm being used with this request
- */
- ActionForm getActionForm();
-
- /**
- * <p>
- * Set the ActionConfig class contains the details
- * for processing this request.
- * </p>
- * @param config The ActionConfig class to use with this request
- */
- void setActionConfig(ActionConfig config);
-
- /**
- * <p>
- * Get the ActionConfig which contains the details for processing this
- * request.
- * @return The ActionConfig class being used with this request
- * </p>
- */
- ActionConfig getActionConfig();
-
- /**
- * <p>
- * Set the ForwardConfig which should be used as the basis of the view
- * segment of the overall processing.
- * This is the primary method of "communication" with
- * the "view" sub-chain.
- * </p>
- * @param forward The ForwardConfig to use with this request
- */
- void setForwardConfig(ForwardConfig forward);
-
- /**
- * <p>
- * Get the ForwardConfig which has been identified as the basis for
- * view-processing.
- * </p>
- * @return The ForwardConfig being used with this request
- */
- ForwardConfig getForwardConfig();
-
- /**
- * <p>
- * Set the include path which should be processed as part of processing
- * this request.
- * </p>
- * @param include The include path to be used with this request
- */
- void setInclude(String include);
-
- /**
- * <p>
- * Get the include path which should be processed as part of processing
- * this request.
- * </p>
- * @return The include path being used with this request
- */
- String getInclude();
-
- /**
- * <p>
- * Set the ModuleConfig which is operative for the current request.
- * </p>
- * @param config The ModuleConfig to be used with this request
- */
- void setModuleConfig(ModuleConfig config);
-
- /**
- * <p>
- * Get the ModuleConfig which is operative for the current request.
- * </p>
- * @return The MooduleConfig being used with this request
- */
- ModuleConfig getModuleConfig();
-
- /**
- * <p>
- * Is the ActionForm for this context valid?
- * This method <em>does not</em> actually perform form validation.
- * It is simply a holder property where processes which perform validation
- * can store the results of the validation for other processes' benefit.
- * </p>
- * @return <code>Boolean.TRUE</code> if the form passed validation;
- * <code>Boolean.FALSE</code> if the form failed validation;
- * null if the form has not yet been validated
- */
- Boolean getFormValid();
-
- /**
- * <p>
- * Store the result of the validation of the Context's ActionForm.
- * </p>
- * @param valid Whether the ActionForm for this request passes validation
- */
- void setFormValid(Boolean valid);
-
- /**
- * <p>
- * Retrieve an exception which may have been caught by some code using
- * this ActionContext, usually by an exception handler.
- * </p>
- * @return Any exception that may have been caught by this ActionContext
- */
- Exception getException();
-
- /**
- * <p>
- * Store an exception in this context for use by other handling code.
- * </p>
- * @param e An exception to be stored for handling by another member
- */
- void setException(Exception e);
-
- // -------------------------------
- // ActionMessage Processing
- // -------------------------------
-
- /**
- * <p>
- * Append the given messages keys to an internal cache,
- * creating the cache if one is not already present.
- * </p>
- * @param messages New ActionMessages to cache
- */
- void addMessages(ActionMessages messages);
-
- /**
- * <p>
- * Append the given errors keys to an internal cache,
- * creating the cache if one is not already present.
- * </p>
- * @param errors New ActionMessages to cache as errors
- */
- void addErrors(ActionMessages errors);
-
- /**
- * <p>
- * Retrieve error messages from an internal cache,
- * creating an empty cache if one is not already present.
- * </p>
- * @return The ActionMessage cache for errors
- */
- ActionMessages getErrors();
-
- /**
- * <p>
- * Retrieve messages from an internal cache,
- * creating an empty cache if one is not already present.
- * </p>
- * @return The ActionMessage cache for errors
- */
- ActionMessages getMessages();
-
- /**
- * <p>
- * Save the given error messages to the internal cache,
- * clearing any previous messages in the cache.
- * </p>
- * <p>
- * If the parameter is null or empty, the internal cache is removed.
- * </p>
- * @param errors ActionMesssages to cache as errors
- */
- void saveErrors(ActionMessages errors);
-
-
- /**
- * <p>
- * Save the given messages to the internal cache,
- * clearing any previous messages in the cache.
- * </p>
- * <p>
- * If the parameter is null or empty, the internal cache is removed.
- * </p>
- * @param messages ActionMesssages to cache
- */
- void saveMessages(ActionMessages messages);
-
-
- /**
- * <p>
- * Save the given messages to the internal cache,
- * clearing any previous messages in the cache,
- * but only for the specified scope.
- * </p>
- * <p>
- * If the parameter is null or empty, the internal cache is removed.
- * </p>
- * @param scope The scope for the internal cache
- * @param messages ActionMesssages to cache
- */
- void saveMessages(String scope, ActionMessages messages);
-
- // -------------------------------
- // Token Processing
- // -------------------------------
-
- /**
- * <p>Generate a new transaction token, to be used for enforcing a single
- * request for a particular transaction.</p>
- *
- */
- String generateToken();
-
- /**
- * <p>
- * Indicate whether a transaction token for this context is valid.
- * </p>
- * <p>
- * A typical implementation will place a transaction token in the
- * session" scope Map and a matching value in the "parameter" Map.
- * If the "session" token does not match the "parameter" attribute,
- * or the session token is missing,
- * then the transactional token is deemed invalid.
- * </p>
- */
- boolean isTokenValid();
-
-
- /**
- * <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>
- * 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 "session" scope for this context,
- * creating new resources, if needed.
- * </p>
- */
- void saveToken();
-
-
- // -------------------------------
- // Cancel Processing
- // -------------------------------
-
- /**
- * <p>
- * Indicate if the "cancel event" state is set for for this context,
- * </p>
- * @see ActionContextBase.CANCEL_KEY
- */
- Boolean getCancelled();
-
- /**
- * <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);
-
-
- // -------------------------------
- // MessageResources Processing
- // -------------------------------
-
- /**
- * <p>Return the default message resources for the current module.</p>
- */
- MessageResources getMessageResources();
-
- /**
- * <p>Set the default message resources for the current module.</p>
- */
- void setMessageResources(MessageResources resources);
-
-
- /**
- * <p>Return the specified message resources for the current module.</p>
- * @param key The key specified in the
- * <code><message-resources></code> element for the
- * requested bundle
- */
- MessageResources getMessageResources(String key);
-
- // -------------------------------
- // Locale Processing
- // -------------------------------
-
- /**
- * <p>Return the user's currently selected Locale.</p>
- */
- Locale getLocale();
-
-
-
- /**
- * <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
- */
- void setLocale(Locale locale);
-}
+/*
+ * $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 org.apache.commons.chain.Context;
+import org.apache.struts.action.Action;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.config.ActionConfig;
+import org.apache.struts.config.ForwardConfig;
+import org.apache.struts.config.ModuleConfig;
+import org.apache.struts.util.MessageResources;
+
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * <p>An ActionContext represents a view of a commons-chain
+ * <code>Context</code> which encapsulates access to request and
+ * session-scoped resources and services</p>
+ */
+public interface ActionContext extends Context {
+ public static final String APPLICATION_SCOPE = "application";
+ public static final String SESSION_SCOPE = "session";
+ public static final String REQUEST_SCOPE = "request";
+
+ // -------------------------------
+ // General Application Support
+ // -------------------------------
+
+ /**
+ * Signal to the instance that it will not be used any more, so that any
+ * resources which should be cleaned up can be cleaned up.
+ */
+ void release();
+
+ /**
+ * <p>Return a <code>Map</code> of Application scoped values.</p>
+ *
+ * <p>This is implemented in analogy with the Application scope in the
+ * Servlet API, but it seems reasonable to expect that any Struts
+ * implementation will have an equivalent concept.</p>
+ *
+ * <p>The ultimate meaning of "application scope" is an implementation
+ * detail left unspecified by Struts.</p>
+ *
+ * @return A Map of "application scope" attributes.
+ */
+ Map getApplicationScope();
+
+ /**
+ * <p>Return a <code>Map</code> of Session scoped values. A session is
+ * understood as a sequence of requests made by the same user.</p>
+ *
+ * <p>This is implemented in analogy with the Session scope in the Servlet
+ * API, but it seems reasonable to expect that any Struts implementation
+ * will have an equivalent concept.</p>
+ *
+ * <p>The ultimate meaning of "session scope" is an implementation detail
+ * left unspecified by Struts.</p>
+ *
+ * @return A Map of "session scope" attributes.
+ */
+ Map getSessionScope();
+
+ /**
+ * <p>Return a <code>Map</code> of request scoped values. A request is
+ * understood as the fundamental motivation for any particular instance of
+ * an <code>ActionContext</code>.</p>
+ *
+ * <p>This is implemented in analogy with the Request Context in the
+ * Servlet API, but it seems reasonable to expect that any Struts
+ * implementation will have an equivalent concept.</p>
+ *
+ * <p>The ultimate meaning of "request scope" is an implementation detail
+ * left unspecified by Struts.</p>
+ *
+ * @return a Map of "request scope" attributes.
+ */
+ Map getRequestScope();
+
+ /**
+ * Return the Map representing the scope identified by
+ * <code>scopeName</code>. Implementations should support at minimum the
+ * names associated with the constants <code>APPLICATION_SCOPE</code>,
+ * <code>SESSION_SCOPE</code>, and <code>REQUEST_SCOPE</code>, but are
+ * permitted to support others as well.
+ *
+ * @param scopeName A token identifying a scope, including but not limited
+ * to <code>APPLICATION_SCOPE</code>, <code>SESSION_SCOPE</code>,
+ * <code>REQUEST_SCOPE</code>.
+ * @return A Map of attributes for the specified scope.
+ */
+ Map getScope(String scopeName);
+
+ /**
+ * <p>Return a <code>Map</code> of parameters submitted by the user as
+ * part of this request. The keys to this map will be request parameter
+ * names (of type <code>String</code>), and the values will be
+ * <code>String[]</code>.</p>
+ *
+ * <p>This is implemented in analogy with the Request parameters of the
+ * Servlet API, but it seems reasonable to expect that any Struts
+ * implementation will have an equivalent concept.</p>
+ *
+ * @return A map of the request parameter attributes
+ */
+ Map getParameterMap();
+
+ // -------------------------------
+ // General Struts properties
+ // -------------------------------
+
+ /**
+ * <p> Set the action which has been identified to be executed as part of
+ * processing this request. </p>
+ *
+ * @param action
+ */
+ void setAction(Action action);
+
+ /**
+ * <p> Get the action which has been identified to be executed as part of
+ * processing this request. </p>
+ *
+ * @return The action to be executed with this request
+ */
+ Action getAction();
+
+ /**
+ * <p> Set the ActionForm instance which will carry any data submitted as
+ * part of this request. </p>
+ *
+ * @param form The ActionForm instance to use with this request
+ */
+ void setActionForm(ActionForm form);
+
+ /**
+ * <p> Get the ActionForm instance which will carry any data submitted as
+ * part of this request. </p>
+ *
+ * @return The ActionForm being used with this request
+ */
+ ActionForm getActionForm();
+
+ /**
+ * <p> Set the ActionConfig class contains the details for processing this
+ * request. </p>
+ *
+ * @param config The ActionConfig class to use with this request
+ */
+ void setActionConfig(ActionConfig config);
+
+ /**
+ * <p> Get the ActionConfig which contains the details for processing this
+ * request.
+ *
+ * @return The ActionConfig class being used with this request </p>
+ */
+ ActionConfig getActionConfig();
+
+ /**
+ * <p> Set the ForwardConfig which should be used as the basis of the view
+ * segment of the overall processing. This is the primary method of
+ * "communication" with the "view" sub-chain. </p>
+ *
+ * @param forward The ForwardConfig to use with this request
+ */
+ void setForwardConfig(ForwardConfig forward);
+
+ /**
+ * <p> Get the ForwardConfig which has been identified as the basis for
+ * view-processing. </p>
+ *
+ * @return The ForwardConfig being used with this request
+ */
+ ForwardConfig getForwardConfig();
+
+ /**
+ * <p> Set the include path which should be processed as part of
+ * processing this request. </p>
+ *
+ * @param include The include path to be used with this request
+ */
+ void setInclude(String include);
+
+ /**
+ * <p> Get the include path which should be processed as part of
+ * processing this request. </p>
+ *
+ * @return The include path being used with this request
+ */
+ String getInclude();
+
+ /**
+ * <p> Set the ModuleConfig which is operative for the current request.
+ * </p>
+ *
+ * @param config The ModuleConfig to be used with this request
+ */
+ void setModuleConfig(ModuleConfig config);
+
+ /**
+ * <p> Get the ModuleConfig which is operative for the current request.
+ * </p>
+ *
+ * @return The MooduleConfig being used with this request
+ */
+ ModuleConfig getModuleConfig();
+
+ /**
+ * <p> Is the ActionForm for this context valid? This method <em>does
+ * not</em> actually perform form validation. It is simply a holder
+ * property where processes which perform validation can store the results
+ * of the validation for other processes' benefit. </p>
+ *
+ * @return <code>Boolean.TRUE</code> if the form passed validation;
+ * <code>Boolean.FALSE</code> if the form failed validation; null
+ * if the form has not yet been validated
+ */
+ Boolean getFormValid();
+
+ /**
+ * <p> Store the result of the validation of the Context's ActionForm.
+ * </p>
+ *
+ * @param valid Whether the ActionForm for this request passes validation
+ */
+ void setFormValid(Boolean valid);
+
+ /**
+ * <p> Retrieve an exception which may have been caught by some code using
+ * this ActionContext, usually by an exception handler. </p>
+ *
+ * @return Any exception that may have been caught by this ActionContext
+ */
+ Exception getException();
+
+ /**
+ * <p> Store an exception in this context for use by other handling code.
+ * </p>
+ *
+ * @param e An exception to be stored for handling by another member
+ */
+ void setException(Exception e);
+
+ // -------------------------------
+ // ActionMessage Processing
+ // -------------------------------
+
+ /**
+ * <p> Append the given messages keys to an internal cache, creating the
+ * cache if one is not already present. </p>
+ *
+ * @param messages New ActionMessages to cache
+ */
+ void addMessages(ActionMessages messages);
+
+ /**
+ * <p> Append the given errors keys to an internal cache, creating the
+ * cache if one is not already present. </p>
+ *
+ * @param errors New ActionMessages to cache as errors
+ */
+ void addErrors(ActionMessages errors);
+
+ /**
+ * <p> Retrieve error messages from an internal cache, creating an empty
+ * cache if one is not already present. </p>
+ *
+ * @return The ActionMessage cache for errors
+ */
+ ActionMessages getErrors();
+
+ /**
+ * <p> Retrieve messages from an internal cache, creating an empty cache
+ * if one is not already present. </p>
+ *
+ * @return The ActionMessage cache for errors
+ */
+ ActionMessages getMessages();
+
+ /**
+ * <p> Save the given error messages to the internal cache, clearing any
+ * previous messages in the cache. </p> <p> If the parameter is null or
+ * empty, the internal cache is removed. </p>
+ *
+ * @param errors ActionMesssages to cache as errors
+ */
+ void saveErrors(ActionMessages errors);
+
+ /**
+ * <p> Save the given messages to the internal cache, clearing any
+ * previous messages in the cache. </p> <p> If the parameter is null or
+ * empty, the internal cache is removed. </p>
+ *
+ * @param messages ActionMesssages to cache
+ */
+ void saveMessages(ActionMessages messages);
+
+ /**
+ * <p> Save the given messages to the internal cache, clearing any
+ * previous messages in the cache, but only for the specified scope. </p>
+ * <p> If the parameter is null or empty, the internal cache is removed.
+ * </p>
+ *
+ * @param scope The scope for the internal cache
+ * @param messages ActionMesssages to cache
+ */
+ void saveMessages(String scope, ActionMessages messages);
+
+ // -------------------------------
+ // Token Processing
+ // -------------------------------
+
+ /**
+ * <p>Generate a new transaction token, to be used for enforcing a single
+ * request for a particular transaction.</p>
+ */
+ String generateToken();
+
+ /**
+ * <p> Indicate whether a transaction token for this context is valid.
+ * </p> <p> A typical implementation will place a transaction token in the
+ * session" scope Map and a matching value in the "parameter" Map. If the
+ * "session" token does not match the "parameter" attribute, or the
+ * session token is missing, then the transactional token is deemed
+ * invalid. </p>
+ */
+ boolean isTokenValid();
+
+ /**
+ * <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> 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 "session" scope for this
+ * context, creating new resources, if needed. </p>
+ */
+ void saveToken();
+
+ // -------------------------------
+ // Cancel Processing
+ // -------------------------------
+
+ /**
+ * <p> Indicate if the "cancel event" state is set for for this context,
+ * </p>
+ *
+ * @see ActionContextBase.CANCEL_KEY
+ */
+ Boolean getCancelled();
+
+ /**
+ * <p> Set the "cancel event" state for this context. </p> <p>
+ *
+ * @param cancelled On true, set the cancel event state to true. On false,
+ * set the cancel event state to false.
+ * @see ActionContextBase.CANCEL_KEY
+ */
+ void setCancelled(Boolean cancelled);
+
+ // -------------------------------
+ // MessageResources Processing
+ // -------------------------------
+
+ /**
+ * <p>Return the default message resources for the current module.</p>
+ */
+ MessageResources getMessageResources();
+
+ /**
+ * <p>Set the default message resources for the current module.</p>
+ */
+ void setMessageResources(MessageResources resources);
+
+ /**
+ * <p>Return the specified message resources for the current module.</p>
+ *
+ * @param key The key specified in the <code><message-resources></code>
+ * element for the requested bundle
+ */
+ MessageResources getMessageResources(String key);
+
+ // -------------------------------
+ // Locale Processing
+ // -------------------------------
+
+ /**
+ * <p>Return the user's currently selected Locale.</p>
+ */
+ Locale getLocale();
+
+ /**
+ * <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
+ */
+ void setLocale(Locale locale);
+}
Modified: struts/action/trunk/src/java/org/apache/struts/chain/contexts/ActionContextBase.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/chain/contexts/ActionContextBase.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/chain/contexts/ActionContextBase.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/chain/contexts/ActionContextBase.java Fri Jan 20 16:19:02 2006
@@ -1,567 +1,554 @@
-/*
- * $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 java.util.Locale;
-import java.util.Map;
-
-import org.apache.commons.chain.Context;
-import org.apache.commons.chain.impl.ContextBase;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.struts.action.Action;
-import org.apache.struts.action.ActionForm;
-import org.apache.struts.action.ActionMessages;
-import org.apache.struts.chain.Constants;
-import org.apache.struts.config.ActionConfig;
-import org.apache.struts.config.FormBeanConfig;
-import org.apache.struts.config.ForwardConfig;
-import org.apache.struts.config.ModuleConfig;
-import org.apache.struts.util.MessageResources;
-import org.apache.struts.util.TokenProcessor;
-
-
-/**
- * <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());
- }
-
- // -------------------------------
- // General Application Support
- // -------------------------------
-
- public void release() {
- this.token = null;
- }
-
- public abstract Map getApplicationScope();
-
- public abstract Map getRequestScope();
-
- public abstract Map getSessionScope();
-
- public Map getScope(String scopeName) {
- if (REQUEST_SCOPE.equals(scopeName)) {
- return this.getRequestScope();
- }
- if (SESSION_SCOPE.equals(scopeName)) {
- return this.getSessionScope();
- }
- if (APPLICATION_SCOPE.equals(scopeName)) {
- return this.getApplicationScope();
- }
- throw new IllegalArgumentException("Invalid scope: " + scopeName);
- }
-
- // -------------------------------
- // General Struts properties
- // -------------------------------
- public void setAction(Action action) {
- this.put(ACTION_KEY, action);
- }
-
- public Action getAction() {
- return (Action) this.get(ACTION_KEY);
- }
-
- public void setActionForm(ActionForm form) {
- this.put(ACTION_FORM_KEY, form);
- }
-
- public ActionForm getActionForm() {
- return (ActionForm) this.get(ACTION_FORM_KEY);
- }
-
- public void setActionConfig(ActionConfig config) {
- this.put(ACTION_CONFIG_KEY, config);
- }
-
- public ActionConfig getActionConfig() {
- return (ActionConfig) this.get(ACTION_CONFIG_KEY);
- }
-
- public void setForwardConfig(ForwardConfig forward) {
- this.put(FORWARD_CONFIG_KEY, forward);
- }
-
- public ForwardConfig getForwardConfig() {
- return (ForwardConfig) this.get(FORWARD_CONFIG_KEY);
- }
-
- public void setInclude(String include) {
- this.put(INCLUDE_KEY, include);
- }
-
- public String getInclude() {
- return (String) this.get(INCLUDE_KEY);
- }
-
- public Boolean getFormValid() {
- return (Boolean) this.get(VALID_KEY);
- }
-
- public void setFormValid(Boolean valid) {
- this.put(VALID_KEY, valid);
- }
-
- public ModuleConfig getModuleConfig() {
- return (ModuleConfig) this.get(MODULE_CONFIG_KEY);
- }
-
- public void setModuleConfig(ModuleConfig config) {
- this.put(MODULE_CONFIG_KEY, config);
- }
-
- public Exception getException() {
- return (Exception) this.get(EXCEPTION_KEY);
- }
-
- public void setException(Exception e) {
- this.put(EXCEPTION_KEY, e);
- }
-
- // -------------------------------
- // ActionMessage Processing
- // -------------------------------
-
- public void addMessages(ActionMessages messages) {
- this.addActionMessages(MESSAGE_ACTION_MESSAGES_KEY, messages);
- }
-
- public void addErrors(ActionMessages errors) {
- this.addActionMessages(ERROR_ACTION_MESSAGES_KEY, errors);
- }
-
- public ActionMessages getErrors() {
- return (ActionMessages) this.get(ERROR_ACTION_MESSAGES_KEY);
- }
-
- public ActionMessages getMessages() {
- return (ActionMessages) this.get(MESSAGE_ACTION_MESSAGES_KEY);
- }
-
- public void saveErrors(ActionMessages errors) {
- this.saveActionMessages(ERROR_ACTION_MESSAGES_KEY, errors);
- }
-
- public void saveMessages(ActionMessages messages) {
- this.saveActionMessages(MESSAGE_ACTION_MESSAGES_KEY, messages);
- }
-
- // 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 (messages == null) {
- // bad programmer! *slap*
- return;
- }
-
- // get any existing messages from the request, or make a new one
- ActionMessages requestMessages = (ActionMessages) this.get(key);
- if (requestMessages == null) {
- requestMessages = new ActionMessages();
- }
- // add incoming messages
- requestMessages.add(messages);
-
- // if still empty, just wipe it out from the request
- this.remove(key);
-
- // save the messages
- this.saveActionMessages(key, requestMessages);
- }
-
- // ISSUE: do we want to add this to the public API?
-
- /**
- * <p>
- * Save the given ActionMessages into the request scope under the given 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) {
- this.saveActionMessages(REQUEST_SCOPE, key, messages);
- }
-
- /**
- * <p>Save the given <code>messages</code> into the map identified by the
- * given <code>scopeId</code> under the given <code>key</code>.</p>
- * @param scopeId
- * @param key
- * @param messages
- */
- public void saveActionMessages(String scopeId,
- String key,
- ActionMessages messages) {
- Map scope = getScope(scopeId);
- if ((messages == null) || messages.isEmpty()) {
- scope.remove(key);
- return;
- }
- scope.put(key, messages);
- }
-
- // ISSUE: Should we deprecate this method, since it is misleading?
- // Do we need it for backward compatibility?
-
- /**
- * <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);
- }
-
-
- // -------------------------------
- // Token Processing
- // -------------------------------
-
- // 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);
- }
-
- public String generateToken() {
- return token.generateToken(getTokenGeneratorId());
-
- }
-
- // 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() {
- return "";
-
- }
-
- public boolean isTokenValid() {
- return this.isTokenValid(false);
- }
-
- public boolean isTokenValid(boolean reset) {
-
- // Retrieve the transaction token from this session, and
- // reset it if requested
- String saved = (String) this.get(TRANSACTION_TOKEN_KEY);
- if (saved == null) {
- return false;
- }
-
- if (reset) {
- this.resetToken();
- }
-
- // Retrieve the transaction token included in this request
- String token = (String) this.get(TOKEN_KEY);
- if (token == null) {
- return false;
- }
-
- return saved.equals(token);
- }
-
- public void resetToken() {
- this.remove(TRANSACTION_TOKEN_KEY);
- }
-
- // -------------------------------
- // Cancel Processing
- // -------------------------------
-
- public Boolean getCancelled() {
- return (Boolean) this.get(CANCEL_KEY);
- }
-
- public void setCancelled(Boolean cancelled) {
- this.put(CANCEL_KEY, cancelled);
- }
-
- // -------------------------------
- // MessageResources Processing
- // -------------------------------
-
- public void setMessageResources(MessageResources messageResources) {
- this.put(MESSAGE_RESOURCES_KEY, messageResources);
- }
-
- public MessageResources getMessageResources() {
- return (MessageResources) this.get(MESSAGE_RESOURCES_KEY);
- }
-
- public MessageResources getMessageResources(String key) {
- return (MessageResources) this.get(key);
- }
-
- // -------------------------------
- // Locale Processing
- // -------------------------------
-
- public void setLocale(Locale locale) {
- this.put(LOCALE_KEY, locale);
- }
-
-
- public Locale getLocale() {
- return (Locale) this.get(LOCALE_KEY);
- }
-
- // -------------------------------
- // Convenience Methods: these are not part of the formal ActionContext API,
- // but are likely to be commonly useful.
- // -------------------------------
-
- /**
- * <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>
- */
- public void setLogger(Log logger) {
- this.logger = logger;
- }
-
- /**
- * <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 this.findOrCreateActionForm(String, String, ModuleConfig)
- */
- 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 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 {
- Map scope = this.getScope(scopeName);
-
- ActionForm instance;
- FormBeanConfig formBeanConfig =
- moduleConfig.findFormBeanConfig(formName);
-
- if (formBeanConfig == null) {
- throw new IllegalArgumentException("No form config found under " +
- formName + " in module " + moduleConfig.getPrefix() );
- }
-
- instance = (ActionForm) scope.get(formName);
- // ISSUE: Can we recycle the existing instance (if any)?
- if (instance != null) {
- 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;
- }
-
-}
+/*
+ * $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 org.apache.commons.chain.Context;
+import org.apache.commons.chain.impl.ContextBase;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts.action.Action;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.chain.Constants;
+import org.apache.struts.config.ActionConfig;
+import org.apache.struts.config.FormBeanConfig;
+import org.apache.struts.config.ForwardConfig;
+import org.apache.struts.config.ModuleConfig;
+import org.apache.struts.util.MessageResources;
+import org.apache.struts.util.TokenProcessor;
+
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * <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());
+ }
+
+ // -------------------------------
+ // General Application Support
+ // -------------------------------
+ public void release() {
+ this.token = null;
+ }
+
+ public abstract Map getApplicationScope();
+
+ public abstract Map getRequestScope();
+
+ public abstract Map getSessionScope();
+
+ public Map getScope(String scopeName) {
+ if (REQUEST_SCOPE.equals(scopeName)) {
+ return this.getRequestScope();
+ }
+
+ if (SESSION_SCOPE.equals(scopeName)) {
+ return this.getSessionScope();
+ }
+
+ if (APPLICATION_SCOPE.equals(scopeName)) {
+ return this.getApplicationScope();
+ }
+
+ throw new IllegalArgumentException("Invalid scope: " + scopeName);
+ }
+
+ // -------------------------------
+ // General Struts properties
+ // -------------------------------
+ public void setAction(Action action) {
+ this.put(ACTION_KEY, action);
+ }
+
+ public Action getAction() {
+ return (Action) this.get(ACTION_KEY);
+ }
+
+ public void setActionForm(ActionForm form) {
+ this.put(ACTION_FORM_KEY, form);
+ }
+
+ public ActionForm getActionForm() {
+ return (ActionForm) this.get(ACTION_FORM_KEY);
+ }
+
+ public void setActionConfig(ActionConfig config) {
+ this.put(ACTION_CONFIG_KEY, config);
+ }
+
+ public ActionConfig getActionConfig() {
+ return (ActionConfig) this.get(ACTION_CONFIG_KEY);
+ }
+
+ public void setForwardConfig(ForwardConfig forward) {
+ this.put(FORWARD_CONFIG_KEY, forward);
+ }
+
+ public ForwardConfig getForwardConfig() {
+ return (ForwardConfig) this.get(FORWARD_CONFIG_KEY);
+ }
+
+ public void setInclude(String include) {
+ this.put(INCLUDE_KEY, include);
+ }
+
+ public String getInclude() {
+ return (String) this.get(INCLUDE_KEY);
+ }
+
+ public Boolean getFormValid() {
+ return (Boolean) this.get(VALID_KEY);
+ }
+
+ public void setFormValid(Boolean valid) {
+ this.put(VALID_KEY, valid);
+ }
+
+ public ModuleConfig getModuleConfig() {
+ return (ModuleConfig) this.get(MODULE_CONFIG_KEY);
+ }
+
+ public void setModuleConfig(ModuleConfig config) {
+ this.put(MODULE_CONFIG_KEY, config);
+ }
+
+ public Exception getException() {
+ return (Exception) this.get(EXCEPTION_KEY);
+ }
+
+ public void setException(Exception e) {
+ this.put(EXCEPTION_KEY, e);
+ }
+
+ // -------------------------------
+ // ActionMessage Processing
+ // -------------------------------
+ public void addMessages(ActionMessages messages) {
+ this.addActionMessages(MESSAGE_ACTION_MESSAGES_KEY, messages);
+ }
+
+ public void addErrors(ActionMessages errors) {
+ this.addActionMessages(ERROR_ACTION_MESSAGES_KEY, errors);
+ }
+
+ public ActionMessages getErrors() {
+ return (ActionMessages) this.get(ERROR_ACTION_MESSAGES_KEY);
+ }
+
+ public ActionMessages getMessages() {
+ return (ActionMessages) this.get(MESSAGE_ACTION_MESSAGES_KEY);
+ }
+
+ public void saveErrors(ActionMessages errors) {
+ this.saveActionMessages(ERROR_ACTION_MESSAGES_KEY, errors);
+ }
+
+ public void saveMessages(ActionMessages messages) {
+ this.saveActionMessages(MESSAGE_ACTION_MESSAGES_KEY, messages);
+ }
+
+ // 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 (messages == null) {
+ // bad programmer! *slap*
+ return;
+ }
+
+ // get any existing messages from the request, or make a new one
+ ActionMessages requestMessages = (ActionMessages) this.get(key);
+
+ if (requestMessages == null) {
+ requestMessages = new ActionMessages();
+ }
+
+ // add incoming messages
+ requestMessages.add(messages);
+
+ // if still empty, just wipe it out from the request
+ this.remove(key);
+
+ // save the messages
+ this.saveActionMessages(key, requestMessages);
+ }
+
+ // ISSUE: do we want to add this to the public API?
+
+ /**
+ * <p> Save the given ActionMessages into the request scope under the
+ * given 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) {
+ this.saveActionMessages(REQUEST_SCOPE, key, messages);
+ }
+
+ /**
+ * <p>Save the given <code>messages</code> into the map identified by the
+ * given <code>scopeId</code> under the given <code>key</code>.</p>
+ *
+ * @param scopeId
+ * @param key
+ * @param messages
+ */
+ public void saveActionMessages(String scopeId, String key,
+ ActionMessages messages) {
+ Map scope = getScope(scopeId);
+
+ if ((messages == null) || messages.isEmpty()) {
+ scope.remove(key);
+
+ return;
+ }
+
+ scope.put(key, messages);
+ }
+
+ // ISSUE: Should we deprecate this method, since it is misleading?
+ // Do we need it for backward compatibility?
+
+ /**
+ * <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);
+ }
+
+ // -------------------------------
+ // Token Processing
+ // -------------------------------
+ // 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);
+ }
+
+ public String generateToken() {
+ return token.generateToken(getTokenGeneratorId());
+ }
+
+ // 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() {
+ return "";
+ }
+
+ public boolean isTokenValid() {
+ return this.isTokenValid(false);
+ }
+
+ public boolean isTokenValid(boolean reset) {
+ // Retrieve the transaction token from this session, and
+ // reset it if requested
+ String saved = (String) this.get(TRANSACTION_TOKEN_KEY);
+
+ if (saved == null) {
+ return false;
+ }
+
+ if (reset) {
+ this.resetToken();
+ }
+
+ // Retrieve the transaction token included in this request
+ String token = (String) this.get(TOKEN_KEY);
+
+ if (token == null) {
+ return false;
+ }
+
+ return saved.equals(token);
+ }
+
+ public void resetToken() {
+ this.remove(TRANSACTION_TOKEN_KEY);
+ }
+
+ // -------------------------------
+ // Cancel Processing
+ // -------------------------------
+ public Boolean getCancelled() {
+ return (Boolean) this.get(CANCEL_KEY);
+ }
+
+ public void setCancelled(Boolean cancelled) {
+ this.put(CANCEL_KEY, cancelled);
+ }
+
+ // -------------------------------
+ // MessageResources Processing
+ // -------------------------------
+ public void setMessageResources(MessageResources messageResources) {
+ this.put(MESSAGE_RESOURCES_KEY, messageResources);
+ }
+
+ public MessageResources getMessageResources() {
+ return (MessageResources) this.get(MESSAGE_RESOURCES_KEY);
+ }
+
+ public MessageResources getMessageResources(String key) {
+ return (MessageResources) this.get(key);
+ }
+
+ // -------------------------------
+ // Locale Processing
+ // -------------------------------
+ public void setLocale(Locale locale) {
+ this.put(LOCALE_KEY, locale);
+ }
+
+ public Locale getLocale() {
+ return (Locale) this.get(LOCALE_KEY);
+ }
+
+ // -------------------------------
+ // Convenience Methods: these are not part of the formal ActionContext API,
+ // but are likely to be commonly useful.
+ // -------------------------------
+
+ /**
+ * <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>
+ */
+ public void setLogger(Log logger) {
+ this.logger = logger;
+ }
+
+ /**
+ * <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 this.findOrCreateActionForm(String, String, ModuleConfig)
+ */
+ 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 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 {
+ Map scope = this.getScope(scopeName);
+
+ ActionForm instance;
+ FormBeanConfig formBeanConfig =
+ moduleConfig.findFormBeanConfig(formName);
+
+ if (formBeanConfig == null) {
+ throw new IllegalArgumentException("No form config found under "
+ + formName + " in module " + moduleConfig.getPrefix());
+ }
+
+ instance = (ActionForm) scope.get(formName);
+
+ // ISSUE: Can we recycle the existing instance (if any)?
+ if (instance != null) {
+ 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/action/trunk/src/java/org/apache/struts/chain/contexts/ContextWrapper.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/chain/contexts/ContextWrapper.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/chain/contexts/ContextWrapper.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/chain/contexts/ContextWrapper.java Fri Jan 20 16:19:02 2006
@@ -1,111 +1,105 @@
-/*
- * $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 org.apache.commons.chain.Context;
-import java.util.Set;
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * <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();
- }
-
- public Set keySet() {
- return this.base.keySet();
- }
-
- public Collection values() {
- return this.base.values();
- }
-
- public void clear() {
- this.base.clear();
- }
-
- public void putAll(Map map) {
- // ISSUE: Should we check this call to putAll?
- this.base.putAll(map);
- }
-
- public Object remove(Object key) {
- return this.base.remove(key);
- }
-
- public Object put(Object key, Object value) {
- // ISSUE: Should we check this call to put?
- return this.base.put(key, value);
- }
-
- public Object get(Object key) {
- return this.base.get(key);
- }
-
- public boolean containsValue(Object o) {
- return this.base.containsValue(o);
- }
-
- public boolean containsKey(Object o) {
- return this.base.containsKey(o);
- }
-
- public boolean isEmpty() {
- return this.base.isEmpty();
- }
-
- public int size() {
- return this.base.size();
- }
-
-}
\ No newline at end of file
+/*
+ * $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 org.apache.commons.chain.Context;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * <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 {
+ private Context base;
+
+ /**
+ * <p> Instantiate object as a composite around the given Context. </p>
+ *
+ * @param context Context instance to wrap
+ */
+ public ContextWrapper(Context context) {
+ this.base = context;
+ }
+
+ /**
+ * 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();
+ }
+
+ public Set keySet() {
+ return this.base.keySet();
+ }
+
+ public Collection values() {
+ return this.base.values();
+ }
+
+ public void clear() {
+ this.base.clear();
+ }
+
+ public void putAll(Map map) {
+ // ISSUE: Should we check this call to putAll?
+ this.base.putAll(map);
+ }
+
+ public Object remove(Object key) {
+ return this.base.remove(key);
+ }
+
+ public Object put(Object key, Object value) {
+ // ISSUE: Should we check this call to put?
+ return this.base.put(key, value);
+ }
+
+ public Object get(Object key) {
+ return this.base.get(key);
+ }
+
+ public boolean containsValue(Object o) {
+ return this.base.containsValue(o);
+ }
+
+ public boolean containsKey(Object o) {
+ return this.base.containsKey(o);
+ }
+
+ public boolean isEmpty() {
+ return this.base.isEmpty();
+ }
+
+ public int size() {
+ return this.base.size();
+ }
+}
Modified: struts/action/trunk/src/java/org/apache/struts/chain/contexts/MockActionContext.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/chain/contexts/MockActionContext.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/chain/contexts/MockActionContext.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/chain/contexts/MockActionContext.java Fri Jan 20 16:19:02 2006
@@ -1,65 +1,67 @@
-/*
- * $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 java.util.HashMap;
-import java.util.Map;
-
-// ISSUE: Are there any useful "assert" type methods we could add to this?
-
-/**
- * <p>
- * Implement <code>ActionContext</code> with empty maps for
- * <code>applicationScope</code>, <code>sessionScope</code>,
- * <code>requestScope</code>,
- * and <code>parameterMap</code> properties.
- * </p>
- */
-public class MockActionContext extends ActionContextBase {
- private Map applicationScope = new HashMap();
- private Map requestScope = new HashMap();
- private Map sessionScope = new HashMap();
- private Map parameterMap = new HashMap();
-
- public Map getApplicationScope() {
- return applicationScope;
- }
- public void setApplicationScope(Map applicationScope) {
- this.applicationScope = applicationScope;
- }
- public Map getParameterMap() {
- return parameterMap;
- }
- public void setParameterMap(Map parameterMap) {
- this.parameterMap = parameterMap;
- }
- public Map getRequestScope() {
- return requestScope;
- }
- public void setRequestScope(Map requestScope) {
- this.requestScope = requestScope;
- }
- public Map getSessionScope() {
- return sessionScope;
- }
- public void setSessionScope(Map sessionScope) {
- this.sessionScope = sessionScope;
- }
-}
-
-
+/*
+ * $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 java.util.HashMap;
+import java.util.Map;
+
+// ISSUE: Are there any useful "assert" type methods we could add to this?
+
+/**
+ * <p> Implement <code>ActionContext</code> with empty maps for
+ * <code>applicationScope</code>, <code>sessionScope</code>,
+ * <code>requestScope</code>, and <code>parameterMap</code> properties. </p>
+ */
+public class MockActionContext extends ActionContextBase {
+ private Map applicationScope = new HashMap();
+ private Map requestScope = new HashMap();
+ private Map sessionScope = new HashMap();
+ private Map parameterMap = new HashMap();
+
+ public Map getApplicationScope() {
+ return applicationScope;
+ }
+
+ public void setApplicationScope(Map applicationScope) {
+ this.applicationScope = applicationScope;
+ }
+
+ public Map getParameterMap() {
+ return parameterMap;
+ }
+
+ public void setParameterMap(Map parameterMap) {
+ this.parameterMap = parameterMap;
+ }
+
+ public Map getRequestScope() {
+ return requestScope;
+ }
+
+ public void setRequestScope(Map requestScope) {
+ this.requestScope = requestScope;
+ }
+
+ public Map getSessionScope() {
+ return sessionScope;
+ }
+
+ public void setSessionScope(Map sessionScope) {
+ this.sessionScope = sessionScope;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org