001/*
002 * ModeShape (http://www.modeshape.org)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *       http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.modeshape.common.collection;
017
018import java.io.IOException;
019import java.io.InputStream;
020import java.io.OutputStream;
021import java.io.PrintStream;
022import java.io.PrintWriter;
023import java.util.Collection;
024import java.util.Collections;
025import java.util.Enumeration;
026import java.util.Map;
027import java.util.Map.Entry;
028import java.util.Properties;
029import java.util.Set;
030import org.modeshape.common.annotation.Immutable;
031
032/**
033 * An immutable {@link Properties} implementation.
034 */
035@Immutable
036public class UnmodifiableProperties extends Properties {
037
038    private static final long serialVersionUID = -4670639332874922546L;
039    private Properties delegate;
040
041    public UnmodifiableProperties( Properties props ) {
042        super();
043        this.delegate = props != null ? props : new Properties();
044    }
045
046    @Override
047    public synchronized Object clone() {
048        return new UnmodifiableProperties(this.delegate);
049    }
050
051    @Override
052    public synchronized boolean contains( Object value ) {
053        return delegate.contains(value);
054    }
055
056    @Override
057    public boolean containsKey( Object key ) {
058        return this.delegate.containsKey(key);
059    }
060
061    @Override
062    public boolean containsValue( Object value ) {
063        return this.delegate.containsValue(value);
064    }
065
066    @Override
067    public Enumeration<Object> elements() {
068        return this.delegate.elements();
069    }
070
071    @Override
072    public boolean equals( Object o ) {
073        return this.delegate.equals(o);
074    }
075
076    @Override
077    public Object get( Object key ) {
078        return this.delegate.get(key);
079    }
080
081    @Override
082    public String getProperty( String key,
083                               String defaultValue ) {
084        return this.delegate.getProperty(key, defaultValue);
085    }
086
087    @Override
088    public String getProperty( String key ) {
089        return this.delegate.getProperty(key);
090    }
091
092    @Override
093    public int hashCode() {
094        return this.delegate.hashCode();
095    }
096
097    @Override
098    public boolean isEmpty() {
099        return this.delegate.isEmpty();
100    }
101
102    @Override
103    public Enumeration<Object> keys() {
104        return this.delegate.keys();
105    }
106
107    @Override
108    public void list( PrintStream out ) {
109        this.delegate.list(out);
110    }
111
112    @Override
113    public void list( PrintWriter out ) {
114        this.delegate.list(out);
115    }
116
117    @Override
118    public Enumeration<?> propertyNames() {
119        return this.delegate.propertyNames();
120    }
121
122    @Override
123    public int size() {
124        return this.delegate.size();
125    }
126
127    @Override
128    public void store( OutputStream out,
129                       String comments ) throws IOException {
130        this.delegate.store(out, comments);
131    }
132
133    @Override
134    public void storeToXML( OutputStream os,
135                            String comment,
136                            String encoding ) throws IOException {
137        this.delegate.storeToXML(os, comment, encoding);
138    }
139
140    @Override
141    public void storeToXML( OutputStream os,
142                            String comment ) throws IOException {
143        this.delegate.storeToXML(os, comment);
144    }
145
146    @Override
147    public String toString() {
148        return this.delegate.toString();
149    }
150
151    @Override
152    public Collection<Object> values() {
153        return this.delegate.values();
154    }
155
156    @Override
157    public synchronized void clear() {
158        throw new UnsupportedOperationException();
159    }
160
161    @Override
162    public Set<Entry<Object, Object>> entrySet() {
163        return Collections.unmodifiableSet(super.entrySet());
164    }
165
166    @Override
167    public Set<Object> keySet() {
168        return Collections.unmodifiableSet(super.keySet());
169    }
170
171    @Override
172    public synchronized void load( InputStream inStream ) {
173        throw new UnsupportedOperationException();
174    }
175
176    @Override
177    public synchronized void loadFromXML( InputStream in ) {
178        throw new UnsupportedOperationException();
179    }
180
181    @Override
182    public synchronized Object put( Object key,
183                                    Object value ) {
184        throw new UnsupportedOperationException();
185    }
186
187    @Override
188    public synchronized void putAll( Map<? extends Object, ? extends Object> t ) {
189        throw new UnsupportedOperationException();
190    }
191
192    /**
193     * {@inheritDoc}
194     */
195    @Override
196    public synchronized Object remove( Object key ) {
197        throw new UnsupportedOperationException();
198    }
199
200    /**
201     * {@inheritDoc}
202     */
203    @Override
204    public synchronized Object setProperty( String key,
205                                            String value ) {
206        throw new UnsupportedOperationException();
207    }
208
209}