- All Implemented Interfaces:
Provider
AbstractProvider
that is capable of proxying certain
interfaces and supplying them as environmental objects.- Author:
- Laird Nelson
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic final String
Decapitalizes the suppliedCharSequence
according to the rules of the Java Beans specification.protected Supplier<?>
protected boolean
isIndexLike
(Class<?> parameterType) Returnstrue
if the suppliedClass
representing a method parameter is index-like, i.e.boolean
isProxiable
(Type type) Returnstrue
if the suppliedType
can be proxied.boolean
isProxiable
(Loader<?> requestor, Path<? extends Type> absolutePath) Returnstrue
if the type identified by the suppliedabsolutePath
can be proxied.protected Object
newProxyInstance
(Loader<?> requestor, Path<? extends Type> absolutePath, Class<?> interfaceToProxy) Invokes theProxy.newProxyInstance(ClassLoader, Class[], InvocationHandler)
method with appropriate arguments and returns the result.static final String
propertyName
(CharSequence cs, boolean methodReturnsBoolean) Given aCharSequence
normally representing the name of a "getter" method, and aboolean
indicating whether the method in question returns aboolean
, applies the rules declared by the Java Beans specification to the name and yields the result.Methods inherited from class org.microbean.loader.spi.AbstractProvider
get, lowerBound
-
Constructor Details
-
ProxyingProvider
Deprecated.This constructor should be invoked by subclasses andServiceLoader
instances only.Creates a newProxyingProvider
.
-
-
Method Details
-
find
Description copied from class:AbstractProvider
Returns aSupplier
suitable for the suppliedLoader
andPath
, ornull
if there is no suchSupplier
now and if there never will be such aSupplier
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 classAbstractProvider
- Parameters:
requestor
- theLoader
seeking aValue
(as originally passed to theAbstractProvider.get(Loader, Path)
method); must not benull
absolutePath
- an absolutePath
for which the suppliedLoader
is seeking a value (as originally passed to theAbstractProvider.get(Loader, Path)
method); must not benull
- Returns:
- a
Supplier
more or less suitable for the combination of the suppliedLoader
andPath
, ornull
if there is no suchSupplier
now and if there never will be such aSupplier
for the supplied arguments - See Also:
-
isProxiable
Returnstrue
if the type identified by the suppliedabsolutePath
can be proxied.A type can be proxied by this
ProxyingProvider
if its type erasure:- is an interface
- is not hidden
- is not sealed
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 theisIndexLike(Class)
method or more than one parameter.- Parameters:
requestor
- theLoader
seeking an environmental object; must not benull
; ignored by the default implementation of this methodabsolutePath
- thePath
identifying the interface to be proxied; must not benull
; must be absolute- Returns:
true
if the type identified by the suppliedabsolutePath
can be proxied;false
otherwise- Throws:
NullPointerException
- if either argument isnull
IllegalArgumentException
- ifabsolutePath
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
Returnstrue
if the suppliedType
can be proxied.A
Type
can be proxied if it:- is not
null
- represents an interface
- is not hidden
- is not sealed
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 theisIndexLike(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
- theType
to test; may benull
in which casefalse
will be returned- Returns:
true
if the suppliedType
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.
- is not
-
path
- Overrides:
path
in classAbstractProvider
- Type Parameters:
T
- the type of the requested and returnedPath
s- Parameters:
requestor
- theLoader
issuing the current request; must not benull
; ignored by this implementationabsolutePath
- the absolutePath
representing the current request; must not benull
- Returns:
- a non-
null
Path
with which anyValue
provided by thisProxyingProvider
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
Returnstrue
if the suppliedClass
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
ifparameterType
represents either anint
, anInteger
, or aCharSequence
.This method is called by the default implementation of the
isProxiable(Loader, Path)
method.- Parameters:
parameterType
- the method parameter type to test; may benull
in which casefalse
will be returned- Returns:
true
if the suppliedClass
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 theProxy.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:interfaceToProxy.getClassLoader()
new Class<?>[] { interfaceToProxy }
- a special
InvocationHandler
backed by the suppliedLoader
andPath
- Parameters:
requestor
- theLoader
performing the current request; must not benull
absolutePath
- an absolutePath
representing the current request; must not benull
interfaceToProxy
- the single interface the new proxy instance will implement; must not benull
; must be an interface- Returns:
- a new proxy instance as produced by the
Proxy.newProxyInstance(ClassLoader, Class[], InvocationHandler)
method; nevernull
- Throws:
NullPointerException
- if any argument isnull
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
Given aCharSequence
normally representing the name of a "getter" method, and aboolean
indicating whether the method in question returns aboolean
, applies the rules declared by the Java Beans specification to the name and yields the result.- Parameters:
cs
- aCharSequence
naming a "getter" method; may benull
in which casenull
will be returnedmethodReturnsBoolean
-true
if the method named by the suppliedCharSequence
hasboolean
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 ifcs
isnull
) - See Also:
- Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method may return
null
but only whencs
isnull
. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
decapitalize
Decapitalizes the suppliedCharSequence
according to the rules of the Java Beans specification.- Parameters:
cs
- theCharSequence
to decapitalize; may benull
in which casenull
will be returned- Returns:
- the decapitalized
String
ornull
- Idempotency:
- This method is idempotent and deterministic.
- Nullability:
- This method may return
null
but only whencs
isnull
. - Thread Safety:
- This method is safe for concurrent use by multiple threads.
-
ServiceLoader
instances only.