Change loading order of configuration backends.
[Sone.git] / src / main / java / net / pterodactylus / sone / main / SonePlugin.java
index 77a1151..6d9e3a0 100644 (file)
@@ -81,7 +81,7 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10
        }
 
        /** The version. */
-       public static final Version VERSION = new Version("RC2", 0, 2);
+       public static final Version VERSION = new Version(0, 3);
 
        /** The logger. */
        private static final Logger logger = Logging.getLogger(SonePlugin.class);
@@ -148,14 +148,20 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10
 
                /* create a configuration. */
                Configuration configuration;
+               Configuration xmlConfiguration = null;
                try {
-                       configuration = new Configuration(new PluginStoreConfigurationBackend(pluginRespirator));
-               } catch (DatabaseDisabledException dde1) {
-                       logger.log(Level.WARNING, "Could not load plugin store, using XML files.");
+                       configuration = new Configuration(new XMLConfigurationBackend(new File("sone.xml"), false));
+                       xmlConfiguration = configuration;
+               } catch (ConfigurationException ce1) {
                        try {
-                               configuration = new Configuration(new XMLConfigurationBackend(new File("sone.xml"), true));
-                       } catch (ConfigurationException ce1) {
-                               logger.log(Level.SEVERE, "Could not load or create the “sone.xml” configuration file!");
+                               xmlConfiguration = new Configuration(new XMLConfigurationBackend(new File("sone.xml"), true));
+                       } catch (ConfigurationException ce2) {
+                               logger.log(Level.SEVERE, "Could not create XML file, using Plugin Store!");
+                       }
+                       try {
+                               configuration = new Configuration(new PluginStoreConfigurationBackend(pluginRespirator));
+                       } catch (DatabaseDisabledException dde1) {
+                               logger.log(Level.SEVERE, "Could not load any configuration, using in-memory configuration!");
                                configuration = new Configuration(new MapConfigurationBackend(Collections.<String, String> emptyMap()));
                        }
                }
@@ -169,12 +175,13 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10
                identityManager = new IdentityManager(webOfTrustConnector);
                identityManager.setContext("Sone");
 
-               /* create the web interface. */
-               webInterface = new WebInterface(this);
-
                /* create core. */
                core = new Core(configuration, freenetInterface, identityManager);
 
+               /* create the web interface. */
+               webInterface = new WebInterface(this);
+               core.addCoreListener(webInterface);
+
                /* create the identity manager. */
                identityManager.addIdentityListener(core);
 
@@ -182,6 +189,9 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10
                boolean startupFailed = true;
                try {
                        core.start();
+                       if ((xmlConfiguration != null) && (configuration != xmlConfiguration)) {
+                               core.setConfiguration(xmlConfiguration);
+                       }
                        webInterface.start();
                        identityManager.start();
                        startupFailed = false;