View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
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  }