Class FunctionalReflection

java.lang.Object
org.jclouds.reflect.FunctionalReflection

@Beta public final class FunctionalReflection extends Object
Static utilities relating to functional Java reflection.
Since:
1.6
  • Constructor Details

    • FunctionalReflection

      public FunctionalReflection()
  • Method Details

    • newProxy

      public static <T> T newProxy(com.google.common.reflect.TypeToken<T> enclosingType, com.google.common.base.Function<Invocation,Object> invocationFunction)
      Returns a proxy instance that implements enclosingType by dispatching method invocations to invocationFunction. The class loader of enclosingType will be used to define the proxy class.

      Usage example:

       httpAdapter = new Function<Invocation, Result>() {
          public Result apply(Invocation in) {
             try {
                HttpRequest request = parseRequest(in);
                HttpResponse response = invoke(request);
                return Result.success(parseJson(response));
             } catch (Exception e) {
                return Result.failure(e);
             }
          }
       };
       
       client = FunctionalReflection.newProxy(Client.class, httpAdapter);
       
      Parameters:
      invocationFunction - returns a result or a top-level exception, or result
      Throws:
      IllegalArgumentException - if enclosingType does not specify the type of a Java interface
      See Also:
      • AbstractInvocationHandler.invoke(Object, Method, Object[])
      • Reflection.newProxy(Class, java.lang.reflect.InvocationHandler)
    • newProxy

      public static <T> T newProxy(Class<T> enclosingType, com.google.common.base.Function<Invocation,Object> invocationFunction)