01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.action.basic;
16:
17: import java.lang.reflect.Method;
18:
19: import org.apache.struts.action.ActionMapping;
20: import org.strecks.action.BasicDispatchAction;
21: import org.strecks.context.ActionContext;
22: import org.strecks.controller.annotation.ActionInterface;
23: import org.strecks.dispatch.internal.DispatchControllerHelper;
24: import org.strecks.util.ReflectHelper;
25: import org.strecks.view.ViewAdapter;
26:
27: /**
28: * Read-only action controller which mimics the behaviour of <code>DispatchAction</code>
29: * @see org.apache.struts.actions.DispatchAction
30: * @author Phil Zoio
31: */
32: @ActionInterface(name=BasicDispatchAction.class)
33: public class BasicDispatchController extends BaseBasicController {
34:
35: private DispatchControllerHelper helper;
36:
37: public BasicDispatchController() {
38: super ();
39: helper = new DispatchControllerHelper();
40: }
41:
42: @Override
43: protected ViewAdapter executeAction(Object actionBean,
44: ActionContext context) {
45:
46: BasicDispatchAction action = (BasicDispatchAction) actionBean;
47: ActionMapping mapping = context.getMapping();
48: String parameterName = mapping.getParameter();
49:
50: helper.checkParameterName(mapping, parameterName);
51:
52: String methodName = getMethodName(context, parameterName);
53: String result = null;
54: if (methodName == null) {
55: result = action.unspecified();
56: } else {
57: Method method = helper.getMethod(action, methodName);
58: result = ReflectHelper.invokeMethod(action, method,
59: String.class);
60: }
61:
62: return getActionForward(context, result);
63:
64: }
65:
66: protected DispatchControllerHelper getHelper() {
67: return helper;
68: }
69:
70: protected String getMethodName(ActionContext context,
71: String parameterName) {
72: String methodName = context.getRequest().getParameter(
73: parameterName);
74: return methodName;
75: }
76:
77: }
|