View Javadoc

1   package twcsckernel.clientKernel.plugins;
2   
3   import java.lang.reflect.Constructor;
4   import java.lang.reflect.InvocationTargetException;
5   
6   
7   
8   /***
9    * Klasa narzędziowa  
10   *
11   */
12  public class ClientPluginLoader {
13      
14      /***
15       *  tworzy instancje pluginu o podanej scieżce pakietowej
16       **/
17      public static ClientPlugin createPlugin(String pluginClassPath
18              ) {
19          ClientPlugin plugin = null;
20          Class pluginDefinition;
21          //Class[] intArgsClass = new Class[] { String.class };
22          //Object[] intArgs = new Object[] { desc };
23          Constructor intArgsConstructor;
24  
25          try {
26              pluginDefinition = Class.forName(pluginClassPath);
27              intArgsConstructor = pluginDefinition
28                      .getConstructor();//intArgsClass);
29              plugin = (ClientPlugin) createObject(intArgsConstructor, null); //intArgs);
30          } catch (ClassNotFoundException e) {
31              System.out.println(e);
32          } 
33      catch (NoSuchMethodException e) {
34              System.out.println(e);
35          }
36          return plugin;
37      }
38  
39      private static Object createObject(Constructor constructor,
40              Object[] arguments) {
41          Object object = null;
42          try {
43              object = constructor.newInstance(arguments);
44              return object;
45          } catch (InstantiationException e) {
46              System.out.println(e);
47          } catch (IllegalAccessException e) {
48              System.out.println(e);
49          } catch (IllegalArgumentException e) {
50              System.out.println(e);
51          } catch (InvocationTargetException e) {
52              System.out.println(e);
53          }
54          return object;
55      }
56  
57  }