2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
27 package org.openecomp.appc.util;
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.io.OutputStream;
32 import java.io.PrintStream;
33 import java.io.PrintWriter;
34 import java.io.Reader;
35 import java.io.Writer;
36 import java.util.Collection;
37 import java.util.Collections;
38 import java.util.Enumeration;
39 import java.util.InvalidPropertiesFormatException;
41 import java.util.Properties;
45 * This utility class is used to wrap a properties object and to delegate all read operations to the property object,
46 * while disallowing any write or modification to the property object.
49 public class UnmodifiableProperties extends Properties implements Cloneable {
54 private static final long serialVersionUID = 1L;
56 private static final String PROPERTY_CANNOT_BE_MODIFIED_MSG = "Property cannot be modified!";
59 * The properties object which we are wrapping
61 private Properties properties;
64 * Create the unmodifiable wrapper around the provided properties object
67 * The properties to be wrapped and protected from modification
69 public UnmodifiableProperties(Properties properties) {
70 this.properties = properties;
74 * @see java.util.Hashtable#clear()
77 public synchronized void clear() {
78 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
82 * @see java.util.Hashtable#clone()
86 public synchronized Object clone() {
87 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
93 * @see java.util.Hashtable#contains(java.lang.Object)
96 public synchronized boolean contains(Object value) {
97 return properties.contains(value);
101 * @see java.util.Hashtable#containsKey(java.lang.Object)
104 public synchronized boolean containsKey(Object key) {
105 return properties.containsKey(key);
109 * @see java.util.Hashtable#containsValue(java.lang.Object)
112 public boolean containsValue(Object value) {
113 return properties.containsValue(value);
117 * @see java.util.Hashtable#elements()
120 public synchronized Enumeration<Object> elements() {
121 return properties.elements();
125 * @see java.util.Hashtable#entrySet()
128 public Set<java.util.Map.Entry<Object, Object>> entrySet() {
129 return Collections.unmodifiableSet(properties.entrySet());
133 * @see java.util.Hashtable#equals(java.lang.Object)
136 public synchronized boolean equals(Object o) {
137 return properties.equals(o);
141 * @see java.util.Hashtable#get(java.lang.Object)
144 public synchronized Object get(Object key) {
145 return properties.get(key);
149 * @see java.util.Properties#getProperty(java.lang.String)
152 public String getProperty(String key) {
153 return properties.getProperty(key);
157 * @see java.util.Properties#getProperty(java.lang.String, java.lang.String)
160 public String getProperty(String key, String defaultValue) {
161 return properties.getProperty(key, defaultValue);
165 * @see java.util.Hashtable#hashCode()
168 public synchronized int hashCode() {
169 return properties.hashCode();
173 * @see java.util.Hashtable#isEmpty()
176 public synchronized boolean isEmpty() {
177 return properties.isEmpty();
181 * @see java.util.Hashtable#keys()
184 public synchronized Enumeration<Object> keys() {
185 return properties.keys();
189 * @see java.util.Hashtable#keySet()
192 public Set<Object> keySet() {
193 return Collections.unmodifiableSet(properties.keySet());
197 * @see java.util.Properties#list(java.io.PrintStream)
200 public void list(PrintStream out) {
201 properties.list(out);
205 * @see java.util.Properties#list(java.io.PrintWriter)
208 public void list(PrintWriter out) {
209 properties.list(out);
213 * @see java.util.Properties#load(java.io.InputStream)
216 public synchronized void load(InputStream inStream) throws IOException {
217 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
221 * @see java.util.Properties#load(java.io.Reader)
224 public synchronized void load(Reader reader) throws IOException {
225 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
229 * @see java.util.Properties#loadFromXML(java.io.InputStream)
232 public synchronized void loadFromXML(InputStream in) throws IOException, InvalidPropertiesFormatException {
233 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
237 * @see java.util.Properties#propertyNames()
240 public Enumeration<?> propertyNames() {
241 return properties.propertyNames();
245 * @see java.util.Hashtable#put(java.lang.Object, java.lang.Object)
248 public synchronized Object put(Object key, Object value) {
249 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
253 * @see java.util.Hashtable#putAll(java.util.Map)
256 public synchronized void putAll(Map<? extends Object, ? extends Object> t) {
257 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
261 * @see java.util.Hashtable#rehash()
264 protected void rehash() {
265 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
269 * @see java.util.Hashtable#remove(java.lang.Object)
272 public synchronized Object remove(Object key) {
273 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
277 * @see java.util.Properties#save(java.io.OutputStream, java.lang.String)
281 public synchronized void save(OutputStream out, String comments) {
282 properties.save(out, comments);
286 * @see java.util.Properties#setProperty(java.lang.String, java.lang.String)
289 public synchronized Object setProperty(String key, String value) {
290 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
294 * @see java.util.Hashtable#size()
297 public synchronized int size() {
298 return properties.size();
302 * @see java.util.Properties#store(java.io.OutputStream, java.lang.String)
305 public void store(OutputStream out, String comments) throws IOException {
306 properties.store(out, comments);
310 * @see java.util.Properties#store(java.io.Writer, java.lang.String)
313 public void store(Writer writer, String comments) throws IOException {
314 properties.store(writer, comments);
318 * @see java.util.Properties#storeToXML(java.io.OutputStream, java.lang.String)
321 public synchronized void storeToXML(OutputStream os, String comment) throws IOException {
322 properties.storeToXML(os, comment);
326 * @see java.util.Properties#storeToXML(java.io.OutputStream, java.lang.String, java.lang.String)
329 public synchronized void storeToXML(OutputStream os, String comment, String encoding) throws IOException {
330 properties.storeToXML(os, comment, encoding);
334 * @see java.util.Properties#stringPropertyNames()
337 public Set<String> stringPropertyNames() {
338 return properties.stringPropertyNames();
342 * @see java.util.Hashtable#toString()
345 public synchronized String toString() {
346 return properties.toString();
350 * @see java.util.Hashtable#values()
353 public Collection<Object> values() {
354 return Collections.unmodifiableCollection(properties.values());