2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
24 package org.openecomp.appc.util;
26 import java.io.IOException;
27 import java.io.InputStream;
28 import java.io.OutputStream;
29 import java.io.PrintStream;
30 import java.io.PrintWriter;
31 import java.io.Reader;
32 import java.io.Writer;
33 import java.util.Collection;
34 import java.util.Collections;
35 import java.util.Enumeration;
36 import java.util.InvalidPropertiesFormatException;
38 import java.util.Properties;
42 * This utility class is used to wrap a properties object and to delegate all read operations to the property object,
43 * while disallowing any write or modification to the property object.
46 public class UnmodifiableProperties extends Properties implements Cloneable {
51 private static final long serialVersionUID = 1L;
53 private static final String PROPERTY_CANNOT_BE_MODIFIED_MSG = "Property cannot be modified!";
56 * The properties object which we are wrapping
58 private Properties properties;
61 * Create the unmodifiable wrapper around the provided properties object
64 * The properties to be wrapped and protected from modification
66 public UnmodifiableProperties(Properties properties) {
67 this.properties = properties;
71 * @see java.util.Hashtable#clear()
74 public synchronized void clear() {
75 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
79 * @see java.util.Hashtable#clone()
83 public synchronized Object clone() {
84 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
90 * @see java.util.Hashtable#contains(java.lang.Object)
93 public synchronized boolean contains(Object value) {
94 return properties.contains(value);
98 * @see java.util.Hashtable#containsKey(java.lang.Object)
101 public synchronized boolean containsKey(Object key) {
102 return properties.containsKey(key);
106 * @see java.util.Hashtable#containsValue(java.lang.Object)
109 public boolean containsValue(Object value) {
110 return properties.containsValue(value);
114 * @see java.util.Hashtable#elements()
117 public synchronized Enumeration<Object> elements() {
118 return properties.elements();
122 * @see java.util.Hashtable#entrySet()
125 public Set<java.util.Map.Entry<Object, Object>> entrySet() {
126 return Collections.unmodifiableSet(properties.entrySet());
130 * @see java.util.Hashtable#equals(java.lang.Object)
133 public synchronized boolean equals(Object o) {
134 return properties.equals(o);
138 * @see java.util.Hashtable#get(java.lang.Object)
141 public synchronized Object get(Object key) {
142 return properties.get(key);
146 * @see java.util.Properties#getProperty(java.lang.String)
149 public String getProperty(String key) {
150 return properties.getProperty(key);
154 * @see java.util.Properties#getProperty(java.lang.String, java.lang.String)
157 public String getProperty(String key, String defaultValue) {
158 return properties.getProperty(key, defaultValue);
162 * @see java.util.Hashtable#hashCode()
165 public synchronized int hashCode() {
166 return properties.hashCode();
170 * @see java.util.Hashtable#isEmpty()
173 public synchronized boolean isEmpty() {
174 return properties.isEmpty();
178 * @see java.util.Hashtable#keys()
181 public synchronized Enumeration<Object> keys() {
182 return properties.keys();
186 * @see java.util.Hashtable#keySet()
189 public Set<Object> keySet() {
190 return Collections.unmodifiableSet(properties.keySet());
194 * @see java.util.Properties#list(java.io.PrintStream)
197 public void list(PrintStream out) {
198 properties.list(out);
202 * @see java.util.Properties#list(java.io.PrintWriter)
205 public void list(PrintWriter out) {
206 properties.list(out);
210 * @see java.util.Properties#load(java.io.InputStream)
213 public synchronized void load(InputStream inStream) throws IOException {
214 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
218 * @see java.util.Properties#load(java.io.Reader)
221 public synchronized void load(Reader reader) throws IOException {
222 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
226 * @see java.util.Properties#loadFromXML(java.io.InputStream)
229 public synchronized void loadFromXML(InputStream in) throws IOException, InvalidPropertiesFormatException {
230 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
234 * @see java.util.Properties#propertyNames()
237 public Enumeration<?> propertyNames() {
238 return properties.propertyNames();
242 * @see java.util.Hashtable#put(java.lang.Object, java.lang.Object)
245 public synchronized Object put(Object key, Object value) {
246 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
250 * @see java.util.Hashtable#putAll(java.util.Map)
253 public synchronized void putAll(Map<? extends Object, ? extends Object> t) {
254 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
258 * @see java.util.Hashtable#rehash()
261 protected void rehash() {
262 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
266 * @see java.util.Hashtable#remove(java.lang.Object)
269 public synchronized Object remove(Object key) {
270 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
274 * @see java.util.Properties#save(java.io.OutputStream, java.lang.String)
278 public synchronized void save(OutputStream out, String comments) {
279 properties.save(out, comments);
283 * @see java.util.Properties#setProperty(java.lang.String, java.lang.String)
286 public synchronized Object setProperty(String key, String value) {
287 throw new UnsupportedOperationException(PROPERTY_CANNOT_BE_MODIFIED_MSG);
291 * @see java.util.Hashtable#size()
294 public synchronized int size() {
295 return properties.size();
299 * @see java.util.Properties#store(java.io.OutputStream, java.lang.String)
302 public void store(OutputStream out, String comments) throws IOException {
303 properties.store(out, comments);
307 * @see java.util.Properties#store(java.io.Writer, java.lang.String)
310 public void store(Writer writer, String comments) throws IOException {
311 properties.store(writer, comments);
315 * @see java.util.Properties#storeToXML(java.io.OutputStream, java.lang.String)
318 public synchronized void storeToXML(OutputStream os, String comment) throws IOException {
319 properties.storeToXML(os, comment);
323 * @see java.util.Properties#storeToXML(java.io.OutputStream, java.lang.String, java.lang.String)
326 public synchronized void storeToXML(OutputStream os, String comment, String encoding) throws IOException {
327 properties.storeToXML(os, comment, encoding);
331 * @see java.util.Properties#stringPropertyNames()
334 public Set<String> stringPropertyNames() {
335 return properties.stringPropertyNames();
339 * @see java.util.Hashtable#toString()
342 public synchronized String toString() {
343 return properties.toString();
347 * @see java.util.Hashtable#values()
350 public Collection<Object> values() {
351 return Collections.unmodifiableCollection(properties.values());