KickJava   Java API By Example, From Geeks To Geeks.

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


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

22 /*
23  * Created on 22.07.2004
24  *
25  */

26 package org.jresearch.gossip.am.values;
27
28 import java.io.Serializable JavaDoc;
29 import java.util.HashMap JavaDoc;
30 import java.util.Hashtable JavaDoc;
31
32 import org.jresearch.gossip.exception.SystemException;
33
34 /**
35  * @author dbelov
36  *
37  */

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

42     private static final long serialVersionUID = 2871133928578166536L;
43
44     /**
45      * Field <code>ALL_ATTRIBUTES</code>
46      */

47     public static final PermissionAttributes ALL_ATTRIBUTES = new PermissionAttributes();
48
49     private HashMap JavaDoc values = new HashMap JavaDoc();
50
51     /**
52      *
53      */

54     public PermissionAttributes() {
55         super();
56     }
57
58     /**
59      * @param key
60      * @param value
61      * @throws SystemException
62      */

63     public void addValue(String JavaDoc key, Integer JavaDoc value) throws SystemException {
64         if (this != ALL_ATTRIBUTES) {
65             this.values.put(key, value);
66         } else {
67             throw new SystemException("value can't be added in ALL_ATTRIBUTES");
68         }
69     }
70
71     /**
72      * @param key
73      * @param value
74      * @throws SystemException
75      */

76     public void addValue(String JavaDoc key, String JavaDoc value) throws SystemException {
77         if (this != ALL_ATTRIBUTES) {
78             this.values.put(key, value);
79         } else {
80             throw new SystemException("value can't be added in ALL_ATTRIBUTES");
81         }
82     }
83
84     /**
85      * @return a hash code value for this object.
86      * @see Object#equals(Object)
87      * @see Hashtable
88      */

89     public int hashCode() {
90         if (values.isEmpty()) {
91             return 0;
92         } else {
93             return values.hashCode();
94         }
95     }
96
97     /*
98      * (non-Javadoc)
99      *
100      * @see java.lang.Object#equals(java.lang.Object)
101      */

102     public boolean equals(Object JavaDoc obj) {
103         if (obj instanceof PermissionAttributes) {
104             PermissionAttributes pa = (PermissionAttributes) obj;
105             return this == ALL_ATTRIBUTES || pa == ALL_ATTRIBUTES
106                     || this.values.equals(pa.values);
107         }
108
109         return false;
110
111     }
112 }
Popular Tags