View Javadoc
1   package org.apache.fulcrum.security.model.turbine.entity;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.Serializable;
23  
24  import org.apache.commons.lang3.builder.HashCodeBuilder;
25  import org.apache.fulcrum.security.entity.Group;
26  import org.apache.fulcrum.security.entity.Role;
27  import org.apache.fulcrum.security.entity.User;
28  
29  /**
30   * Represents the "turbine" model where permissions are in a many to many
31   * relationship to roles, roles are related to groups are related to users, all
32   * in many to many relationships.
33   * 
34   * @author <a href="mailto:epugh@upstate.com">Eric Pugh </a>
35   * @version $Id$
36   */
37  public class TurbineUserGroupRole implements Serializable
38  {
39      /**
40       * Serial number
41       */
42      private static final long serialVersionUID = 265670888102016829L;
43  
44      private User user;
45  
46      private Group group;
47  
48      private Role role;
49  
50      /**
51       * Get the group
52       * 
53       * @return Returns the group.
54       */
55      public Group getGroup()
56      {
57          return group;
58      }
59  
60      /**
61       * Get the role
62       * 
63       * @return Returns the role.
64       */
65      public Role getRole()
66      {
67          return role;
68      }
69  
70      /**
71       * Get the user
72       * 
73       * @return Returns the user.
74       */
75      public User getUser()
76      {
77          return user;
78      }
79  
80      /**
81       * Set the group
82       * 
83       * @param group
84       *            The group to set.
85       */
86      public void setGroup(Group group)
87      {
88          this.group = group;
89      }
90  
91      /**
92       * Set the role
93       * 
94       * @param role
95       *            The role to set.
96       */
97      public void setRole(Role role)
98      {
99          this.role = role;
100     }
101 
102     /**
103      * Set the user
104      * 
105      * @param user
106      *            The user to set.
107      */
108     public void setUser(User user)
109     {
110         this.user = user;
111     }
112 
113     @Override
114     public boolean equals(Object obj)
115     {
116         if (null == obj)
117         {
118             return false;
119         }
120         if (!(obj instanceof TurbineUserGroupRole))
121         {
122             return false;
123         }
124         else
125         {
126             TurbineUserGroupRole../../../org/apache/fulcrum/security/model/turbine/entity/TurbineUserGroupRole.html#TurbineUserGroupRole">TurbineUserGroupRole mObj = (TurbineUserGroupRole) obj;
127             if (null != this.getRole() && null != mObj.getRole())
128             {
129                 if (!this.getRole().equals(mObj.getRole()))
130                 {
131                     return false;
132                 }
133             }
134             else
135             {
136                 return false;
137             }
138             if (null != this.getUser() && null != mObj.getUser())
139             {
140                 if (!this.getUser().equals(mObj.getUser()))
141                 {
142                     return false;
143                 }
144             }
145             else
146             {
147                 return false;
148             }
149             if (null != this.getGroup() && null != mObj.getGroup())
150             {
151                 if (!this.getGroup().equals(mObj.getGroup()))
152                 {
153                     return false;
154                 }
155             }
156             else
157             {
158                 return false;
159             }
160             return true;
161         }
162     }
163 
164     @Override
165     public int hashCode()
166     {
167         HashCodeBuilder hcBuilder = new HashCodeBuilder(39, 17);
168 
169         Role role = getRole();
170         if (null != role)
171         {
172             hcBuilder.append(role);
173         }
174 
175         User user = getUser();
176         if (null != user)
177         {
178             hcBuilder.append(user);
179         }
180 
181         Group group = getGroup();
182         if (null != group)
183         {
184             hcBuilder.append(group);
185         }
186 
187         return hcBuilder.toHashCode();
188     }
189 
190     @Override
191     public String toString()
192     {
193         StringBuilder sb = new StringBuilder();
194 
195         sb.append(null != getUser() ? getUser().toString() : "null");
196         sb.append('\n');
197         sb.append(null != getGroup() ? getGroup().toString() : "null");
198         sb.append('\n');
199         sb.append(null != getRole() ? getRole().toString() : "null");
200         sb.append('\n');
201 
202         return sb.toString();
203     }
204 }