001/*
002 * JPPF.
003 * Copyright (C) 2005-2018 JPPF Team.
004 * http://www.jppf.org
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.jppf.utils;
019
020
021import java.io.*;
022import java.util.*;
023
024/**
025 * This class is an extension of {@link TypedProperties} which does not allow modifying the properties it contains.
026 * The methods in the super class that modify the properties have been overriden such that they do nothing, without
027 * rasing any exception.
028 * @author Laurent Cohen
029 */
030public class UnmodifiableTypedProperties extends TypedProperties {
031  /**
032   * Explicit serialVersionUID.
033   */
034  private static final long serialVersionUID = 1L;
035
036  /**
037   * Creates an empty unmodifiable properties map.
038   */
039  public UnmodifiableTypedProperties() {
040  }
041
042  /**
043   * Initialize this object with a set of existing properties.
044   * This will copy into the present object all map entries such that both key and value are strings.
045   * @param map the properties to be copied. No reference to this parameter is kept in this TypedProperties object.
046   */
047  public UnmodifiableTypedProperties(final Map<Object, Object> map) {
048    if (map != null) {
049      for (Map.Entry<Object, Object> entry: map.entrySet()) {
050        if ((entry.getKey() instanceof String) && (entry.getValue() instanceof String)) {
051          super.put(entry.getKey(), entry.getValue());
052        }
053      }
054    }
055  }
056
057  /**
058   * This method does nothing as modification is not permitted.
059   * @param key not used.
060   * @param value not used.
061   * @return <code>null</code>.
062   */
063  @Override
064  public synchronized Object setProperty(final String key, final String value) {
065    return null;
066  }
067
068  /**
069   * This method does nothing as modification is not permitted.
070   * @param reader not used.
071   * @throws IOException never thrown.
072   */
073  @Override
074  public synchronized void load(final Reader reader) throws IOException {
075  }
076
077  /**
078   * This method does nothing as modification is not permitted.
079   * @param in not used.
080   * @throws IOException never thrown.
081   */
082  @Override
083  public synchronized void load(final InputStream in) throws IOException {
084  }
085
086  /**
087   * This method does nothing as modification is not permitted.
088   * @param in not used.
089   * @throws IOException never thrown.
090   * @throws InvalidPropertiesFormatException never thrown.
091   */
092  @Override
093  public synchronized void loadFromXML(final InputStream in) throws IOException, InvalidPropertiesFormatException {
094  }
095
096  /**
097   * This method does nothing as modification is not permitted.
098   * @param key not used.
099   * @param value not used.
100   * @return <code>null</code>.
101   */
102  @Override
103  public synchronized Object put(final Object key, final Object value) {
104    return null;
105  }
106
107  /**
108   * This method does nothing as modification is not permitted.
109   * @param key not used.
110   * @return <code>null</code>.
111   */
112  @Override
113  public synchronized Object remove(final Object key) {
114    return null;
115  }
116
117  /**
118   * This method does nothing as modification is not permitted.
119   * @param map not used.
120   */
121  @Override
122  public synchronized void putAll(final Map<? extends Object, ? extends Object> map) {
123  }
124}