Class ProxyingProvider

java.lang.Object
org.microbean.loader.spi.AbstractProvider
org.microbean.loader.ProxyingProvider
All Implemented Interfaces:
Provider

public class ProxyingProvider extends AbstractProvider
An AbstractProvider that is capable of proxying certain interfaces and supplying them as environmental objects.
Author:
Laird Nelson
See Also:
  • Constructor Details

  • Method Details

    • find

      protected Supplier<?> find(Loader<?> requestor, Path<? extends Type> absolutePath)
      Description copied from class: AbstractProvider
      Returns a Supplier suitable for the supplied Loader and Path, or null if there is no such Supplier now and if there never will be such a Supplier for the supplied arguments.

      Overrides of this method must not call the AbstractProvider.get(Loader, Path) method or undefined behavior (such as an infinite loop) may result.

      Specified by:
      find in class AbstractProvider
      Parameters:
      requestor - the Loader seeking a Value (as originally passed to the AbstractProvider.get(Loader, Path) method); must not be null
      absolutePath - an absolute Path for which the supplied Loader is seeking a value (as originally passed to the AbstractProvider.get(Loader, Path) method); must not be null
      Returns:
      a Supplier more or less suitable for the combination of the supplied Loader and Path, or null if there is no such Supplier now and if there never will be such a Supplier for the supplied arguments
      See Also:
    • isProxiable

      public boolean isProxiable(Loader<?> requestor, Path<? extends Type> absolutePath)
      Returns true if the type identified by the supplied absolutePath can be proxied.

      A type can be proxied by this ProxyingProvider if its type erasure:

      In addition, the default implementation of this method rules out interfaces that declare or inherit public instance methods with either exactly one parameter that does not pass the test codified by the isIndexLike(Class) method or more than one parameter.

      Parameters:
      requestor - the Loader seeking an environmental object; must not be null; ignored by the default implementation of this method
      absolutePath - the Path identifying the interface to be proxied; must not be null; must be absolute
      Returns:
      true if the type identified by the supplied absolutePath can be proxied; false otherwise
      Throws:
      NullPointerException - if either argument is null
      IllegalArgumentException - if absolutePath is not absolute
      See Also:
      Idempotency:
      This method is, and its overrides must be, idempotent and deterministic.
      Thread Safety:
      This method is, and its overrides must be, safe for concurrent use by multiple threads.
    • isProxiable

      public boolean isProxiable(Type type)
      Returns true if the supplied Type can be proxied.

      A Type can be proxied if it:

      In addition, the default implementation of this method rules out interfaces that declare or inherit public instance methods with either exactly one parameter that does not pass the test codified by the isIndexLike(Class) method or more than one parameter.

      This method does not, and its overrides must not, call the isProxiable(Loader, Path) method or undefined behavior (such as an infinite loop) may result.

      Parameters:
      type - the Type to test; may be null in which case false will be returned
      Returns:
      true if the supplied Type can be proxied; false otherwise
      See Also:
      Idempotency:
      This method is, and its overrides must be, idempotent and deterministic.
      Thread Safety:
      This method is, and its overrides must be, safe for concurrent use by multiple threads.
    • path

      protected <T extends Type> Path<T> path(Loader<?> requestor, Path<T> absolutePath)
      Returns a Path suitable for the combination of the supplied Loader and requested Path.
      Overrides:
      path in class AbstractProvider
      Type Parameters:
      T - the type of the requested and returned Paths
      Parameters:
      requestor - the Loader issuing the current request; must not be null; ignored by this implementation
      absolutePath - the absolute Path representing the current request; must not be null
      Returns:
      a non-null Path with which any Value provided by this ProxyingProvider will be associated
      See Also:
      Idempotency:
      This method is, and its overrides must be, idempotent but not necessarily deterministic.
      Nullability:
      This method does not, and its overrides must not, return null.
      Thread Safety:
      This method is, and its overrides must be, safe for concurrent use by multiple threads.
    • isIndexLike

      protected boolean isIndexLike(Class<?> parameterType)
      Returns true if the supplied Class representing a method parameter is index-like, i.e. if it is something typically used as an index into a larger collection or map.

      The default implementation of this method returns true if parameterType represents either an int, an Integer, or a CharSequence.

      This method is called by the default implementation of the isProxiable(Loader, Path) method.

      Parameters:
      parameterType - the method parameter type to test; may be null in which case false will be returned
      Returns:
      true if the supplied Class representing a method parameter is index-like, i.e. if it is something typically used as an index into a larger collection or map
      Idempotency:
      This method is, and its overrides must be, idempotent and deterministic.
      Thread Safety:
      This method is, and its overrides must be, safe for concurrent use by multiple threads.
    • newProxyInstance

      protected Object newProxyInstance(Loader<?> requestor, Path<? extends Type> absolutePath, Class<?> interfaceToProxy)
      Invokes the Proxy.newProxyInstance(ClassLoader, Class[], InvocationHandler) method with appropriate arguments and returns the result.

      The Proxy.newProxyInstance(ClassLoader, Class[], InvocationHandler) method is invoked with the following arguments:

      1. interfaceToProxy.getClassLoader()
      2. new Class<?>[] { interfaceToProxy }
      3. a special InvocationHandler backed by the supplied Loader and Path
      Parameters:
      requestor - the Loader performing the current request; must not be null
      absolutePath - an absolute Path representing the current request; must not be null
      interfaceToProxy - the single interface the new proxy instance will implement; must not be null; must be an interface
      Returns:
      a new proxy instance as produced by the Proxy.newProxyInstance(ClassLoader, Class[], InvocationHandler) method; never null
      Throws:
      NullPointerException - if any argument is null
      IllegalArgumentException - if any argument is unsuitable
      See Also:
      Idempotency:
      This method is, and its overrides must be, idempotent and deterministic.
      Nullability:
      This method does not, and its overrides must not, return null.
      Thread Safety:
      This method is, and its overrides must be, safe for concurrent use by multiple threads.
    • propertyName

      @Convenience public static final String propertyName(CharSequence cs, boolean methodReturnsBoolean)
      Given a CharSequence normally representing the name of a "getter" method, and a boolean indicating whether the method in question returns a boolean, applies the rules declared by the Java Beans specification to the name and yields the result.
      Parameters:
      cs - a CharSequence naming a "getter" method; may be null in which case null will be returned
      methodReturnsBoolean - true if the method named by the supplied CharSequence has boolean as its return type
      Returns:
      the property name corresponding to the supplied method name, according to the rules of the Java Beans specification, or null (only if cs is null)
      See Also:
      Idempotency:
      This method is idempotent and deterministic.
      Nullability:
      This method may return null but only when cs is null.
      Thread Safety:
      This method is safe for concurrent use by multiple threads.
    • decapitalize

      public static final String decapitalize(CharSequence cs)
      Decapitalizes the supplied CharSequence according to the rules of the Java Beans specification.
      Parameters:
      cs - the CharSequence to decapitalize; may be null in which case null will be returned
      Returns:
      the decapitalized String or null
      Idempotency:
      This method is idempotent and deterministic.
      Nullability:
      This method may return null but only when cs is null.
      Thread Safety:
      This method is safe for concurrent use by multiple threads.