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.io.InputStream; 020 import java.io.OutputStream; 021 022 /** 023 * Facade for working with <code>Settings</code>. Provides methods for 024 * <code>Settings</code> creation, export, import, ... 025 * <p> 026 * Creation of <code>Settings</code> is delegated to a 027 * <code>SettingsFactory</code>. 028 * <p> 029 * The export and import of <code>Settings</code> is done with xml files 030 * 031 * @author Peter De Bruycker 032 */ 033 public class SettingsManager { 034 private SettingsFactory settingsFactory = new TransientSettingsFactory(); 035 036 private Settings internalSettings; 037 038 private Settings userSettings; 039 040 public static final String INTERNAL = "internal"; 041 042 public static final String USER = "user"; 043 044 /** 045 * Returns the internal settings, i.e. the settings used for storing ui 046 * state, and other settings normally not visible and configurable to the 047 * user. 048 * 049 * @return the internal <code>Settings</code> 050 * @throws SettingsException 051 */ 052 public Settings getInternalSettings() throws SettingsException { 053 if (internalSettings == null) { 054 internalSettings = createSettings(INTERNAL); 055 } 056 return internalSettings; 057 } 058 059 /** 060 * Returns the user settings, i.e. the settings used for the user 061 * preferences, normally these settings can be changed by the user, and 062 * affect the applications appearance and behaviour. These settings can also 063 * be exported/imported. 064 * 065 * @return the user <code>Settings</code> 066 * @throws SettingsException 067 */ 068 public Settings getUserSettings() throws SettingsException { 069 if (userSettings == null) { 070 userSettings = createSettings(USER); 071 } 072 return userSettings; 073 } 074 075 /** 076 * Returns the <code>Settings</code> for the given key. This method should 077 * not be called directly, use <code>{@link #getInternalSettings()}</code> 078 * or <code>{@link #getUserSettings()}</code> instead. 079 * 080 * @param key 081 * the key 082 * @return the Settings 083 * @throws SettingsException 084 * if the <code>Settings</code> could not be created 085 */ 086 public Settings createSettings(String key) throws SettingsException { 087 return settingsFactory.createSettings(key); 088 } 089 090 /** 091 * Set the settings factory. If the factory is set to <code>null</code>, 092 * the TransientSettingsFactory will be used. 093 * 094 * @param factory 095 * the factory 096 */ 097 public void setSettingsFactory(SettingsFactory factory) { 098 settingsFactory = factory; 099 if (settingsFactory == null) { 100 settingsFactory = new TransientSettingsFactory(); 101 } 102 } 103 104 /** 105 * Returns the settings factory. 106 * 107 * @return the factory 108 */ 109 public SettingsFactory getSettingsFactory() { 110 return settingsFactory; 111 } 112 113 /** 114 * Export <code>settings</code> to an <code>OutputStream</code> 115 * 116 * @param settings 117 * the <code>settings</code> 118 * @param out 119 * the <code>OutputStream</code> 120 * @throws IOException 121 * if the settings could not be exported 122 */ 123 public void exportSettings(Settings settings, OutputStream out) throws IOException { 124 throw new UnsupportedOperationException("Not yet implemented"); 125 } 126 127 /** 128 * Import <code>settings</code> from an <code>InputStream</code> 129 * 130 * @param settings 131 * the <code>settings</code> 132 * @param in 133 * the <code>InputStream</code> 134 * @throws IOException 135 * if the settings could not be imported 136 */ 137 public void importSettings(Settings settings, InputStream in) throws IOException { 138 throw new UnsupportedOperationException("Not yet implemented"); 139 } 140 }