Author: pbenedict
Date: Tue Nov 25 14:33:33 2008
New Revision: 720628
URL: http://svn.apache.org/viewvc?rev=720628&view=rev
Log:
STR-3168: Introduce new dispatcher package
Added:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractDispatcher.java
(with props)
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractMappingDispatcher.java
(with props)
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractParameterDispatcher.java
(with props)
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/Dispatcher.java
(contents, props changed)
- copied, changed from r718127,
struts/struts1/trunk/core/src/main/java/org/apache/struts/action/Dispatcher.java
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletDispatchUtils.java
(with props)
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletMappingDispatcher.java
(with props)
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletParameterDispatcher.java
(with props)
Removed:
struts/struts1/trunk/core/src/main/java/org/apache/struts/action/Dispatcher.java
Modified:
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/Constants.java
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/ExecuteDispatcher.java
struts/struts1/trunk/core/src/main/java/org/apache/struts/config/ActionConfig.java
struts/struts1/trunk/extras/src/main/java/org/apache/struts/actions/ActionDispatcher.java
Modified:
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/Constants.java
URL:
http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/Constants.java?rev=720628&r1=720627&r2=720628&view=diff
==============================================================================
---
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/Constants.java
(original)
+++
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/Constants.java
Tue Nov 25 14:33:33 2008
@@ -20,7 +20,7 @@
*/
package org.apache.struts.chain;
-import org.apache.struts.action.Dispatcher;
+import org.apache.struts.dispatcher.Dispatcher;
/**
Modified:
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/ExecuteDispatcher.java
URL:
http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/ExecuteDispatcher.java?rev=720628&r1=720627&r2=720628&view=diff
==============================================================================
---
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/ExecuteDispatcher.java
(original)
+++
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/ExecuteDispatcher.java
Tue Nov 25 14:33:33 2008
@@ -22,12 +22,12 @@
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionMapping;
-import org.apache.struts.action.Dispatcher;
import org.apache.struts.chain.Constants;
import org.apache.struts.chain.commands.util.ClassUtils;
import org.apache.struts.chain.contexts.ActionContext;
import org.apache.struts.config.ActionConfig;
import org.apache.struts.config.ForwardConfig;
+import org.apache.struts.dispatcher.Dispatcher;
import java.util.HashMap;
import java.util.Map;
@@ -89,7 +89,7 @@
}
// Dispatch
- Object result = dispatcher.dispatchAction(context);
+ Object result = dispatcher.dispatch(context);
processDispatchResult(result, context);
return CONTINUE_PROCESSING;
}
Modified:
struts/struts1/trunk/core/src/main/java/org/apache/struts/config/ActionConfig.java
URL:
http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/config/ActionConfig.java?rev=720628&r1=720627&r2=720628&view=diff
==============================================================================
---
struts/struts1/trunk/core/src/main/java/org/apache/struts/config/ActionConfig.java
(original)
+++
struts/struts1/trunk/core/src/main/java/org/apache/struts/config/ActionConfig.java
Tue Nov 25 14:33:33 2008
@@ -252,7 +252,7 @@
protected String catalog = null;
/**
- * The name of the [EMAIL PROTECTED] org.apache.struts.action.Dispatcher}
implementation
+ * The name of the [EMAIL PROTECTED]
org.apache.struts.dispatcher.Dispatcher} implementation
* that will dispatch to the end point of this action.
*
* @since Struts 1.4
@@ -889,7 +889,7 @@
/**
* Retrieves the fully-qualified class name of the
- * [EMAIL PROTECTED] org.apache.struts.action.Dispatcher} implementation
that will
+ * [EMAIL PROTECTED] org.apache.struts.dispatcher.Dispatcher}
implementation that will
* dispatch to the this action.
*
* @return the dispatcher class name or <code>null</code>
@@ -902,7 +902,7 @@
/**
* Stores the fully-qualified class name of the
- * [EMAIL PROTECTED] org.apache.struts.action.Dispatcher} implementation
that will
+ * [EMAIL PROTECTED] org.apache.struts.dispatcher.Dispatcher}
implementation that will
* dispatch to the this action.
*
* @param dispatcher the dispatcher class name
Added:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractDispatcher.java
URL:
http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractDispatcher.java?rev=720628&view=auto
==============================================================================
---
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractDispatcher.java
(added)
+++
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractDispatcher.java
Tue Nov 25 14:33:33 2008
@@ -0,0 +1,302 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.dispatcher;
+
+import org.apache.struts.Globals;
+import org.apache.struts.action.Action;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.chain.contexts.ActionContext;
+import org.apache.struts.config.ActionConfig;
+import org.apache.struts.util.MessageResources;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * TODO
+ *
+ * @version $Rev$
+ * @since Struts 1.4
+ */
+public abstract class AbstractDispatcher implements Dispatcher {
+
+ // Package constants
+ static final String KEY_DISPATCH_ERROR = "dispatch.error";
+ static final String KEY_MISSING_METHOD = "dispatch.method.user";
+ static final String KEY_MISSING_HANDLER_PROPERTY = "dispatch.handler";
+ static final String KEY_WRONG_RETURN_TYPE = "dispatch.return";
+ static final String KEY_MISSING_NAMED_METHOD = "dispatch.method";
+ static final String KEY_MISSING_PARAMETER = "dispatch.parameter";
+ static final String KEY_RECURSIVE_DISPATCH = "dispatch.recursive";
+ static final String LOCAL_STRINGS =
"org.apache.struts.actions.LocalStrings";
+
+ /**
+ * The name of the <code>cancelled</code> method.
+ *
+ * @see #cancelled(ActionContext)
+ * @see ActionContext#getCancelled()
+ */
+ public static final String CANCELLED_METHOD_NAME = "cancelled";
+
+ /**
+ * The name of the <code>unspecified</code> method.
+ *
+ * @see #unspecified(ActionContext)
+ */
+ public static final String UNSPECIFIED_METHOD_NAME = "unspecified";
+
+ /**
+ * The message resources for this package.
+ */
+ static MessageResources messages =
MessageResources.getMessageResources(LOCAL_STRINGS);
+
+ /**
+ * Commons Logging instance.
+ */
+ protected final Log log;
+
+ /**
+ * The dictionary of [EMAIL PROTECTED] Method} objects we have
introspected for this
+ * class, keyed by method name. This collection is populated as different
+ * methods are called, so that introspection needs to occur only once per
+ * method name.
+ */
+ private final HashMap methods;
+
+ /**
+ * Construct an instance of this class from the supplied parameters.
+ *
+ * @param actionInstance the action instance to be invoked
+ * @see #ActionDispatcher(Action, int)
+ */
+ public AbstractDispatcher() {
+ log = LogFactory.getLog(getClass());
+ methods = new HashMap();
+ }
+
+ protected Object cancelled(ActionContext context) throws Exception {
+ Method method = getMethod(context, CANCELLED_METHOD_NAME);
+ return dispatchMethod(context, method, CANCELLED_METHOD_NAME);
+ }
+
+ public Object dispatch(ActionContext context) throws Exception {
+ // Process cancelled requests
+ if (isCancelled(context)) {
+ try {
+ return cancelled(context);
+ } catch (NoSuchMethodException e) {
+ // expected and ignore
+ }
+ }
+
+ // Ensure there is a valid method name to call.
+ // This may be null if the user hacks the query string.
+ String methodName = resolveMethodName(context);
+ if (methodName == null) {
+ return unspecified(context);
+ }
+
+ // Identify the method object to be dispatched to
+ Method method;
+ try {
+ method = getMethod(context, methodName);
+ } catch (NoSuchMethodException e) {
+ String path = context.getActionConfig().getPath();
+ String message = messages.getMessage(KEY_MISSING_NAMED_METHOD,
path, methodName);
+ log.error(message, e);
+
+ String userMsg = messages.getMessage(KEY_MISSING_METHOD, path);
+ NoSuchMethodException e2 = new NoSuchMethodException(userMsg);
+ e2.initCause(e);
+ throw e2;
+ }
+
+ // Invoke the named method and return its result
+ return dispatchMethod(context, method, methodName);
+ }
+
+ /**
+ * Dispatch to the specified method.
+ *
+ * @param method The method to invoke
+ * @param name The name of the method to invoke
+ * @param mapping The ActionMapping used to select this instance
+ * @param form The optional ActionForm bean for this request (if any)
+ * @param request The non-HTTP request we are processing
+ * @param response The non-HTTP response we are creating
+ *
+ * @return The forward to which control should be transferred, or
+ * <code>null</code> if the response has been completed.
+ * @throws Exception if the application business logic throws an exception.
+ * @see #dispatchMethod(ActionMapping, ActionForm, HttpServletRequest,
+ * HttpServletResponse, String)
+ */
+ protected abstract Object dispatchMethod(ActionContext context, Method
method, String name) throws Exception;
+
+ /**
+ * Retrieves the name of the method to fallback upon if no value can be
+ * obtained from the parameter. The default implementation returns
+ * [EMAIL PROTECTED] #UNSPECIFIED_METHOD_NAME}.
+ *
+ * @return the fallback method name; can be <code>null</code>
+ * @see #UNSPECIFIED_METHOD_NAME
+ */
+ protected String getFallbackMethodName() {
+ return UNSPECIFIED_METHOD_NAME;
+ }
+
+ /**
+ * Introspect the action to identify a method of the specified name that
+ * will receive the invocation of this dispatch. This implementation caches
+ * the method instance for subsequent invocations.
+ *
+ * @param methodName the name of the method to be introspected
+ * @return the method of the specified name
+ * @throws NoSuchMethodException if no such method can be found
+ * @see #resolveMethod(ActionContext, String)
+ */
+ protected final Method getMethod(ActionContext context, String methodName)
throws NoSuchMethodException {
+ synchronized (methods) {
+ String key = context.getAction().getClass().getName() + ":" +
methodName;
+ Method method = (Method) methods.get(key);
+
+ if (method == null) {
+ method = resolveMethod(methodName, context);
+ methods.put(key, method);
+ }
+
+ return method;
+ }
+ }
+
+ protected final Object invoke(Object target, Method method, Object[] args,
String path, String name)
+ throws Exception {
+ try {
+ return method.invoke(target, args);
+ } catch (IllegalAccessException e) {
+ String message = messages.getMessage(KEY_DISPATCH_ERROR, path,
name);
+ log.error(message, e);
+ throw e;
+ } catch (InvocationTargetException e) {
+ // Rethrow the target exception if possible so that the
+ // exception handling machinery can deal with it
+ Throwable t = e.getTargetException();
+ if (t instanceof Exception) {
+ throw ((Exception) t);
+ } else {
+ String message = messages.getMessage(KEY_DISPATCH_ERROR, path,
name);
+ log.error(message, e);
+ throw new ServletException(t);
+ }
+ }
+ }
+
+ /**
+ * Determines whether the current form's cancel button was pressed. This
+ * method will check if the [EMAIL PROTECTED] Globals#CANCEL_KEY} request
attribute has
+ * been set, which normally occurs if the cancel button generated by
+ * <strong>CancelTag</strong> was pressed by the user in the current
+ * request. If <code>true</code>, validation performed by the
+ * <code>validate()</code> method of the form; otherwise it will have been
+ * skipped by the controller servlet.
+ *
+ * @param context the current action context
+ * @return <code>true</code> if the cancel button was pressed;
+ * <code>false</code> otherwise
+ * @see org.apache.struts.taglib.html.CancelTag
+ */
+ protected boolean isCancelled(ActionContext context) {
+ Boolean cancelled = context.getCancelled();
+ return (cancelled != null) && cancelled.booleanValue();
+ }
+
+ /**
+ * Decides the appropriate method instance for the specified method name.
+ * Implementations may introspect for any desired method signature. The
+ * resolution is only needed if [EMAIL PROTECTED] #getMethod(String)} does
not find a
+ * match in its method cache.
+ *
+ * @param methodName the method name to use for introspection
+ * @param context the current action context
+ * @return the method to invoke
+ * @throws NoSuchMethodException if an appropriate method cannot be found
+ * @see #getMethod(String)
+ * @see #invoke(Object, Method, Object[], String, String)
+ */
+ protected abstract Method resolveMethod(String methodName, ActionContext
context) throws NoSuchMethodException;
+
+ /**
+ * Decides the method name that can handle the request.
+ *
+ * @param context the current action context
+ * @return the method name or <code>null</code> if no name can be resolved
+ */
+ protected abstract String resolveMethodName(ActionContext context);
+
+ /**
+ * Invoked when a method cannot be resolved. The default behavior delegates
+ * to the fallback method, if specified; otherwise throw an
+ * [EMAIL PROTECTED] IllegalStateException}. Subclasses should override
this to
+ * provide custom handling such as sending an HTTP 404 error.
+ *
+ * @param context the current action context
+ * @throws NoSuchMethodException if the fallback method name is specified
+ * but the corresponding method does not exist
+ * @throws IllegalStateException always unless supressed by subclass
+ * @see #getFallbackMethodName()
+ */
+ protected Object unspecified(ActionContext context) throws Exception {
+ // Is the fallback method present?
+ Method method = null;
+ String name = getFallbackMethodName();
+ if (name != null) {
+ try {
+ method = getMethod(context, name);
+ } catch (NoSuchMethodException e) {
+ String msg = messages.getMessage(KEY_MISSING_METHOD, name);
+ NoSuchMethodException e2 = new NoSuchMethodException(msg);
+ e2.initCause(e);
+ throw e2;
+ }
+ }
+
+ // Dispatch if fallback is available
+ if (method != null) {
+ return dispatchMethod(context, method, name);
+ }
+
+ // Otherwise the dispatch has failed
+ ActionConfig config = context.getActionConfig();
+ String msg = messages.getMessage(KEY_MISSING_PARAMETER,
config.getPath(), config.getParameter());
+ log.error(msg);
+ throw new IllegalStateException(msg);
+ }
+
+}
Propchange:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractDispatcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractDispatcher.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractMappingDispatcher.java
URL:
http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractMappingDispatcher.java?rev=720628&view=auto
==============================================================================
---
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractMappingDispatcher.java
(added)
+++
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractMappingDispatcher.java
Tue Nov 25 14:33:33 2008
@@ -0,0 +1,54 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.dispatcher;
+
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.chain.contexts.ActionContext;
+
+/**
+ * <p>
+ * This abstract class is a template for choosing the target method based on
the
+ * <code>parameter</code> attribute of the [EMAIL PROTECTED] ActionMapping}.
+ * </p>
+ *
+ * @version $Rev$
+ * @since Struts 1.4
+ */
+public abstract class AbstractMappingDispatcher extends AbstractDispatcher {
+
+ protected String resolveMethodName(ActionContext context) {
+ // Null out an empty string parameter
+ ActionMapping mapping = (ActionMapping) context.getActionConfig();
+ String parameter = mapping.getParameter();
+ if ("".equals(parameter)) {
+ parameter = null;
+ }
+
+ if ((parameter == null)) {
+ String message = messages.getMessage(KEY_MISSING_HANDLER_PROPERTY,
mapping.getPath());
+ log.error(message);
+ throw new IllegalStateException(message);
+ }
+
+ return parameter;
+ }
+
+}
Propchange:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractMappingDispatcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractMappingDispatcher.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractParameterDispatcher.java
URL:
http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractParameterDispatcher.java?rev=720628&view=auto
==============================================================================
---
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractParameterDispatcher.java
(added)
+++
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractParameterDispatcher.java
Tue Nov 25 14:33:33 2008
@@ -0,0 +1,107 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.dispatcher;
+
+import org.apache.struts.chain.contexts.ActionContext;
+
+/**
+ * <p>
+ * This abstract class is a template for choosing the target method based on a
+ * servlet request parameter. It is based upon the functionality of
+ * <code>org.apache.struts.actions.DispatchAction</code>.
+ * </p>
+ * <p>
+ * To configure the use of this dispatcher in your configuration, create an
+ * entry like below. The dispatcher will use the value of the request parameter
+ * named "method" (or whatever specified) to pick the appropriate method on the
+ * action.
+ * </p>
+ *
+ * <code>
+ * <action path="/saveSubscription"
+ *
dispatcher="org.apache.struts.dispatcher.servlet.ServletParameterDispatcher"
+ * name="subscriptionForm"
+ * scope="request"
+ * input="/subscription.jsp"
+ * parameter="method"/>
+ * </code>
+ * <p>
+ *
+ * @version $Rev$
+ * @since Struts 1.4
+ */
+public abstract class AbstractParameterDispatcher extends AbstractDispatcher {
+
+ /**
+ * The default parameter name if no parameter is set.
+ *
+ * @see #getDefaultParameterName()
+ */
+ protected static final String DEFAULT_PARAMETER_NAME = "method";
+
+ /**
+ * Retrieves the name of the parameter to fallback upon if the action
+ * configuration did not set the <code>parameter</code> attribute. The
+ * default implementation returns [EMAIL PROTECTED]
#DEFAULT_PARAMETER_NAME}.
+ *
+ * @return the fallback parameter name; can be <code>null</code>
+ * @see #DEFAULT_PARAMETER_NAME
+ * @see #getParameter(ActionContext)
+ */
+ protected String getDefaultParameterName() {
+ return DEFAULT_PARAMETER_NAME;
+ }
+
+ /**
+ * Retrieves the parameter name whose value will identity the intended
+ * method to dispatch. The value is not necessarily a method name, but a
key
+ * that can resolve to one. The default implementation returns the
mapping's
+ * <code>parameter</code> attribute; otherwise fallback to the default
+ * parameter name.
+ *
+ * @param context the action context
+ * @return the mapping's parameter name
+ * @see #getDefaultParameterName()
+ */
+ protected String getParameter(ActionContext context) {
+ String parameter = context.getActionConfig().getParameter();
+ if ((parameter != null) && (parameter.trim().length() > 0)) {
+ return parameter;
+ }
+ return getDefaultParameterName();
+ }
+
+ protected final String resolveMethodName(ActionContext context) {
+ String parameter = getParameter(context);
+ if ("".equals(parameter)) {
+ parameter = null;
+ }
+
+ if (parameter != null) {
+ return resolveParameterValue(context, parameter);
+ }
+
+ return null;
+ }
+
+ protected abstract String resolveParameterValue(ActionContext context,
String parameter);
+
+}
Propchange:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractParameterDispatcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/AbstractParameterDispatcher.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Copied:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/Dispatcher.java
(from r718127,
struts/struts1/trunk/core/src/main/java/org/apache/struts/action/Dispatcher.java)
URL:
http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/Dispatcher.java?p2=struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/Dispatcher.java&p1=struts/struts1/trunk/core/src/main/java/org/apache/struts/action/Dispatcher.java&r1=718127&r2=720628&rev=720628&view=diff
==============================================================================
---
struts/struts1/trunk/core/src/main/java/org/apache/struts/action/Dispatcher.java
(original)
+++
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/Dispatcher.java
Tue Nov 25 14:33:33 2008
@@ -18,15 +18,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.struts.action;
+package org.apache.struts.dispatcher;
+import org.apache.struts.action.Action;
import org.apache.struts.chain.contexts.ActionContext;
/**
* This interface defines an intermediate handler that determines what method
to
- * execute in an [EMAIL PROTECTED] Action}. Unlike the classical execute
signature, it is
- * up to the implementation to determine the particular arguments and return
- * type.
+ * execute in an [EMAIL PROTECTED] Action}. Unlike the classical
<code>execute</code>
+ * signature, it is up to the dispatcher implementation to determine the
+ * particular arguments and return type.
*
* @version $Rev$
* @since Struts 1.4
@@ -42,6 +43,6 @@
* signature
* @throws Exception if an exception occurs
*/
- Object dispatchAction(ActionContext context) throws Exception;
+ Object dispatch(ActionContext context) throws Exception;
}
Propchange:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/Dispatcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/Dispatcher.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/Dispatcher.java
------------------------------------------------------------------------------
svn:mergeinfo =
Added:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletDispatchUtils.java
URL:
http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletDispatchUtils.java?rev=720628&view=auto
==============================================================================
---
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletDispatchUtils.java
(added)
+++
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletDispatchUtils.java
Tue Nov 25 14:33:33 2008
@@ -0,0 +1,67 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.dispatcher.servlet;
+
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.chain.contexts.ActionContext;
+import org.apache.struts.chain.contexts.ServletActionContext;
+import org.apache.struts.config.ActionConfig;
+
+import java.lang.reflect.Method;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+final class ServletDispatchUtils {
+
+ /**
+ * The set of argument type classes for the reflected method call. These
are
+ * the same for all calls, so calculate them only once.
+ *
+ * @see org.apache.struts.action.Action#execute(ActionMapping, ActionForm,
+ * javax.servlet.ServletRequest, javax.servlet.ServletResponse)
+ */
+ public static final Class[] SERVLET_EXECUTE_SIGNATURE = {
ActionMapping.class, ActionForm.class,
+ HttpServletRequest.class, HttpServletResponse.class };
+
+ public static Object[] buildClassicExecuteArguments(ServletActionContext
context) throws Exception {
+ ActionConfig mapping = context.getActionConfig();
+ ActionForm form = context.getActionForm();
+ HttpServletRequest request = context.getRequest();
+ HttpServletResponse response = context.getResponse();
+ return new Object[] { mapping, form, request, response };
+ }
+
+ /**
+ * Obtains the method instance with the classic <code>execute</code>
+ * servlet signature.
+ *
+ * @return [EMAIL PROTECTED]
+ * @throws [EMAIL PROTECTED]
+ * @see #SERVLET_EXECUTE_SIGNATURE
+ */
+ public static Method resolveClassicExecuteMethod(ActionContext context,
String name) throws NoSuchMethodException {
+ Class actionClass = context.getAction().getClass();
+ return actionClass.getMethod(name, SERVLET_EXECUTE_SIGNATURE);
+ }
+
+}
Propchange:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletDispatchUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletDispatchUtils.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletMappingDispatcher.java
URL:
http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletMappingDispatcher.java?rev=720628&view=auto
==============================================================================
---
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletMappingDispatcher.java
(added)
+++
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletMappingDispatcher.java
Tue Nov 25 14:33:33 2008
@@ -0,0 +1,43 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.dispatcher.servlet;
+
+import org.apache.struts.action.Action;
+import org.apache.struts.chain.contexts.ActionContext;
+import org.apache.struts.chain.contexts.ServletActionContext;
+import org.apache.struts.dispatcher.AbstractMappingDispatcher;
+
+import java.lang.reflect.Method;
+
+public class ServletMappingDispatcher extends AbstractMappingDispatcher {
+
+ protected Object dispatchMethod(ActionContext context, Method method,
String name) throws Exception {
+ Action target = context.getAction();
+ Object[] args =
ServletDispatchUtils.buildClassicExecuteArguments((ServletActionContext)
context);
+ String path = context.getActionConfig().getPath();
+ return invoke(target, method, args, path, name);
+ }
+
+ protected Method resolveMethod(String methodName, ActionContext context)
throws NoSuchMethodException {
+ return ServletDispatchUtils.resolveClassicExecuteMethod(context,
methodName);
+ }
+
+}
Propchange:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletMappingDispatcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletMappingDispatcher.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletParameterDispatcher.java
URL:
http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletParameterDispatcher.java?rev=720628&view=auto
==============================================================================
---
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletParameterDispatcher.java
(added)
+++
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletParameterDispatcher.java
Tue Nov 25 14:33:33 2008
@@ -0,0 +1,48 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.dispatcher.servlet;
+
+import org.apache.struts.action.Action;
+import org.apache.struts.chain.contexts.ActionContext;
+import org.apache.struts.chain.contexts.ServletActionContext;
+import org.apache.struts.dispatcher.AbstractParameterDispatcher;
+
+import java.lang.reflect.Method;
+
+public class ServletParameterDispatcher extends AbstractParameterDispatcher {
+
+ protected Object dispatchMethod(ActionContext context, Method method,
String name) throws Exception {
+ Action target = context.getAction();
+ Object[] args =
ServletDispatchUtils.buildClassicExecuteArguments((ServletActionContext)
context);
+ String path = context.getActionConfig().getPath();
+ return invoke(target, method, args, path, name);
+ }
+
+ protected Method resolveMethod(String methodName, ActionContext context)
throws NoSuchMethodException {
+ return ServletDispatchUtils.resolveClassicExecuteMethod(context,
methodName);
+ }
+
+ protected String resolveParameterValue(ActionContext context, String
parameter) {
+ ServletActionContext servletContext = (ServletActionContext) context;
+ return (String) servletContext.getParam().get(parameter);
+ }
+
+}
Propchange:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletParameterDispatcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
struts/struts1/trunk/core/src/main/java/org/apache/struts/dispatcher/servlet/ServletParameterDispatcher.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified:
struts/struts1/trunk/extras/src/main/java/org/apache/struts/actions/ActionDispatcher.java
URL:
http://svn.apache.org/viewvc/struts/struts1/trunk/extras/src/main/java/org/apache/struts/actions/ActionDispatcher.java?rev=720628&r1=720627&r2=720628&view=diff
==============================================================================
---
struts/struts1/trunk/extras/src/main/java/org/apache/struts/actions/ActionDispatcher.java
(original)
+++
struts/struts1/trunk/extras/src/main/java/org/apache/struts/actions/ActionDispatcher.java
Tue Nov 25 14:33:33 2008
@@ -27,9 +27,9 @@
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
-import org.apache.struts.action.Dispatcher;
import org.apache.struts.chain.contexts.ActionContext;
import org.apache.struts.chain.contexts.ServletActionContext;
+import org.apache.struts.dispatcher.Dispatcher;
import org.apache.struts.util.MessageResources;
import javax.servlet.ServletException;
@@ -504,7 +504,7 @@
/**
* @since Struts 1.4
*/
- public Object dispatchAction(ActionContext context) throws Exception {
+ public Object dispatch(ActionContext context) throws Exception {
ServletActionContext servletContext = (ServletActionContext) context;
return execute((ActionMapping) context.getActionConfig(),
context.getActionForm(),
servletContext.getRequest(), servletContext.getResponse());