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.AttributeNotFoundException;
21 import net.pterodactylus.util.config.Configuration;
22 import net.pterodactylus.util.config.ConfigurationException;
23 import net.pterodactylus.util.config.ExtendedConfigurationBackend;
24 import freenet.pluginmanager.PluginStore;
27 * Backend for a {@link Configuration} that is based on a {@link PluginStore}.
29 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
31 public class PluginStoreConfigurationBackend implements ExtendedConfigurationBackend {
33 /** The backing plugin store. */
34 private final PluginStore pluginStore;
37 * Creates a new configuration backend based on a plugin store.
40 * The backing plugin store
42 public PluginStoreConfigurationBackend(PluginStore pluginStore) {
43 this.pluginStore = pluginStore;
50 public String getValue(String attribute) throws ConfigurationException {
51 if (!pluginStore.strings.containsKey(attribute)) {
52 throw new AttributeNotFoundException(attribute);
54 return pluginStore.strings.get(attribute);
61 public void putValue(String attribute, String value) throws ConfigurationException {
62 pluginStore.strings.put(attribute, value);
69 public Boolean getBooleanValue(String attribute) throws ConfigurationException {
70 if (!pluginStore.booleans.containsKey(attribute)) {
71 throw new AttributeNotFoundException(attribute);
73 return pluginStore.booleans.get(attribute);
80 public void setBooleanValue(String attribute, Boolean value) throws ConfigurationException {
81 pluginStore.booleans.put(attribute, value);
88 public Double getDoubleValue(String attribute) throws ConfigurationException {
89 if (!pluginStore.strings.containsKey(attribute)) {
90 throw new AttributeNotFoundException(attribute);
92 String stringValue = pluginStore.strings.get(attribute);
93 if (stringValue == null) {
97 return Double.valueOf(pluginStore.strings.get(attribute));
98 } catch (NumberFormatException nfe1) {
99 throw new ConfigurationException("Could not parse “" + stringValue + "”.", nfe1);
107 public void setDoubleValue(String attribute, Double value) throws ConfigurationException {
108 pluginStore.strings.put(attribute, String.valueOf(value));
115 public Integer getIntegerValue(String attribute) throws ConfigurationException {
116 if (!pluginStore.integers.containsKey(attribute)) {
117 throw new AttributeNotFoundException(attribute);
119 return pluginStore.integers.get(attribute);
126 public void setIntegerValue(String attribute, Integer value) throws ConfigurationException {
127 pluginStore.integers.put(attribute, value);
134 public Long getLongValue(String attribute) throws ConfigurationException {
135 if (!pluginStore.longs.containsKey(attribute)) {
136 throw new AttributeNotFoundException(attribute);
138 return pluginStore.longs.get(attribute);
145 public void setLongValue(String attribute, Long value) throws ConfigurationException {
146 pluginStore.longs.put(attribute, value);