public class BeansLinker extends Object implements GuardingDynamicLinker
DynamicLinkerFactory
so it is given
the chance to link calls to all objects that no other language runtime recognizes. Specifically, this linker will:
setXxx()
, getXxx()
, and isXxx()
as property setters and
getters for dyn:setProp
and dyn:getProp
operations;dyn:callMethod
operation;dyn:getMethod
operation; the methods thus retrieved can then
be invoked using dyn:call
;dyn:getLength
, dyn:getElem
and dyn:setElem
on native Java arrays, as well as
List
and Map
objects; (dyn:getLength
works on any
Collection
);length
on Java arrays;dyn:new
on instances of StaticClass
as calls to constructors, including those static class
objects that represent Java arrays (their constructors take a single int
parameter representing the length of
the array to create);StaticClass
objects.static
on instances of Class
to access their
StaticClass
.Overloaded method resolution is performed automatically for property setters, methods, and
constructors. Additionally, manual overloaded method selection is supported by having a call site specify a name for
a method that contains an explicit signature, i.e. dyn:getMethod:parseInt(String,int)
. You can use
non-qualified class names in such signatures regardless of those classes' packages, they will match any class with
the same non-qualified name. You only have to use a fully qualified class name in case non-qualified class names
would cause selection ambiguity (that is extremely rare).
Variable argument invocation is handled for both methods and constructors.
Currently, only public fields and methods are supported. Any Lookup objects passed in the
LinkRequest
s are ignored and MethodHandles.publicLookup()
is used instead.
Constructor and Description |
---|
BeansLinker()
Creates a new POJO linker.
|
Modifier and Type | Method and Description |
---|---|
GuardedInvocation |
getGuardedInvocation(LinkRequest request,
LinkerServices linkerServices)
Creates a guarded invocation appropriate for a particular invocation with the specified arguments at a call site.
|
static Collection<String> |
getInstanceMethodNames(Class<?> clazz)
Returns a collection of names of all instance methods of a class.
|
static TypeBasedGuardingDynamicLinker |
getLinkerForClass(Class<?> clazz)
Returns a bean linker for a particular single class.
|
static Collection<String> |
getReadableInstancePropertyNames(Class<?> clazz)
Returns a collection of names of all readable instance properties of a class.
|
static Collection<String> |
getReadableStaticPropertyNames(Class<?> clazz)
Returns a collection of names of all readable static properties of a class.
|
static Collection<String> |
getStaticMethodNames(Class<?> clazz)
Returns a collection of names of all static methods of a class.
|
static Collection<String> |
getWritableInstancePropertyNames(Class<?> clazz)
Returns a collection of names of all writable instance properties of a class.
|
static Collection<String> |
getWritableStaticPropertyNames(Class<?> clazz)
Returns a collection of names of all writable static properties of a class.
|
public static TypeBasedGuardingDynamicLinker getLinkerForClass(Class<?> clazz)
clazz
- the classpublic static Collection<String> getReadableInstancePropertyNames(Class<?> clazz)
clazz
- the classpublic static Collection<String> getWritableInstancePropertyNames(Class<?> clazz)
clazz
- the classpublic static Collection<String> getInstanceMethodNames(Class<?> clazz)
clazz
- the classpublic static Collection<String> getReadableStaticPropertyNames(Class<?> clazz)
clazz
- the classpublic static Collection<String> getWritableStaticPropertyNames(Class<?> clazz)
clazz
- the classpublic static Collection<String> getStaticMethodNames(Class<?> clazz)
clazz
- the classpublic GuardedInvocation getGuardedInvocation(LinkRequest request, LinkerServices linkerServices) throws Exception
GuardingDynamicLinker
getGuardedInvocation
in interface GuardingDynamicLinker
request
- the object describing the request for linking a particular invocationlinkerServices
- linker servicesLinkRequest.withoutRuntimeContext()
and link for that.Exception
- if the operation fails for whatever reasonCopyright © 2015 Attila Szegedi. All rights reserved.