Skip to content

Instantly share code, notes, and snippets.

Created May 17, 2012 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2715803 to your computer and use it in GitHub Desktop.
Save anonymous/2715803 to your computer and use it in GitHub Desktop.
Container with access to module via Java API
public class ContainerUsingInterface implements IContainer
{
private final Collection<IModule> modules = new HashSet<IModule>();
public synchronized void loadModule(ClassLoader moduleLoader, String moduleClass) throws ClassNotFoundException, InstantiationException, IllegalAccessException
{
Class<? extends IModule> clazz = (Class<? extends IModule>) moduleLoader.loadClass(moduleClass);
IModule module = clazz.newInstance();
// keep a reference to the module interface; we can communicate with it via the java api
modules.add(module);
}
public synchronized void clearModules()
{
modules.clear();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment