KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > util > ResourceSet


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18
19 package org.apache.catalina.util;
20
21
22 import java.util.Collection JavaDoc;
23 import java.util.HashSet JavaDoc;
24
25
26 /**
27  * Extended implementation of <strong>HashSet</strong> that includes a
28  * <code>locked</code> property. This class can be used to safely expose
29  * resource path sets to user classes without having to clone them in order
30  * to avoid modifications. When first created, a <code>ResourceMap</code>
31  * is not locked.
32  *
33  * @author Craig R. McClanahan
34  * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
35  */

36
37 public final class ResourceSet extends HashSet JavaDoc {
38
39
40     // ----------------------------------------------------------- Constructors
41

42
43     /**
44      * Construct a new, empty set with the default initial capacity and
45      * load factor.
46      */

47     public ResourceSet() {
48
49         super();
50
51     }
52
53
54     /**
55      * Construct a new, empty set with the specified initial capacity and
56      * default load factor.
57      *
58      * @param initialCapacity The initial capacity of this set
59      */

60     public ResourceSet(int initialCapacity) {
61
62         super(initialCapacity);
63
64     }
65
66
67     /**
68      * Construct a new, empty set with the specified initial capacity and
69      * load factor.
70      *
71      * @param initialCapacity The initial capacity of this set
72      * @param loadFactor The load factor of this set
73      */

74     public ResourceSet(int initialCapacity, float loadFactor) {
75
76         super(initialCapacity, loadFactor);
77
78     }
79
80
81     /**
82      * Construct a new set with the same contents as the existing collection.
83      *
84      * @param coll The collection whose contents we should copy
85      */

86     public ResourceSet(Collection JavaDoc coll) {
87
88         super(coll);
89
90     }
91
92
93     // ------------------------------------------------------------- Properties
94

95
96     /**
97      * The current lock state of this parameter map.
98      */

99     private boolean locked = false;
100
101
102     /**
103      * Return the locked state of this parameter map.
104      */

105     public boolean isLocked() {
106
107         return (this.locked);
108
109     }
110
111
112     /**
113      * Set the locked state of this parameter map.
114      *
115      * @param locked The new locked state
116      */

117     public void setLocked(boolean locked) {
118
119         this.locked = locked;
120
121     }
122
123
124     /**
125      * The string manager for this package.
126      */

127     private static final StringManager sm =
128         StringManager.getManager("org.apache.catalina.util");
129
130
131     // --------------------------------------------------------- Public Methods
132

133
134     /**
135      * Add the specified element to this set if it is not already present.
136      * Return <code>true</code> if the element was added.
137      *
138      * @param o The object to be added
139      *
140      * @exception IllegalStateException if this ResourceSet is locked
141      */

142     public boolean add(Object JavaDoc o) {
143
144         if (locked)
145             throw new IllegalStateException JavaDoc
146               (sm.getString("resourceSet.locked"));
147         return (super.add(o));
148
149     }
150
151
152     /**
153      * Remove all of the elements from this set.
154      *
155      * @exception IllegalStateException if this ResourceSet is locked
156      */

157     public void clear() {
158
159         if (locked)
160             throw new IllegalStateException JavaDoc
161               (sm.getString("resourceSet.locked"));
162         super.clear();
163
164     }
165
166
167     /**
168      * Remove the given element from this set if it is present.
169      * Return <code>true</code> if the element was removed.
170      *
171      * @param o The object to be removed
172      *
173      * @exception IllegalStateException if this ResourceSet is locked
174      */

175     public boolean remove(Object JavaDoc o) {
176
177         if (locked)
178             throw new IllegalStateException JavaDoc
179               (sm.getString("resourceSet.locked"));
180         return (super.remove(o));
181
182     }
183
184
185 }
186
Popular Tags