Introduce ISettings
diff --git a/org.eclipse.userstorage/src/org/eclipse/userstorage/StorageFactory.java b/org.eclipse.userstorage/src/org/eclipse/userstorage/StorageFactory.java
index 7e2bd0f..53dc8bb 100644
--- a/org.eclipse.userstorage/src/org/eclipse/userstorage/StorageFactory.java
+++ b/org.eclipse.userstorage/src/org/eclipse/userstorage/StorageFactory.java
@@ -18,11 +18,13 @@
import org.eclipse.userstorage.spi.StorageCache;
import org.eclipse.userstorage.util.BadApplicationTokenException;
import org.eclipse.userstorage.util.Settings;
+import org.eclipse.userstorage.util.Settings.MemorySettings;
import java.util.NoSuchElementException;
/**
- * Creates {@link IStorage storages}.
+ * Creates {@link IStorage storages} and maintains their preferred {@link IStorage#getService() services}
+ * in the supplied {@link #getSettings() settings}.
*
* @author Eike Stepper
*/
@@ -32,13 +34,18 @@
private final ISettings settings;
+ /**
+ * Constructs this storage factory with the given settings.
+ *
+ * @param settings the settings to use with this storage factory, or <code>null</code> for {@link Settings#NONE no settings}.
+ */
public StorageFactory(ISettings settings)
{
this.settings = settings != null ? settings : Settings.NONE;
}
/**
- * Constructs this storage factory.
+ * Constructs this storage factory with {@link MemorySettings in-memory settings}.
*/
public StorageFactory()
{
diff --git a/org.eclipse.userstorage/src/org/eclipse/userstorage/util/Settings.java b/org.eclipse.userstorage/src/org/eclipse/userstorage/util/Settings.java
index 076fde6..ccc15a0 100644
--- a/org.eclipse.userstorage/src/org/eclipse/userstorage/util/Settings.java
+++ b/org.eclipse.userstorage/src/org/eclipse/userstorage/util/Settings.java
@@ -109,6 +109,58 @@
/**
* @author Eike Stepper
*/
+ public static final class EclipseSettings implements ISettings
+ {
+ private final Preferences node;
+
+ public EclipseSettings(String scope) throws Exception
+ {
+ IEclipsePreferences rootNode = Platform.getPreferencesService().getRootNode();
+ if (!rootNode.nodeExists(scope))
+ {
+ throw new BackingStoreException("Invalid scope: " + scope);
+ }
+
+ String nodeName = getNodeName();
+ node = rootNode.node(scope).node(nodeName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getValue(String key) throws Exception
+ {
+ return node.get(key, null);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setValue(String key, String value) throws Exception
+ {
+ if (value == null)
+ {
+ node.remove(key);
+ }
+ else
+ {
+ node.put(key, value);
+ }
+
+ node.flush();
+ }
+
+ protected String getNodeName()
+ {
+ return Activator.PLUGIN_ID;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
public static final class MemorySettings implements ISettings
{
private final Map<String, String> map = new HashMap<String, String>();
@@ -146,58 +198,6 @@
/**
* @author Eike Stepper
*/
- public static final class EclipseSettings implements ISettings
- {
- private final Preferences node;
-
- public EclipseSettings(String scope) throws BackingStoreException
- {
- IEclipsePreferences rootNode = Platform.getPreferencesService().getRootNode();
- if (!rootNode.nodeExists(scope))
- {
- throw new BackingStoreException("Invalid scope: " + scope);
- }
-
- String nodeName = getNodeName();
- node = rootNode.node(scope).node(nodeName);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getValue(String key) throws Exception
- {
- return node.get(key, null);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setValue(String key, String value) throws Exception
- {
- if (value == null)
- {
- node.remove(key);
- }
- else
- {
- node.put(key, value);
- }
-
- node.flush();
- }
-
- protected String getNodeName()
- {
- return Activator.PLUGIN_ID;
- }
- }
-
- /**
- * @author Eike Stepper
- */
public final class FileSettings implements ISettings
{
private final File file;