Interface WrappingProxy
-
- All Known Implementing Classes:
de.aristaflow.adept2.model.common.defaultimplementation.DefaultWrappingProxy
,HTMLContext.CloseIgnoringAttachment
,LocalisationResolver
public interface WrappingProxy
This interface resemblesWrapper
. It is usually used forInvocationHandler
to allow for unwrapping their wrapped object instance. Unwrapping is required within the communication (a proxy may itself not be serialisable) but also allows to unwrap localised objects and access the fields directly.Subclasses which implement
InvocationHandler.invoke(Object, java.lang.reflect.Method, Object[])
have to make sure that the methods of this interface are handled as normal method calls instead of the interception logic for which the proxy exists.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static List<Class<?>>
getAllInterfaces(Class<?> cls, Map<Class<?>,List<Class<?>>> cache)
Gets all interfaces implemented by the designated class and additionally the designated interfaces.static <T> T
getProxy(ClassLoader cl, T target, Function<? super T,? extends InvocationHandler> ctor, Map<Class<?>,List<Class<?>>> cache, Class<?>... addIfaces)
Creates a new proxy for the designatedtarget
using the designated classloader and the designatedFunction
for creating the proxy.default boolean
isWrapperFor(Class<?> iface)
Gets whether thisWrappingProxy
wraps an object instance that is an instance of the designated class.Object
unwrap()
Gets the object instance that is wrapped by this proxy.default <T> T
unwrap(Class<T> iface)
Gets an object instance that is an instance of the designated class.
-
-
-
Method Detail
-
unwrap
Object unwrap()
Gets the object instance that is wrapped by this proxy. This simply unwraps, so there are no type checks. In case of a cascaded proxy, this may even be an instance ofWrappingProxy
again.- Returns:
- The object that is wrapped by a proxy. Since this object has to exist,
null
will never be returned.
-
isWrapperFor
default boolean isWrapperFor(Class<?> iface)
Gets whether thisWrappingProxy
wraps an object instance that is an instance of the designated class. This also applies transitively, that is, the wrapped object instance may be aWrappingProxy
that wraps an instance of the designated class.- Parameters:
iface
- The interface which to check for whether this proxy wraps an object instance of.- Returns:
- Whether the object instance wrapped by this
WrappingProxy
is an instance (or aWrappingProxy
) of the designated class/interface.
-
unwrap
default <T> T unwrap(Class<T> iface)
Gets an object instance that is an instance of the designated class. This will be the first (transitively) wrapped object instance that is an instance of the designated class. In this case this unwraps. However, if there is no such wrapped object but this (WrappingProxy
) instance itself is an instance of this class, this will be returned, thus not unwrapping. If neither this object instance nor the wrapped object instance nor the possibly further wrapped object instances are instances of the designated class,null
will be returned.- Parameters:
iface
- The interface for which to get an unwrapped object instance of.- Returns:
- The first directly or indirectly wrapped object instance that implements the
designated class. If this object instance implements it, this will be returned. If
no object instance of the designated class is (transitively) found,
null
will be returned.
-
getProxy
static <T> T getProxy(ClassLoader cl, T target, Function<? super T,? extends InvocationHandler> ctor, Map<Class<?>,List<Class<?>>> cache, Class<?>... addIfaces)
Creates a new proxy for the designatedtarget
using the designated classloader and the designatedFunction
for creating the proxy. The proxy will implement/simulate all transitive classes and interfaces of the designated target as well as the designated additional interfaces. This allows to logic defined in interfaces via the createdInvocationHandler
.
Additionally, the created proxy will implementWrappingProxy
.- Type Parameters:
T
- The type of the target class for which to create a proxy.- Parameters:
cl
- The classloader which to use for creating the proxy.target
- The target class for which to create a proxy.ctor
- The constructor creating the appropriateInvocationHandler
accepting the designatedtarget
.cache
- The cache providing already found class hierarchies ornull
.addIfaces
- Additional interfaces the created proxy will implement/simulate. If one of these is already part of the class hierarchy, it will not be added again.- Returns:
- A proxy object (
InvocationHandler
) for the designatedtarget
created by the designatedctor
.
-
getAllInterfaces
static List<Class<?>> getAllInterfaces(Class<?> cls, Map<Class<?>,List<Class<?>>> cache)
Gets all interfaces implemented by the designated class and additionally the designated interfaces. This includes the interfaces implemented by super-classes of the designated class.
If the designatedcache
is notnull
, it will be inspected for containing the class. If found, the corresponding entry will be used instead of accumulating the transitive parent classes and interfaces again.- Parameters:
cls
- The class for which to determine all implemented interfaces including the ones implemented by super-classes.cache
- The cache providing already accumulated parent interfaces and classes. This will be searched first and if not found, the final result will be added to the cache. This may benull
.- Returns:
- All interfaces implemented by the designated class including the ones implemented by super-classes.
-
-