1 package org.enhydra.shark.toolagent; 2 3 import java.io.File ; 4 import java.io.FilenameFilter ; 5 import java.net.MalformedURLException ; 6 import java.net.URL ; 7 import java.net.URLClassLoader ; 8 9 import org.enhydra.shark.api.internal.working.CallbackUtilities; 10 11 28 public class ToolAgentLoader { 29 30 46 public static Class load(CallbackUtilities cus, String name) 47 throws ClassNotFoundException , MalformedURLException { 48 49 File toolAgentPluginDir = new File (cus.getProperty( 51 "ToolAgentPluginDir", "plugins")); 52 53 FilenameFilter jarAndPropFiles = new FilenameFilter () { 55 public boolean accept(File dir, String name) { 56 return name.endsWith(".jar") || name.endsWith(".properties"); 57 } 58 }; 59 60 File [] files = toolAgentPluginDir.listFiles(jarAndPropFiles); 61 62 URL [] urls = new URL [files.length]; 65 for (int i = 0; i < files.length; ++i) { 66 70 urls[i] = new URL ("file:" + files[i].getPath()); 72 } 73 74 ClassLoader cl = new URLClassLoader (urls, ToolAgentLoader.class 80 .getClassLoader()); 81 82 return cl.loadClass(name); 84 } 85 } | Popular Tags |