/* * Copyright (C) 2014 Vinu K.N * * 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 3 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, see <http://www.gnu.org/licenses/>. */ package org.domainmath.gui.tools; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.logging.Level; import java.util.logging.Logger; import org.domainmath.gui.MainFrame; /** * * @author Vinu K.N */ public class ToolsLoader { public ToolsLoader(MainFrame frame) { File dir = new File(System.getProperty("user.dir")+File.separator+"tools"); File jars[] = dir.listFiles(); for(File pkg:jars){ if(pkg.getName().endsWith(".jar")) { load(pkg,frame); } } } private void load(File f,MainFrame frame){ ToolsInterface authorizedPlugin; try { ClassLoader authorizedLoader = URLClassLoader.newInstance(new URL[] { f.toURI().toURL() }); authorizedPlugin = (ToolsInterface) authorizedLoader.loadClass("org.domainmath.gui.Tool").newInstance(); authorizedPlugin.connect(frame); } catch (ClassNotFoundException | MalformedURLException | InstantiationException | IllegalAccessException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } } }