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