plugin.java

来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 106 行

JAVA
106
字号
/*
 * $Id: Plugin.java,v 1.4 2004/02/24 08:04:44 epr Exp $
 */
package org.jnode.plugin;

import org.jnode.system.BootLog;

/**
 * Abstract plugin class.
 * 
 * @author Ewout Prangsma (epr@users.sourceforge.net)
 */
public abstract class Plugin {

	/** The descriptor of this plugin */
	private final PluginDescriptor descriptor;
	/** Has this plugin been started? */
	private boolean started;

	/**
	 * Initialize a new instance
	 * 
	 * @param descriptor
	 */
	public Plugin(PluginDescriptor descriptor) {
		this.descriptor = descriptor;
		this.started = false;
		if (descriptor == null) {
			throw new IllegalArgumentException("descriptor cannot be null");
		}
	}

	/**
	 * Gets the descriptor of this plugin
	 * 
	 * @return The descriptor
	 */
	public final PluginDescriptor getDescriptor() {
		return descriptor;
	}

	/**
	 * Start this plugin
	 * 
	 * @throws PluginException
	 */
	final void start() throws PluginException {
		if (!started) {
			startPlugin();
			started = true;
		} else {
			BootLog.debug("Plugin " + descriptor.getId() + " already started");
		}
	}

	/**
	 * Stop this plugin.
	 * 
	 * @throws PluginException
	 */
	final void stop() throws PluginException {
		if (started) {
			stopPlugin();
			started = false;
		}
	}

	/**
	 * Is this plugin active. A plugin if active between a call to start and stop.
	 * 
	 * @see #start()
	 * @see #stop()
	 * @return boolean
	 */
	public final boolean isActive() {
		return started;
	}

	/**
	 * Has this plugin finished its startup work.
	 * Most plugins do their start work in the {@link #startPlugin()} method.
	 * However, some plugins create thread there to do some work in the background.
	 * These plugins should overwrite this method and return true when the startup
	 * process is fully finished.
	 * 
	 * @return True if this plugins has fully finished its startup process, false otherwise.
	 */
	public boolean isStartFinished() {
	    return started;
	}
	
	/**
	 * Actually start this plugin.
	 * 
	 * @throws PluginException
	 */
	protected abstract void startPlugin() throws PluginException;

	/**
	 * Actually start this plugin.
	 * 
	 * @throws PluginException
	 */
	protected abstract void stopPlugin() throws PluginException;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?