KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2005 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
20 /**
21  * <p>
22  * Represents an association between user, role and group: when a user is placed
23  * into a group, group roles are assigned to him; so, for each role in group
24  * a triad is created: &lt;user, role, group&gt;, where <em>user</em> is a user
25  * which is placed to a group, <em>role</em> is role which belongs to a group,
26  * and <em>group</em> is a group to which user is placed. Such triad is
27  * represented with this class.
28  * </p>
29  * <p>
30  * When a role is assigned directly to user, not through group, third component
31  * is <code>null</code>.
32  * </p>
33  * <p><a HREF="UserRoleAssociation.java.htm"><i>View source</i></a></p>
34  *
35  * @author Roman Puchkovskiy <a HREF="mailto:roman.puchkovskiy@blandware.com">
36  * &lt;roman.puchkovskiy@blandware.com&gt;</a>
37  * @version $Revision: 1.1 $ $Date: 2006/03/06 18:12:28 $
38  */

39 public class UserRoleAssociation extends BaseObject implements Serializable JavaDoc {
40
41     /**
42      * User which is a member of association
43      */

44     private User user;
45     /**
46      * Role which is a member of association
47      */

48     private Role role;
49     /**
50      * Group which is a member of association
51      */

52     private Group group;
53
54     /**
55      * Creates a UserRoleAssociation instance
56      */

57     public UserRoleAssociation() {
58     }
59
60     /**
61      * Creates a UserRoleAssociation instance initializing its fields
62      *
63      * @param user user which is a member of association
64      * @param role role which is a member of association
65      * @param group group which is a member of association
66      */

67     public UserRoleAssociation(User user, Role role, Group group) {
68         this.user = user;
69         this.role = role;
70         this.group = group;
71     }
72
73     /**
74      * Returns user
75      *
76      * @return user
77      * @hibernate.parent name="user"
78      */

79     public User getUser() {
80         return user;
81     }
82
83     /**
84      * Sets user
85      *
86      * @param user user to set
87      */

88     public void setUser(User user) {
89         this.user = user;
90     }
91
92     /**
93      * Returns role
94      *
95      * @return role
96      * @hibernate.many-to-one class="com.blandware.atleap.model.core.Role"
97      * column="`rolename`" not-null="true"
98      */

99     public Role getRole() {
100         return role;
101     }
102
103     /**
104      * Sets role
105      *
106      * @param role role to set
107      */

108     public void setRole(Role role) {
109         this.role = role;
110     }
111
112     /**
113      * Returns group
114      *
115      * @return group
116      * @hibernate.many-to-one class="com.blandware.atleap.model.core.Group"
117      * column="`groupname`" not-null="false"
118      */

119     public Group getGroup() {
120         return group;
121     }
122
123     /**
124      * Sets group
125      *
126      * @param group group to set
127      */

128     public void setGroup(Group group) {
129         this.group = group;
130     }
131
132     public boolean equals(Object JavaDoc o) {
133         if (this == o) return true;
134         if (!(o instanceof UserRoleAssociation)) return false;
135
136         final UserRoleAssociation userRoleAssociation = (UserRoleAssociation) o;
137
138         if (group != null ? !group.equals(userRoleAssociation.group) : userRoleAssociation.group != null) return false;
139         if (role != null ? !role.equals(userRoleAssociation.role) : userRoleAssociation.role != null) return false;
140         if (user != null ? !user.equals(userRoleAssociation.user) : userRoleAssociation.user != null) return false;
141
142         return true;
143     }
144
145     public int hashCode() {
146         int result;
147         result = (role != null ? role.hashCode() : 0);
148         result = 29 * result + (user != null ? user.hashCode() : 0);
149         result = 29 * result + (group != null ? group.hashCode() : 0);
150         return result;
151     }
152 }
153
Popular Tags