Source code: com/flexstor/common/data/ejb/user/GroupData.java
1 /*
2 * GroupData.java
3 *
4 * Copyright $Date: 2003/08/11 02:22:48 $ FLEXSTOR.net Inc.
5 *
6 * This work is licensed for use and distribution under license terms found at
7 * http://www.flexstor.org/license.html
8 *
9 */
10
11 package com.flexstor.common.data.ejb.user;
12
13 import java.sql.Timestamp;
14 import java.util.Vector;
15
16 import com.flexstor.common.data.ejb.Data;
17 import com.flexstor.common.data.ejb.role.RoleData;
18 import com.flexstor.common.keys.ejb.GroupKey;
19 import com.flexstor.common.keys.ejb.RoleKey;
20
21 /**
22 * This class supports state data for <code>Group</code>. A Data class holds <br>
23 * all of the state information for a corresponding class and reference <br>
24 * pointers to other classes <br>
25 *
26 * @author Perry Hoekstra
27 * @version 1.0, 12/19/98
28 *
29 * @since FLEXSTOR.db 3.0
30 *
31 * Revision History Description of Change
32 * ---------------- ---------------------------------------------------
33 * PJH 12/19/98 Creation
34 */
35
36 public class GroupData extends Data {
37 // MKS macro expander
38 public final static String IDENTIFIER = "$Id: GroupData.java,v 1.3 2003/08/11 02:22:48 aleric Exp $";
39
40 // name of group
41 protected String name = null;
42
43 // timestamp of record in database when the object was retrieved
44 protected Timestamp currentTimestamp;
45
46 // object reference to the group's associated role in the database
47 protected RoleData roleData = null;
48
49 // object reference to this instance in the database
50 protected GroupKey groupKey = null;
51
52 // This is a Vector that holds a list of UserData objects assigned to this group by the Admin Tool
53 protected Vector vAssignedUsers;
54
55 /**
56 * Default constructor for the GroupData class<p>
57 *
58 * <b>Warning</b> Any objects created with this constructor are not updatable or insertable to the database
59 */
60
61 public GroupData() {
62 super();
63 }
64 /**
65 * Create an GroupData class and initialize the instance with the group name<p>
66 *
67 * <b>Warning</b> Any objects created with this constructor are not updatable (insertable, but not updatable) to the database
68 *
69 * @param java.lang.String a group name
70 */
71
72 public GroupData(String aGroupName) {
73 setName(aGroupName);
74 }
75
76 /**
77 * Determine if these two objects are equal, i.e. their attributes are equal.
78 * This method <b>will not</b> test the equality of references to other objects
79 *
80 * @param com.flexstor.common.data.ejb.user.GroupData a group data object
81 *
82 * @return boolean <code>true</code> if the objects are equal; <code>false</code> if they are not
83 */
84 public boolean equals(Object o)
85 {
86 if ( o != null && o instanceof GroupData )
87 {
88 String otherName = ((GroupData)o).getName();
89
90 if ( name != null && otherName != null )
91 return name.equals(otherName);
92 }
93
94 return false;
95 }
96
97 public int hashCode()
98 {
99 return getName().hashCode();
100 }
101
102 /**
103 * Return the group's name
104 *
105 * @return java.lang.String
106 */
107
108 public java.lang.String getName() {
109 if (name == null) {
110 name = new String();
111 }
112
113 return name;
114 }
115 /**
116 * Return the reference to this object
117 *
118 * @return com.flexstor.common.keys.ejb.GroupKey - an object reference
119 * @deprecated see getKey()
120 */
121
122 public GroupKey getReference() {
123 return groupKey;
124 }
125 /**
126 * Return the reference to this object
127 *
128 * @return com.flexstor.common.keys.ejb.GroupKey - an object reference
129 */
130
131 public GroupKey getKey() {
132 return groupKey;
133 }
134
135 /**
136 * Return the primary key to group's role
137 *
138 * @return com.flexstor.common.keys.ejb.RoleKey - an reference to the group's Role
139 */
140
141 public RoleKey getRoleKey()
142 {
143 if ( roleData != null )
144 return roleData.getKey();
145 else
146 return null;
147 }
148 /**
149 * Return the timestamp of this object in database when the object was retrieved
150 *
151 * @return java.sql.Timestamp
152 */
153
154 public Timestamp getTimestamp() {
155 return currentTimestamp;
156 }
157
158 /**
159 * Store the name of this group
160 *
161 * @param java.lang.String a group's name such as 'DBA Group'
162 */
163
164 public void setName(String aGroupName) {
165 name = aGroupName;
166 }
167 /**
168 * Store the reference to this object
169 *
170 * @param com.flexstor.common.keys.ejb.GroupKey an object reference
171 * @deprecated see setKey()
172 */
173
174 public void setReference(GroupKey aKey) {
175 groupKey = aKey;
176 }
177 /**
178 * Store the reference to this object
179 *
180 * @param com.flexstor.common.keys.ejb.GroupKey an object reference
181 */
182
183 public void setKey(GroupKey aKey) {
184 groupKey = aKey;
185 }
186 /**
187 * Set the primary key to group's role
188 *
189 * @param com.flexstor.common.keys.ejb.RoleKey object reference to a Role
190 */
191
192 public void setRoleKey(RoleKey aKey) {
193 if ( roleData == null )
194 roleData = new RoleData();
195
196 roleData.setKey(aKey);
197 }
198 /**
199 * Assign the current timestamp of the object
200 *
201 * @param java.sql.Timestamp current timestamp of the database object
202 */
203
204 public void setTimestamp(Timestamp aTimeStamp) {
205 currentTimestamp = aTimeStamp;
206 }
207 /**
208 * Return the contents of the instance as a String. This method is strictly for use by testing classes
209 * and should not be called by business objects
210 *
211 * @return java.lang.String String representation of GroupData contents
212 *
213 */
214
215 public String toString() {
216 String t_lineSeparator = System.getProperty("line.separator", "\n");
217
218 StringBuffer t_groupDataContents = new StringBuffer(t_lineSeparator);
219
220 t_groupDataContents.append("Class: GroupData");
221 t_groupDataContents.append(t_lineSeparator);
222
223 t_groupDataContents.append("Name: ");
224 t_groupDataContents.append(getName());
225
226 return t_groupDataContents.toString();
227 }
228
229 /**
230 * Set the language associated with the Group's Role
231 */
232 public void setLanguage( String lang )
233 {
234 if ( roleData == null )
235 roleData = new RoleData();
236
237 roleData.setLanguage(lang);
238 }
239
240 /**
241 * Retrieve the language associated with the Group's Role
242 */
243 public String getLanguage()
244 {
245 if ( roleData != null )
246 return roleData.getLanguage();
247 else
248 return null;
249 }
250
251 /**
252 * Assign a role to a group
253 *
254 * @param com.flexstor.common.data.ejb.role.RoleData an object reference to the group's role
255 */
256 public void setRoleData(RoleData aRoleData)
257 {
258 roleData = aRoleData;
259 }
260
261 /**
262 * Return the group role data
263 *
264 * @return com.flexstor.common.data.ejb.role.RoleData - the role data for this group
265 */
266 public RoleData getRoleData()
267 {
268 if ( roleData == null )
269 roleData = new RoleData();
270 return roleData;
271 }
272
273 /**
274 * Sets the list of UserData objects for the users this group has been updated
275 * through the Admin Tool.
276 * This method will be invoked by the Admin Tool prior to calling the GroupPersistBean
277 * to update the database.
278 *
279 * @param vAssignedUsers A Vector of UserData objects
280 */
281 public void setAssignedUsers( Vector vAssignedUsers ) { this.vAssignedUsers = vAssignedUsers; }
282
283 /**
284 * Gets the list of UserData objects for the users this group has been updated
285 * through the Admin Tool.
286 * This method will be invoked by the GroupPersistBean to update the database.
287 *
288 * @return A vector of UserData objects
289 */
290 public Vector getAssignedUsers() { return vAssignedUsers; }
291 }