* introduced factory methods to create @PluginRegistry@ instances with a list of plugins initially

git-svn-id: svn+ssh://svn.synyx.de/var/svn/synyx/opensource/hera/trunk@5401 5a64d73e-33d6-4ccc-9058-23f8668ecac9
This commit is contained in:
Oliver Gierke
2009-04-21 14:11:16 +00:00
parent 63b1724f06
commit a9eff35651
4 changed files with 93 additions and 5 deletions

View File

@@ -29,12 +29,30 @@ public class OrderAwarePluginRegistry<T extends Plugin<S>, S> extends
* @param <S>
* @return
*/
public static <S, T extends Plugin<S>> OrderAwarePluginRegistry<T, S> create() {
public static <S, T extends Plugin<S>> PluginRegistry<T, S> create() {
return new OrderAwarePluginRegistry<T, S>();
}
/**
* Creates a new {@link OrderAwarePluginRegistry} with the given plugins.
*
* @param <S>
* @param <T>
* @param plugins
* @return
*/
public static <S, T extends Plugin<S>> PluginRegistry<T, S> create(
List<T> plugins) {
PluginRegistry<T, S> registry = create();
registry.setPlugins(plugins);
return registry;
}
/*
* (non-Javadoc)
*

View File

@@ -29,6 +29,14 @@ public interface PluginRegistry<T extends Plugin<S>, S> extends Iterable<T> {
void addPlugin(T plugin);
/**
* Removes a given plugin from the registry.
*
* @param plugin
*/
boolean removePlugin(T plugin);
/**
* Returns the first plugin found for the given originating system. Thus,
* further configured plugins are ignored.
@@ -107,4 +115,12 @@ public interface PluginRegistry<T extends Plugin<S>, S> extends Iterable<T> {
*/
int countPlugins();
/**
* Returns whether the registry contains a given plugin.
*
* @param plugin
* @return
*/
boolean contains(T plugin);
}

View File

@@ -58,6 +58,23 @@ public class SimplePluginRegistry<T extends Plugin<S>, S> implements
}
/**
* Creates a new {@link SimplePluginRegistry}.
*
* @param <T>
* @param <S>
* @return
*/
public static <S, T extends Plugin<S>> PluginRegistry<T, S> create(
List<T> plugins) {
PluginRegistry<T, S> registry = create();
registry.setPlugins(plugins);
return registry;
}
/*
* (non-Javadoc)
*
@@ -81,6 +98,19 @@ public class SimplePluginRegistry<T extends Plugin<S>, S> implements
}
/*
* (non-Javadoc)
*
* @see
* org.synyx.hera.core.PluginRegistry#removePlugin(org.synyx.hera.core.Plugin
* )
*/
public boolean removePlugin(T plugin) {
return this.plugins.remove(plugin);
}
/*
* (non-Javadoc)
*
@@ -206,6 +236,18 @@ public class SimplePluginRegistry<T extends Plugin<S>, S> implements
}
/*
* (non-Javadoc)
*
* @see
* org.synyx.hera.core.PluginRegistry#contains(org.synyx.hera.core.Plugin)
*/
public boolean contains(T plugin) {
return this.plugins.contains(plugin);
}
/*
* (non-Javadoc)
*

View File

@@ -31,7 +31,7 @@ import org.junit.Test;
*/
public class SimplePluginRegistryUnitTest {
private SamplePlugin provider;
private SamplePlugin plugin;
private PluginRegistry<SamplePlugin, String> registry;
@@ -43,10 +43,22 @@ public class SimplePluginRegistryUnitTest {
@Before
public void setUp() {
provider = new SamplePluginImplementation();
plugin = new SamplePluginImplementation();
registry = new SimplePluginRegistry<SamplePlugin, String>();
registry.setPlugins(Arrays.asList(provider));
registry = SimplePluginRegistry.create(Arrays.asList(plugin));
}
/**
* Asserts that the registry contains the plugin it was initialized with.
*
* @throws Exception
*/
@Test
public void assertRegistryInitialized() throws Exception {
assertEquals(1, registry.countPlugins());
assertTrue(registry.contains(plugin));
}