public static < T > T createDeepProxy ( Class < T > clazz ) { return ( T ) Proxy . newProxyInstance ( clazz . getClassLoader ( ) , new Class [ ] { clazz } , new InvocationHandler ( ) { @ Override public Object invoke ( Object proxy , Method method , Object [ ] args ) throws Throwable { if ( PRIMITIVE_RETURN_VALUES . containsKey ( method . getReturnType ( ) . getName ( ) ) ) { return PRIMITIVE_RETURN_VALUES . get ( method . getReturnType ( ) . getName ( ) ) ; } else if ( method . getReturnType ( ) . isInterface ( ) ) { return createDeepProxy ( method . getReturnType ( ) ) ; } else { return null ; } } } ) ; }
Create a proxy for the given class which returns other deep proxies from all it s methods .