001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/msgcntr/trunk/messageforums-api/src/java/org/sakaiproject/api/app/messageforums/PermissionsMask.java $
003: * $Id: PermissionsMask.java 9227 2006-05-15 15:02:42Z cwen@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.api.app.messageforums;
021:
022: import java.util.Collection;
023: import java.util.HashMap;
024: import java.util.Iterator;
025: import java.util.Map;
026: import java.util.Set;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030:
031: /**
032: * This class is critical for the interaction with AuthorizationManager.
033: * This class will be used for creating Authorizations and querying
034: * Authorizations. The implementation of this class is not thread safe.
035: *
036: * @author <a href="mailto:lance@indiana.edu">Lance Speelmon</a>
037: * @version $Id: PermissionsMask.java 632 2005-07-14 21:22:50 +0000 (Thu, 14 Jul 2005) janderse@umich.edu $
038: */
039: public class PermissionsMask implements Map {
040: private static final Log LOG = LogFactory
041: .getLog(PermissionsMask.class);
042:
043: private Map map;
044:
045: /**
046: * @see HashMap#HashMap()
047: */
048: public PermissionsMask() {
049: map = new HashMap();
050: }
051:
052: /**
053: * @see HashMap#HashMap(int)
054: */
055: public PermissionsMask(int initialCapacity) {
056: map = new HashMap(initialCapacity);
057: }
058:
059: /**
060: * @see HashMap#HashMap(int, float)
061: */
062: public PermissionsMask(int initialCapacity, float loadFactor) {
063: map = new HashMap(initialCapacity, loadFactor);
064: }
065:
066: /**
067: * @see java.util.Map#clear()
068: */
069: public void clear() {
070: map.clear();
071: }
072:
073: /**
074: * @see java.util.Map#containsKey(java.lang.Object)
075: */
076: public boolean containsKey(Object key) {
077: return map.containsKey(key);
078: }
079:
080: /**
081: * @see java.util.Map#containsValue(java.lang.Object)
082: */
083: public boolean containsValue(Object value) {
084: return map.containsValue(value);
085: }
086:
087: /**
088: * @see java.util.Map#entrySet()
089: */
090: public Set entrySet() {
091: return map.entrySet();
092: }
093:
094: /**
095: * @see java.util.Map#equals(java.lang.Object)
096: */
097: public boolean equals(Object o) {
098: return map.equals(o);
099: }
100:
101: /**
102: * @see java.util.Map#get(java.lang.Object)
103: */
104: public Object get(Object key) {
105: return map.get(key);
106: }
107:
108: /**
109: * @see java.util.Map#hashCode()
110: */
111: public int hashCode() {
112: return map.hashCode();
113: }
114:
115: /**
116: * @see java.util.Map#isEmpty()
117: */
118: public boolean isEmpty() {
119: return map.isEmpty();
120: }
121:
122: /**
123: * @see java.util.Map#keySet()
124: */
125: public Set keySet() {
126: return map.keySet();
127: }
128:
129: /**
130: * @param key Must be of type String.
131: * @param value Must be of type Boolean or null.
132: * @see java.util.Map#put(java.lang.Object, java.lang.Object)
133: */
134: public Object put(Object key, Object value) {
135: if (LOG.isDebugEnabled()) {
136: LOG.debug("put(Object " + key + ", Object " + value + ")");
137: }
138: if (key == null || !(key instanceof String))
139: throw new IllegalArgumentException(
140: "Illegal key argument passed!");
141: if (value != null && !(value instanceof Boolean))
142: throw new IllegalArgumentException(
143: "Illegal value argument passed!");
144:
145: return map.put(key, value);
146: }
147:
148: /**
149: * @throws IllegalArgumentException if the specified map is null or any of the
150: * keys are not Strings.
151: * @see java.util.Map#putAll(java.util.Map)
152: */
153: public void putAll(Map t) {
154: if (LOG.isDebugEnabled()) {
155: LOG.debug("putAll(Map " + t + ")");
156: }
157: if (t == null)
158: throw new IllegalArgumentException(
159: "Illegal map argument passed!");
160: for (Iterator iter = t.entrySet().iterator(); iter.hasNext();) {
161: Map.Entry entry = (Entry) iter.next();
162: if (!(entry.getKey() instanceof String))
163: throw new IllegalArgumentException(
164: "Illegal key found in Map, must be a String!");
165: if (entry.getValue() != null
166: && !(entry.getValue() instanceof Boolean))
167: throw new IllegalArgumentException(
168: "Illegal value found in Map; must be a Boolean or null!");
169: }
170:
171: map.putAll(t);
172: }
173:
174: /**
175: * @see java.util.Map#remove(java.lang.Object)
176: */
177: public Object remove(Object key) {
178: return map.remove(key);
179: }
180:
181: /**
182: * @see java.util.Map#size()
183: */
184: public int size() {
185: return map.size();
186: }
187:
188: /**
189: * @see java.util.Map#values()
190: */
191: public Collection values() {
192: return map.values();
193: }
194:
195: /**
196: * @see java.lang.Object#toString()
197: */
198: public String toString() {
199: return map.toString();
200: }
201:
202: }
|