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.navigable;
16:
17: import java.lang.reflect.Method;
18:
19: import org.apache.struts.action.ActionMapping;
20: import org.strecks.action.NavigableDispatchAction;
21: import org.strecks.context.ActionContext;
22: import org.strecks.controller.annotation.ActionInterface;
23: import org.strecks.dispatch.internal.DispatchControllerHelper;
24: import org.strecks.navigate.annotation.ReadNavigation;
25: import org.strecks.util.ReflectHelper;
26: import org.strecks.view.ViewAdapter;
27:
28: /**
29: * Read-only action controller which mimics the behaviour of <code>DispatchAction</code>
30: * @see org.apache.struts.actions.DispatchAction
31: * @author Phil Zoio
32: */
33: @ActionInterface(name=NavigableDispatchAction.class)
34: @ReadNavigation
35: public class NavigableDispatchController extends NavigableController {
36:
37: private DispatchControllerHelper helper;
38:
39: public NavigableDispatchController() {
40: super ();
41: helper = new DispatchControllerHelper();
42: }
43:
44: @Override
45: protected ViewAdapter executeAction(Object actionBean,
46: ActionContext context) {
47:
48: NavigableDispatchAction action = (NavigableDispatchAction) actionBean;
49: ActionMapping mapping = context.getMapping();
50: String parameterName = mapping.getParameter();
51:
52: helper.checkParameterName(mapping, parameterName);
53:
54: String methodName = getMethodName(context, parameterName);
55:
56: if (methodName == null) {
57: action.unspecified();
58: } else {
59: Method method = helper.getMethod(action, methodName);
60: ReflectHelper.invokeMethod(action, method, String.class);
61: }
62:
63: return findActionForward(actionBean, context);
64:
65: }
66:
67: public String getMethodName(ActionContext context,
68: String parameterName) {
69: String methodName = context.getRequest().getParameter(
70: parameterName);
71: return methodName;
72: }
73:
74: }
|