Package org.jclouds.reflect
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 Summary
Constructors Constructor Description FunctionalReflection()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
newProxy(com.google.common.reflect.TypeToken<T> enclosingType, com.google.common.base.Function<Invocation,Object> invocationFunction)
Returns a proxy instance that implementsenclosingType
by dispatching method invocations toinvocationFunction
.static <T> T
newProxy(Class<T> enclosingType, com.google.common.base.Function<Invocation,Object> invocationFunction)
-
-
-
Method Detail
-
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 implementsenclosingType
by dispatching method invocations toinvocationFunction
. The class loader ofenclosingType
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
- ifenclosingType
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)
-
-