KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > security > permissions > impl > hibernate > PermissionEntryImpl


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.security.permissions.impl.hibernate;
18
19 import org.alfresco.util.EqualsHelper;
20
21 /**
22  * Persisted permission entries
23  *
24  * @author andyh
25  */

26 public class PermissionEntryImpl implements PermissionEntry
27 {
28     /**
29      * The object id
30      */

31     private long id;
32     
33     /**
34      * The container of this permissions
35      */

36     private NodePermissionEntry nodePermissionEntry;
37
38     /**
39      * The permission to which this applies
40      * (non null - all is a special string)
41      */

42     private PermissionReference permissionReference;
43
44     /**
45      * The recipient to which this applies
46      * (non null - all is a special string)
47      */

48     private Recipient recipient;
49
50     /**
51      * Is this permission allowed?
52      */

53     private boolean allowed;
54
55     public PermissionEntryImpl()
56     {
57         super();
58     }
59     
60     public long getId()
61     {
62         return id;
63     }
64     
65     // Hibernate
66

67     /* package */ void setId(long id)
68     {
69         this.id = id;
70     }
71
72     public NodePermissionEntry getNodePermissionEntry()
73     {
74         return nodePermissionEntry;
75     }
76
77     private void setNodePermissionEntry(NodePermissionEntry nodePermissionEntry)
78     {
79         this.nodePermissionEntry = nodePermissionEntry;
80     }
81
82     public PermissionReference getPermissionReference()
83     {
84         return permissionReference;
85     }
86
87     private void setPermissionReference(PermissionReference permissionReference)
88     {
89         this.permissionReference = permissionReference;
90     }
91
92     public Recipient getRecipient()
93     {
94         return recipient;
95     }
96
97     private void setRecipient(Recipient recipient)
98     {
99         this.recipient = recipient;
100     }
101
102     public boolean isAllowed()
103     {
104         return allowed;
105     }
106
107     public void setAllowed(boolean allowed)
108     {
109         this.allowed = allowed;
110     }
111
112
113     /**
114      * Factory method to create an entry and wire it in to the contained nodePermissionEntry
115      *
116      * @param nodePermissionEntry
117      * @param permissionReference
118      * @param recipient
119      * @param allowed
120      * @return
121      */

122     public static PermissionEntryImpl create(NodePermissionEntry nodePermissionEntry, PermissionReference permissionReference, Recipient recipient, boolean allowed)
123     {
124         PermissionEntryImpl permissionEntry = new PermissionEntryImpl();
125         permissionEntry.setNodePermissionEntry(nodePermissionEntry);
126         permissionEntry.setPermissionReference(permissionReference);
127         permissionEntry.setRecipient(recipient);
128         permissionEntry.setAllowed(allowed);
129         nodePermissionEntry.getPermissionEntries().add(permissionEntry);
130         return permissionEntry;
131     }
132
133     /**
134      * Unwire
135      */

136     public void delete()
137     {
138         nodePermissionEntry.getPermissionEntries().remove(this);
139     }
140     
141     //
142
// Hibernate object pattern
143
//
144

145     @Override JavaDoc
146     public boolean equals(Object JavaDoc o)
147     {
148         if (this == o)
149         {
150             return true;
151         }
152         if (!(o instanceof PermissionEntryImpl))
153         {
154             return false;
155         }
156         PermissionEntryImpl other = (PermissionEntryImpl) o;
157         return EqualsHelper.nullSafeEquals(this.nodePermissionEntry,
158                 other.nodePermissionEntry)
159                 && EqualsHelper.nullSafeEquals(this.permissionReference,
160                         other.permissionReference)
161                 && EqualsHelper.nullSafeEquals(this.recipient, other.recipient)
162                 && (this.allowed == other.allowed);
163     }
164
165     @Override JavaDoc
166     public int hashCode()
167     {
168         int hashCode = nodePermissionEntry.hashCode();
169         if (permissionReference != null)
170         {
171             hashCode = hashCode * 37 + permissionReference.hashCode();
172         }
173         if (recipient != null)
174         {
175             hashCode = hashCode * 37 + recipient.hashCode();
176         }
177         hashCode = hashCode * 37 + (allowed ? 1 : 0);
178         return hashCode;
179     }
180
181 }
182
Popular Tags