Пример #1
0
 public <T> T getInterface(Object thiz, Class<T> iface) throws ScriptException {
   if (iface == null || !iface.isInterface()) {
     throw new IllegalArgumentException("interface Class expected");
   }
   AccessControlContext accCtxt = AccessController.getContext();
   return iface.cast(
       Proxy.newProxyInstance(
           iface.getClassLoader(),
           new Class[] {iface},
           new InterfaceImplementorInvocationHandler(thiz, accCtxt)));
 }
Пример #2
0
 public static void executeMethodClass(
     String pathToJar,
     String pkg,
     String classToGet,
     String methodName,
     String pathToFile,
     long logIdSyncMin,
     long logIdSyncMax)
     throws IOException, ClassNotFoundException, SecurityException, InstantiationException,
         IllegalAccessException, NoSuchMethodException, IllegalArgumentException,
         InvocationTargetException {
   Class<?> c = getClassFromJar(pathToJar, pkg, classToGet);
   Method method = c.getDeclaredMethod(methodName, String.class, long.class, long.class);
   method.invoke(null, pathToFile, logIdSyncMin, logIdSyncMax);
 }
Пример #3
0
  private static Class<?> getClassFromJar(String pathToJar, String pkg, String classToGet)
      throws IOException, ClassNotFoundException, SecurityException, InstantiationException,
          IllegalAccessException, NoSuchMethodException, IllegalArgumentException,
          InvocationTargetException {

    JarFile jarFile = new JarFile(pathToJar);
    Enumeration e = jarFile.entries();

    URL[] urls = {new URL("jar:file:" + pathToJar + "!/")};
    ClassLoader cl = URLClassLoader.newInstance(urls);

    Class<?> c = Class.forName(pkg + "." + classToGet, true, cl);

    return c;
  }