⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pluginhandler.java

📁 java 开发的一个电子邮局,挺实用的
💻 JAVA
字号:
/* CVS ID: $Id: PluginHandler.java,v 1.3 2000/09/13 10:35:22 wastl Exp $ */
package net.wastl.webmail.server;

import net.wastl.webmail.config.*;
import net.wastl.webmail.misc.*;
import net.wastl.webmail.exceptions.WebMailException;
import java.io.*;
import java.util.*;

/**
 * PluginHandler.java
 *
 * Handle WebMail Plugins
 *
 * Created: Tue Aug 31 15:28:45 1999
 *
 * Copyright (C) 1999-2000 Sebastian Schaffert
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
/**
 *
 *
 *
 * @author Sebastian Schaffert
 * @version
 */

public class PluginHandler  {
    
    WebMailServer parent;
    String plugin_list;
    Vector plugins;

    public PluginHandler(WebMailServer parent) throws WebMailException {
	this.parent=parent;
	this.plugin_list=parent.getProperty("webmail.plugins");
	if(plugin_list == null) {
	    throw new WebMailException("Error: No Plugins defined (Property webmail.plugins).");
	}
	plugins=new Vector();
	registerPlugins();
    }


     /**
     * Initialize and register WebMail Plugins.
     */
    public void registerPlugins() {
	System.err.println("- Initializing WebMail Plugins ...");
	System.err.flush();
	//	System.setProperty("java.class.path",System.getProperty("java.class.path")+System.getProperty("path.separator")+pluginpath);


	System.err.print("  * loading: ");

	StringTokenizer tok=new StringTokenizer(plugin_list,":;, ");

	Class plugin_class=null;
	try {
	    plugin_class=Class.forName("net.wastl.webmail.server.Plugin");
	} catch(ClassNotFoundException ex) {
	    System.err.println("===> Could not find interface 'Plugin'!!");
	    System.exit(1);
	}

	PluginDependencyTree pt=new PluginDependencyTree("");
	Queue q=new Queue();
	
	int count=0;
	
	while(tok.hasMoreTokens()) {
	    String name=(String)tok.nextToken();
	    try {
		Class c=Class.forName(name);
		if(plugin_class.isAssignableFrom(c)) {
		    Plugin p=(Plugin) c.newInstance();
		    q.queue(p);
		    plugins.addElement(p);
		    //System.err.print(p.getName()+" ");
		    //System.err.flush();
		    count++;
		}
	    } catch(Exception ex) {
		System.err.println("   * Error: could not register \""+name+"\"!");
		ex.printStackTrace();
	    }
	}
	
	System.err.println(count+" plugins loaded correctly.");


	System.err.print("  * initializing: ");
	count=0;
	while(!q.isEmpty()) {
	    Plugin p=(Plugin)q.next();
	    if(!pt.addPlugin(p)) {
		q.queue(p);
	    }
	}
	pt.register(parent);
	System.err.println("plugins initialized.");
    };
   
    public Enumeration getPlugins() {
	return plugins.elements();
    }

    /**
     * A filter to find WebMail Plugins.
     */
    class FFilter implements FilenameFilter {
	FFilter() {
	}
	
	public boolean accept(File f, String s) {
	    if(s.endsWith(".class")) {
		return true;
	    } else {
		return false;
	    }
	}	
    }

} // PluginHandler

⌨️ 快捷键说明

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