public class BeansLinker extends Object implements GuardingDynamicLinker
DynamicLinkerFactory so it is given the chance to link
calls to all objects that no other linker recognized. Specifically, this
linker will:
setXxx(), getXxx(),
and isXxx() as property setters and getters for
StandardOperation.SET_PROPERTY and StandardOperation.GET_PROPERTY
operations;StandardOperation.CALL_METHOD operation;StandardOperation.GET_METHOD operation; the methods thus retrieved
can then be invoked using StandardOperation.CALL.StandardOperation.GET_LENGTH,
StandardOperation.GET_ELEMENT and StandardOperation.SET_ELEMENT
on native Java arrays, as well as List and
Map objects; (StandardOperation.GET_LENGTH works on
any Collection);length on Java arrays;StandardOperation.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.
NamedMethod(GET_METHOD, "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). Overloaded
resolution for constructors is not automatic as there is no logical place to
attach that functionality to but if a language wishes to provide this
functionality, it can use getConstructorMethod(Class, String) as a
useful building block for it.
Variable argument invocation is handled for both methods and constructors.
Caller sensitive methods can be linked as long as they
are otherwise public and link requests have call site descriptors carrying
full-strength MethodHandles.Lookup objects and not weakened lookups or the public
lookup.
The behavior for handling missing members can be
customized by passing a MissingMemberHandlerFactory to the
constructor.
The class also exposes various methods for discovery of available
property and method names on classes and class instances, as well as access
to per-class linkers using the getLinkerForClass(Class)
method.
| Constructor and Description |
|---|
BeansLinker()
Creates a new beans linker.
|
BeansLinker(MissingMemberHandlerFactory missingMemberHandlerFactory)
Creates a new beans linker with the specified factory for creating
missing member handlers.
|
| Modifier and Type | Method and Description |
|---|---|
static Object |
getConstructorMethod(Class<?> clazz,
String signature)
Return the dynamic method of constructor of the given class and the given
signature.
|
GuardedInvocation |
getGuardedInvocation(LinkRequest request,
LinkerServices linkerServices)
Creates a guarded invocation appropriate for a particular invocation with
the specified arguments at a call site.
|
static Set<String> |
getInstanceMethodNames(Class<?> clazz)
Returns a set of names of all instance methods of a class.
|
TypeBasedGuardingDynamicLinker |
getLinkerForClass(Class<?> clazz)
Returns a bean linker for a particular single class.
|
static Set<String> |
getReadableInstancePropertyNames(Class<?> clazz)
Returns a set of names of all readable instance properties of a class.
|
static Set<String> |
getReadableStaticPropertyNames(Class<?> clazz)
Returns a set of names of all readable static properties of a class.
|
static Set<String> |
getStaticMethodNames(Class<?> clazz)
Returns a set of names of all static methods of a class.
|
static Set<String> |
getWritableInstancePropertyNames(Class<?> clazz)
Returns a set of names of all writable instance properties of a class.
|
static Set<String> |
getWritableStaticPropertyNames(Class<?> clazz)
Returns a set of names of all writable static properties of a class.
|
static boolean |
isDynamicConstructor(Object obj)
Returns true if the object is a Java constructor (obtained through
getConstructorMethod(Class, String)}. |
static boolean |
isDynamicMethod(Object obj)
Returns true if the object is a Java dynamic method (e.g., one
obtained through a
GET_METHOD operation on a Java object or
StaticClass or through
getConstructorMethod(Class, String). |
public BeansLinker()
BeansLinker(MissingMemberHandlerFactory) with
null passed as the missing member handler factory, resulting in
the default behavior for linking and evaluating missing members.public BeansLinker(MissingMemberHandlerFactory missingMemberHandlerFactory)
MissingMemberHandlerFactory for details.missingMemberHandlerFactory - a factory for creating handlers for
operations on missing members.public TypeBasedGuardingDynamicLinker getLinkerForClass(Class<?> clazz)
clazz - the classpublic static boolean isDynamicMethod(Object obj)
GET_METHOD operation on a Java object or
StaticClass or through
getConstructorMethod(Class, String).obj - the object we want to test for being a Java dynamic method.public static boolean isDynamicConstructor(Object obj)
getConstructorMethod(Class, String)}.obj - the object we want to test for being a Java constructor.public static Object getConstructorMethod(Class<?> clazz, String signature)
StaticClass objects act as overloaded constructors without
explicit signature selection. Example usage would be:
getConstructorMethod(java.awt.Color.class, "int, int, int").clazz - the classsignature - full signature of the constructor. Note how you can use
names of primitive types, array names with normal Java notation (e.g.
"int[]"), and normally you can even use unqualified class names
(e.g. "String, List" instead of
"java.lang.String, java.util.List" as long as they don't cause
ambiguity in the specific parameter position.public static Set<String> getReadableInstancePropertyNames(Class<?> clazz)
clazz - the classpublic static Set<String> getWritableInstancePropertyNames(Class<?> clazz)
clazz - the classpublic static Set<String> getInstanceMethodNames(Class<?> clazz)
clazz - the classpublic static Set<String> getReadableStaticPropertyNames(Class<?> clazz)
clazz - the classpublic static Set<String> getWritableStaticPropertyNames(Class<?> clazz)
clazz - the classpublic static Set<String> getStaticMethodNames(Class<?> clazz)
clazz - the classpublic GuardedInvocation getGuardedInvocation(LinkRequest request, LinkerServices linkerServices) throws Exception
GuardingDynamicLinkergetGuardedInvocation in interface GuardingDynamicLinkerrequest - the object describing the request for linking a
particular invocationlinkerServices - linker servicesThrowable subclass that describes an expected exception
condition that also triggers relinking (often it is faster to rely on an
infrequent but expected ClassCastException than on an always
evaluated instanceof guard). While the linker must produce an
invocation with parameter types matching those in the call site
descriptor of the link request, it should not try to match the return
type expected at the call site except when it can do it with only the
conversions that lose neither precision nor magnitude, see
LinkerServices.asTypeLosslessReturn(MethodHandle, MethodType) for
further explanation.Exception - if the operation fails for whatever reason
Copyright © 2015, 2016, Oracle and/or its affiliates. All rights reserved.
DRAFT 9-internal+0-2016-04-14-195246.buildd.src