/
area/
classes/net/sourceforge/pain/logic/
classes/net/sourceforge/pain/logic/event/
classes/net/sourceforge/pain/logic/fn/util/
classes/net/sourceforge/pain/network/console/
classes/net/sourceforge/pain/plugin/
classes/net/sourceforge/pain/plugin/reset/
classes/net/sourceforge/pain/plugin/shutdown/
classes/net/sourceforge/pain/plugin/social/
classest/net/sourceforge/pain/db/data/
doc/
doc/paindb/resources/
src/net/sourceforge/pain/logic/
src/net/sourceforge/pain/logic/event/
src/net/sourceforge/pain/logic/fn/util/
src/net/sourceforge/pain/network/console/
src/net/sourceforge/pain/network/console/telnet/
src/net/sourceforge/pain/plugin/
src/net/sourceforge/pain/plugin/command/
src/net/sourceforge/pain/plugin/reset/
src/net/sourceforge/pain/plugin/shutdown/
src/net/sourceforge/pain/plugin/social/
src/net/sourceforge/pain/util/
tests/
tests/net/sourceforge/pain/db/data/
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);
	}

}