2 * FreenetSone - SonePlugin.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.main;
21 import java.util.Collections;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
25 import net.pterodactylus.sone.core.Core;
26 import net.pterodactylus.sone.core.FreenetInterface;
27 import net.pterodactylus.sone.freenet.PluginStoreConfigurationBackend;
28 import net.pterodactylus.util.config.Configuration;
29 import net.pterodactylus.util.config.ConfigurationException;
30 import net.pterodactylus.util.config.MapConfigurationBackend;
31 import net.pterodactylus.util.config.XMLConfigurationBackend;
32 import net.pterodactylus.util.logging.Logging;
33 import freenet.client.async.DatabaseDisabledException;
34 import freenet.pluginmanager.FredPlugin;
35 import freenet.pluginmanager.PluginRespirator;
38 * This class interfaces with Freenet. It is the class that is loaded by the
39 * node and starts up the whole Sone system.
41 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
43 public class SonePlugin implements FredPlugin {
46 /* initialize logging. */
47 Logging.setup("sone");
51 private static final Logger logger = Logging.getLogger(SonePlugin.class);
64 public void runPlugin(PluginRespirator pluginRespirator) {
66 /* create a configuration. */
67 Configuration configuration;
69 configuration = new Configuration(new PluginStoreConfigurationBackend(pluginRespirator.getStore()));
70 } catch (DatabaseDisabledException dde1) {
71 logger.log(Level.WARNING, "Could not load plugin store, using XML files.");
73 configuration = new Configuration(new XMLConfigurationBackend(new File("sone.xml"), true));
74 } catch (ConfigurationException ce1) {
75 logger.log(Level.SEVERE, "Could not load or create the “sone.xml” configuration file!");
76 configuration = new Configuration(new MapConfigurationBackend(Collections.<String, String> emptyMap()));
80 /* create freenet interface. */
81 FreenetInterface freenetInterface = new FreenetInterface(pluginRespirator.getNode(), pluginRespirator.getHLSimpleClient());
85 core.configuration(configuration);
86 core.freenetInterface(freenetInterface);
96 public void terminate() {
100 /* TODO wait for core to stop? */