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 [13/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/str...
Modified: struts/action/trunk/src/java/org/apache/struts/config/impl/DefaultModuleConfigFactory.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/config/impl/DefaultModuleConfigFactory.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/config/impl/DefaultModuleConfigFactory.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/config/impl/DefaultModuleConfigFactory.java Fri Jan 20 16:19:02 2006
@@ -15,37 +15,32 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.struts.config.impl;
-import java.io.Serializable;
-
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.config.ModuleConfigFactory;
+import java.io.Serializable;
+
/**
* A factory for creating {@link ModuleConfig} instances.
*
+ * @version $Rev$ $Date: 2005-05-07 12:45:39 -0400 (Sat, 07 May 2005)
+ * $
* @see ModuleConfig
* @see ModuleConfigFactory
- *
- * @version $Rev$ $Date$
*/
-public class DefaultModuleConfigFactory extends ModuleConfigFactory implements Serializable {
+public class DefaultModuleConfigFactory extends ModuleConfigFactory
+ implements Serializable {
// --------------------------------------------------------- Public Methods
/**
- * Create and return a newly instansiated {@link ModuleConfig}.
- * This method must be implemented by concrete subclasses.
+ * Create and return a newly instansiated {@link ModuleConfig}. This
+ * method must be implemented by concrete subclasses.
*
* @param prefix Module prefix for Configuration
*/
public ModuleConfig createModuleConfig(String prefix) {
-
return new ModuleConfigImpl(prefix);
-
}
-
-
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/config/impl/ModuleConfigImpl.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/config/impl/ModuleConfigImpl.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/config/impl/ModuleConfigImpl.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/config/impl/ModuleConfigImpl.java Fri Jan 20 16:19:02 2006
@@ -15,17 +15,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.struts.config.impl;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.HashMap;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
import org.apache.struts.config.ActionConfig;
import org.apache.struts.config.ActionConfigMatcher;
import org.apache.struts.config.BaseConfig;
@@ -37,19 +30,114 @@
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.config.PlugInConfig;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
/**
* <p>The collection of static configuration information that describes a
- * Struts-based module. Multiple modules are identified by
- * a <em>prefix</em> at the beginning of the context
- * relative portion of the request URI. If no module prefix can be
- * matched, the default configuration (with a prefix equal to a zero-length
- * string) is selected, which is elegantly backwards compatible with the
- * previous Struts behavior that only supported one module.</p>
+ * Struts-based module. Multiple modules are identified by a <em>prefix</em>
+ * at the beginning of the context relative portion of the request URI. If no
+ * module prefix can be matched, the default configuration (with a prefix
+ * equal to a zero-length string) is selected, which is elegantly backwards
+ * compatible with the previous Struts behavior that only supported one
+ * module.</p>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-12-31 03:57:16 -0500 (Sat, 31 Dec 2005)
+ * $
* @since Struts 1.1
*/
-public class ModuleConfigImpl extends BaseConfig implements Serializable, ModuleConfig {
+public class ModuleConfigImpl extends BaseConfig implements Serializable,
+ ModuleConfig {
+ /**
+ * Commons Logging instance.
+ */
+ protected static Log log = LogFactory.getLog(ModuleConfigImpl.class);
+
+ // ----------------------------------------------------- Instance Variables
+ // Instance Variables at end to make comparing Interface and implementation easier.
+
+ /**
+ * The set of action configurations for this module, if any, keyed by the
+ * <code>path</code> property.
+ */
+ protected HashMap actionConfigs = null;
+
+ /**
+ * The set of action configurations for this module, if any, listed in the
+ * order in which they are added.
+ */
+ protected List actionConfigList = null;
+
+ /**
+ * The set of exception handling configurations for this module, if any,
+ * keyed by the <code>type</code> property.
+ */
+ protected HashMap exceptions = null;
+
+ /**
+ * The set of form bean configurations for this module, if any, keyed by
+ * the <code>name</code> property.
+ */
+ protected HashMap formBeans = null;
+
+ /**
+ * The set of global forward configurations for this module, if any, keyed
+ * by the <code>name</code> property.
+ */
+ protected HashMap forwards = null;
+
+ /**
+ * The set of message resources configurations for this module, if any,
+ * keyed by the <code>key</code> property.
+ */
+ protected HashMap messageResources = null;
+
+ /**
+ * The set of configured plug-in Actions for this module, if any, in the
+ * order they were declared and configured.
+ */
+ protected ArrayList plugIns = null;
+
+ /**
+ * The controller configuration object for this module.
+ */
+ protected ControllerConfig controllerConfig = null;
+
+ /**
+ * The prefix of the context-relative portion of the request URI, used to
+ * select this configuration versus others supported by the controller
+ * servlet. A configuration with a prefix of a zero-length String is the
+ * default configuration for this web module.
+ */
+ protected String prefix = null;
+
+ /**
+ * The default class name to be used when creating action form bean
+ * instances.
+ */
+ protected String actionFormBeanClass =
+ "org.apache.struts.action.ActionFormBean";
+
+ /**
+ * The default class name to be used when creating action mapping
+ * instances.
+ */
+ protected String actionMappingClass =
+ "org.apache.struts.action.ActionMapping";
+
+ /**
+ * The default class name to be used when creating action forward
+ * instances.
+ */
+ protected String actionForwardClass =
+ "org.apache.struts.action.ActionForward";
+
+ /**
+ * Matches action config paths against compiled wildcard patterns
+ */
+ protected ActionConfigMatcher matcher = null;
/**
* Constructor for ModuleConfigImpl. Assumes default configuration.
@@ -83,12 +171,11 @@
this.plugIns = new ArrayList();
}
-
// --------------------------------------------------------- Public Methods
/**
- * Has this module been completely configured yet. Once this flag
- * has been set, any attempt to modify the configuration will return an
+ * Has this module been completely configured yet. Once this flag has
+ * been set, any attempt to modify the configuration will return an
* IllegalStateException.
*/
public boolean getConfigured() {
@@ -102,12 +189,14 @@
if (this.controllerConfig == null) {
this.controllerConfig = new ControllerConfig();
}
+
return (this.controllerConfig);
}
/**
* The controller configuration object for this module.
- * @param cc The controller configuration object for this module.
+ *
+ * @param cc The controller configuration object for this module.
*/
public void setControllerConfig(ControllerConfig cc) {
throwIfConfigured();
@@ -155,14 +244,16 @@
}
/**
- * The default class name to be used when creating action mapping instances.
+ * The default class name to be used when creating action mapping
+ * instances.
*/
public String getActionMappingClass() {
return this.actionMappingClass;
}
/**
- * The default class name to be used when creating action mapping instances.
+ * The default class name to be used when creating action mapping
+ * instances.
*
* @param actionMappingClass default class name to be used when creating
* action mapping instances.
@@ -172,25 +263,25 @@
}
/**
- * Add a new <code>ActionConfig</code> instance to the set associated
- * with this module.
+ * Add a new <code>ActionConfig</code> instance to the set associated with
+ * this module.
*
* @param config The new configuration instance to be added
- *
- * @exception java.lang.IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
public void addActionConfig(ActionConfig config) {
-
throwIfConfigured();
config.setModuleConfig(this);
+
String key = config.getPath();
+
if (actionConfigs.containsKey(key)) {
- log.warn("Overriding ActionConfig of path " + key);
- }
+ log.warn("Overriding ActionConfig of path " + key);
+ }
+
actionConfigs.put(key, config);
actionConfigList.add(config);
-
}
/**
@@ -198,19 +289,19 @@
* with this module.
*
* @param config The new configuration instance to be added
- *
- * @exception java.lang.IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
public void addExceptionConfig(ExceptionConfig config) {
-
throwIfConfigured();
+
String key = config.getType();
+
if (exceptions.containsKey(key)) {
- log.warn("Overriding ExceptionConfig of type " + key);
- }
- exceptions.put(key, config);
+ log.warn("Overriding ExceptionConfig of type " + key);
+ }
+ exceptions.put(key, config);
}
/**
@@ -218,36 +309,38 @@
* with this module.
*
* @param config The new configuration instance to be added
- *
- * @exception java.lang.IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
public void addFormBeanConfig(FormBeanConfig config) {
-
throwIfConfigured();
+
String key = config.getName();
+
if (formBeans.containsKey(key)) {
- log.warn("Overriding ActionForm of name " + key);
- }
- formBeans.put(key, config);
+ log.warn("Overriding ActionForm of name " + key);
+ }
+ formBeans.put(key, config);
}
/**
- * The default class name to be used when creating action forward instances.
+ * The default class name to be used when creating action forward
+ * instances.
*/
public String getActionForwardClass() {
return this.actionForwardClass;
}
/**
- * The default class name to be used when creating action forward instances.
+ * The default class name to be used when creating action forward
+ * instances.
*
* @param actionForwardClass default class name to be used when creating
* action forward instances.
*/
public void setActionForwardClass(String actionForwardClass) {
- this.actionForwardClass= actionForwardClass;
+ this.actionForwardClass = actionForwardClass;
}
/**
@@ -255,19 +348,19 @@
* forwards associated with this module.
*
* @param config The new configuration instance to be added
- *
- * @exception java.lang.IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
public void addForwardConfig(ForwardConfig config) {
-
throwIfConfigured();
+
String key = config.getName();
+
if (forwards.containsKey(key)) {
- log.warn("Overriding global ActionForward of name " + key);
- }
- forwards.put(key, config);
+ log.warn("Overriding global ActionForward of name " + key);
+ }
+ forwards.put(key, config);
}
/**
@@ -275,64 +368,59 @@
* associated with this module.
*
* @param config The new configuration instance to be added
- *
- * @exception java.lang.IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
public void addMessageResourcesConfig(MessageResourcesConfig config) {
-
throwIfConfigured();
+
String key = config.getKey();
+
if (messageResources.containsKey(key)) {
- log.warn("Overriding MessageResources bundle of key " + key);
- }
- messageResources.put(key, config);
+ log.warn("Overriding MessageResources bundle of key " + key);
+ }
+ messageResources.put(key, config);
}
/**
- * Add a newly configured {@link org.apache.struts.config.PlugInConfig} instance to the set of
- * plug-in Actions for this module.
+ * Add a newly configured {@link org.apache.struts.config.PlugInConfig}
+ * instance to the set of plug-in Actions for this module.
*
* @param plugInConfig The new configuration instance to be added
*/
public void addPlugInConfig(PlugInConfig plugInConfig) {
-
throwIfConfigured();
plugIns.add(plugInConfig);
-
}
/**
- * Return the action configuration for the specified path, first looking
- * a direct match, then if none found, a wildcard pattern match;
- * otherwise return <code>null</code>.
+ * Return the action configuration for the specified path, first looking a
+ * direct match, then if none found, a wildcard pattern match; otherwise
+ * return <code>null</code>.
*
* @param path Path of the action configuration to return
*/
public ActionConfig findActionConfig(String path) {
-
ActionConfig config = (ActionConfig) actionConfigs.get(path);
// If a direct match cannot be found, try to match action configs
// containing wildcard patterns only if a matcher exists.
- if (config == null && matcher != null) {
+ if ((config == null) && (matcher != null)) {
config = matcher.match(path);
}
return config;
-
}
/**
- * Return the action configurations for this module. If there are
- * none, a zero-length array is returned.
+ * Return the action configurations for this module. If there are none, a
+ * zero-length array is returned.
*/
public ActionConfig[] findActionConfigs() {
+ ActionConfig[] results = new ActionConfig[actionConfigList.size()];
- ActionConfig results[] = new ActionConfig[actionConfigList.size()];
return ((ActionConfig[]) actionConfigList.toArray(results));
-
}
/**
@@ -342,61 +430,59 @@
* @param type Exception class name to find a configuration for
*/
public ExceptionConfig findExceptionConfig(String type) {
-
return ((ExceptionConfig) exceptions.get(type));
-
}
-
/**
* <p>Find and return the <code>ExceptionConfig</code> instance defining
* how <code>Exceptions</code> of the specified type should be handled.
- *
- * <p>In original Struts usage, this was only available in <code>ActionConfig</code>,
- * but there are cases when an exception could be thrown before an <code>ActionConfig</code>
- * has been identified, where global exception handlers may still be pertinent.</p>
- *
- * <p>TODO: Look for a way to share this logic with <code>ActionConfig</code>, although
- * there are subtle differences, and it certainly doesn't seem like it should be done with
- * inheritance.</p>
+ *
+ * <p>In original Struts usage, this was only available in
+ * <code>ActionConfig</code>, but there are cases when an exception could
+ * be thrown before an <code>ActionConfig</code> has been identified,
+ * where global exception handlers may still be pertinent.</p>
+ *
+ * <p>TODO: Look for a way to share this logic with
+ * <code>ActionConfig</code>, although there are subtle differences, and
+ * it certainly doesn't seem like it should be done with inheritance.</p>
*
* @param type Exception class for which to find a handler
* @since Struts 1.3.0
*/
public ExceptionConfig findException(Class type) {
-
// Check through the entire superclass hierarchy as needed
ExceptionConfig config = null;
- while (true) {
+ while (true) {
// Check for a locally defined handler
String name = type.getName();
+
log.debug("findException: look locally for " + name);
config = findExceptionConfig(name);
+
if (config != null) {
return (config);
}
// Loop again for our superclass (if any)
type = type.getSuperclass();
+
if (type == null) {
break;
}
-
}
- return (null); // No handler has been configured
+ return (null); // No handler has been configured
}
/**
- * Return the exception configurations for this module. If there
- * are none, a zero-length array is returned.
+ * Return the exception configurations for this module. If there are
+ * none, a zero-length array is returned.
*/
public ExceptionConfig[] findExceptionConfigs() {
+ ExceptionConfig[] results = new ExceptionConfig[exceptions.size()];
- ExceptionConfig results[] = new ExceptionConfig[exceptions.size()];
return ((ExceptionConfig[]) exceptions.values().toArray(results));
-
}
/**
@@ -406,20 +492,17 @@
* @param name Name of the form bean configuration to return
*/
public FormBeanConfig findFormBeanConfig(String name) {
-
return ((FormBeanConfig) formBeans.get(name));
-
}
/**
- * Return the form bean configurations for this module. If there
- * are none, a zero-length array is returned.
+ * Return the form bean configurations for this module. If there are
+ * none, a zero-length array is returned.
*/
public FormBeanConfig[] findFormBeanConfigs() {
+ FormBeanConfig[] results = new FormBeanConfig[formBeans.size()];
- FormBeanConfig results[] = new FormBeanConfig[formBeans.size()];
return ((FormBeanConfig[]) formBeans.values().toArray(results));
-
}
/**
@@ -429,96 +512,96 @@
* @param name Name of the forward configuration to return
*/
public ForwardConfig findForwardConfig(String name) {
-
return ((ForwardConfig) forwards.get(name));
-
}
/**
- * Return the form bean configurations for this module. If there
- * are none, a zero-length array is returned.
+ * Return the form bean configurations for this module. If there are
+ * none, a zero-length array is returned.
*/
public ForwardConfig[] findForwardConfigs() {
+ ForwardConfig[] results = new ForwardConfig[forwards.size()];
- ForwardConfig results[] = new ForwardConfig[forwards.size()];
return ((ForwardConfig[]) forwards.values().toArray(results));
-
}
/**
- * Return the message resources configuration for the specified key,
- * if any; otherwise return <code>null</code>.
+ * Return the message resources configuration for the specified key, if
+ * any; otherwise return <code>null</code>.
*
* @param key Key of the data source configuration to return
*/
public MessageResourcesConfig findMessageResourcesConfig(String key) {
-
return ((MessageResourcesConfig) messageResources.get(key));
-
}
/**
- * Return the message resources configurations for this module.
- * If there are none, a zero-length array is returned.
+ * Return the message resources configurations for this module. If there
+ * are none, a zero-length array is returned.
*/
public MessageResourcesConfig[] findMessageResourcesConfigs() {
+ MessageResourcesConfig[] results =
+ new MessageResourcesConfig[messageResources
+ .size()];
- MessageResourcesConfig results[] =
- new MessageResourcesConfig[messageResources.size()];
- return ((MessageResourcesConfig[])
- messageResources.values().toArray(results));
-
+ return ((MessageResourcesConfig[]) messageResources.values()
+ .toArray(results));
}
/**
- * Return the configured plug-in actions for this module. If there
- * are none, a zero-length array is returned.
+ * Return the configured plug-in actions for this module. If there are
+ * none, a zero-length array is returned.
*/
public PlugInConfig[] findPlugInConfigs() {
+ PlugInConfig[] results = new PlugInConfig[plugIns.size()];
- PlugInConfig results[] = new PlugInConfig[plugIns.size()];
return ((PlugInConfig[]) plugIns.toArray(results));
-
}
/**
- * Freeze the configuration of this module. After this method
- * returns, any attempt to modify the configuration will return
- * an IllegalStateException.
+ * Freeze the configuration of this module. After this method returns,
+ * any attempt to modify the configuration will return an
+ * IllegalStateException.
*/
public void freeze() {
-
super.freeze();
ActionConfig[] aconfigs = findActionConfigs();
+
for (int i = 0; i < aconfigs.length; i++) {
aconfigs[i].freeze();
}
+
matcher = new ActionConfigMatcher(aconfigs);
getControllerConfig().freeze();
ExceptionConfig[] econfigs = findExceptionConfigs();
+
for (int i = 0; i < econfigs.length; i++) {
econfigs[i].freeze();
}
FormBeanConfig[] fbconfigs = findFormBeanConfigs();
+
for (int i = 0; i < fbconfigs.length; i++) {
fbconfigs[i].freeze();
}
ForwardConfig[] fconfigs = findForwardConfigs();
+
for (int i = 0; i < fconfigs.length; i++) {
fconfigs[i].freeze();
}
MessageResourcesConfig[] mrconfigs = findMessageResourcesConfigs();
+
for (int i = 0; i < mrconfigs.length; i++) {
mrconfigs[i].freeze();
}
PlugInConfig[] piconfigs = findPlugInConfigs();
+
for (int i = 0; i < piconfigs.length; i++) {
piconfigs[i].freeze();
}
@@ -528,164 +611,61 @@
* Remove the specified action configuration instance.
*
* @param config ActionConfig instance to be removed
- *
- * @exception IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
public void removeActionConfig(ActionConfig config) {
-
throwIfConfigured();
config.setModuleConfig(null);
actionConfigs.remove(config.getPath());
actionConfigList.remove(config);
-
}
/**
* Remove the specified exception configuration instance.
*
* @param config ActionConfig instance to be removed
- *
- * @exception IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
public void removeExceptionConfig(ExceptionConfig config) {
-
throwIfConfigured();
exceptions.remove(config.getType());
-
}
/**
* Remove the specified form bean configuration instance.
*
* @param config FormBeanConfig instance to be removed
- *
- * @exception IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
public void removeFormBeanConfig(FormBeanConfig config) {
-
throwIfConfigured();
formBeans.remove(config.getName());
-
}
/**
* Remove the specified forward configuration instance.
*
* @param config ForwardConfig instance to be removed
- *
- * @exception IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
public void removeForwardConfig(ForwardConfig config) {
-
throwIfConfigured();
forwards.remove(config.getName());
-
}
/**
* Remove the specified message resources configuration instance.
*
* @param config MessageResourcesConfig instance to be removed
- *
- * @exception IllegalStateException if this module configuration
- * has been frozen
+ * @throws IllegalStateException if this module configuration has been
+ * frozen
*/
public void removeMessageResourcesConfig(MessageResourcesConfig config) {
-
throwIfConfigured();
messageResources.remove(config.getKey());
-
}
-
- // ----------------------------------------------------- Instance Variables
- // Instance Variables at end to make comparing Interface and implementation easier.
-
-
- /**
- * The set of action configurations for this module, if any,
- * keyed by the <code>path</code> property.
- */
- protected HashMap actionConfigs = null;
-
- /**
- * The set of action configurations for this module, if any,
- * listed in the order in which they are added.
- */
- protected List actionConfigList = null;
-
- /**
- * The set of exception handling configurations for this
- * module, if any, keyed by the <code>type</code> property.
- */
- protected HashMap exceptions = null;
-
- /**
- * The set of form bean configurations for this module, if any,
- * keyed by the <code>name</code> property.
- */
- protected HashMap formBeans = null;
-
- /**
- * The set of global forward configurations for this module, if any,
- * keyed by the <code>name</code> property.
- */
- protected HashMap forwards = null;
-
- /**
- * The set of message resources configurations for this
- * module, if any, keyed by the <code>key</code> property.
- */
- protected HashMap messageResources = null;
-
- /**
- * The set of configured plug-in Actions for this module,
- * if any, in the order they were declared and configured.
- */
- protected ArrayList plugIns = null;
-
- /**
- * The controller configuration object for this module.
- */
- protected ControllerConfig controllerConfig = null;
-
- /**
- * The prefix of the context-relative portion of the request URI, used to
- * select this configuration versus others supported by the controller
- * servlet. A configuration with a prefix of a zero-length String is the
- * default configuration for this web module.
- */
- protected String prefix = null;
-
- /**
- * The default class name to be used when creating action form bean
- * instances.
- */
- protected String actionFormBeanClass = "org.apache.struts.action.ActionFormBean";
-
- /**
- * The default class name to be used when creating action mapping instances.
- */
- protected String actionMappingClass = "org.apache.struts.action.ActionMapping";
-
- /**
- * The default class name to be used when creating action forward instances.
- */
- protected String actionForwardClass = "org.apache.struts.action.ActionForward";
-
- /**
- * Matches action config paths against compiled wildcard patterns
- */
- protected ActionConfigMatcher matcher = null;
-
- /**
- * Commons Logging instance.
- */
- protected static Log log = LogFactory.getLog(ModuleConfigImpl.class);
-
-
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/config/package.html
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/config/package.html?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/config/package.html (original)
+++ struts/action/trunk/src/java/org/apache/struts/config/package.html Fri Jan 20 16:19:02 2006
@@ -1,7 +1,7 @@
<body>
<p>The "config" package contains configuration objects that correspond to
-elements that may be specified in the <code>struts-config.xml</code>
-module configuration file.</p>
+ elements that may be specified in the <code>struts-config.xml</code>
+ module configuration file.</p>
<img src="doc-files/configUML.gif" alt="Config UML">
<br>
</body>
Modified: struts/action/trunk/src/java/org/apache/struts/mock/MockAction.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/mock/MockAction.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/mock/MockAction.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/mock/MockAction.java Fri Jan 20 16:19:02 2006
@@ -15,21 +15,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.struts.mock;
-
import org.apache.struts.action.Action;
-
/**
* <p>General purpose Action for unit tests.</p>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-05-07 12:11:38 -0400 (Sat, 07 May 2005)
+ * $
*/
-
public class MockAction extends Action {
-
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/mock/MockActionServlet.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/mock/MockActionServlet.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/mock/MockActionServlet.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/mock/MockActionServlet.java Fri Jan 20 16:19:02 2006
@@ -15,23 +15,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.struts.mock;
+import org.apache.struts.action.ActionServlet;
-import javax.servlet.ServletContext;
import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
import javax.servlet.ServletException;
-
-import org.apache.struts.action.ActionServlet;
-
/**
- * <p>Mock <strong>ActionServlet</strong> object for low-level unit tests
- * of Struts controller components. Coarser grained tests should be
- * implemented in terms of the Cactus framework, instead of the mock
- * object classes.</p>
+ * <p>Mock <strong>ActionServlet</strong> object for low-level unit tests of
+ * Struts controller components. Coarser grained tests should be implemented
+ * in terms of the Cactus framework, instead of the mock object classes.</p>
*
* <p><strong>WARNING</strong> - Only getter methods for servletContext and
* servletConfig are provided, plus additional methods to configure this
@@ -41,7 +36,8 @@
* <p><strong>WARNING</strong> - Because unit tests operate in a single
* threaded environment, no synchronization is performed.</p>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-05-14 02:09:06 -0400 (Sat, 14 May 2005)
+ * $
*/
public class MockActionServlet extends ActionServlet {
protected ServletContext servletContext;
@@ -51,7 +47,7 @@
* Constructor.
*/
public MockActionServlet(ServletContext servletContext,
- ServletConfig servletConfig) {
+ ServletConfig servletConfig) {
this.servletContext = servletContext;
this.servletConfig = servletConfig;
}
@@ -60,11 +56,12 @@
* Constructor.
*/
public MockActionServlet() {
- ; // do nothing
+ ; // do nothing
}
/**
* Set property
+ *
* @param servletContext
*/
public void setServletContext(ServletContext servletContext) {
@@ -73,6 +70,7 @@
/**
* Get property
+ *
* @return
*/
public ServletContext getServletContext() {
@@ -81,6 +79,7 @@
/**
* Set property
+ *
* @param servletConfig
*/
public void setServletConfig(ServletConfig servletConfig) {
@@ -89,6 +88,7 @@
/**
* Get property
+ *
* @return
*/
public ServletConfig getServletConfig() {
@@ -99,8 +99,8 @@
* Expose as public so that test classes can exercise things which
* retrieve messages.
*/
- public void initInternal() throws ServletException {
+ public void initInternal()
+ throws ServletException {
super.initInternal();
}
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/mock/MockEnumeration.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/mock/MockEnumeration.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/mock/MockEnumeration.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/mock/MockEnumeration.java Fri Jan 20 16:19:02 2006
@@ -15,41 +15,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.struts.mock;
-
import java.util.Enumeration;
import java.util.Iterator;
-
/**
* <p>General purpose <code>Enumeration</code> wrapper around an
* <code>Iterator</code> specified to our controller.</p>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-05-07 12:11:38 -0400 (Sat, 07 May 2005)
+ * $
*/
-
public class MockEnumeration implements Enumeration {
-
+ protected Iterator iterator;
public MockEnumeration(Iterator iterator) {
this.iterator = iterator;
}
-
- protected Iterator iterator;
-
-
public boolean hasMoreElements() {
return (iterator.hasNext());
}
-
public Object nextElement() {
return (iterator.next());
}
-
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/mock/MockFormBean.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/mock/MockFormBean.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/mock/MockFormBean.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/mock/MockFormBean.java Fri Jan 20 16:19:02 2006
@@ -15,39 +15,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.struts.mock;
+import org.apache.struts.action.ActionForm;
import java.util.HashMap;
import java.util.Map;
-import org.apache.struts.action.ActionForm;
-
/**
* <p>General purpose form bean for unit tests.</p>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-05-07 12:45:39 -0400 (Sat, 07 May 2005)
+ * $
*/
-
public class MockFormBean extends ActionForm {
-
/*
* Flag to indicate whether certain methods should complete properly
* or throw an Exception
*/
private boolean throwException = false;
-
-
- private boolean returnNulls = false;
- private String defaultValue;
- private Double defaultDouble;
- private int arrayCount;
+ private boolean returnNulls = false;
+ private String defaultValue;
+ private Double defaultDouble;
+ private int arrayCount;
protected boolean booleanProperty = false;
+ protected String stringProperty = null;
// ------------------- Constructors
-
public MockFormBean() {
this(null);
}
@@ -55,78 +49,93 @@
public MockFormBean(boolean throwException, boolean returnNulls) {
super();
this.throwException = throwException;
- this.returnNulls = returnNulls;
+ this.returnNulls = returnNulls;
}
public MockFormBean(boolean throwException) {
this.throwException = throwException;
}
- public MockFormBean(boolean throwException,
- boolean returnNulls, String defaultValue) {
+ public MockFormBean(boolean throwException, boolean returnNulls,
+ String defaultValue) {
this(throwException, returnNulls);
this.defaultValue = defaultValue;
-
}
+
public MockFormBean(String stringProperty) {
this.stringProperty = stringProperty;
}
-
- public MockFormBean(boolean throwException,
- boolean returnNulls, String defaultValue, int arrayCount) {
+ public MockFormBean(boolean throwException, boolean returnNulls,
+ String defaultValue, int arrayCount) {
this(throwException, returnNulls, defaultValue);
this.arrayCount = arrayCount;
-
}
- public MockFormBean(boolean throwException,
- boolean returnNulls, Double defaultDouble) {
+ public MockFormBean(boolean throwException, boolean returnNulls,
+ Double defaultDouble) {
this(throwException, returnNulls);
this.defaultDouble = defaultDouble;
-
}
// ------------------- public methods
-
- public String getJustThrowAnException() throws Exception {
- throw new Exception();
+ public String getJustThrowAnException()
+ throws Exception {
+ throw new Exception();
}
- public Object getThrowIllegalAccessException() throws Exception {
- if (true)
+ public Object getThrowIllegalAccessException()
+ throws Exception {
+ if (true) {
throw new IllegalAccessException();
+ }
+
return null;
}
- public String getStringValue() throws Exception {
- if (throwException)
+ public String getStringValue()
+ throws Exception {
+ if (throwException) {
throw new Exception();
- if (returnNulls)
+ }
+
+ if (returnNulls) {
return null;
+ }
+
return defaultValue;
}
- public String[] getStringArray() throws Exception {
- if (throwException)
+ public String[] getStringArray()
+ throws Exception {
+ if (throwException) {
throw new Exception();
- if (returnNulls)
+ }
+
+ if (returnNulls) {
return null;
+ }
String[] rtn = new String[arrayCount];
+
for (int i = 0; i < rtn.length; i++) {
rtn[i] = defaultValue + i;
}
+
return rtn;
}
- public Double getDoubleValue() throws Exception {
- if (throwException)
+ public Double getDoubleValue()
+ throws Exception {
+ if (throwException) {
throw new Exception();
- if (returnNulls)
+ }
+
+ if (returnNulls) {
return null;
- return defaultDouble;
+ }
+ return defaultDouble;
}
public boolean getBooleanProperty() {
@@ -137,23 +146,23 @@
this.booleanProperty = booleanProperty;
}
-
public Map getMapProperty() {
HashMap map = new HashMap();
+
map.put("foo1", "bar1");
map.put("foo2", "bar2");
+
return (map);
}
public Map getMapPropertyArrayValues() {
HashMap map = new HashMap();
- map.put("foo1", new String[] {"bar1", "baz1"});
- map.put("foo2", new String[] {"bar2", "baz2"});
- return (map);
- }
+ map.put("foo1", new String[]{"bar1", "baz1"});
+ map.put("foo2", new String[]{"bar2", "baz2"});
- protected String stringProperty = null;
+ return (map);
+ }
public String getStringProperty() {
return (this.stringProperty);
@@ -162,6 +171,4 @@
public void setStringProperty(String stringProperty) {
this.stringProperty = stringProperty;
}
-
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/mock/MockHttpServletRequest.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/mock/MockHttpServletRequest.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/mock/MockHttpServletRequest.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/mock/MockHttpServletRequest.java Fri Jan 20 16:19:02 2006
@@ -15,11 +15,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.struts.mock;
-
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
import java.io.BufferedReader;
import java.security.Principal;
import java.util.Enumeration;
@@ -27,19 +29,11 @@
import java.util.Locale;
import java.util.Map;
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletInputStream;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
-
-
/**
* <p>Mock <strong>HttpServletRequest</strong> object for low-level unit tests
* of Struts controller components. Coarser grained tests should be
- * implemented in terms of the Cactus framework, instead of the mock
- * object classes.</p>
+ * implemented in terms of the Cactus framework, instead of the mock object
+ * classes.</p>
*
* <p><strong>WARNING</strong> - Only the minimal set of methods needed to
* create unit tests is provided, plus additional methods to configure this
@@ -49,220 +43,178 @@
* <p><strong>WARNING</strong> - Because unit tests operate in a single
* threaded environment, no synchronization is performed.</p>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-11-12 11:52:08 -0500 (Sat, 12 Nov 2005)
+ * $
*/
-
public class MockHttpServletRequest implements HttpServletRequest {
-
-
-
- // ----------------------------------------------------------- Constructors
-
-
- public MockHttpServletRequest() {
- super();
- }
-
-
- public MockHttpServletRequest(HttpSession session) {
- super();
- setHttpSession(session);
- }
-
-
- public MockHttpServletRequest(String contextPath, String servletPath,
- String pathInfo, String queryString) {
- super();
- setPathElements(contextPath, servletPath, pathInfo, queryString);
- }
-
-
-
- public MockHttpServletRequest(String contextPath, String servletPath,
- String pathInfo, String queryString,
- HttpSession session) {
- super();
- setPathElements(contextPath, servletPath, pathInfo, queryString);
- setHttpSession(session);
- }
-
-
-
// ----------------------------------------------------- Instance Variables
-
/**
* The set of request attributes.
*/
protected HashMap attributes = new HashMap();
-
/**
* The context path for this request.
*/
protected String contextPath = null;
-
/**
* The preferred locale for this request.
*/
protected Locale locale = null;
-
/**
* The set of arrays of parameter values, keyed by parameter name.
*/
protected HashMap parameters = new HashMap();
-
/**
* The extra path information for this request.
*/
protected String pathInfo = null;
-
/**
* The authenticated user for this request.
*/
protected Principal principal = null;
-
/**
* The query string for this request.
*/
protected String queryString = null;
-
/**
* The servlet path for this request.
*/
protected String servletPath = null;
-
/**
* The HttpSession with which we are associated.
*/
protected HttpSession session = null;
-
-
+
/**
* The HTTP request method.
- */
+ */
protected String method = null;
+ // ----------------------------------------------------------- Constructors
+ public MockHttpServletRequest() {
+ super();
+ }
- // --------------------------------------------------------- Public Methods
+ public MockHttpServletRequest(HttpSession session) {
+ super();
+ setHttpSession(session);
+ }
+
+ public MockHttpServletRequest(String contextPath, String servletPath,
+ String pathInfo, String queryString) {
+ super();
+ setPathElements(contextPath, servletPath, pathInfo, queryString);
+ }
+ public MockHttpServletRequest(String contextPath, String servletPath,
+ String pathInfo, String queryString,
+ HttpSession session) {
+ super();
+ setPathElements(contextPath, servletPath, pathInfo, queryString);
+ setHttpSession(session);
+ }
+ // --------------------------------------------------------- Public Methods
public void addParameter(String name, String value) {
- String values[] = (String[]) parameters.get(name);
+ String[] values = (String[]) parameters.get(name);
+
if (values == null) {
- String results[] = new String[] { value };
+ String[] results = new String[]{value};
+
parameters.put(name, results);
+
return;
}
- String results[] = new String[values.length + 1];
+
+ String[] results = new String[values.length + 1];
+
System.arraycopy(values, 0, results, 0, values.length);
results[values.length] = value;
parameters.put(name, results);
}
-
public void setHttpSession(HttpSession session) {
this.session = session;
}
-
public void setLocale(Locale locale) {
this.locale = locale;
}
-
-
+
public void setMethod(String method) {
this.method = method;
}
-
public void setPathElements(String contextPath, String servletPath,
String pathInfo, String queryString) {
-
this.contextPath = contextPath;
this.servletPath = servletPath;
this.pathInfo = pathInfo;
this.queryString = queryString;
-
}
-
public void setUserPrincipal(Principal principal) {
this.principal = principal;
}
-
-
// --------------------------------------------- HttpServletRequest Methods
-
-
public String getAuthType() {
throw new UnsupportedOperationException();
}
-
public String getContextPath() {
return (contextPath);
}
-
public Cookie[] getCookies() {
throw new UnsupportedOperationException();
}
-
public long getDateHeader(String name) {
throw new UnsupportedOperationException();
}
-
public String getHeader(String name) {
throw new UnsupportedOperationException();
}
-
public Enumeration getHeaderNames() {
throw new UnsupportedOperationException();
}
-
public Enumeration getHeaders(String name) {
throw new UnsupportedOperationException();
}
-
public int getIntHeader(String name) {
throw new UnsupportedOperationException();
}
-
public String getMethod() {
return (method);
}
-
public String getPathInfo() {
return (pathInfo);
}
-
public String getPathTranslated() {
throw new UnsupportedOperationException();
}
-
public String getQueryString() {
return (queryString);
}
-
public String getRemoteUser() {
if (principal != null) {
return (principal.getName());
@@ -271,46 +223,45 @@
}
}
-
public String getRequestedSessionId() {
throw new UnsupportedOperationException();
}
-
public String getRequestURI() {
StringBuffer sb = new StringBuffer();
+
if (contextPath != null) {
sb.append(contextPath);
}
+
if (servletPath != null) {
sb.append(servletPath);
}
+
if (pathInfo != null) {
sb.append(pathInfo);
}
+
if (sb.length() > 0) {
return (sb.toString());
}
+
throw new UnsupportedOperationException();
}
-
public StringBuffer getRequestURL() {
throw new UnsupportedOperationException();
}
-
public String getServletPath() {
return (servletPath);
}
-
public HttpSession getSession() {
return (getSession(true));
}
-
- public HttpSession getSession( boolean create ) {
+ public HttpSession getSession(boolean create) {
if (create && (session == null)) {
session = new MockHttpSession();
@@ -318,35 +269,30 @@
// call with (false) if you want null
// throw new UnsupportedOperationException();
}
+
return (session);
}
-
public Principal getUserPrincipal() {
return (principal);
}
-
public boolean isRequestedSessionIdFromCookie() {
throw new UnsupportedOperationException();
}
-
public boolean isRequestedSessionIdFromUrl() {
throw new UnsupportedOperationException();
}
-
public boolean isRequestedSessionIdFromURL() {
throw new UnsupportedOperationException();
}
-
public boolean isRequestedSessionIdValid() {
throw new UnsupportedOperationException();
}
-
public boolean isUserInRole(String role) {
if ((principal != null) && (principal instanceof MockPrincipal)) {
return (((MockPrincipal) principal).isUserInRole(role));
@@ -355,52 +301,42 @@
}
}
-
// ------------------------------------------------- ServletRequest Methods
-
-
public Object getAttribute(String name) {
return (attributes.get(name));
}
-
public Enumeration getAttributeNames() {
return (new MockEnumeration(attributes.keySet().iterator()));
}
-
public String getCharacterEncoding() {
throw new UnsupportedOperationException();
}
-
public int getContentLength() {
throw new UnsupportedOperationException();
}
-
public String getContentType() {
throw new UnsupportedOperationException();
}
-
public ServletInputStream getInputStream() {
throw new UnsupportedOperationException();
}
-
public Locale getLocale() {
return (locale);
}
-
public Enumeration getLocales() {
throw new UnsupportedOperationException();
}
-
public String getParameter(String name) {
- String values[] = (String[]) parameters.get(name);
+ String[] values = (String[]) parameters.get(name);
+
if (values != null) {
return (values[0]);
} else {
@@ -408,77 +344,62 @@
}
}
-
public Map getParameterMap() {
return (parameters);
}
-
public Enumeration getParameterNames() {
return (new MockEnumeration(parameters.keySet().iterator()));
}
-
public String[] getParameterValues(String name) {
return ((String[]) parameters.get(name));
}
-
public String getProtocol() {
throw new UnsupportedOperationException();
}
-
public BufferedReader getReader() {
throw new UnsupportedOperationException();
}
-
public String getRealPath(String path) {
throw new UnsupportedOperationException();
}
-
public String getRemoteAddr() {
throw new UnsupportedOperationException();
}
-
public String getRemoteHost() {
throw new UnsupportedOperationException();
}
-
public RequestDispatcher getRequestDispatcher(String path) {
throw new UnsupportedOperationException();
}
-
public String getScheme() {
return ("http");
}
-
public String getServerName() {
return ("localhost");
}
-
public int getServerPort() {
return (8080);
}
-
public boolean isSecure() {
return (false);
}
-
public void removeAttribute(String name) {
attributes.remove(name);
}
-
public void setAttribute(String name, Object value) {
if (value == null) {
attributes.remove(name);
@@ -487,10 +408,7 @@
}
}
-
public void setCharacterEncoding(String name) {
throw new UnsupportedOperationException();
}
-
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/mock/MockHttpServletResponse.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/mock/MockHttpServletResponse.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/mock/MockHttpServletResponse.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/mock/MockHttpServletResponse.java Fri Jan 20 16:19:02 2006
@@ -15,26 +15,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.struts.mock;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Locale;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
-
-
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Locale;
/**
- * <p>Mock <strong>HttpServletResponse</strong> object for low-level unit tests
- * of Struts controller components. Coarser grained tests should be
- * implemented in terms of the Cactus framework, instead of the mock
- * object classes.</p>
+ * <p>Mock <strong>HttpServletResponse</strong> object for low-level unit
+ * tests of Struts controller components. Coarser grained tests should be
+ * implemented in terms of the Cactus framework, instead of the mock object
+ * classes.</p>
*
* <p><strong>WARNING</strong> - Only the minimal set of methods needed to
* create unit tests is provided, plus additional methods to configure this
@@ -44,175 +38,133 @@
* <p><strong>WARNING</strong> - Because unit tests operate in a single
* threaded environment, no synchronization is performed.</p>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-05-07 12:11:38 -0400 (Sat, 07 May 2005)
+ * $
*/
-
public class MockHttpServletResponse implements HttpServletResponse {
-
-
-
// ----------------------------------------------------- Instance Variables
-
-
// --------------------------------------------------------- Public Methods
-
-
-
-
// -------------------------------------------- HttpServletResponse Methods
-
-
public void addCookie(Cookie cookie) {
throw new UnsupportedOperationException();
}
-
public void addDateHeader(String name, long value) {
throw new UnsupportedOperationException();
}
-
public void addHeader(String name, String value) {
throw new UnsupportedOperationException();
}
-
public void addIntHeader(String name, int value) {
throw new UnsupportedOperationException();
}
-
public boolean containsHeader(String name) {
throw new UnsupportedOperationException();
}
-
public String encodeRedirectUrl(String url) {
return (encodeRedirectURL(url));
}
-
public String encodeRedirectURL(String url) {
return (url);
}
-
public String encodeUrl(String url) {
return (encodeURL(url));
}
-
public String encodeURL(String url) {
return (url);
}
-
public void sendError(int status) {
throw new UnsupportedOperationException();
}
-
public void sendError(int status, String message) {
throw new UnsupportedOperationException();
}
-
public void sendRedirect(String location) {
throw new UnsupportedOperationException();
}
-
public void setDateHeader(String name, long value) {
throw new UnsupportedOperationException();
}
-
public void setHeader(String name, String value) {
throw new UnsupportedOperationException();
}
-
public void setIntHeader(String name, int value) {
throw new UnsupportedOperationException();
}
-
public void setStatus(int status) {
throw new UnsupportedOperationException();
}
-
public void setStatus(int status, String message) {
throw new UnsupportedOperationException();
}
-
// ------------------------------------------------ ServletResponse Methods
-
-
public void flushBuffer() {
throw new UnsupportedOperationException();
}
-
public int getBufferSize() {
throw new UnsupportedOperationException();
}
-
public String getCharacterEncoding() {
throw new UnsupportedOperationException();
}
-
public Locale getLocale() {
throw new UnsupportedOperationException();
}
-
- public ServletOutputStream getOutputStream() throws IOException {
+ public ServletOutputStream getOutputStream()
+ throws IOException {
throw new UnsupportedOperationException();
}
-
- public PrintWriter getWriter() throws IOException {
+ public PrintWriter getWriter()
+ throws IOException {
throw new UnsupportedOperationException();
}
-
public boolean isCommitted() {
throw new UnsupportedOperationException();
}
-
public void reset() {
throw new UnsupportedOperationException();
}
-
public void resetBuffer() {
throw new UnsupportedOperationException();
}
-
public void setBufferSize(int size) {
throw new UnsupportedOperationException();
}
-
public void setContentLength(int length) {
throw new UnsupportedOperationException();
}
-
public void setContentType(String type) {
throw new UnsupportedOperationException();
}
-
public void setLocale(Locale locale) {
throw new UnsupportedOperationException();
}
-
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/mock/MockHttpSession.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/mock/MockHttpSession.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/mock/MockHttpSession.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/mock/MockHttpSession.java Fri Jan 20 16:19:02 2006
@@ -15,24 +15,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.struts.mock;
-
-import java.util.Enumeration;
-import java.util.HashMap;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionContext;
-
-
+import java.util.Enumeration;
+import java.util.HashMap;
/**
- * <p>Mock <strong>HttpSession</strong> object for low-level unit tests
- * of Struts controller components. Coarser grained tests should be
- * implemented in terms of the Cactus framework, instead of the mock
- * object classes.</p>
+ * <p>Mock <strong>HttpSession</strong> object for low-level unit tests of
+ * Struts controller components. Coarser grained tests should be implemented
+ * in terms of the Cactus framework, instead of the mock object classes.</p>
*
* <p><strong>WARNING</strong> - Only the minimal set of methods needed to
* create unit tests is provided, plus additional methods to configure this
@@ -42,129 +36,98 @@
* <p><strong>WARNING</strong> - Because unit tests operate in a single
* threaded environment, no synchronization is performed.</p>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-05-07 12:11:38 -0400 (Sat, 07 May 2005)
+ * $
*/
-
public class MockHttpSession implements HttpSession {
-
-
-
- // ----------------------------------------------------------- Constructors
-
-
- public MockHttpSession() {
- super();
- }
-
-
- public MockHttpSession(ServletContext servletContext) {
- super();
- setServletContext(servletContext);
- }
-
-
-
// ----------------------------------------------------- Instance Variables
-
/**
* The set of session attributes.
*/
protected HashMap attributes = new HashMap();
-
/**
* The ServletContext with which we are associated.
*/
protected ServletContext servletContext = null;
+ // ----------------------------------------------------------- Constructors
+ public MockHttpSession() {
+ super();
+ }
- // --------------------------------------------------------- Public Methods
-
+ public MockHttpSession(ServletContext servletContext) {
+ super();
+ setServletContext(servletContext);
+ }
+ // --------------------------------------------------------- Public Methods
public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
}
-
// ---------------------------------------------------- HttpSession Methods
-
-
public Object getAttribute(String name) {
return (attributes.get(name));
}
-
public Enumeration getAttributeNames() {
return (new MockEnumeration(attributes.keySet().iterator()));
}
-
public long getCreationTime() {
throw new UnsupportedOperationException();
}
-
public String getId() {
throw new UnsupportedOperationException();
}
-
public long getLastAccessedTime() {
throw new UnsupportedOperationException();
}
-
public int getMaxInactiveInterval() {
throw new UnsupportedOperationException();
}
-
public ServletContext getServletContext() {
return (this.servletContext);
}
-
public HttpSessionContext getSessionContext() {
throw new UnsupportedOperationException();
}
-
public Object getValue(String name) {
throw new UnsupportedOperationException();
}
-
public String[] getValueNames() {
throw new UnsupportedOperationException();
}
-
public void invalidate() {
throw new UnsupportedOperationException();
}
-
public boolean isNew() {
throw new UnsupportedOperationException();
}
-
public void putValue(String name, Object value) {
throw new UnsupportedOperationException();
}
-
public void removeAttribute(String name) {
attributes.remove(name);
}
-
public void removeValue(String name) {
throw new UnsupportedOperationException();
}
-
public void setAttribute(String name, Object value) {
if (value == null) {
attributes.remove(name);
@@ -173,10 +136,7 @@
}
}
-
public void setMaxInactiveInterval(int interval) {
throw new UnsupportedOperationException();
}
-
-
}
Modified: struts/action/trunk/src/java/org/apache/struts/mock/MockPageContext.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/mock/MockPageContext.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/mock/MockPageContext.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/mock/MockPageContext.java Fri Jan 20 16:19:02 2006
@@ -15,18 +15,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.struts.mock;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
@@ -37,13 +27,17 @@
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyContent;
-
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
/**
- * <p>Mock <strong>ServletContext</strong> object for low-level unit tests
- * of Struts controller components. Coarser grained tests should be
- * implemented in terms of the Cactus framework, instead of the mock
- * object classes.</p>
+ * <p>Mock <strong>ServletContext</strong> object for low-level unit tests of
+ * Struts controller components. Coarser grained tests should be implemented
+ * in terms of the Cactus framework, instead of the mock object classes.</p>
*
* <p><strong>WARNING</strong> - Only the minimal set of methods needed to
* create unit tests is provided, plus additional methods to configure this
@@ -53,34 +47,26 @@
* <p><strong>WARNING</strong> - Because unit tests operate in a single
* threaded environment, no synchronization is performed.</p>
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-05-07 12:45:39 -0400 (Sat, 07 May 2005)
+ * $
*/
-
public class MockPageContext extends PageContext {
-
// ----------------------------------------------------- Instance Variables
protected ServletContext application = null;
- protected HashMap attributes = new HashMap(); // Page scope attributes
+ protected HashMap attributes = new HashMap(); // Page scope attributes
protected ServletConfig config = null;
protected ServletRequest request = null;
protected ServletResponse response = null;
protected HttpSession session = null;
-
private boolean throwIOException;
private boolean returnBodyContent;
-
-
-
// ----------------------------------------------------------- Constructors
-
public MockPageContext() {
super();
}
-
- public MockPageContext(ServletConfig config,
- ServletRequest request,
+ public MockPageContext(ServletConfig config, ServletRequest request,
ServletResponse response) {
super();
setValues(config, request, response);
@@ -88,35 +74,38 @@
/**
* Construct a new PageContext impl.
+ *
* @param throwIOException Determines if the returned JspWriter should
* throw an IOException on any method call.
- * @param returnBody Determines if getOut() should return a new
- * <code>JspWriter</code> or a <code>BodyContent</code>.
+ * @param returnBody Determines if getOut() should return a new
+ * <code>JspWriter</code> or a <code>BodyContent</code>.
*/
public MockPageContext(boolean throwIOException, boolean returnBody) {
this.throwIOException = throwIOException;
this.returnBodyContent = returnBody;
}
- private void checkAndThrow() throws IOException {
+
+ private void checkAndThrow()
+ throws IOException {
if (throwIOException) {
throw new IOException();
}
}
// --------------------------------------------------------- Public Methods
-
-
- public void setValues(ServletConfig config,
- ServletRequest request,
+ public void setValues(ServletConfig config, ServletRequest request,
ServletResponse response) {
this.config = config;
+
if (config != null) {
this.application = config.getServletContext();
} else {
this.application = null;
}
+
this.request = request;
this.response = response;
+
if (request != null) {
session = ((HttpServletRequest) request).getSession(false);
} else {
@@ -124,36 +113,33 @@
}
}
-
-
// ---------------------------------------------------- PageContext Methods
-
-
public Object findAttribute(String name) {
Object value = getAttribute(name, PageContext.PAGE_SCOPE);
+
if (value == null) {
value = getAttribute(name, PageContext.REQUEST_SCOPE);
}
+
if (value == null) {
value = getAttribute(name, PageContext.SESSION_SCOPE);
}
+
if (value == null) {
value = getAttribute(name, PageContext.APPLICATION_SCOPE);
}
+
return (value);
}
-
public void forward(String path) {
throw new UnsupportedOperationException();
}
-
public Object getAttribute(String name) {
return (getAttribute(name, PageContext.PAGE_SCOPE));
}
-
public Object getAttribute(String name, int scope) {
if (scope == PageContext.PAGE_SCOPE) {
return (attributes.get(name));
@@ -161,23 +147,25 @@
if (request != null) {
return (request.getAttribute(name));
}
+
return (null);
} else if (scope == PageContext.SESSION_SCOPE) {
if (session != null) {
return (session.getAttribute(name));
}
+
return (null);
} else if (scope == PageContext.APPLICATION_SCOPE) {
if (application != null) {
return (application.getAttribute(name));
}
+
return (null);
} else {
throw new IllegalArgumentException("Invalid scope " + scope);
}
}
-
public Enumeration getAttributeNamesInScope(int scope) {
if (scope == PageContext.PAGE_SCOPE) {
return (new MockEnumeration(attributes.keySet().iterator()));
@@ -185,196 +173,389 @@
if (request != null) {
return (request.getAttributeNames());
}
+
return (new MockEnumeration(Collections.EMPTY_LIST.iterator()));
} else if (scope == PageContext.SESSION_SCOPE) {
if (session != null) {
return (session.getAttributeNames());
}
+
return (new MockEnumeration(Collections.EMPTY_LIST.iterator()));
} else if (scope == PageContext.APPLICATION_SCOPE) {
if (application != null) {
return (application.getAttributeNames());
}
+
return new MockEnumeration(Collections.EMPTY_LIST.iterator());
} else {
throw new IllegalArgumentException("Invalid scope " + scope);
}
}
-
public int getAttributesScope(String name) {
if (attributes.get(name) != null) {
return (PageContext.PAGE_SCOPE);
- } else if ((request != null) &&
- (request.getAttribute(name) != null)) {
+ } else
+ if ((request != null) && (request.getAttribute(name) != null)) {
return (PageContext.REQUEST_SCOPE);
- } else if ((session != null) &&
- (session.getAttribute(name) != null)) {
+ } else
+ if ((session != null) && (session.getAttribute(name) != null)) {
return (PageContext.SESSION_SCOPE);
- } else if ((application != null) &&
- (application.getAttribute(name) != null)) {
+ } else if ((application != null)
+ && (application.getAttribute(name) != null)) {
return (PageContext.APPLICATION_SCOPE);
} else {
return (0);
}
}
-
public Exception getException() {
throw new UnsupportedOperationException();
}
-
/**
- * Custom JspWriter that throws the specified exception
- * (supplied on the constructor...if any), else it simply
- * returns.
+ * Custom JspWriter that throws the specified exception (supplied on the
+ * constructor...if any), else it simply returns.
*/
public JspWriter getOut() {
- JspWriter jspWriter = new JspWriter(0, false) {
- public void print(String s) throws IOException {
- checkAndThrow();
- }
- public void newLine() throws IOException {checkAndThrow();}
- public void print(boolean b) throws IOException {checkAndThrow();}
- public void print(char c) throws IOException {checkAndThrow();}
- public void print(int i) throws IOException {checkAndThrow();}
- public void print(long l) throws IOException {checkAndThrow();}
- public void print(float f) throws IOException {checkAndThrow();}
- public void print(double d) throws IOException {checkAndThrow();}
- public void print(char[] s) throws IOException {checkAndThrow();}
- public void print(Object obj) throws IOException {checkAndThrow();}
- public void println() throws IOException {checkAndThrow();}
- public void println(boolean x) throws IOException {checkAndThrow();}
- public void println(char x) throws IOException {checkAndThrow();}
- public void println(int x) throws IOException {checkAndThrow();}
- public void println(long x) throws IOException {checkAndThrow();}
- public void println(float x) throws IOException {checkAndThrow();}
- public void println(double x) throws IOException {checkAndThrow();}
- public void println(char[] x) throws IOException {checkAndThrow();}
- public void println(String x) throws IOException {checkAndThrow();}
- public void println(Object x) throws IOException {checkAndThrow();}
- public void clear() throws IOException {checkAndThrow();}
- public void clearBuffer() throws IOException {checkAndThrow();}
- public void flush() throws IOException {checkAndThrow();}
- public void close() throws IOException {checkAndThrow();}
- public int getRemaining() {return 0;}
- public void write(char[] cbuf, int off, int len) throws IOException {checkAndThrow();}
-
- };
- if (returnBodyContent)
- return new BodyContent(jspWriter) {
- public Reader getReader() {return null;}
- public String getString() {return null;}
- public void writeOut(Writer out) throws IOException {checkAndThrow();}
- public void newLine() throws IOException {checkAndThrow();}
- public void print(boolean b) throws IOException {checkAndThrow();}
- public void print(char c) throws IOException {checkAndThrow();}
- public void print(int i) throws IOException {checkAndThrow();}
- public void print(long l) throws IOException {checkAndThrow();}
- public void print(float f) throws IOException {checkAndThrow();}
- public void print(double d) throws IOException {checkAndThrow();}
- public void print(char[] s) throws IOException {checkAndThrow();}
- public void print(String s) throws IOException {checkAndThrow();}
- public void print(Object obj) throws IOException {checkAndThrow();}
- public void println() throws IOException {checkAndThrow();}
- public void println(boolean x) throws IOException {checkAndThrow();}
- public void println(char x) throws IOException {checkAndThrow();}
- public void println(int x) throws IOException {checkAndThrow();}
- public void println(long x) throws IOException {checkAndThrow();}
- public void println(float x) throws IOException {checkAndThrow();}
- public void println(double x) throws IOException {checkAndThrow();}
- public void println(char[] x) throws IOException {checkAndThrow();}
- public void println(String x) throws IOException {checkAndThrow();}
- public void println(Object x) throws IOException {checkAndThrow();}
- public void clear() throws IOException {checkAndThrow();}
- public void clearBuffer() throws IOException {checkAndThrow();}
- public void close() throws IOException {checkAndThrow();}
- public int getRemaining() {return 0;}
- public void write(char[] cbuf, int off, int len) throws IOException {checkAndThrow();}
+ JspWriter jspWriter = new JspWriter(0, false) {
+ public void print(String s)
+ throws IOException {
+ checkAndThrow();
+ }
- };
- return jspWriter;
- }
+ public void newLine()
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void print(boolean b)
+ throws IOException {
+ checkAndThrow();
+ }
+ public void print(char c)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void print(int i)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void print(long l)
+ throws IOException {
+ checkAndThrow();
+ }
+ public void print(float f)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void print(double d)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void print(char[] s)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void print(Object obj)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println()
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println(boolean x)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println(char x)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println(int x)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println(long x)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println(float x)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println(double x)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println(char[] x)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println(String x)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println(Object x)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void clear()
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void clearBuffer()
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void flush()
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void close()
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public int getRemaining() {
+ return 0;
+ }
+
+ public void write(char[] cbuf, int off, int len)
+ throws IOException {
+ checkAndThrow();
+ }
+ };
+
+ if (returnBodyContent) {
+ return new BodyContent(jspWriter) {
+ public Reader getReader() {
+ return null;
+ }
+
+ public String getString() {
+ return null;
+ }
+
+ public void writeOut(Writer out)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void newLine()
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void print(boolean b)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void print(char c)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void print(int i)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void print(long l)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void print(float f)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void print(double d)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void print(char[] s)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void print(String s)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void print(Object obj)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println()
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println(boolean x)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println(char x)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println(int x)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println(long x)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println(float x)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println(double x)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println(char[] x)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println(String x)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void println(Object x)
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void clear()
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void clearBuffer()
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public void close()
+ throws IOException {
+ checkAndThrow();
+ }
+
+ public int getRemaining() {
+ return 0;
+ }
+
+ public void write(char[] cbuf, int off, int len)
+ throws IOException {
+ checkAndThrow();
+ }
+ };
+ }
+
+ return jspWriter;
+ }
public Object getPage() {
throw new UnsupportedOperationException();
}
-
public ServletRequest getRequest() {
return (this.request);
}
-
public ServletResponse getResponse() {
return (this.response);
}
-
public ServletConfig getServletConfig() {
return (this.config);
}
-
public ServletContext getServletContext() {
return (this.application);
}
-
public HttpSession getSession() {
return (this.session);
}
-
public void handlePageException(Exception e) {
throw new UnsupportedOperationException();
}
-
public void handlePageException(Throwable t) {
throw new UnsupportedOperationException();
}
-
public void include(String path) {
throw new UnsupportedOperationException();
}
-
public void initialize(Servlet servlet, ServletRequest request,
ServletResponse response, String errorPageURL,
- boolean needsSession, int bufferSize,
- boolean autoFlush) {
+ boolean needsSession,
+ int bufferSize, boolean autoFlush) {
throw new UnsupportedOperationException();
}
-
public JspWriter popBody() {
throw new UnsupportedOperationException();
}
-
public BodyContent pushBody() {
throw new UnsupportedOperationException();
}
-
public void release() {
throw new UnsupportedOperationException();
}
-
public void removeAttribute(String name) {
int scope = getAttributesScope(name);
+
if (scope != 0) {
removeAttribute(name, scope);
}
}
-
public void removeAttribute(String name, int scope) {
if (scope == PageContext.PAGE_SCOPE) {
attributes.remove(name);
@@ -395,12 +576,10 @@
}
}
-
public void setAttribute(String name, Object value) {
setAttribute(name, value, PageContext.PAGE_SCOPE);
}
-
public void setAttribute(String name, Object value, int scope) {
if (scope == PageContext.PAGE_SCOPE) {
attributes.put(name, value);
@@ -420,6 +599,4 @@
throw new IllegalArgumentException("Invalid scope " + scope);
}
}
-
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org