PluginHandler.java
上传用户:huihesys
上传日期:2007-01-04
资源大小:3877k
文件大小:3k
- /* CVS ID: $Id: PluginHandler.java,v 1.2 2000/04/06 08:02:02 wastl Exp $ */
- package net.wastl.webmail.server;
- import net.wastl.webmail.config.*;
- import net.wastl.webmail.misc.*;
- 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_path;
- Vector plugins;
- public PluginHandler(WebMailServer parent) {
- this.parent=parent;
- this.plugin_path=parent.getProperty("webmail.plugin.path");
- 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: ");
- File f=new File(plugin_path);
- String[] classlist=f.list(new FFilter());
- 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;
-
- for(int i=0;i<classlist.length;i++) {
- try {
- String name=classlist[i].substring(0,classlist[i].length()-6);
- 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 ""+classlist[i]+""!");
- 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