Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
javax.management.openmbean.CompositeDataInvocationHandler
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(ClassLoader,Class[],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 | |
|
Method Summary | |
CompositeData |
|
Object |
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public CompositeDataInvocationHandler(CompositeData data)
Constructs a newCompositeDataInvocationHandler
with the specifiedCompositeData
instance.
- Parameters:
data
- theCompositeData
instance to use.
- Throws:
IllegalArgumentException
- ifdata
isnull
.
public CompositeData getCompositeData()
Returns theCompositeData
instance which provides the key-value mappings for this instance. This is nevernull
.
- Returns:
- the
CompositeData
instance.
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
Called by the proxy class whenever a method is called. The handler only deals with accessor methods (beginning with"get"
or"is"
),equals
, and"hashCode"
. Accessor methods are implemented by returning the appropriate value from theCompositeData
instance, whileequals
andhashCode
allow two proxies with aCompositeDataInvocationHandler
using the sameCompositeData
instance to be classified as equivalent.
- Specified by:
- invoke in interface InvocationHandler
- Parameters:
proxy
- the proxy on which the method was called.method
- the method which was called.args
- the arguments supplied to the method.
- Returns:
- the return value from the method.
- Throws:
Throwable
- if an exception is thrown in the process.