1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.security;
17
18 import org.apache.commons.lang.ArrayUtils;
19
20 public class Action {
21
22 private String actionName;
23
24 private String parameter;
25
26 public static final Action PAGE_VIEW = new Action("/page/view");
27
28 public static final Action PAGE_MANAGE = new Action("/page/manage");
29
30 public static final Action DB_VIEW = new Action("/db/view");
31
32 public static final Action DB_MANAGE = new Action("/db/manage");
33
34 public static final Action LOGIC_VIEW = new Action("/logic/view");
35
36 public static final Action LOGIC_MANAGE = new Action("/logic/manage");
37
38 public static final Action SITE_MANAGE = new Action("/site/manage");
39
40 public static final Action[] ACTIONS = { PAGE_VIEW, PAGE_MANAGE, DB_VIEW,
41 DB_MANAGE, LOGIC_VIEW, LOGIC_MANAGE, SITE_MANAGE };
42
43 private static final String[] ACTION_NAMES;
44
45 static {
46 ACTION_NAMES = new String[ACTIONS.length];
47 for (int i = 0; i < ACTIONS.length; i++) {
48 ACTION_NAMES[i] = ACTIONS[i].getActionName();
49 }
50 }
51
52 public Action(String actionName) {
53 if (actionName == null) {
54 throw new IllegalAccessError("invalid creation");
55 }
56 this.actionName = actionName;
57 }
58
59 public Action(String actionName, String parameter) {
60 if (actionName == null) {
61 throw new IllegalAccessError("invalid creation");
62 }
63 this.actionName = actionName;
64 this.parameter = parameter;
65 }
66
67 public String getActionName() {
68 return actionName;
69 }
70
71 public String getParameter() {
72 return parameter;
73 }
74
75 public Action createParameteredAction(String parameter) {
76 return new Action(this.actionName, parameter);
77 }
78
79 public static Action getAction(String actionName) {
80 int index = ArrayUtils.indexOf(ACTION_NAMES, actionName);
81 if (index >= 0) {
82 return ACTIONS[index];
83 }
84 return new Action(actionName);
85 }
86 }