KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > madvoc > ActionConfig


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2

3 package jodd.madvoc;
4
5 import jodd.introspector.DefaultIntrospector;
6 import jodd.madvoc.interceptor.ActionInterceptor;
7
8 import java.lang.reflect.Method JavaDoc;
9
10 /**
11  * Contains everything needed to configure and execute an action.
12  */

13 public class ActionConfig {
14
15     public final String JavaDoc actionPath;
16     public Class JavaDoc actionClass;
17     public Method JavaDoc actionMethod;
18     public ActionInterceptor[] interceptors;
19     public int usage;
20
21     /**
22      * Defines an action.
23      */

24     public ActionConfig(String JavaDoc actionPath, Class JavaDoc actionClass, Method JavaDoc actionMethod, ActionInterceptor[] actionInterceptors) {
25         this.actionPath = actionPath;
26         this.actionClass = actionClass;
27         this.actionMethod = actionMethod;
28         this.interceptors = actionInterceptors;
29         this.usage = 0;
30     }
31
32
33     /**
34      * Defines an action when method is given as a string.
35      */

36     public ActionConfig(String JavaDoc actionPath, Class JavaDoc actionClass, String JavaDoc actionMethodName, ActionInterceptor[] actionInterceptors) {
37         Method JavaDoc actionMethod = DefaultIntrospector.lookup(actionClass).getMethod(actionMethodName);
38         if (actionMethod == null) {
39             throw new MadvocException("Provided action class doesn't contain public method '" + actionMethodName + "'.");
40         }
41         this.actionPath = actionPath;
42         this.actionClass = actionClass;
43         this.actionMethod = actionMethod;
44         this.interceptors = actionInterceptors;
45         this.usage = 0;
46     }
47
48
49
50     // ---------------------------------------------------------------- clones
51

52     /**
53      * Clones action config to new one but with changed action path.
54      */

55     public ActionConfig clone(String JavaDoc newActionPath) {
56         return new ActionConfig(newActionPath, this.actionClass, this.actionMethod, this.interceptors);
57     }
58
59
60
61     // ---------------------------------------------------------------- to string
62

63
64     public String JavaDoc toString() {
65         return "action: " + actionPath + " -> " + getActionString();
66     }
67
68     public String JavaDoc getActionString() {
69         return actionClass.getName() + '#' + actionMethod.getName() + "()";
70     }
71 }
72
Popular Tags