Class ProxyBuilder<I>

  • Type Parameters:
    I - type of proxies built

    @Immutable
    public final class ProxyBuilder<I>
    extends Object
    Builder pattern for proxies.

    This class allows chained and intuitive creation of proxy instances. It uses ProxyService to actually create proxies, and loads required service automatically.

    See Also:
    ProxyService
    • Method Detail

      • forClass

        public static <X> ProxyBuilder<X> forClass​(Class<X> superclass)
        Creates new builder for class that is actually a class (not an interface).

        This class will be used as a superclass of a proxy class. The class must not be final or primitive.

        This builder will use service that supports building proxies with superclasses.

        Type Parameters:
        X - type of proxy
        Parameters:
        superclass - class to be used as superclass for a proxy
        Returns:
        new proxy builder with specified class
      • forInterface

        public static <X> ProxyBuilder<X> forInterface​(Class<X> baseInterface)
        Creates new builder for interface.

        This interface will be implemented by proxy class. Proxy class will not have any specific superclass, it will probably be Object.

        Type Parameters:
        X - type of proxy
        Parameters:
        baseInterface - interface that will be implemented by proxy class
        Returns:
        new proxy builder with specified interface
      • forType

        public static <X> ProxyBuilder<X> forType​(Class<X> resultClass)
        Creates new builder for specified type.

        Depending on if resultClass is an interface or not, this method will behave either as forInterface(java.lang.Class<X>) or forClass(java.lang.Class<X>)

        Type Parameters:
        X - type of proxy
        Parameters:
        resultClass - base proxy type
        Returns:
        new proxy builder with specified interface
      • withInterface

        public ProxyBuilder<I> withInterface​(Class<?> additionalInterface)
        Creates proxy builder that have additional interface added to the proxy class.
        Parameters:
        additionalInterface - added interface
        Returns:
        new proxy builder with additional interface
      • usingService

        public ProxyBuilder<I> usingService​(ProxyService newService)
        Creates proxy builder that have proxy service replaced.

        This method is optional, and needed only if specific service needs to be used. ProxyBuilder will normally select suitable service.

        Parameters:
        newService - proxy service to use for creating services
        Returns:
        new proxy builder with replaced service
      • instantiate

        public I instantiate​(InvocationHandler<? super MethodInvocation<I>> handler)
        Creates instance of configured proxy class.
        Parameters:
        handler - method that proxy will delegate its calls to
        Returns:
        proxy instance