1 package org.apache.turbine.om.security;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.util.Collections;
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import org.apache.torque.om.BaseObject;
24
25 /***
26 * This class represents a generic object used in the Access Control Lists.
27 *
28 * @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a>
29 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
30 * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
31 * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
32 * @version $Id: SecurityObject.java 264148 2005-08-29 14:21:04Z henning $
33 */
34 public abstract class SecurityObject extends BaseObject implements Comparable
35 {
36 /*** The name of this object. */
37 private String name;
38
39 /*** The id of this object */
40 private int id;
41
42 /*** The attributes of this object. */
43 private Map attributes;
44
45 /***
46 * Constructs a new SecurityObject
47 */
48 public SecurityObject()
49 {
50 this("");
51 }
52
53 /***
54 * Constructs a new SecurityObject with the specified name.
55 *
56 * @param name The name of the new object.
57 */
58 public SecurityObject(String name)
59 {
60 setName(name);
61 setId(0);
62 setAttributes(Collections.synchronizedMap(new HashMap()));
63 }
64
65 /***
66 * Returns a Map containing this object's attributes.
67 *
68 * @return the object's attributes.
69 */
70 public Map getAttributes()
71 {
72 return attributes;
73 }
74
75 /***
76 * Replaces this object's attributes with the specified Map.
77 *
78 * @param attributes The new attributes of the object.
79 */
80 public void setAttributes(Map attributes)
81 {
82 this.attributes = attributes;
83 }
84
85 /***
86 * Retrieves the value of specific attribute of this object.
87 *
88 * @param name the name of the attribute
89 * @return the value of the attribute
90 */
91 public Object getAttribute(String name)
92 {
93 return attributes.get(name);
94 }
95
96 /***
97 * Sets the value of specific attribute of this object.
98 *
99 * @param name the name of the attribute
100 * @param value the value of the attribute
101 */
102 public void setAttribute(String name, Object value)
103 {
104 attributes.put(name, value);
105 }
106
107 /***
108 * Returns the name of this object.
109 *
110 * @return The name of the object.
111 */
112 public String getName()
113 {
114 return name;
115 }
116
117 /***
118 * Sets the name of this object.
119 *
120 * @param name The name of the object.
121 */
122 public void setName(String name)
123 {
124 this.name = name;
125 }
126
127 /***
128 * Unused. There is an ID column in the
129 * database scheme but it doesn't seem
130 * to be used.
131 *
132 * @return 0
133 */
134 public int getId()
135 {
136 return id;
137 }
138
139 /***
140 * Unused. There is an ID column in the
141 * database scheme but it doesn't seem
142 * to be used.
143 *
144 * @return null
145 */
146 public Integer getIdAsObj()
147 {
148 return new Integer(id);
149 }
150
151 /***
152 * Unused. There is an ID column in the
153 * database scheme but it doesn't seem
154 * to be used.
155 *
156 * @param id The id of the User.
157 */
158 public void setId(int id)
159 {
160 this.id = id;
161 }
162
163 /***
164 * Used for ordering SecurityObjects.
165 *
166 * @param obj The Object to compare to.
167 * @return -1 if the name of the other object is lexically greater than this
168 * group, 1 if it is lexically lesser, 0 if they are equal.
169 */
170 public int compareTo(Object obj)
171 {
172 if (this.getClass() != obj.getClass())
173 {
174 throw new ClassCastException();
175 }
176 String name1 = ((SecurityObject) obj).getName();
177 String name2 = this.getName();
178
179 return name2.compareTo(name1);
180 }
181
182 /***
183 * Returns a textual representation of this object, consisted by
184 * it's name and attributes.
185 *
186 * @return a textual representation of this group.
187 */
188 public String toString()
189 {
190 return (getName() + ':' + getAttributes().toString());
191 }
192 }