1 package org.columba.core.plugin; 19 20 import java.lang.reflect.Constructor ; 21 import java.util.logging.Logger ; 22 23 import org.columba.api.plugin.IExtensionInterface; 24 25 33 public class DefaultPluginLoader { 34 35 private static final Logger LOG = Logger 36 .getLogger("org.columba.core.loader"); 37 38 43 46 ClassLoader loader; 47 48 public DefaultPluginLoader() { 49 super(); 50 51 loader = this.getClass().getClassLoader(); 52 53 } 54 55 public IExtensionInterface loadPlugin(String id, String className, 56 Object [] arguments) throws Exception { 57 58 if (className == null) 59 throw new IllegalArgumentException ("className == null"); 60 61 IExtensionInterface plugin = null; 62 63 Class actClass; 64 65 actClass = loader.loadClass(className); 66 67 if ((arguments == null) || (arguments.length == 0)) { 73 74 plugin = (IExtensionInterface) actClass.newInstance(); 75 76 } else { 77 Constructor constructor; 78 79 constructor = ClassLoaderHelper 80 .findConstructor(arguments, actClass); 81 82 if (constructor == null) { 84 LOG.severe("Couldn't find constructor for " + className 85 + " with matching argument-list: "); 86 for (int i = 0; i < arguments.length; i++) { 87 LOG.severe("argument[" + i + "]=" + arguments[i]); 88 } 89 90 return null; 91 } else { 92 93 plugin = (IExtensionInterface) constructor 94 .newInstance(arguments); 95 96 } 97 98 } 99 100 return plugin; 101 } 102 103 } 104 | Popular Tags |