2 * FreenetSone - PluginStoreConfigurationBackend.java - Copyright © 2010 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.freenet;
20 import net.pterodactylus.util.config.Configuration;
21 import net.pterodactylus.util.config.ConfigurationException;
22 import net.pterodactylus.util.config.ExtendedConfigurationBackend;
23 import freenet.pluginmanager.PluginStore;
26 * Backend for a {@link Configuration} that is based on a {@link PluginStore}.
28 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
30 public class PluginStoreConfigurationBackend implements ExtendedConfigurationBackend {
32 /** The backing plugin store. */
33 private final PluginStore pluginStore;
36 * Creates a new configuration backend based on a plugin store.
39 * The backing plugin store
41 public PluginStoreConfigurationBackend(PluginStore pluginStore) {
42 this.pluginStore = pluginStore;
49 public String getValue(String attribute) throws ConfigurationException {
50 return pluginStore.strings.get(attribute);
57 public void putValue(String attribute, String value) throws ConfigurationException {
58 pluginStore.strings.put(attribute, value);
65 public Boolean getBooleanValue(String attribute) throws ConfigurationException {
66 return pluginStore.booleans.get(attribute);
73 public void setBooleanValue(String attribute, Boolean value) throws ConfigurationException {
74 pluginStore.booleans.put(attribute, value);
81 public Double getDoubleValue(String attribute) throws ConfigurationException {
82 String stringValue = pluginStore.strings.get(attribute);
83 if (stringValue == null) {
87 return Double.valueOf(pluginStore.strings.get(attribute));
88 } catch (NumberFormatException nfe1) {
89 throw new ConfigurationException("Could not parse “" + stringValue + "”.", nfe1);
97 public void setDoubleValue(String attribute, Double value) throws ConfigurationException {
98 pluginStore.strings.put(attribute, String.valueOf(value));
105 public Integer getIntegerValue(String attribute) throws ConfigurationException {
106 return pluginStore.integers.get(attribute);
113 public void setIntegerValue(String attribute, Integer value) throws ConfigurationException {
114 pluginStore.integers.put(attribute, value);
121 public Long getLongValue(String attribute) throws ConfigurationException {
122 return pluginStore.longs.get(attribute);
129 public void setLongValue(String attribute, Long value) throws ConfigurationException {
130 pluginStore.longs.put(attribute, value);