001: package org.tanukisoftware.wrapper;
002:
003: /*
004: * Copyright (c) 1999, 2006 Tanuki Software Inc.
005: *
006: * Permission is hereby granted, free of charge, to any person
007: * obtaining a copy of the Java Service Wrapper and associated
008: * documentation files (the "Software"), to deal in the Software
009: * without restriction, including without limitation the rights
010: * to use, copy, modify, merge, publish, distribute, sub-license,
011: * and/or sell copies of the Software, and to permit persons to
012: * whom the Software is furnished to do so, subject to the
013: * following conditions:
014: *
015: * The above copyright notice and this permission notice shall be
016: * included in all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
019: * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
020: * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
021: * NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
022: * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
023: * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
024: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
025: * OTHER DEALINGS IN THE SOFTWARE.
026: */
027:
028: import java.io.InputStream;
029: import java.io.IOException;
030: import java.util.Collection;
031: import java.util.Collections;
032: import java.util.Iterator;
033: import java.util.Map;
034: import java.util.Properties;
035: import java.util.Set;
036:
037: /**
038: * Provides a Properties object which can be locked to prevent modification
039: * by the user.
040: *
041: * @author Leif Mortenson <leif@tanukisoftware.com>
042: */
043: class WrapperProperties extends Properties {
044: boolean m_locked = false;
045:
046: /**
047: * Locks the Properties object against future modification.
048: */
049: public void lock() {
050: m_locked = true;
051: }
052:
053: public void load(InputStream inStream) throws IOException {
054: if (m_locked) {
055: throw new IllegalStateException("Read Only");
056: }
057: super .load(inStream);
058: }
059:
060: public Object setProperty(String key, String value) {
061: if (m_locked) {
062: throw new IllegalStateException("Read Only");
063: }
064: return super .setProperty(key, value);
065: }
066:
067: public void clear() {
068: if (m_locked) {
069: throw new IllegalStateException("Read Only");
070: }
071: super .clear();
072: }
073:
074: public Set entrySet() {
075: if (m_locked) {
076: return Collections.unmodifiableSet(super .entrySet());
077: } else {
078: return super .entrySet();
079: }
080: }
081:
082: public Set keySet() {
083: if (m_locked) {
084: return Collections.unmodifiableSet(super .keySet());
085: } else {
086: return super .keySet();
087: }
088: }
089:
090: public Object put(Object key, Object value) {
091: if (m_locked) {
092: throw new IllegalStateException("Read Only");
093: }
094: return super .put(key, value);
095: }
096:
097: public void putAll(Map map) {
098: if (m_locked) {
099: throw new IllegalStateException("Read Only");
100: }
101: super .putAll(map);
102: }
103:
104: public Object remove(Object key) {
105: if (m_locked) {
106: throw new IllegalStateException("Read Only");
107: }
108: return super .remove(key);
109: }
110:
111: public Collection values() {
112: if (m_locked) {
113: return Collections.unmodifiableCollection(super.values());
114: } else {
115: return super.values();
116: }
117: }
118: }
|