Interface WrappingProxy

  • All Known Implementing Classes:
    de.aristaflow.adept2.model.common.defaultimplementation.DefaultWrappingProxy, HTMLContext.CloseIgnoringAttachment, LocalisationResolver

    public interface WrappingProxy
    This interface resembles Wrapper. It is usually used for InvocationHandler 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 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 of WrappingProxy 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 this WrappingProxy wraps an object instance that is an instance of the designated class. This also applies transitively, that is, the wrapped object instance may be a WrappingProxy 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 a WrappingProxy) 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 designated target using the designated classloader and the designated Function 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 created InvocationHandler.
        Additionally, the created proxy will implement WrappingProxy.
        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 appropriate InvocationHandler accepting the designated target.
        cache - The cache providing already found class hierarchies or null.
        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 designated target created by the designated ctor.
      • 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 designated cache is not null, 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 be null.
        Returns:
        All interfaces implemented by the designated class including the ones implemented by super-classes.