01: package com.jat.business.privileges;
02:
03: import java.util.Enumeration;
04:
05: /**
06: * <p>Title: JAT</p>
07: * <p>Description: </p>
08: * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
09: * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
10: * @author stf
11: * @version 1.0
12: * @since 1.2
13: */
14:
15: public class Profile {
16:
17: public Profile(String dataSourceName, String name) {
18: this .name = name;
19: this .dataSourceName = dataSourceName;
20: this .privileges = new PrivilegeList(dataSourceName);
21: }
22:
23: public String getName() {
24: return this .name;
25: }
26:
27: public boolean hasPrivilege(Privilege privilege) {
28: for (Enumeration e = this .privileges.elements(); e
29: .hasMoreElements();) {
30: Privilege priv = (Privilege) e.nextElement();
31: if (priv.equals(privilege))
32: return true;
33: }
34: return false;
35: }
36:
37: public boolean hasPrivilege(String privilegeName) {
38: for (Enumeration e = this .privileges.elements(); e
39: .hasMoreElements();) {
40: Privilege privilege = (Privilege) e.nextElement();
41: if (privilege.getName().equals(privilegeName))
42: return true;
43: }
44: return false;
45: }
46:
47: public PrivilegeList getPrivileges() {
48: return this .privileges;
49: }
50:
51: public void addPrivilege(Privilege privilege) {
52: this .privileges.addElement(privilege);
53: }
54:
55: public boolean removePrivilege(Privilege privilege) {
56: return this .privileges.remove(privilege);
57: }
58:
59: public boolean removePrivilege(String privilegeName) {
60: for (Enumeration e = this .privileges.elements(); e
61: .hasMoreElements();) {
62: Privilege privilege = (Privilege) e.nextElement();
63: if (privilege.getName().equals(privilegeName))
64: return this .privileges.remove(privilege);
65: }
66: return false;
67: }
68:
69: public void setPrivileges(PrivilegeList privileges) {
70: this .privileges = privileges;
71: }
72:
73: public String toString() {
74: String ret = this .getClass().getName() + ":{";
75: ret += "[name=" + this .getName() + "]";
76: ret += "[data source=" + this .dataSourceName + "]";
77: ret += "[privleges={" + this .privileges + "}]";
78: return ret;
79: }
80:
81: private String name;
82: private String dataSourceName;
83: private PrivilegeList privileges;
84: }
|