- /* create a configuration. */
- Configuration oldConfiguration;
- Configuration newConfiguration = null;
- boolean firstStart = !new File("sone.properties").exists();
- boolean newConfig = false;
- try {
- oldConfiguration = new Configuration(new MapConfigurationBackend(new File("sone.properties"), false));
- newConfiguration = oldConfiguration;
- } catch (ConfigurationException ce1) {
- newConfig = true;
- logger.log(Level.INFO, "Could not load configuration file, trying plugin store…", ce1);
- try {
- newConfiguration = new Configuration(new MapConfigurationBackend(new File("sone.properties"), true));
- logger.log(Level.INFO, "Created new configuration file.");
- } catch (ConfigurationException ce2) {
- logger.log(Level.SEVERE, "Could not create configuration file, using Plugin Store!", ce2);
- }
- try {
- oldConfiguration = new Configuration(new PluginStoreConfigurationBackend(pluginRespirator));
- logger.log(Level.INFO, "Plugin store loaded.");
- } catch (DatabaseDisabledException dde1) {
- logger.log(Level.SEVERE, "Could not load any configuration, using empty configuration!");
- oldConfiguration = new Configuration(new MapConfigurationBackend());
- }
- }
-
- final Configuration startConfiguration = oldConfiguration;
- final EventBus eventBus = new EventBus();
-
- /* Freenet injector configuration. */
- AbstractModule freenetModule = new AbstractModule() {
-
- @Override
- @SuppressWarnings("synthetic-access")
- protected void configure() {
- bind(PluginRespirator.class).toInstance(SonePlugin.this.pluginRespirator);
- bind(Node.class).toInstance(SonePlugin.this.pluginRespirator.getNode());
- }
- };
- /* Sone injector configuration. */
- AbstractModule soneModule = new AbstractModule() {
-
- @Override
- protected void configure() {
- bind(Core.class).in(Singleton.class);
- bind(MemoryDatabase.class).in(Singleton.class);
- bind(EventBus.class).toInstance(eventBus);
- bind(Configuration.class).toInstance(startConfiguration);
- bind(FreenetInterface.class).in(Singleton.class);
- bind(PluginConnector.class).in(Singleton.class);
- bind(WebOfTrustConnector.class).in(Singleton.class);
- bind(WebOfTrustUpdater.class).in(Singleton.class);
- bind(IdentityManager.class).in(Singleton.class);
- bind(String.class).annotatedWith(Names.named("WebOfTrustContext")).toInstance("Sone");
- bind(SonePlugin.class).toInstance(SonePlugin.this);
- bind(FcpInterface.class).in(Singleton.class);
- bind(Database.class).to(MemoryDatabase.class);
- bind(PostBuilderFactory.class).to(MemoryDatabase.class);
- bind(PostReplyBuilderFactory.class).to(MemoryDatabase.class);
- bind(SoneProvider.class).to(Core.class).in(Singleton.class);
- bind(PostProvider.class).to(MemoryDatabase.class);
- bindListener(Matchers.any(), new TypeListener() {
-
- @Override
- public <I> void hear(TypeLiteral<I> typeLiteral, TypeEncounter<I> typeEncounter) {
- typeEncounter.register(new InjectionListener<I>() {
-
- @Override
- public void afterInjection(I injectee) {
- eventBus.register(injectee);
- }
- });
- }
- });
- }
-
- };
- Injector injector = Guice.createInjector(freenetModule, soneModule);