Plugin.java

codebase/src/net/sourceforge/pain/plugin/Plugin.java · 1.5 KB

From the archive pain_0_44.tgz

Download the archive   « Back to the archive contents

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
	protected 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!");
		}
	}

	protected abstract void init() throws Exception;

	protected 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 final Set getDependedPlugins() {
		return Collections.unmodifiableSet(childs);
	}

    public final String getPluginName() {
        return pluginName;
    }
}

Site Stats

Snippets: 1791
Codebases: 571