Commits

Anonymous committed 35740ae

Configure WebApp modules

  • Participants
  • Parent commits 7e2b22f

Comments (0)

Files changed (6)

chempound-app/src/main/java/net/chempound/datastore/JenaTripleStoreModule.java

+package net.chempound.datastore;
+
+import com.google.inject.AbstractModule;
+
+public class JenaTripleStoreModule extends AbstractModule {
+
+    @Override
+    protected void configure() {
+        bind(TripleStore.class).to(JenaTripleStore.class);
+    }
+}

chempound-app/src/main/java/net/chempound/storage/FileSystemResourceStoreModule.java

+package net.chempound.storage;
+
+import com.google.inject.AbstractModule;
+
+public class FileSystemResourceStoreModule extends AbstractModule {
+
+    @Override
+    protected void configure() {
+        bind(ResourceStore.class).to(FileSystemResourceStore.class);
+    }
+}

chempound-webapp/src/main/java/net/chempound/webapp/ChempoundServletConfig.java

 package net.chempound.webapp;
 
-import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-import com.google.inject.Module;
+import com.google.inject.Stage;
 import com.google.inject.servlet.GuiceServletContextListener;
-import com.google.inject.servlet.ServletModule;
-import net.chempound.DefaultChempoundModule;
 
 /**
  * @author sea36
 
     @Override
     public Injector getInjector() {
-        return Guice.createInjector(
-                getChempoundModule(),
-                getServletModule(),
-                getPluginsModule(),
-                getWebappModule()
-        );
+        return Guice.createInjector(Stage.PRODUCTION,
+                new ChempoundWebappModule(),
+                new ChempoundServletModule());
     }
-
-    protected Module getWebappModule() {
-        return new DefaultChempoundWebModule();
-    }
-
-    protected Module getChempoundModule() {
-        return new DefaultChempoundModule();
-    }
-
-    protected ServletModule getServletModule() {
-        return new ChempoundServletModule();
-    }
-
-    protected Module getPluginsModule() {
-        return new AbstractModule() {
-            @Override
-            protected void configure() {
-
-            }
-        };
-    }
-
-
-
 }

chempound-webapp/src/main/java/net/chempound/webapp/ChempoundWebappLauncher.java

  */
 public class ChempoundWebappLauncher {
 
+    private final ChempoundWebappModule module;
     private final Stage stage;
 
-    public ChempoundWebappLauncher() {
+    public ChempoundWebappLauncher(final ChempoundWebappModule chempoundWebappModule) {
+        this.module = chempoundWebappModule;
         this.stage = Stage.PRODUCTION;
     }
 
     public static void main(final String[] args) throws Exception {
-        final ChempoundWebappLauncher launcher = new ChempoundWebappLauncher();
+        final ChempoundWebappLauncher launcher = new ChempoundWebappLauncher(new ChempoundWebappModule());
         launcher.start();
     }
 
-
     public void start() throws Exception {
-        final Injector injector = getInjector();
+        final Injector injector = Guice.createInjector(stage, module);
 
         final URI uri = injector.getInstance(Key.get(URI.class, BaseUri.class));
         final int port = uri.getPort() == -1 ? 80 : uri.getPort();
+        final String path = uri.getPath().replaceFirst("(.*)/$", "$1");
 
-        final String path = uri.getPath().replaceFirst("(.*)/$", "$1");
-        
         final Component component = injector.getInstance(Component.class);
         component.getServers().add(Protocol.HTTP, port)
                 .getContext().getParameters().add("maxThreads", "256");
     }
 
     protected Injector getInjector() throws IOException {
-        return Guice.createInjector(stage,
-                getConfigurationModule(),
-                getChempoundModule(),
-                getPluginsModule(),
-                getWebappModule()
-        );
+        return Guice.createInjector(stage, module);
     }
 
     protected Module getConfigurationModule() throws IOException {
         return new ChempoundConfigurationModule(new DefaultPropertySource());
     }
 
-    protected Module getWebappModule() {
-        return new DefaultChempoundWebModule();
-    }
-
     protected Module getChempoundModule() {
         return new DefaultChempoundModule();
     }

chempound-webapp/src/main/java/net/chempound/webapp/ChempoundWebappModule.java

+package net.chempound.webapp;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Module;
+import net.chempound.ChempoundConfigurationModule;
+import net.chempound.DefaultChempoundModule;
+import net.chempound.config.DefaultPropertySource;
+import net.chempound.config.PropertySource;
+import net.chempound.datastore.JenaTripleStoreModule;
+import net.chempound.storage.FileSystemResourceStoreModule;
+
+public class ChempoundWebappModule extends AbstractModule {
+
+    @Override
+    protected void configure() {
+        install(getConfigurationModule());
+        install(getChempoundModule());
+        install(getWebAppModule());
+        install(getTripleStoreModule());
+        install(getResourceStoreModule());
+        installPlugins();
+    }
+
+    protected PropertySource getPropertySource() {
+        return new DefaultPropertySource();
+    }
+
+    protected Module getConfigurationModule() {
+        return new ChempoundConfigurationModule(getPropertySource());
+    }
+
+    protected Module getChempoundModule() {
+        return new DefaultChempoundModule();
+    }
+
+    protected Module getWebAppModule() {
+        return new DefaultChempoundWebModule();
+    }
+
+    protected Module getTripleStoreModule() {
+          return new JenaTripleStoreModule();
+    }
+
+    protected Module getResourceStoreModule() {
+        return new FileSystemResourceStoreModule();
+    }
+
+    protected void installPlugins() {
+
+    }
+}

chempound-webapp/src/main/java/net/chempound/webapp/DefaultChempoundWebModule.java

 import com.google.inject.Module;
 import com.google.inject.multibindings.MapBinder;
 import com.google.inject.multibindings.Multibinder;
-import net.chempound.datastore.JenaTripleStore;
-import net.chempound.datastore.TripleStore;
 import net.chempound.services.FreemarkerService;
-import net.chempound.storage.FileSystemResourceStore;
-import net.chempound.storage.ResourceStore;
 import net.chempound.webapp.output.ContentType;
 import net.chempound.webapp.plugin.DefaultCssRegistry;
 import net.chempound.webapp.plugin.DefaultPluginRegistry;
         install(getRestletModule());
         install(getSwordModule());
 
-        bindTripleStore();
-        bindResourceStore();
         bind(FreemarkerService.class).to(DefaultFreemarkerService.class);
 
         bind(PluginRegistry.class).to(DefaultPluginRegistry.class);
         MapBinder.newMapBinder(binder(), String.class, ChempoundWebPlugin.class);
     }
 
-    protected void bindResourceStore() {
-        bind(ResourceStore.class).to(FileSystemResourceStore.class);
-    }
-
-    protected void bindTripleStore() {
-        bind(TripleStore.class).to(JenaTripleStore.class);
-    }
-
     protected SwordModule getSwordModule() {
         return new SwordModule();
     }