Class AbstractClientProxier<T>
- Type Parameters:
T
- the type of descriptor this implementation uses to represent (normally unloaded) generated classes
- All Implemented Interfaces:
ClientProxier
- Direct Known Subclasses:
ReflectiveClientProxier
ClientProxier
interface.- Author:
- Laird Nelson
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractClientProxier
(Domain domain) Creates a newAbstractClientProxier
. -
Method Summary
Modifier and TypeMethodDescriptionprotected ClassLoader
Given aTypeElement
that is a declared type, returns aClassLoader
suitable for eventually transforming it into aClass
.final <R> R
clientProxy
(Request<R> r, Supplier<? extends R> instanceSupplier) Returns a contextual reference of typeR
, which is also aClientProxy<R>
, given aSupplier
of contextual instances of the appropriate type.protected Class
<?> clientProxyClass
(T t, ClassLoader cl) Called by the default implementation of theinstantiate(ProxySpecification, Supplier)
method, converts the supplied class definition into aClass
, using the suppliedClassLoader
, and returns it (optional operation).protected final Domain
domain()
Returns theDomain
supplied at construction time.protected T
Called indirectly by the default implementation of theinstantiate(ProxySpecification, Supplier)
method, creates a generated class definition from the information present in the suppliedProxySpecification
, and returns it for eventual supplying to an inovcation of theclientProxyClass(Object, ClassLoader)
method (optional operation).protected <R> ClientProxy
<R> instantiate
(Class<?> clientProxyClass, Supplier<? extends R> instanceSupplier) Called by theinstantiate(ProxySpecification, Supplier)
method, creates a new instance of the suppliedclientProxyClass
that proxies contextual instances supplied by the suppliedinstanceSupplier
.protected <R> ClientProxy
<R> instantiate
(ProxySpecification ps, Supplier<? extends R> instanceSupplier) Called indirectly by theclientProxy(Request, Supplier)
method when a newClientProxy<R>
instance needs to be created, creates a new instance of aClientProxy<R>
that proxies contextual instances supplied by the suppliedinstanceSupplier
, and returns it.protected abstract MethodHandles.Lookup
Returns aMethodHandles.Lookup
suitable for the suppliedClass
.
-
Constructor Details
-
AbstractClientProxier
Creates a newAbstractClientProxier
.- Parameters:
domain
- aDomain
; must not benull
- Throws:
NullPointerException
- ifdomain
isnull
-
-
Method Details
-
classLoader
Given aTypeElement
that is a declared type, returns aClassLoader
suitable for eventually transforming it into aClass
.The default implementation of this method returns the context classloader.
- Parameters:
e
- aTypeElement
; must not benull
; must be a declared type- Returns:
- a non-
null
ClassLoader
- Throws:
NullPointerException
- ife
isnull
IllegalArgumentException
- ife
is not a declared type
-
clientProxy
Returns a contextual reference of typeR
, which is also aClientProxy<R>
, given aSupplier
of contextual instances of the appropriate type.This method never returns
null
.- Specified by:
clientProxy
in interfaceClientProxier
- Type Parameters:
R
- the type of the contextual reference- Parameters:
r
- theRequest
necessitating this invocation; must not benull
instanceSupplier
- aSupplier
of contextual instances of typeR
; must not benull
- Returns:
- a contextual reference that is also a
ClientProxy<R>
; nevernull
- Throws:
NullPointerException
- if any argument isnull
, or if theinstantiate(ProxySpecification, Supplier)
method, invoked as part of the implementation of this method, returnsnull
IllegalArgumentException
- if the suppliedRequest
is not proxiable for any reasonReferenceException
- if theinstantiate(ProxySpecification, Supplier)
method throws a checkedException
- See Also:
-
clientProxyClass
Called by the default implementation of theinstantiate(ProxySpecification, Supplier)
method, converts the supplied class definition into aClass
, using the suppliedClassLoader
, and returns it (optional operation).If an override of the
instantiate(ProxySpecification, Supplier)
method does something entirely different, this method may never be called.The default implementation of this method throws an
UnsupportedOperationException
.In general, implementations of this method should not call the
instantiate(ProxySpecification, Supplier)
method, or undefined behavior may result.- Parameters:
t
- a class definition; must not benull
cl
- aClassLoader
; must not benull
- Returns:
- a non-
null
Class
- Throws:
NullPointerException
- if any argument isnull
UnsupportedOperationException
- if class generation is not supported by thisAbstractClientProxier
ClassNotFoundException
- if an invocation ofClassLoader.loadClass(String)
fails- See Also:
-
domain
Returns theDomain
supplied at construction time.- Returns:
- a non-
null
Domain
- See Also:
-
generate
Called indirectly by the default implementation of theinstantiate(ProxySpecification, Supplier)
method, creates a generated class definition from the information present in the suppliedProxySpecification
, and returns it for eventual supplying to an inovcation of theclientProxyClass(Object, ClassLoader)
method (optional operation).If an override of the
instantiate(ProxySpecification, Supplier)
method does something entirely different, this method may never be called.The default implementation of this method throws an
UnsupportedOperationException
.Implementations of this method must not call the
instantiate(ProxySpecification, Supplier)
method, or undefined behavior may result.- Parameters:
ps
- aProxySpecification
; must not benull
- Returns:
- a non-
null
generated class definition - Throws:
NullPointerException
- ifps
isnull
UnsupportedOperationException
- if class generation is unsupported by thisAbstractClientProxier
implementationThrowable
- if creation of the generated class definition fails- See Also:
-
instantiate
protected <R> ClientProxy<R> instantiate(ProxySpecification ps, Supplier<? extends R> instanceSupplier) throws Throwable Called indirectly by theclientProxy(Request, Supplier)
method when a newClientProxy<R>
instance needs to be created, creates a new instance of aClientProxy<R>
that proxies contextual instances supplied by the suppliedinstanceSupplier
, and returns it.The default implementation of this method eventually calls the
instantiate(Class, Supplier)
method with the return value of an indirect invocation of theclientProxyClass(Object, ClassLoader)
method and the suppliedSupplier
and returns the result.Overrides of this method that do something entirely different are not obligated to call the
clientProxyClass(Object, ClassLoader)
method or theinstantiate(Class, Supplier)
method. In such a case, those methods will be effectively orphaned.- Type Parameters:
R
- the type of contextual instance being proxied- Parameters:
ps
- aProxySpecification
; must not benull
instanceSupplier
- aSupplier
of contextual instances of the<R>
type; must not benull
- Returns:
- a non-
null
ClientProxy<R>
- Throws:
NullPointerException
- if any argument isnull
ReferenceException
- if instantiation failsThrowable
- if instantiation fails- See Also:
-
instantiate
protected <R> ClientProxy<R> instantiate(Class<?> clientProxyClass, Supplier<? extends R> instanceSupplier) throws Throwable Called by theinstantiate(ProxySpecification, Supplier)
method, creates a new instance of the suppliedclientProxyClass
that proxies contextual instances supplied by the suppliedinstanceSupplier
.If a subclass overrides the
instantiate(ProxySpecification, Supplier)
method to do something entirely different, this method may not be called.Overrides of this method must not call the
instantiate(ProxySpecification, Supplier)
method or undefined behavior may result.- Type Parameters:
R
- the type of contextual instance being proxied- Parameters:
clientProxyClass
- aClass
assignable toClientProxy.class
and castable to theR
type; must not benull
instanceSupplier
- aSupplier
of contextual instances of theR
type; must not benull
- Returns:
- a non-
null
ClientProxy<R>
- Throws:
NullPointerException
- if any argument isnull
ReferenceException
- if instantiation failsThrowable
- if instantiation fails- See Also:
-
lookup
Returns aMethodHandles.Lookup
suitable for the suppliedClass
.- Parameters:
c
- aClass
; must not benull
- Returns:
- a
MethodHandles.Lookup
; nevernull
- Throws:
NullPointerException
- ifc
isnull
- See Also:
-