SecurityManager s = System.getSecurityManager();
if (s != null) {
s.checkPermission(new DynamicAccessPermission("access"));
}
return new InvocationHandler() {
public Object invoke( Object proxy, Method method, Object[] args )
throws Throwable
{
// This throws an IllegalArgument exception if the delegate
// is not assignable from method.getDeclaring class.
try {
return method.invoke( delegate, args ) ;
} catch (InvocationTargetException ite) {
// Propagate the underlying exception as the
// result of the invocation
throw ite.getCause() ;
}
}
} ;