org.zkoss.lang.reflect
Class FacadeInvoker

java.lang.Object
  extended by org.zkoss.lang.reflect.FacadeInvoker
All Implemented Interfaces:
InvocationHandler

public class FacadeInvoker
extends Object
implements InvocationHandler

The facade invocation handler. Like the facade pattern, this invocation handler is used to facade an object with a set of interfaces.

This Invocation handler assumes the object being facaded (a.k.a, the target) has all methods of these interfaces, but it might not implement all of these interfaces directly.

It happens when you need to provide interfaces to classes that come from third parties.

Example:

class A {
  public void f() {...}
}
interface I {
  public void f();
}
Then, you could do:
I i = (I)FacadeInvoker.newInstance(new A(), new Class[] {I});

Author:
tomyeh

Constructor Summary
protected FacadeInvoker(Object target)
           
 
Method Summary
 Object invoke(Object proxy, Method method, Object[] args)
           
static Object newInstance(Object target, Class[] interfaces)
          Creates an object that implements the giving interfaces by wrapping a giving object, target.
static Object newInstance(Object target, Class[] interfaces, ClassLoader clsLoader)
          Creates an object that implements the giving interfaces by wrapping a giving object, target.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FacadeInvoker

protected FacadeInvoker(Object target)
Method Detail

newInstance

public static final Object newInstance(Object target,
                                       Class[] interfaces,
                                       ClassLoader clsLoader)
Creates an object that implements the giving interfaces by wrapping a giving object, target.

The target must have all methods in all given interfaces, but might not implement all these interfaces.


newInstance

public static final Object newInstance(Object target,
                                       Class[] interfaces)
Creates an object that implements the giving interfaces by wrapping a giving object, target.

A shortcut: newInstance( target, interfaces, Thread.currentThread().getContextClassLoader()).


invoke

public Object invoke(Object proxy,
                     Method method,
                     Object[] args)
              throws Throwable
Specified by:
invoke in interface InvocationHandler
Throws:
Throwable


Copyright © 2013. All Rights Reserved.