package net.sourceforge.pain.plugin; import java.util.*; public abstract class Plugin { protected PluginClassLoader loader; // plugin name is a package suffix after net.sf.pain.plugin. prefix public String pluginName; /** * child plugin names, should not be modified from other package! */ protected final Set childs = new HashSet(); public Plugin() { if (getClass().getClassLoader().getClass() != PluginClassLoader.class) { throw new RuntimeException("Plugin class:" + getClass().getName() + " must be loaded by PluginManager!"); } } public abstract void init() throws Exception; public abstract void deinit(); /** * This method is used from static PAIN code. Static code should not to have any direct links to reloadable plugins * @param key * @param args * @return */ public Object invoke(int key, Object[] args) { throw new UnsupportedOperationException(); } /** * plugin * child plugin should be reloaded when parent is reloading * @param pluginName */ synchronized final void addChild(String pluginName) { if (childs.contains(pluginName)) { return; } childs.add(pluginName); }; final void removeChild(String pluginName) { childs.remove(pluginName); }; public String toString() { return getClass().getName(); } public Set getDependedPlugins() { return Collections.unmodifiableSet(childs); } }