Exemple #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)));
 }
Exemple #2
0
 public Object invoke(Object proxy, Method method, Object[] args) throws java.lang.Throwable {
   // give chance to convert input args
   args = convertArguments(method, args);
   Object result;
   final Method m = method;
   final Object[] a = args;
   result =
       AccessController.doPrivileged(
           new PrivilegedExceptionAction<Object>() {
             public Object run() throws Exception {
               if (thiz == null) {
                 return engine.invokeFunction(m.getName(), a);
               } else {
                 return engine.invokeMethod(thiz, m.getName(), a);
               }
             }
           },
           accCtxt);
   // give chance to convert the method result
   return convertResult(method, result);
 }