improve ScmWebPlugin api

This commit is contained in:
Sebastian Sdorra
2010-09-20 14:51:10 +02:00
parent 2e4d54b325
commit 075e266620
12 changed files with 266 additions and 127 deletions

View File

@@ -1,29 +0,0 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.scm;
import com.google.inject.Module;
import java.io.InputStream;
/**
*
* @author Sebastian Sdorra
*/
public class ScmWebPluginAdapter implements ScmWebPlugin {
@Override
public Module[] getModules()
{
return new Module[0];
}
@Override
public InputStream getScript()
{
return null;
}
}

View File

@@ -5,30 +5,28 @@
package sonia.scm;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.util.ServiceUtil;
package sonia.scm.web;
//~--- JDK imports ------------------------------------------------------------
import java.util.List;
import java.io.InputStream;
/**
*
* @author Sebastian Sdorra
*/
public class ScmWebPluginContext
public class ClasspathWebResource implements WebResource
{
/**
* Constructs ...
*
*
* @param contentPath
*/
public ScmWebPluginContext()
public ClasspathWebResource(String contentPath)
{
plugins = ServiceUtil.getServices(ScmWebPlugin.class);
this.contentPath = contentPath;
}
//~--- get methods ----------------------------------------------------------
@@ -39,13 +37,14 @@ public class ScmWebPluginContext
*
* @return
*/
public List<ScmWebPlugin> getPlugins()
@Override
public InputStream getContent()
{
return plugins;
return ClasspathWebResource.class.getResourceAsStream(contentPath);
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private List<ScmWebPlugin> plugins;
private String contentPath;
}

View File

@@ -5,7 +5,7 @@
package sonia.scm;
package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
@@ -22,19 +22,7 @@ import java.io.InputStream;
public interface ScmWebPlugin
{
/**
* Method description
*
*
* @return
*/
public Module[] getModules();
public void contextInitialized( ScmWebPluginContext context );
/**
* Method description
*
*
* @return
*/
public InputStream getScript();
public void contextDestroyed( ScmWebPluginContext context );
}

View File

@@ -0,0 +1,102 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.scm.web;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Module;
//~--- JDK imports ------------------------------------------------------------
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
/**
*
* @author Sebastian Sdorra
*/
public class ScmWebPluginContext
{
/**
* Method description
*
*
* @param module
*/
public void addInjectModule(Module module)
{
injectModules.add(module);
}
/**
* Method description
*
*
* @param resource
*/
public void addScriptResource(WebResource resource)
{
scriptResources.add(resource);
}
/**
* Method description
*
*
* @param module
*/
public void removeInjectModule(Module module)
{
injectModules.remove(module);
}
/**
* Method description
*
*
* @param resource
*/
public void removeScriptResource(WebResource resource)
{
scriptResources.remove(resource);
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
*/
public Collection<Module> getInjectModules()
{
return injectModules;
}
/**
* Method description
*
*
* @return
*/
public Collection<WebResource> getScriptResources()
{
return scriptResources;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private Set<WebResource> scriptResources = new HashSet<WebResource>();
/** Field description */
private Set<Module> injectModules = new HashSet<Module>();
}

View File

@@ -0,0 +1,31 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sonia.scm.web;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.io.InputStream;
/**
*
* @author Sebastian Sdorra
*/
public interface WebResource
{
/**
* Method description
*
*
* @return
*
* @throws IOException
*/
public InputStream getContent() throws IOException;
}