2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=========================================================
26 package org.onap.appc.util;
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;
40 import java.util.Properties;
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.
48 public class UnmodifiableProperties extends Properties implements Cloneable {
53 private static final long serialVersionUID = 1L;
55 private static final String PROPERTY_CANNOT_BE_MODIFIED_MSG = "Property cannot be modified!";
58 * The properties object which we are wrapping
60 private Properties properties;
63 * Create the unmodifiable wrapper around the provided properties object
66 * The properties to be wrapped and protected from modification
68 public UnmodifiableProperties(Properties properties) {
69 this.properties = properties;
73 * @see java.util.Hashtable#clear()
76 public synchronized void clear() {
77 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
81 * @see java.util.Hashtable#clone()
85 public synchronized Object clone() {
86 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
92 * @see java.util.Hashtable#contains(java.lang.Object)
95 public synchronized boolean contains(Object value) {
96 return properties.contains(value);
100 * @see java.util.Hashtable#containsKey(java.lang.Object)
103 public synchronized boolean containsKey(Object key) {
104 return properties.containsKey(key);
108 * @see java.util.Hashtable#containsValue(java.lang.Object)
111 public boolean containsValue(Object value) {
112 return properties.containsValue(value);
116 * @see java.util.Hashtable#elements()
119 public synchronized Enumeration<Object> elements() {
120 return properties.elements();
124 * @see java.util.Hashtable#entrySet()
127 public Set<java.util.Map.Entry<Object, Object>> entrySet() {
128 return Collections.unmodifiableSet(properties.entrySet());
132 * @see java.util.Hashtable#equals(java.lang.Object)
135 public synchronized boolean equals(Object o) {
136 return properties.equals(o);
140 * @see java.util.Hashtable#get(java.lang.Object)
143 public synchronized Object get(Object key) {
144 return properties.get(key);
148 * @see java.util.Properties#getProperty(java.lang.String)
151 public String getProperty(String key) {
152 return properties.getProperty(key);
156 * @see java.util.Properties#getProperty(java.lang.String, java.lang.String)
159 public String getProperty(String key, String defaultValue) {
160 return properties.getProperty(key, defaultValue);
164 * @see java.util.Hashtable#hashCode()
167 public synchronized int hashCode() {
168 return properties.hashCode();
172 * @see java.util.Hashtable#isEmpty()
175 public synchronized boolean isEmpty() {
176 return properties.isEmpty();
180 * @see java.util.Hashtable#keys()
183 public synchronized Enumeration<Object> keys() {
184 return properties.keys();
188 * @see java.util.Hashtable#keySet()
191 public Set<Object> keySet() {
192 return Collections.unmodifiableSet(properties.keySet());
196 * @see java.util.Properties#list(java.io.PrintStream)
199 public void list(PrintStream out) {
200 properties.list(out);
204 * @see java.util.Properties#list(java.io.PrintWriter)
207 public void list(PrintWriter out) {
208 properties.list(out);
212 * @see java.util.Properties#load(java.io.InputStream)
215 public synchronized void load(InputStream inStream) throws IOException {
216 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
220 * @see java.util.Properties#load(java.io.Reader)
223 public synchronized void load(Reader reader) throws IOException {
224 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
228 * @see java.util.Properties#loadFromXML(java.io.InputStream)
231 public synchronized void loadFromXML(InputStream in) throws IOException, InvalidPropertiesFormatException {
232 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
236 * @see java.util.Properties#propertyNames()
239 public Enumeration<?> propertyNames() {
240 return properties.propertyNames();
244 * @see java.util.Hashtable#put(java.lang.Object, java.lang.Object)
247 public synchronized Object put(Object key, Object value) {
248 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
252 * @see java.util.Hashtable#putAll(java.util.Map)
255 public synchronized void putAll(Map<? extends Object, ? extends Object> t) {
256 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
260 * @see java.util.Hashtable#rehash()
263 protected void rehash() {
264 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
268 * @see java.util.Hashtable#remove(java.lang.Object)
271 public synchronized Object remove(Object key) {
272 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
276 * @see java.util.Properties#save(java.io.OutputStream, java.lang.String)
280 public synchronized void save(OutputStream out, String comments) {
281 properties.save(out, comments);
285 * @see java.util.Properties#setProperty(java.lang.String, java.lang.String)
288 public synchronized Object setProperty(String key, String value) {
289 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
293 * @see java.util.Hashtable#size()
296 public synchronized int size() {
297 return properties.size();
301 * @see java.util.Properties#store(java.io.OutputStream, java.lang.String)
304 public void store(OutputStream out, String comments) throws IOException {
305 properties.store(out, comments);
309 * @see java.util.Properties#store(java.io.Writer, java.lang.String)
312 public void store(Writer writer, String comments) throws IOException {
313 properties.store(writer, comments);
317 * @see java.util.Properties#storeToXML(java.io.OutputStream, java.lang.String)
320 public synchronized void storeToXML(OutputStream os, String comment) throws IOException {
321 properties.storeToXML(os, comment);
325 * @see java.util.Properties#storeToXML(java.io.OutputStream, java.lang.String, java.lang.String)
328 public synchronized void storeToXML(OutputStream os, String comment, String encoding) throws IOException {
329 properties.storeToXML(os, comment, encoding);
333 * @see java.util.Properties#stringPropertyNames()
336 public Set<String> stringPropertyNames() {
337 return properties.stringPropertyNames();
341 * @see java.util.Hashtable#toString()
344 public synchronized String toString() {
345 return properties.toString();
349 * @see java.util.Hashtable#values()
352 public Collection<Object> values() {
353 return Collections.unmodifiableCollection(properties.values());