@HashCodeAndEqualsPlugin.Enhance public abstract class InvocationHandlerAdapter extends Object implements Implementation
InvocationHandler
. The adapter allows the invocation handler
to also intercept method calls to non-interface methods.Modifier and Type | Class and Description |
---|---|
static interface |
InvocationHandlerAdapter.AssignerConfigurable
Allows for the configuration of an
Assigner
of an InvocationHandlerAdapter . |
protected static class |
InvocationHandlerAdapter.ForField
An implementation of an
InvocationHandlerAdapter that delegates method
invocations to an adapter that is stored in an instance field. |
protected static class |
InvocationHandlerAdapter.ForInstance
An implementation of an
InvocationHandlerAdapter that delegates method
invocations to an adapter that is stored in a static field. |
static interface |
InvocationHandlerAdapter.WithoutPrivilegeConfiguration
Allows the configuration of privileged lookup for the resolution of
Method
constants that are provided to the invocation handler. |
Implementation.Composable, Implementation.Compound, Implementation.Context, Implementation.Simple, Implementation.SpecialMethodInvocation, Implementation.Target
Modifier and Type | Field and Description |
---|---|
protected Assigner |
assigner
The assigner that is used for assigning the return invocation handler's return value to the
intercepted method's return value.
|
protected boolean |
cached
Determines if the
Method instances that are handed to the intercepted methods are
cached in static fields. |
protected String |
fieldName
The name of the field for storing an invocation handler.
|
protected boolean |
privileged
Determines if the
Method instances are retrieved by using an AccessController . |
Modifier | Constructor and Description |
---|---|
protected |
InvocationHandlerAdapter(String fieldName,
boolean cached,
boolean privileged,
Assigner assigner)
Creates a new invocation handler for a given field.
|
Modifier and Type | Method and Description |
---|---|
protected ByteCodeAppender.Size |
apply(MethodVisitor methodVisitor,
Implementation.Context implementationContext,
MethodDescription instrumentedMethod,
StackManipulation preparingManipulation,
FieldDescription fieldDescription)
Applies an implementation that delegates to a invocation handler.
|
static InvocationHandlerAdapter |
of(InvocationHandler invocationHandler)
Creates an implementation for any instance of an
InvocationHandler that delegates
all method interceptions to the given instance which will be stored in a static field. |
static InvocationHandlerAdapter |
of(InvocationHandler invocationHandler,
String fieldName)
Creates an implementation for any instance of an
InvocationHandler that delegates
all method interceptions to the given instance which will be stored in a static field. |
static InvocationHandlerAdapter |
toField(String name)
Creates an implementation for any
InvocationHandler that delegates
all method interceptions to a field with the given name. |
static InvocationHandlerAdapter |
toField(String name,
FieldLocator.Factory fieldLocatorFactory)
Creates an implementation for any
InvocationHandler that delegates
all method interceptions to a field with the given name. |
abstract Implementation |
withAssigner(Assigner assigner)
Configures an assigner to use with this invocation handler adapter.
|
abstract InvocationHandlerAdapter.WithoutPrivilegeConfiguration |
withoutMethodCache()
By default, any
Method instance that is handed over to an
InvocationHandler is cached in a static field. |
abstract InvocationHandlerAdapter.AssignerConfigurable |
withPrivilegedLookup()
Configures that the method constants supplied to the invocation handler adapter are resolved using an
AccessController . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
appender
prepare
protected final String fieldName
protected final Assigner assigner
protected final boolean cached
Method
instances that are handed to the intercepted methods are
cached in static
fields.protected final boolean privileged
Method
instances are retrieved by using an AccessController
.protected InvocationHandlerAdapter(String fieldName, boolean cached, boolean privileged, Assigner assigner)
fieldName
- The name of the field.cached
- Determines if the Method
instances that are handed to the
intercepted methods are cached in static
fields.privileged
- Determines if the Method
instances are retrieved by using an AccessController
.assigner
- The assigner to apply when defining this implementation.public static InvocationHandlerAdapter of(InvocationHandler invocationHandler)
InvocationHandler
that delegates
all method interceptions to the given instance which will be stored in a static
field.invocationHandler
- The invocation handler to which all method calls are delegated.public static InvocationHandlerAdapter of(InvocationHandler invocationHandler, String fieldName)
InvocationHandler
that delegates
all method interceptions to the given instance which will be stored in a static
field.invocationHandler
- The invocation handler to which all method calls are delegated.fieldName
- The name of the field.public static InvocationHandlerAdapter toField(String name)
InvocationHandler
that delegates
all method interceptions to a field with the given name. This field has to be of a subtype of invocation
handler and needs to be set before any invocations are intercepted. Otherwise, a NullPointerException
will be thrown.name
- The name of the field.public static InvocationHandlerAdapter toField(String name, FieldLocator.Factory fieldLocatorFactory)
InvocationHandler
that delegates
all method interceptions to a field with the given name. This field has to be of a subtype of invocation
handler and needs to be set before any invocations are intercepted. Otherwise, a NullPointerException
will be thrown.name
- The name of the field.fieldLocatorFactory
- The field locator factorypublic abstract InvocationHandlerAdapter.WithoutPrivilegeConfiguration withoutMethodCache()
Method
instance that is handed over to an
InvocationHandler
is cached in a static field. By invoking this method,
this feature can be disabled.public abstract Implementation withAssigner(Assigner assigner)
assigner
- The assigner to apply when defining this implementation.assigner
configured.public abstract InvocationHandlerAdapter.AssignerConfigurable withPrivilegedLookup()
AccessController
.protected ByteCodeAppender.Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod, StackManipulation preparingManipulation, FieldDescription fieldDescription)
methodVisitor
- The method visitor for writing the byte code to.implementationContext
- The implementation context for the current implementation.instrumentedMethod
- The method that is instrumented.preparingManipulation
- A stack manipulation that applies any preparation to the operand stack.fieldDescription
- The field that contains the value for the invocation handler.Copyright © 2014–2020. All rights reserved.