KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > am > values > PermissionPoint


1 /*
2  * $Id: PermissionPoint.java,v 1.3 2005/06/07 12:32:30 bel70 Exp $
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  * The contents of this file are subject to the Mozilla Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License
8  * at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific language governing rights and
13  * limitations under the License.
14  *
15  * The Original Code is JGossip forum code.
16  *
17  * The Initial Developer of the Original Code is the JResearch, Org.
18  * Portions created by the Initial Developer are Copyright (C) 2004
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Dmitriy Belov <bel@jresearch.org>
23  * .
24  * * ***** END LICENSE BLOCK ***** */

25 /*
26  * Created on 16.07.2004
27  *
28  */

29 package org.jresearch.gossip.am.values;
30
31 import java.io.Serializable JavaDoc;
32 import java.util.Hashtable JavaDoc;
33
34 /**
35  * @author Dmitry Belov
36  *
37  */

38 public class PermissionPoint implements Serializable JavaDoc {
39
40     /**
41      *
42      */

43     private static final long serialVersionUID = 5408127418759175026L;
44
45     /**
46      * Field <code>ALL_PERMISSIONS</code>
47      */

48     public static PermissionPoint ALL_PERMISSIONS = new PermissionPoint(
49             PermissionObject.ALL_OBJECTS, PermissionOperation.ALL_OPERATIONS);
50
51     /**
52      * Field <code>ADM_USER</code>
53      */

54     public static PermissionPoint ADM_USER = new PermissionPoint(
55             new PermissionObject(PermissionObject.USER),
56             PermissionOperation.ALL_OPERATIONS);
57
58     /**
59      * Field <code>ADM_FORUM</code>
60      */

61     public static PermissionPoint ADM_FORUM = new PermissionPoint(
62             new PermissionObject(PermissionObject.FORUM),
63             PermissionOperation.ALL_OPERATIONS);
64
65     /**
66      * Field <code>ADM_GROUP</code>
67      */

68     public static PermissionPoint ADM_GROUP = new PermissionPoint(
69             new PermissionObject(PermissionObject.GROUP),
70             PermissionOperation.ALL_OPERATIONS);
71
72     /**
73      * Field <code>ADM_TOPIC</code>
74      */

75     public static PermissionPoint ADM_TOPIC = new PermissionPoint(
76             new PermissionObject(PermissionObject.TOPIC),
77             PermissionOperation.ALL_OPERATIONS);
78
79     /**
80      * Field <code>ADM_MESSAGE</code>
81      */

82     public static PermissionPoint ADM_MESSAGE = new PermissionPoint(
83             new PermissionObject(PermissionObject.MESSAGE),
84             PermissionOperation.ALL_OPERATIONS);
85
86     private PermissionObject object;
87
88     public static final int ALL = -1;
89
90     public static final int UNKNOWN = -2;
91
92     private PermissionOperation operation;
93
94     private PermissionAttributes args;
95
96     private StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
97
98     /**
99      * @param object
100      * @param operation
101      * @param args
102      */

103     public PermissionPoint(int object, int operation, PermissionAttributes args) {
104         this(new PermissionObject(object), new PermissionOperation(operation),
105                 args);
106     }
107
108     /**
109      * @param object
110      * @param operation
111      * @param args
112      */

113     public PermissionPoint(PermissionObject object,
114             PermissionOperation operation, PermissionAttributes args) {
115         if (object == null || operation == null || args == null) {
116             throw new IllegalArgumentException JavaDoc(
117                     "parameters for creating PermissionPoint can't be null");
118         }
119         this.object = object;
120         this.operation = operation;
121         this.args = args;
122     }
123
124     /**
125      * @param object
126      * @param operation
127      */

128     public PermissionPoint(int object, int operation) {
129         this(new PermissionObject(object), new PermissionOperation(operation),
130                 PermissionAttributes.ALL_ATTRIBUTES);
131     }
132
133     /**
134      * @param object
135      * @param operation
136      */

137     public PermissionPoint(PermissionObject object,
138             PermissionOperation operation) {
139         this(object, operation, PermissionAttributes.ALL_ATTRIBUTES);
140     }
141
142     /**
143      * @return a hash code value for this object.
144      * @see Object#equals(Object)
145      * @see Hashtable
146      */

147     public int hashCode() {
148         if (sb.length() > 0) {
149             sb.delete(0, sb.length());
150         }
151         sb.append(object.hashCode());
152         sb.append(operation.hashCode());
153         sb.append(args.hashCode());
154         return sb.toString().hashCode();
155     }
156
157     /*
158      * (non-Javadoc)
159      *
160      * @see java.lang.Object#equals(java.lang.Object)
161      */

162     public boolean equals(Object JavaDoc obj) {
163         if (obj instanceof PermissionPoint) {
164             PermissionPoint p = (PermissionPoint) obj;
165             return (this.object.equals(p.object)
166                     && this.operation.equals(p.operation) && this.args
167                     .equals(p.args));
168         }
169         return false;
170     }
171 }
Popular Tags