javax.management.openmbean
Class CompositeDataInvocationHandler
- InvocationHandler
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(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.
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
invoke
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 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.
- the return value from the method.
Throwable
- if an exception is thrown in the process.
CompositeDataInvocationHandler.java - Pseudo-accessors for CompositeData.
Copyright (C) 2007 Free Software Foundation
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.