Class BeanProxyInvocationHandler<T>
- Type Parameters:
T- The interface class type
- All Implemented Interfaces:
InvocationHandler
InvocationHandler for creating dynamic proxy instances of bean interfaces.
This class enables the creation of bean instances from interfaces without requiring concrete implementations.
When the useInterfaceProxies setting is enabled in BeanContext, this handler is used to create
proxy instances that implement bean interfaces.
The handler stores bean property values in an internal map and intercepts method calls to:
- Getter methods - Returns values from the internal property map
- Setter methods - Stores values in the internal property map
equals(Object)- Compares property maps, with special handling for other proxy instanceshashCode()- Returns hash code based on the property maptoString()- Serializes the property map to JSON
When comparing two proxy instances using equals(), if both are created with BeanProxyInvocationHandler,
the comparison is optimized by directly comparing their internal property maps rather than converting to BeanMap.
Example:
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
BeanProxyInvocationHandler
Constructor.- Parameters:
meta- The bean metadata for the interface. Must not benull .
-
-
Method Details
-
invoke
Handles method invocations on the proxy instance.This method intercepts all method calls on the proxy and routes them appropriately:
- If the method is
equals(Object), compares property maps - If the method is
hashCode(), returns the hash code of the property map - If the method is
toString(), serializes the property map to JSON - If the method is a getter (identified via
BeanMeta.getGetterProps()), returns the property value - If the method is a setter (identified via
BeanMeta.getSetterProps()), stores the property value - Otherwise, throws
UnsupportedOperationException
The
equals()method has special optimization: when comparing two proxy instances created with this handler, it directly compares their internal property maps usingProxy.getInvocationHandler(Object)to access the other instance's handler.- Specified by:
invokein interfaceInvocationHandler- Parameters:
proxy- The proxy instance on which the method was invokedmethod- The method that was invokedargs- The arguments passed to the method, ornull if no arguments- Returns:
- The return value of the method invocation
- Throws:
UnsupportedOperationException- If the method is not a supported bean method (getter, setter, equals, hashCode, or toString)
- If the method is
-