Package com.storedobject.common
Class ProxyFactory
java.lang.Object
com.storedobject.common.ProxyFactory
Utility class for creating proxies that implement multiple interfaces, handling classloader visibility.
- Author:
- Syam
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TcreateProxy(InvocationHandler handler, Class<T>... interfaceTypes) Creates a dynamic proxy instance that implements the specified interfaces and routes method calls to the providedInvocationHandler.static <T> TcreateProxyWithClassLoader(ClassLoader classLoader, InvocationHandler handler, Class<T>... interfaceTypes) Creates a dynamic proxy instance with the specifiedClassLoader, handler, and interfaces.
-
Constructor Details
-
ProxyFactory
public ProxyFactory()
-
-
Method Details
-
createProxy
Creates a dynamic proxy instance that implements the specified interfaces and routes method calls to the providedInvocationHandler.- Type Parameters:
T- the type of the proxy being returned- Parameters:
handler- theInvocationHandlerfor handling method calls on the proxy instanceinterfaceTypes- the array of interface classes that the proxy instance will implement- Returns:
- a proxy instance that implements the specified interfaces and forwards method calls to the handler
- Throws:
IllegalArgumentException- if the handler is null, no interfaces are provided, or one of the specified classes is not an interfaceRuntimeException- if the proxy cannot be created due to classloader visibility issues
-
createProxyWithClassLoader
@SafeVarargs public static <T> T createProxyWithClassLoader(ClassLoader classLoader, InvocationHandler handler, Class<T>... interfaceTypes) Creates a dynamic proxy instance with the specifiedClassLoader, handler, and interfaces. The proxy instance will implement the specified interfaces and route method calls to the providedInvocationHandler.- Type Parameters:
T- the type of the proxy being returned- Parameters:
classLoader- theClassLoaderused to define the proxy classhandler- theInvocationHandlerfor intercepting method calls on the proxy instanceinterfaceTypes- the array of interface classes that the proxy instance will implement- Returns:
- a proxy instance that implements the specified interfaces and forwards method calls to the handler
- Throws:
IllegalArgumentException- if the classLoader is null, the handler is null, no interfaces are provided, or any of the specified classes is not an interfaceRuntimeException- if the proxy cannot be created due to classLoader visibility issues
-