01: // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
02:
03: package jodd.madvoc;
04:
05: import jodd.introspector.DefaultIntrospector;
06: import jodd.madvoc.interceptor.ActionInterceptor;
07:
08: import java.lang.reflect.Method;
09:
10: /**
11: * Contains everything needed to configure and execute an action.
12: */
13: public class ActionConfig {
14:
15: public final String actionPath;
16: public Class actionClass;
17: public Method actionMethod;
18: public ActionInterceptor[] interceptors;
19: public int usage;
20:
21: /**
22: * Defines an action.
23: */
24: public ActionConfig(String actionPath, Class actionClass,
25: Method actionMethod, ActionInterceptor[] actionInterceptors) {
26: this .actionPath = actionPath;
27: this .actionClass = actionClass;
28: this .actionMethod = actionMethod;
29: this .interceptors = actionInterceptors;
30: this .usage = 0;
31: }
32:
33: /**
34: * Defines an action when method is given as a string.
35: */
36: public ActionConfig(String actionPath, Class actionClass,
37: String actionMethodName,
38: ActionInterceptor[] actionInterceptors) {
39: Method actionMethod = DefaultIntrospector.lookup(actionClass)
40: .getMethod(actionMethodName);
41: if (actionMethod == null) {
42: throw new MadvocException(
43: "Provided action class doesn't contain public method '"
44: + actionMethodName + "'.");
45: }
46: this .actionPath = actionPath;
47: this .actionClass = actionClass;
48: this .actionMethod = actionMethod;
49: this .interceptors = actionInterceptors;
50: this .usage = 0;
51: }
52:
53: // ---------------------------------------------------------------- clones
54:
55: /**
56: * Clones action config to new one but with changed action path.
57: */
58: public ActionConfig clone(String newActionPath) {
59: return new ActionConfig(newActionPath, this .actionClass,
60: this .actionMethod, this .interceptors);
61: }
62:
63: // ---------------------------------------------------------------- to string
64:
65: @Override
66: public String toString() {
67: return "action: " + actionPath + " -> " + getActionString();
68: }
69:
70: public String getActionString() {
71: return actionClass.getName() + '#' + actionMethod.getName()
72: + "()";
73: }
74: }
|