📄 plugin.java
字号:
/* * YALE - Yet Another Learning Environment * Copyright (C) 2002, 2003 * Simon Fischer, Ralf Klinkenberg, Ingo Mierswa, * Katharina Morik, Oliver Ritthoff * Artificial Intelligence Unit * Computer Science Department * University of Dortmund * 44221 Dortmund, Germany * email: yale@ls8.cs.uni-dortmund.de * web: http://yale.cs.uni-dortmund.de/ * * 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. */package edu.udo.cs.yale.tools.plugin;import edu.udo.cs.yale.Yale;import edu.udo.cs.yale.tools.ParameterService;import edu.udo.cs.yale.tools.OperatorService;import edu.udo.cs.yale.tools.LogService;import java.util.jar.JarFile;import java.util.jar.JarEntry;import java.util.List;import java.util.Iterator;import java.util.LinkedList;import java.io.File;import java.io.Reader;import java.io.FilenameFilter;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.net.URL;import java.net.URLClassLoader;/** * @version $Id: Plugin.java,v 1.3 2003/09/03 14:27:28 fischer Exp $ */public class Plugin { private JarFile archive; private ClassLoader classLoader; public Plugin(File file) throws IOException { archive = new JarFile(file); URL url = new URL("file", null, file.getAbsolutePath()); this.classLoader = new URLClassLoader(new URL[] { url }); } public void register() { URL operatorsURL = classLoader.getResource("operators.xml"); if (operatorsURL == null) { LogService.logMessage("Plugin '"+archive.getName()+"' does not contain operators.xml!", LogService.ERROR); } else { Reader reader = null; try { reader = new InputStreamReader(operatorsURL.openStream()); } catch (IOException e) { LogService.logMessage("Cannot read operators.xml from '"+archive.getName()+"'!", LogService.ERROR); } Yale.getInstance().splashMessage("Loading "+archive.getName()); LogService.logMessage("Loading "+archive.getName(), LogService.INIT); OperatorService.registerOperators(archive.getName(), reader, classLoader); } } /** Returns a list of Plugins found in the plugins directory. */ public static List findPlugins() { File pluginDir = ParameterService.getPluginDir(); if (!(pluginDir.exists() && pluginDir.isDirectory())) return new LinkedList(); File[] files = pluginDir.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".jar"); } }); List plugins = new LinkedList(); for (int i = 0; i < files.length; i++) { try { plugins.add(new Plugin(files[i])); } catch (Throwable e) { LogService.logException("Cannot load plugin '"+files[i]+"'", e); } } return plugins; } /** Returns a list of Plugins found in the plugins directory. */ public static void registerAllPlugins() { List plugins = findPlugins(); if (plugins.size() > 0) { LogService.logMessage("Found "+plugins.size()+" plugins in "+ParameterService.getPluginDir(), LogService.INIT); Iterator i = plugins.iterator(); while(i.hasNext()) { ((Plugin)i.next()).register(); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -