|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.management.openmbean.CompositeDataInvocationHandler
public class CompositeDataInvocationHandler
Provides an InvocationHandler
which
implements a series of accessor methods (those beginning with
"get"
or "is"
) using the content of a
CompositeData
object. An instance of CompositeData
consists of a series of key-value mappings. This handler assumes
these keys to be the names of attributes, and thus provides
accessor methods by returning the associated value.
As an example, consider the following interface:
public interface Person { public String getName(); public Date getBirthday(); }
This specifies two accessor methods for retrieving the attributes,
name
and birthday
. An implementation of this interface
can be provided by creating an instance of this class, using a
CompositeData
object with appropriate key-value mappings
(e.g. "name" => "Fred", "birthday" => 30/06/1974), and then passing
that to Proxy.newProxyInstance(java.lang.ClassLoader, java.lang.Class>[], java.lang.reflect.InvocationHandler)
along with
the interface itself. The invocation handler implements the methods
by calling CompositeData.get(String)
with the appropriate key.
The attribute name is derived by taking the remainder of the method
name following "get"
. If the first letter of this substring
is uppercase, then two attempts are made to retrieve the attribute
from the CompositeData
instance: one using the original substring,
and one with the first letter changed to its lower-case equivalent.
If the first letter is lowercase, only the exact substring is used.
An Object.equals(Object)
implementation is provided. This returns
true if the argument is a proxy with a CompositeDataInvocationHandler
using an equivalent CompositeData
instance. Object.hashCode()
is also defined so as to match this implementation and give equivalent instances
the same hashcode.
Constructor Summary | |
---|---|
CompositeDataInvocationHandler(CompositeData data)
Constructs a new CompositeDataInvocationHandler
with the specified CompositeData instance. |
Method Summary | |
---|---|
CompositeData |
getCompositeData()
Returns the CompositeData instance which provides
the key-value mappings for this instance. |
Object |
invoke(Object proxy,
Method method,
Object[] args)
Called by the proxy class whenever a method is called. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CompositeDataInvocationHandler(CompositeData data)
CompositeDataInvocationHandler
with the specified CompositeData
instance.
data
- the CompositeData
instance to use.
IllegalArgumentException
- if data
is null
.Method Detail |
---|
public CompositeData getCompositeData()
CompositeData
instance which provides
the key-value mappings for this instance. This is never
null
.
CompositeData
instance.public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
"get"
or "is"
), equals
, and
"hashCode"
. Accessor methods are implemented by
returning the appropriate value from the CompositeData
instance, while equals
and hashCode
allow
two proxies with a CompositeDataInvocationHandler
using
the same CompositeData
instance to be classified
as equivalent.
invoke
in interface InvocationHandler
proxy
- the proxy on which the method was called.method
- the method which was called.args
- the arguments supplied to the method.
Throwable
- if an exception is thrown in the process.Proxy
,
UndeclaredThrowableException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |