Class InvocationUtils
- java.lang.Object
-
- com.broadleafcommerce.common.extension.reflection.InvocationUtils
-
public final class InvocationUtils extends Object
TypeSafe invocation of a method on a target object based on a method exposed from a example class. It is presumed the two share the same method signatures.
This utility requires that the reference object can be subclassed dynamically. As such, it must have a zero arg constructor and the class definition must not be final. Also, the utility is aware of complex Object graphs and can safely traverse nested structures via the sample API. This can lead to deeper, proxied objects that share the same behavior. However, the utility is only aware of several types of references during traversal that will allow it to deep proxy: an instance variable type, a generic collection type, and generic map key/value types. Lastly, the utility expects the target object(s) to implementReferenceAwarein order to ascertain when a target object (or nested object) requires proxy creation. Be aware of these caveats as you consider using this utility.
This utility is oft used to interact with auto-generated projections based on methods exposed in the originating domain class.- Author:
- Jeff Fischer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classInvocationUtils.ApiInterceptorstatic interfaceInvocationUtils.Targetable<T>Supply a target object instance (i.e.static classInvocationUtils.TargetInterceptor
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> InvocationUtils.Targetable<T>withExample(Class<T> exampleClass)Establish aInvocationUtils.Targetableproxy based on an example class.
-
-
-
Method Detail
-
withExample
public static <T> InvocationUtils.Targetable<T> withExample(Class<T> exampleClass)
Establish aInvocationUtils.Targetableproxy based on an example class. Then, the idea is to provide an object instance to the proxy (InvocationUtils.Targetable.andTarget(Object)) and get back the original refClass API in order to make method calls on that API. Behind the scenes, those method calls will be executed on the target object. Example:InvocationUtils.withExample(MyProduct.class).andTarget(projectionInstance).getMyProperty()
- Type Parameters:
T- The type of the example class- Parameters:
exampleClass- The example class containing the API you want to call- Returns:
- A Targetable proxy
-
-