Package org.jclouds.reflect
Class FunctionalReflection
java.lang.Object
org.jclouds.reflect.FunctionalReflection
Static utilities relating to functional Java reflection.
- Since:
- 1.6
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <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)
-
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 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:
-
newProxy
public static <T> T newProxy(Class<T> enclosingType, com.google.common.base.Function<Invocation, Object> invocationFunction)
-