public class HalfDynamicProxy extends java.lang.Object implements InvocationHandlerWithTarget
Modifier and Type | Class and Description |
---|---|
private static class |
HalfDynamicProxy.HDPState
Holds the state of a HalfDynamicProxy.
|
static interface |
HalfDynamicProxy.MessageInterface
Used to emit a message.
|
Modifier and Type | Field and Description |
---|---|
private static java.lang.Class<?>[][] |
proxyClassTable
Holds a mapping table, that determinates the invocation handler class for
a proxy target class.
|
private HalfDynamicProxy.HDPState |
state
holds the state
|
protected java.lang.Object |
target
holds the target.
|
Constructor and Description |
---|
HalfDynamicProxy() |
Modifier and Type | Method and Description |
---|---|
java.lang.reflect.Proxy |
dynamicProxyInstance()
Get the dynamic proxy for this object.
|
boolean |
equals(java.lang.Object obj)
This equals-method calls the equals
for the unwrapped proxy target objects.
|
protected java.lang.Object |
getHDPProxy(java.lang.Object obj,
java.lang.Class<?> expect)
Get the proxy for an object using the same state as this proxy uses.
|
static java.lang.Object |
getHDPProxy(java.lang.Object obj,
java.lang.Class<?> expect,
HalfDynamicProxy.HDPState state)
Get the dynamic proxy for an object.
|
protected java.lang.Object |
getHDPStateUserObject()
Get the user object.
|
java.lang.Object |
getInvocationTarget()
Get the target object, for which this invocation handler is a
proxy for.
|
static java.lang.Class<?>[][] |
getProxyClassTable() |
int |
hashCode()
Calls the hashCode method of the proxy target.
|
java.lang.Object |
invoke(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args) |
static void |
setProxyClassTable(java.lang.Class<?>[][] proxyClassTable)
Set the proxy class table.
|
void |
setupInvocationHandler(java.lang.Object target,
java.lang.Object state)
Initialize this invocation handler.
|
static HalfDynamicProxy.HDPState |
stateFactory(java.lang.Object userState,
HalfDynamicProxy.MessageInterface reciver)
Create a new state object.
|
java.lang.String |
toString()
Calls the toString method of the proxy target.
|
protected static java.lang.Object |
unwrap(java.lang.Object proxy)
Get the unwrapped proxy target.
|
private static java.lang.Class<?>[][] proxyClassTable
protected java.lang.Object target
private HalfDynamicProxy.HDPState state
public static HalfDynamicProxy.HDPState stateFactory(java.lang.Object userState, HalfDynamicProxy.MessageInterface reciver)
userState
- an arbitrary object provided by the caller. May be
null
.reciver
- where to send messages to. May be null
.public static java.lang.Class<?>[][] getProxyClassTable()
public static void setProxyClassTable(java.lang.Class<?>[][] proxyClassTable)
InvocationHandlerWithTarget
, to be used for a given proxy target
class. Each entry of the table is a Class[]
, that
contains a class implementing InvocationHandlerWithTarget
as its
first entry and zero or more interfaces as additional entries, that must
be implemented by the object to create a proxy for. The first matching
invocation handler is used.proxyClassTable
- The proxyClassTable to set.public final void setupInvocationHandler(java.lang.Object target, java.lang.Object state)
InvocationHandlerWithTarget
setupInvocationHandler
in interface InvocationHandlerWithTarget
target
- object, for which this object is a proxy.state
- an arbitrary object used to hold state informationpublic final java.lang.Object getInvocationTarget()
InvocationHandlerWithTarget
getInvocationTarget
in interface InvocationHandlerWithTarget
public java.lang.reflect.Proxy dynamicProxyInstance()
Proxy
.protected java.lang.Object getHDPStateUserObject()
stateFactory(Object, HalfDynamicProxy.MessageInterface)
.protected java.lang.Object getHDPProxy(java.lang.Object obj, java.lang.Class<?> expect)
obj
- the object to create a proxy forexpect
- the expected type of the object,
if obj
is an array. If expect is Object
or
null
, then the type of obj is used instead of expect.getHDPProxy(Object, Class, HalfDynamicProxy.HDPState)
public static java.lang.Object getHDPProxy(java.lang.Object obj, java.lang.Class<?> expect, HalfDynamicProxy.HDPState state)
obj
is null
or primitive
or, if obj
is already a dynamic proxy, or, if
no InvocationHandlerWithTarget
implementation is found in the
proxyClassTable
(see setProxyClassTable(Class[][])
).obj
- the object to create a proxy for.expect
- the expected type of the object,
if obj
is an array. If expect is Object
or
null
, then the type of obj is used instead of expect.state
- the state object for the proxysetProxyClassTable(Class[][])
public java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.Throwable
java.lang.Throwable
protected static java.lang.Object unwrap(java.lang.Object proxy)
proxy
- an objectInvocationHandlerWithTarget
interface. In
that case the target object will be returned.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
Object.equals(java.lang.Object)
public int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()