Class MyInvocationHandler

java.lang.Object
info.ejava.examples.svc.aop.items.dynamicproxies.MyInvocationHandler
All Implemented Interfaces:
InvocationHandler

public class MyInvocationHandler extends Object implements InvocationHandler
This is an example Dynamic Proxy. The Proxy class implements the supplied interfaces and delegates calls to the invoke() method within this class.
  • Field Details

    • target

      private final Object target
  • Constructor Details

    • MyInvocationHandler

      public MyInvocationHandler()
  • Method Details

    • newInstance

      public static Object newInstance(Object target)
      A convenience method to build a Dynamic Proxy for the interfaces of a target object of an unknown type.
      Parameters:
      target - object to proxy
      Returns:
      the proxy wrapping the target
    • invoke

      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
      This method will get called for each method call to the proxy. The method will simply log when called, invoke the target method, and log when complete. A real handler might do things like check security accesses, begin/terminate a database transaction, etc.
      Specified by:
      invoke in interface InvocationHandler
      Throws:
      Throwable