X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffreenet%2FPluginStoreConfigurationBackend.java;h=a0690a4e7a7164e1ba04887ac368ab54bbaffa1f;hb=2e03e9dddbea4b81aacaf1aa316f5c3ccffd4bf9;hp=97b463cd7108233f2b6379d337a5ac494f232fce;hpb=8cb84027861a382525fb206a6aa320a5796115a1;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/freenet/PluginStoreConfigurationBackend.java b/src/main/java/net/pterodactylus/sone/freenet/PluginStoreConfigurationBackend.java index 97b463c..a0690a4 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/PluginStoreConfigurationBackend.java +++ b/src/main/java/net/pterodactylus/sone/freenet/PluginStoreConfigurationBackend.java @@ -1,5 +1,5 @@ /* - * FreenetSone - PluginStoreConfigurationBackend.java - Copyright © 2010 David Roden + * Sone - PluginStoreConfigurationBackend.java - Copyright © 2010–2013 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,10 +17,15 @@ package net.pterodactylus.sone.freenet; +import java.util.logging.Logger; + import net.pterodactylus.util.config.AttributeNotFoundException; import net.pterodactylus.util.config.Configuration; import net.pterodactylus.util.config.ConfigurationException; import net.pterodactylus.util.config.ExtendedConfigurationBackend; +import net.pterodactylus.util.logging.Logging; +import freenet.client.async.DatabaseDisabledException; +import freenet.pluginmanager.PluginRespirator; import freenet.pluginmanager.PluginStore; /** @@ -30,22 +35,32 @@ import freenet.pluginmanager.PluginStore; */ public class PluginStoreConfigurationBackend implements ExtendedConfigurationBackend { + /** The logger. */ + @SuppressWarnings("unused") + private static final Logger logger = Logging.getLogger(PluginStoreConfigurationBackend.class); + + /** The plugin respirator. */ + private final PluginRespirator pluginRespirator; + /** The backing plugin store. */ private final PluginStore pluginStore; /** * Creates a new configuration backend based on a plugin store. * - * @param pluginStore - * The backing plugin store + * @param pluginRespirator + * The plugin respirator + * @throws DatabaseDisabledException + * if the plugin store is not available */ - public PluginStoreConfigurationBackend(PluginStore pluginStore) { - this.pluginStore = pluginStore; + public PluginStoreConfigurationBackend(PluginRespirator pluginRespirator) throws DatabaseDisabledException { + this.pluginRespirator = pluginRespirator; + this.pluginStore = pluginRespirator.getStore(); + if (this.pluginStore == null) { + throw new DatabaseDisabledException(); + } } - /** - * {@inheritDoc} - */ @Override public String getValue(String attribute) throws ConfigurationException { if (!pluginStore.strings.containsKey(attribute)) { @@ -54,17 +69,12 @@ public class PluginStoreConfigurationBackend implements ExtendedConfigurationBac return pluginStore.strings.get(attribute); } - /** - * {@inheritDoc} - */ @Override public void putValue(String attribute, String value) throws ConfigurationException { pluginStore.strings.put(attribute, value); + save(); } - /** - * {@inheritDoc} - */ @Override public Boolean getBooleanValue(String attribute) throws ConfigurationException { if (!pluginStore.booleans.containsKey(attribute)) { @@ -73,17 +83,12 @@ public class PluginStoreConfigurationBackend implements ExtendedConfigurationBac return pluginStore.booleans.get(attribute); } - /** - * {@inheritDoc} - */ @Override public void setBooleanValue(String attribute, Boolean value) throws ConfigurationException { pluginStore.booleans.put(attribute, value); + save(); } - /** - * {@inheritDoc} - */ @Override public Double getDoubleValue(String attribute) throws ConfigurationException { if (!pluginStore.strings.containsKey(attribute)) { @@ -100,17 +105,12 @@ public class PluginStoreConfigurationBackend implements ExtendedConfigurationBac } } - /** - * {@inheritDoc} - */ @Override public void setDoubleValue(String attribute, Double value) throws ConfigurationException { pluginStore.strings.put(attribute, String.valueOf(value)); + save(); } - /** - * {@inheritDoc} - */ @Override public Integer getIntegerValue(String attribute) throws ConfigurationException { if (!pluginStore.integers.containsKey(attribute)) { @@ -119,17 +119,12 @@ public class PluginStoreConfigurationBackend implements ExtendedConfigurationBac return pluginStore.integers.get(attribute); } - /** - * {@inheritDoc} - */ @Override public void setIntegerValue(String attribute, Integer value) throws ConfigurationException { pluginStore.integers.put(attribute, value); + save(); } - /** - * {@inheritDoc} - */ @Override public Long getLongValue(String attribute) throws ConfigurationException { if (!pluginStore.longs.containsKey(attribute)) { @@ -138,12 +133,19 @@ public class PluginStoreConfigurationBackend implements ExtendedConfigurationBac return pluginStore.longs.get(attribute); } - /** - * {@inheritDoc} - */ @Override public void setLongValue(String attribute, Long value) throws ConfigurationException { pluginStore.longs.put(attribute, value); + save(); + } + + @Override + public void save() throws ConfigurationException { + try { + pluginRespirator.putStore(pluginStore); + } catch (DatabaseDisabledException dde1) { + throw new ConfigurationException("Could not store plugin store, database is disabled.", dde1); + } } }