KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > model > core > Role


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
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, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.model.core;
17
18 import java.io.Serializable JavaDoc;
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21
22 /**
23  * <p>This class is used to represent available roles in the database. Such roles
24  * are assigned to some entities to restrict access to them. Each user has a set
25  * of roles. When a user tries to gain access to some entity with restricted
26  * assess (content page, for instance), each his role is checked whether it's
27  * allowed to access this entity. If at least one role is allowed, user is
28  * permitted to access that entity. The algorithm to determine whether role
29  * has access to entity is as follows: if none of the roles is assigned to the
30  * entity, access is granted, otherwise access is granted when and only when
31  * the checked role is assigned to the entity.
32  * </p>
33  * <p>
34  * User may also be a member of some groups. Each group may have roles assigned
35  * to it. When checking for user's roles, his groups' roles are considered too.
36  * </p>
37  * <p>
38  * So, roles may be assigned to user in two ways: directly (such roles are
39  * called 'free') and through group (placing a user into some group).
40  * </p>
41  * <p><a HREF="Role.java.htm"><i>View Source</i></a></p>
42  *
43  * @author Matt Raible <a HREF="mailto:matt@raibledesigns.com">&lt;matt@raibledesigns.com&gt;</a>
44  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
45  * @author Roman Puchkovskiy <a HREF="mailto:roman.puchkovskiy@blandware.com">
46  * &lt;roman.puchkovskiy@blandware.com&gt;</a>
47  * @version $Revision: 1.32 $ $Date: 2006/03/16 11:09:37 $
48  * @see User
49  * @see Group
50  * @struts.form include-all="false" extends="BaseForm"
51  * @hibernate.class table="`al_core_role`" lazy="false"
52  * @hibernate.cache usage="read-write"
53  */

54 public class Role extends BaseObject implements Serializable JavaDoc {
55     //~ Instance fields ========================================================
56

57     /**
58      * Name of the role (used as a system identifier)
59      */

60     private String JavaDoc name;
61     /**
62      * Human-readable name of the role
63      */

64     private String JavaDoc title;
65     /**
66      * Description of the role; this may be quite long
67      */

68     private String JavaDoc description;
69     /**
70      * Whether role is fixed. Fixed roles cannot be deleted
71      */

72     private Boolean JavaDoc fixed;
73     /**
74      * Version of this role (used in optimistic locking)
75      */

76     protected Long JavaDoc version;
77
78     /**
79      * List of groups to which this role belongs
80      */

81     private List JavaDoc groups = new ArrayList JavaDoc();
82
83     /**
84      * List of pages for which this role has been assigned
85      */

86     private List JavaDoc pages = new ArrayList JavaDoc();
87
88     /**
89      * List if menu items for which this role has been assigned
90      */

91     private List JavaDoc menuItems = new ArrayList JavaDoc();
92
93     /**
94      * List of resources for which this role has been assigned
95      */

96     private List JavaDoc resources = new ArrayList JavaDoc();
97
98     /**
99      * Creates a role
100      */

101     public Role() {
102     }
103
104     /**
105      * Creates a role with a given name
106      *
107      * @param name role name
108      * @param title role title
109      */

110     public Role(String JavaDoc name, String JavaDoc title) {
111         this.name = name;
112         this.title = title;
113     }
114
115     //~ Methods ================================================================
116

117     /**
118      * Returns the name of the role (it's the analog of system identifier)
119      *
120      * @return role name
121      * @struts.form-field
122      * @struts.validator type="required"
123      * @struts.validator type="mask" msgkey="core.commons.errors.identifierAllowingCapitals"
124      * @struts.validator-args arg0resource="core.role.form.name"
125      * @struts.validator-var name="mask" value="${identifierAllowingCapitals}"
126      * @hibernate.id column="`rolename`" length="40"
127      * generator-class="assigned" unsaved-value="null"
128      */

129     public String JavaDoc getName() {
130         return this.name;
131     }
132
133     /**
134      * Returns human-readable title of the role.
135      *
136      * @return role title
137      * @struts.form-field
138      * @struts.validator type="required"
139      * @struts.validator-args arg0resource="core.role.form.title"
140      * @hibernate.property
141      * @hibernate.column name="`title`" not-null="true" unique="true" length="252"
142      */

143     public String JavaDoc getTitle() {
144         return this.title;
145     }
146
147     /**
148      * Returns the description of the role
149      *
150      * @return role description
151      * @struts.form-field
152      * @hibernate.property column="`description`" length="252"
153      */

154     public String JavaDoc getDescription() {
155         return this.description;
156     }
157
158     /**
159      * Returns <code>Boolean.TRUE</code>, if role is fixed, i.e. it cannot be deleted
160      *
161      * @return whether role is fixed
162      * @hibernate.property column="`fixed`" not-null="true" type="true_false"
163      */

164     public Boolean JavaDoc getFixed() {
165         return fixed;
166     }
167
168     /**
169      * Sets name of the role
170      *
171      * @param name role name
172      */

173     public void setName(String JavaDoc name) {
174         this.name = name;
175     }
176
177     /**
178      * Sets human-readable title of the role
179      *
180      * @param title role title
181      */

182     public void setTitle(String JavaDoc title) {
183         this.title = title;
184     }
185
186     /**
187      * Sets description of the role
188      *
189      * @param description role description
190      */

191     public void setDescription(String JavaDoc description) {
192         this.description = description;
193     }
194
195     /**
196      * Sets whether the role will be fixed (and no one will be able to delete it)
197      *
198      * @param fixed whether the role will be fixed
199      */

200     public void setFixed(Boolean JavaDoc fixed) {
201         this.fixed = fixed;
202     }
203
204     /**
205      * Returns version of the role
206      *
207      * @return version
208      * @struts.form-field
209      * @hibernate.version column="`version`" type="long" unsaved-value="null"
210      */

211     public Long JavaDoc getVersion() {
212         return version;
213     }
214
215     /**
216      * Sets version of the role
217      *
218      * @param version the version to set
219      */

220     public void setVersion(Long JavaDoc version) {
221         this.version = version;
222     }
223
224     /**
225      * Returns list of groups to which this role belongs
226      *
227      * @return list of groups
228      * @hibernate.bag table="`al_core_group_role`" cascade="none" lazy="true" inverse="true" outer-join="false"
229      * @hibernate.collection-key
230      * @hibernate.collection-key-column name="`rolename`" length="40"
231      * @hibernate.collection-many-to-many class="com.blandware.atleap.model.core.Group"
232      * column="`groupname`" outer-join="false"
233      */

234     public List JavaDoc getGroups() {
235         return groups;
236     }
237
238     /**
239      * Sets list of groups to which this role belongs
240      *
241      * @param groups list of groups
242      */

243     public void setGroups(List JavaDoc groups) {
244         this.groups = groups;
245     }
246
247     /**
248      * Returns list of pages to which this role is assigned
249      *
250      * @return list of pages
251      * @hibernate.bag table="`al_core_page_role`" cascade="none" lazy="true" inverse="true" outer-join="false"
252      * @hibernate.collection-key column="`rolename`"
253      * @hibernate.collection-many-to-many class="com.blandware.atleap.model.core.Page"
254      * column="`page_id`" outer-join="false"
255      */

256     public List JavaDoc getPages() {
257         return pages;
258     }
259
260     /**
261      * Sets list of pages to which this role is assigned
262      *
263      * @param pages list of pages
264      */

265     public void setPages(List JavaDoc pages) {
266         this.pages = pages;
267     }
268
269     /**
270      * Returns list of menu items to which this role is assigned
271      *
272      * @return list of menu items
273      * @hibernate.bag table="`al_core_menu_item_role`" cascade="none" lazy="true" inverse="true" outer-join="false"
274      * @hibernate.collection-key column="`rolename`"
275      * @hibernate.collection-many-to-many class="com.blandware.atleap.model.core.MenuItem"
276      * column="`menu_item_id`" outer-join="false"
277      */

278     public List JavaDoc getMenuItems() {
279         return menuItems;
280     }
281
282     /**
283      * Gets list of menu items to which this role is assigned
284      *
285      * @param menuItems list of menu items
286      */

287     public void setMenuItems(List JavaDoc menuItems) {
288         this.menuItems = menuItems;
289     }
290
291     /**
292      * Returns list of content resources to which this role is assigned
293      *
294      * @return list of content resources
295      * @hibernate.bag table="`al_core_resource_role`" cascade="none" lazy="true" inverse="true" outer-join="false"
296      * @hibernate.collection-key column="`rolename`"
297      * @hibernate.collection-many-to-many class="com.blandware.atleap.model.core.ContentResource"
298      * column="`resource_id`" outer-join="false"
299      */

300     public List JavaDoc getResources() {
301         return resources;
302     }
303
304     /**
305      * Sets list of content resources to which this role is assigned
306      *
307      * @param resources list of content resources
308      */

309     public void setResources(List JavaDoc resources) {
310         this.resources = resources;
311     }
312
313
314     public boolean equals(Object JavaDoc o) {
315         if ( this == o ) {
316             return true;
317         }
318
319         if ( !(o instanceof Role) ) {
320             return false;
321         }
322         final Role role = (Role) o;
323
324         if ( title != null ? !title.equals(role.title) : role.title != null ) {
325             return false;
326         }
327
328         return true;
329     }
330
331     public int hashCode() {
332         if ( title == null ) {
333             return 0;
334         } else {
335             return title.hashCode();
336         }
337     }
338
339 }
340
Popular Tags