001 /*
002 * Copyright 2002-2004 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005 * use this file except in compliance with the License. You may obtain a copy of
006 * 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, WITHOUT
012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013 * License for the specific language governing permissions and limitations under
014 * the License.
015 */
016 package org.springframework.richclient.settings;
017
018 import java.io.IOException;
019 import java.util.HashMap;
020 import java.util.Map;
021
022 /**
023 * Helper class, essential when testing with settings. Completely functional
024 * <code>Settings</code> implementation, but the settings values are not
025 * stored in any backing store.
026 *
027 * @author Peter De Bruycker
028 */
029 public class TransientSettings extends AbstractSettings {
030
031 private Map values = new HashMap();
032
033 public TransientSettings() {
034 this(null, "");
035 }
036
037 public TransientSettings(TransientSettings parent, String name) {
038 super(parent, name);
039 }
040
041 protected void internalSet(String key, String value) {
042 values.put(key, value);
043 }
044
045 protected String internalGet(String key) {
046 return (String) values.get(key);
047 }
048
049 public String[] getKeys() {
050 return (String[]) values.keySet().toArray(new String[0]);
051 }
052
053 public void save() throws IOException {
054 }
055
056 public void load() throws IOException {
057 }
058
059 protected Settings internalCreateChild(String key) {
060 return new TransientSettings(this, key);
061 }
062
063 protected void internalRemove(String key) {
064 values.remove(key);
065 }
066
067 protected boolean internalContains(String key) {
068 return values.containsKey(key);
069 }
070
071 protected String[] internalGetChildSettings() {
072 return new String[0];
073 }
074
075 public void internalRemoveSettings() {
076
077 }
078 }