package ie.dcu.plugin; import java.io.File; import java.net.URLClassLoader; import java.util.Map; public class Plugin { private final File root; private final Map metadata; private final URLClassLoader loader; Plugin(File root, Map metadata, URLClassLoader loader) { this.root = root; this.metadata = metadata; this.loader = loader; } public String getName() { return getMetadata("name"); } public Map getMetadata() { return metadata; } public String getMetadata(String key) { return metadata.get(key); } public File getRootFolder() { return root; } public File getResource(String name) { return new File(root, name); } public Class loadClass(String name) throws ClassNotFoundException { return loader.loadClass(name); } public Object loadObject(String name) throws PluginException { try { Class clazz = loadClass(name); Object instance = clazz.newInstance(); return instance; } catch (ClassNotFoundException e) { throw new PluginException(e); } catch (InstantiationException e) { throw new PluginException(e); } catch (IllegalAccessException e) { throw new PluginException(e); } } }