Exemple #1
0
  public Object intercept(
      Object obj, java.lang.reflect.Method method, Object[] args, MethodProxy proxy)
      throws Throwable {
    printIdent(ident);
    System.out.println(method);
    for (int i = 0; i < args.length; i++) {
      printIdent(ident);
      System.out.print("arg" + (i + 1) + ": ");
      if (obj == args[i]) System.out.println("this");
      else System.out.println(args[i]);
    }
    ident++;

    Object retValFromSuper = null;
    try {
      retValFromSuper = proxy.invokeSuper(obj, args);
      ident--;
    } catch (Throwable t) {
      ident--;
      printIdent(ident);
      System.out.println("throw " + t);
      System.out.println();
      throw t.fillInStackTrace();
    }

    printIdent(ident);
    System.out.print("return ");
    if (obj == retValFromSuper) System.out.println("this");
    else System.out.println(retValFromSuper);

    if (ident == 1) System.out.println();

    return retValFromSuper;
  }
Exemple #2
0
 public static Object newInstance(Class clazz) {
   try {
     Enhancer e = new Enhancer();
     e.setSuperclass(clazz);
     e.setCallback(callback);
     return e.create();
   } catch (Throwable e) {
     e.printStackTrace();
     throw new Error(e.getMessage());
   }
 }