APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.dynalink.beans

public Class BeansLinker

extends Object
implements GuardingDynamicLinker
Class Inheritance
All Implemented Interfaces
jdk.dynalink.linker.GuardingDynamicLinker
Imports
java.lang.invoke.MethodHandles.Lookup, java.util.Collections, .Set, jdk.dynalink.DynamicLinkerFactory, .StandardNamespace, .StandardOperation, jdk.dynalink.linker.GuardedInvocation, .GuardingDynamicLinker, .LinkRequest, .LinkerServices, .TypeBasedGuardingDynamicLinker

A linker for ordinary Java objects. Normally used as the ultimate fallback linker by the DynamicLinkerFactory so it is given the chance to link calls to all objects that no other linker recognized. Specifically, this linker will:

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, e.g. StandardOperation.GET.withNamespace(METHOD).named("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 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.

Since
9

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final ClassValue<TypeBasedGuardingDynamicLinker>
private final MissingMemberHandlerFactory

Constructor Summary

AccessConstructor and Description
public
BeansLinker()

Creates a new beans linker.

public
BeansLinker(final MissingMemberHandlerFactory
a factory for creating handlers for operations on missing members.
missingMemberHandlerFactory
)

Creates a new beans linker with the specified factory for creating missing member handlers.

Method Summary

Modifier and TypeMethod and Description
public static Object

Returns:

dynamic method for the constructor or null if no constructor with the specified signature exists.
getConstructorMethod
(final Class<?>
the class
clazz
,
final String
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.
signature
)

Return the dynamic method of constructor of the given class and the given signature.

public GuardedInvocation
getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices)

Implements jdk.dynalink.linker.GuardingDynamicLinker.getGuardedInvocation.

Creates a guarded invocation appropriate for a particular invocation with the specified arguments at a call site.

public static Set<String>

Returns:

a set of names of all instance methods of a class.
getInstanceMethodNames
(final Class<?>
the class
clazz
)

Returns a set of names of all instance methods of a class.

public TypeBasedGuardingDynamicLinker

Returns:

a bean linker for that class
getLinkerForClass
(final Class<?>
the class
clazz
)

Returns a bean linker for a particular single class.

public static Set<String>

Returns:

a set of names of all readable instance properties of a class.
getReadableInstancePropertyNames
(final Class<?>
the class
clazz
)

Returns a set of names of all readable instance properties of a class.

public static Set<String>

Returns:

a set of names of all readable static properties of a class.
getReadableStaticPropertyNames
(final Class<?>
the class
clazz
)

Returns a set of names of all readable static properties of a class.

pack-priv static TypeBasedGuardingDynamicLinker
public static Set<String>

Returns:

a set of names of all static methods of a class.
getStaticMethodNames
(final Class<?>
the class
clazz
)

Returns a set of names of all static methods of a class.

public static Set<String>

Returns:

a set of names of all writable instance properties of a class.
getWritableInstancePropertyNames
(final Class<?>
the class
clazz
)

Returns a set of names of all writable instance properties of a class.

public static Set<String>

Returns:

a set of names of all writable static properties of a class.
getWritableStaticPropertyNames
(final Class<?>
the class
clazz
)

Returns a set of names of all writable static properties of a class.

public static boolean

Returns:

true if it is a constructor, false otherwise.
isDynamicConstructor
(final Object
the object we want to test for being a Java constructor.
obj
)

Returns true if the object is a Java constructor (obtained through getConstructorMethod(Class, String)}.

public static boolean

Returns:

true if it is a dynamic method, false otherwise.
isDynamicMethod
(final Object
the object we want to test for being a Java dynamic method.
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).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

linkersback to summary
private static final ClassValue<TypeBasedGuardingDynamicLinker> linkers
missingMemberHandlerFactoryback to summary
private final MissingMemberHandlerFactory missingMemberHandlerFactory

Constructor Detail

BeansLinkerback to summary
public BeansLinker()

Creates a new beans linker. Equivalent to BeansLinker#BeansLinker(MissingMemberHandlerFactory) with null passed as the missing member handler factory, resulting in the default behavior for linking and evaluating missing members.

BeansLinkerback to summary
public BeansLinker(final MissingMemberHandlerFactory missingMemberHandlerFactory)

Creates a new beans linker with the specified factory for creating missing member handlers. The passed factory can be null if the default behavior is adequate. See MissingMemberHandlerFactory for details.

Parameters
missingMemberHandlerFactory:MissingMemberHandlerFactory

a factory for creating handlers for operations on missing members.

Method Detail

getConstructorMethodback to summary
public static Object getConstructorMethod(final Class<?> clazz, final String signature)

Return the dynamic method of constructor of the given class and the given signature. This method is useful for exposing a functionality for selecting an overloaded constructor based on an explicit signature, as this functionality is not otherwise exposed by Dynalink as StaticClass objects act as overloaded constructors without explicit signature selection. Example usage would be: getConstructorMethod(java.awt.Color.class, "int, int, int").

Parameters
clazz:Class<?>

the class

signature:String

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.

Returns:Object

dynamic method for the constructor or null if no constructor with the specified signature exists.

getGuardedInvocationback to summary
public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception

Implements jdk.dynalink.linker.GuardingDynamicLinker.getGuardedInvocation.

Doc from jdk.dynalink.linker.GuardingDynamicLinker.getGuardedInvocation.

Creates a guarded invocation appropriate for a particular invocation with the specified arguments at a call site.

Annotations
@Override
Exceptions
Exception:
if the operation fails for whatever reason
getInstanceMethodNamesback to summary
public static Set<String> getInstanceMethodNames(final Class<?> clazz)

Returns a set of names of all instance methods of a class.

Parameters
clazz:Class<?>

the class

Returns:Set<String>

a set of names of all instance methods of a class.

getLinkerForClassback to summary
public TypeBasedGuardingDynamicLinker getLinkerForClass(final Class<?> clazz)

Returns a bean linker for a particular single class. Useful when you need to override or extend the behavior of linking for some classes in your language runtime's linker, but still want to delegate to the default behavior in some cases.

Parameters
clazz:Class<?>

the class

Returns:TypeBasedGuardingDynamicLinker

a bean linker for that class

getReadableInstancePropertyNamesback to summary
public static Set<String> getReadableInstancePropertyNames(final Class<?> clazz)

Returns a set of names of all readable instance properties of a class.

Parameters
clazz:Class<?>

the class

Returns:Set<String>

a set of names of all readable instance properties of a class.

getReadableStaticPropertyNamesback to summary
public static Set<String> getReadableStaticPropertyNames(final Class<?> clazz)

Returns a set of names of all readable static properties of a class.

Parameters
clazz:Class<?>

the class

Returns:Set<String>

a set of names of all readable static properties of a class.

getStaticLinkerForClassback to summary
pack-priv static TypeBasedGuardingDynamicLinker getStaticLinkerForClass(final Class<?> clazz)
getStaticMethodNamesback to summary
public static Set<String> getStaticMethodNames(final Class<?> clazz)

Returns a set of names of all static methods of a class.

Parameters
clazz:Class<?>

the class

Returns:Set<String>

a set of names of all static methods of a class.

getWritableInstancePropertyNamesback to summary
public static Set<String> getWritableInstancePropertyNames(final Class<?> clazz)

Returns a set of names of all writable instance properties of a class.

Parameters
clazz:Class<?>

the class

Returns:Set<String>

a set of names of all writable instance properties of a class.

getWritableStaticPropertyNamesback to summary
public static Set<String> getWritableStaticPropertyNames(final Class<?> clazz)

Returns a set of names of all writable static properties of a class.

Parameters
clazz:Class<?>

the class

Returns:Set<String>

a set of names of all writable static properties of a class.

isDynamicConstructorback to summary
public static boolean isDynamicConstructor(final Object obj)

Returns true if the object is a Java constructor (obtained through getConstructorMethod(Class, String)}.

Parameters
obj:Object

the object we want to test for being a Java constructor.

Returns:boolean

true if it is a constructor, false otherwise.

isDynamicMethodback to summary
public static boolean isDynamicMethod(final 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).

Parameters
obj:Object

the object we want to test for being a Java dynamic method.

Returns:boolean

true if it is a dynamic method, false otherwise.

jdk.dynalink.beans back to summary

private Class BeansLinker.NoSuchMemberHandlerBindingLinker

extends Object
implements TypeBasedGuardingDynamicLinker
Class Inheritance
  • java.lang.Object
  • jdk.dynalink.beans.BeansLinker.NoSuchMemberHandlerBindingLinker
All Implemented Interfaces
jdk.dynalink.linker.TypeBasedGuardingDynamicLinker, jdk.dynalink.linker.GuardingDynamicLinker

Field Summary

Modifier and TypeField and Description
private final TypeBasedGuardingDynamicLinker
private final MissingMemberHandlerFactory

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
canLinkType(final Class<?> type)

Implements jdk.dynalink.linker.TypeBasedGuardingDynamicLinker.canLinkType.

Returns true if the linker can link an invocation where the first argument (receiver) is of the specified type.

public GuardedInvocation
getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices)

Implements jdk.dynalink.linker.GuardingDynamicLinker.getGuardedInvocation.

Creates a guarded invocation appropriate for a particular invocation with the specified arguments at a call site.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

linkerback to summary
private final TypeBasedGuardingDynamicLinker linker
missingMemberHandlerFactoryback to summary
private final MissingMemberHandlerFactory missingMemberHandlerFactory

Constructor Detail

NoSuchMemberHandlerBindingLinkerback to summary
pack-priv NoSuchMemberHandlerBindingLinker(final TypeBasedGuardingDynamicLinker linker, final MissingMemberHandlerFactory missingMemberHandlerFactory)

Method Detail

canLinkTypeback to summary
public boolean canLinkType(final Class<?> type)

Implements jdk.dynalink.linker.TypeBasedGuardingDynamicLinker.canLinkType.

Doc from jdk.dynalink.linker.TypeBasedGuardingDynamicLinker.canLinkType.

Returns true if the linker can link an invocation where the first argument (receiver) is of the specified type.

Annotations
@Override
getGuardedInvocationback to summary
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) throws Exception

Implements jdk.dynalink.linker.GuardingDynamicLinker.getGuardedInvocation.

Doc from jdk.dynalink.linker.GuardingDynamicLinker.getGuardedInvocation.

Creates a guarded invocation appropriate for a particular invocation with the specified arguments at a call site.

Annotations
@Override
Exceptions
Exception:
if the operation fails for whatever reason