Fix request handler class error
[appc.git] / appc-common / src / main / java / org / onap / appc / util / UnmodifiableProperties.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ============LICENSE_END=========================================================
22  */
23
24
25
26 package org.onap.appc.util;
27
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.io.OutputStream;
31 import java.io.PrintStream;
32 import java.io.PrintWriter;
33 import java.io.Reader;
34 import java.io.Writer;
35 import java.util.Collection;
36 import java.util.Collections;
37 import java.util.Enumeration;
38 import java.util.InvalidPropertiesFormatException;
39 import java.util.Map;
40 import java.util.Properties;
41 import java.util.Set;
42
43 /**
44  * This utility class is used to wrap a properties object and to delegate all read operations to the property object,
45  * while disallowing any write or modification to the property object.
46  * 
47  */
48 public class UnmodifiableProperties extends Properties implements Cloneable {
49
50     /**
51      * Serial number
52      */
53     private static final long serialVersionUID = 1L;
54
55     private static final String PROPERTY_CANNOT_BE_MODIFIED_MSG = "Property cannot be modified!";
56
57     /**
58      * The properties object which we are wrapping
59      */
60     private Properties properties;
61
62     /**
63      * Create the unmodifiable wrapper around the provided properties object
64      * 
65      * @param properties
66      *            The properties to be wrapped and protected from modification
67      */
68     public UnmodifiableProperties(Properties properties) {
69         this.properties = properties;
70     }
71
72     /**
73      * @see java.util.Hashtable#clear()
74      */
75     @Override
76     public synchronized void clear() {
77         throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
78     }
79
80     /**
81      * @see java.util.Hashtable#clone()
82      */
83     // @sonar:off
84     @Override
85     public synchronized Object clone() {
86         throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
87     }
88
89     // @sonar:on
90
91     /**
92      * @see java.util.Hashtable#contains(java.lang.Object)
93      */
94     @Override
95     public synchronized boolean contains(Object value) {
96         return properties.contains(value);
97     }
98
99     /**
100      * @see java.util.Hashtable#containsKey(java.lang.Object)
101      */
102     @Override
103     public synchronized boolean containsKey(Object key) {
104         return properties.containsKey(key);
105     }
106
107     /**
108      * @see java.util.Hashtable#containsValue(java.lang.Object)
109      */
110     @Override
111     public boolean containsValue(Object value) {
112         return properties.containsValue(value);
113     }
114
115     /**
116      * @see java.util.Hashtable#elements()
117      */
118     @Override
119     public synchronized Enumeration<Object> elements() {
120         return properties.elements();
121     }
122
123     /**
124      * @see java.util.Hashtable#entrySet()
125      */
126     @Override
127     public Set<java.util.Map.Entry<Object, Object>> entrySet() {
128         return Collections.unmodifiableSet(properties.entrySet());
129     }
130
131     /**
132      * @see java.util.Hashtable#equals(java.lang.Object)
133      */
134     @Override
135     public synchronized boolean equals(Object o) {
136         return properties.equals(o);
137     }
138
139     /**
140      * @see java.util.Hashtable#get(java.lang.Object)
141      */
142     @Override
143     public synchronized Object get(Object key) {
144         return properties.get(key);
145     }
146
147     /**
148      * @see java.util.Properties#getProperty(java.lang.String)
149      */
150     @Override
151     public String getProperty(String key) {
152         return properties.getProperty(key);
153     }
154
155     /**
156      * @see java.util.Properties#getProperty(java.lang.String, java.lang.String)
157      */
158     @Override
159     public String getProperty(String key, String defaultValue) {
160         return properties.getProperty(key, defaultValue);
161     }
162
163     /**
164      * @see java.util.Hashtable#hashCode()
165      */
166     @Override
167     public synchronized int hashCode() {
168         return properties.hashCode();
169     }
170
171     /**
172      * @see java.util.Hashtable#isEmpty()
173      */
174     @Override
175     public synchronized boolean isEmpty() {
176         return properties.isEmpty();
177     }
178
179     /**
180      * @see java.util.Hashtable#keys()
181      */
182     @Override
183     public synchronized Enumeration<Object> keys() {
184         return properties.keys();
185     }
186
187     /**
188      * @see java.util.Hashtable#keySet()
189      */
190     @Override
191     public Set<Object> keySet() {
192         return Collections.unmodifiableSet(properties.keySet());
193     }
194
195     /**
196      * @see java.util.Properties#list(java.io.PrintStream)
197      */
198     @Override
199     public void list(PrintStream out) {
200         properties.list(out);
201     }
202
203     /**
204      * @see java.util.Properties#list(java.io.PrintWriter)
205      */
206     @Override
207     public void list(PrintWriter out) {
208         properties.list(out);
209     }
210
211     /**
212      * @see java.util.Properties#load(java.io.InputStream)
213      */
214     @Override
215     public synchronized void load(InputStream inStream) throws IOException {
216         throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
217     }
218
219     /**
220      * @see java.util.Properties#load(java.io.Reader)
221      */
222     @Override
223     public synchronized void load(Reader reader) throws IOException {
224         throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
225     }
226
227     /**
228      * @see java.util.Properties#loadFromXML(java.io.InputStream)
229      */
230     @Override
231     public synchronized void loadFromXML(InputStream in) throws IOException, InvalidPropertiesFormatException {
232         throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
233     }
234
235     /**
236      * @see java.util.Properties#propertyNames()
237      */
238     @Override
239     public Enumeration<?> propertyNames() {
240         return properties.propertyNames();
241     }
242
243     /**
244      * @see java.util.Hashtable#put(java.lang.Object, java.lang.Object)
245      */
246     @Override
247     public synchronized Object put(Object key, Object value) {
248         throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
249     }
250
251     /**
252      * @see java.util.Hashtable#putAll(java.util.Map)
253      */
254     @Override
255     public synchronized void putAll(Map<? extends Object, ? extends Object> t) {
256         throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
257     }
258
259     /**
260      * @see java.util.Hashtable#rehash()
261      */
262     @Override
263     protected void rehash() {
264         throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
265     }
266
267     /**
268      * @see java.util.Hashtable#remove(java.lang.Object)
269      */
270     @Override
271     public synchronized Object remove(Object key) {
272         throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
273     }
274
275     /**
276      * @see java.util.Properties#save(java.io.OutputStream, java.lang.String)
277      */
278     @Override
279     @Deprecated
280     public synchronized void save(OutputStream out, String comments) {
281         properties.save(out, comments);
282     }
283
284     /**
285      * @see java.util.Properties#setProperty(java.lang.String, java.lang.String)
286      */
287     @Override
288     public synchronized Object setProperty(String key, String value) {
289         throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
290     }
291
292     /**
293      * @see java.util.Hashtable#size()
294      */
295     @Override
296     public synchronized int size() {
297         return properties.size();
298     }
299
300     /**
301      * @see java.util.Properties#store(java.io.OutputStream, java.lang.String)
302      */
303     @Override
304     public void store(OutputStream out, String comments) throws IOException {
305         properties.store(out, comments);
306     }
307
308     /**
309      * @see java.util.Properties#store(java.io.Writer, java.lang.String)
310      */
311     @Override
312     public void store(Writer writer, String comments) throws IOException {
313         properties.store(writer, comments);
314     }
315
316     /**
317      * @see java.util.Properties#storeToXML(java.io.OutputStream, java.lang.String)
318      */
319     @Override
320     public synchronized void storeToXML(OutputStream os, String comment) throws IOException {
321         properties.storeToXML(os, comment);
322     }
323
324     /**
325      * @see java.util.Properties#storeToXML(java.io.OutputStream, java.lang.String, java.lang.String)
326      */
327     @Override
328     public synchronized void storeToXML(OutputStream os, String comment, String encoding) throws IOException {
329         properties.storeToXML(os, comment, encoding);
330     }
331
332     /**
333      * @see java.util.Properties#stringPropertyNames()
334      */
335     @Override
336     public Set<String> stringPropertyNames() {
337         return properties.stringPropertyNames();
338     }
339
340     /**
341      * @see java.util.Hashtable#toString()
342      */
343     @Override
344     public synchronized String toString() {
345         return properties.toString();
346     }
347
348     /**
349      * @see java.util.Hashtable#values()
350      */
351     @Override
352     public Collection<Object> values() {
353         return Collections.unmodifiableCollection(properties.values());
354     }
355 }