|
Java™ Platform Standard Ed. 7 DRAFT ea-b76 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.management.openmbean.MXBeanMappingFactory
public abstract class MXBeanMappingFactory extends Object
Defines how types are mapped for a given MXBean or set of MXBeans.
An MXBeanMappingFactory can be specified either through the
MXBeanMappingFactoryClass annotation, or through the
JMX.MBeanOptions argument to a
StandardMBean constructor or MXBean
proxy.
An MXBeanMappingFactory must return an MXBeanMapping
for any Java type that appears in the MXBeans that the factory is being
used for. Usually it does that by handling any custom types, and
forwarding everything else to the default mapping
factory.
Consider the MyLinkedList example from the MXBeanMapping
documentation. If we are unable to change the MyLinkedList class
to add an MXBeanMappingClass annotation, we could achieve the same
effect by defining MyLinkedListMappingFactory as follows:
public class MyLinkedListMappingFactory extends MXBeanMappingFactory {
public MyLinkedListMappingFactory() {}
public MXBeanMapping mappingForType(Type t, MXBeanMappingFactory f)
throws OpenDataException {
if (t == MyLinkedList.class)
return new MyLinkedListMapping(t);
else
return MXBeanMappingFactory.DEFAULT.mappingForType(t, f);
}
}
The mapping factory handles only the MyLinkedList class.
Every other type is forwarded to the default mapping factory.
This includes types such as MyLinkedList[] and
List<MyLinkedList>; the default mapping factory will recursively
invoke MyLinkedListMappingFactory to map the contained
MyLinkedList type.
Once we have defined MyLinkedListMappingFactory, we can use
it in an MXBean interface like this:
@MXBeanMappingFactoryClass(MyLinkedListMappingFactory.class)
public interface SomethingMXBean {
public MyLinkedList getSomething();
}
Alternatively we can annotate the package that SomethingMXBean
appears in, or we can supply the factory to a StandardMBean constructor or MXBean
proxy.
| Modifier and Type | Field and Description |
|---|---|
static MXBeanMappingFactory |
DEFAULT
Mapping factory that applies the default rules for MXBean mappings, as described in the MXBean specification. |
| Modifier | Constructor and Description |
|---|---|
protected |
MXBeanMappingFactory()
Construct an instance of this class. |
| Modifier and Type | Method and Description |
|---|---|
static MXBeanMappingFactory |
forInterface(Class<?> intf)
Determine the appropriate MXBeanMappingFactory to use for the given MXBean interface, based on its annotations. |
abstract MXBeanMapping |
mappingForType(Type t,
MXBeanMappingFactory f)
Return the mapping for the given Java type. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final MXBeanMappingFactory DEFAULT
Mapping factory that applies the default rules for MXBean mappings, as described in the MXBean specification.
| Constructor Detail |
|---|
protected MXBeanMappingFactory()
Construct an instance of this class.
| Method Detail |
|---|
public static MXBeanMappingFactory forInterface(Class<?> intf)
Determine the appropriate MXBeanMappingFactory to use for the given
MXBean interface, based on its annotations. If the interface has an
@MXBeanMappingFactoryClass annotation,
that is used to determine the MXBeanMappingFactory. Otherwise, if the
package containing the interface has such an annotation, that is used.
Otherwise the MXBeanMappingFactory is the default
one.
intf - the MXBean interface for which to determine the
MXBeanMappingFactory.IllegalArgumentException - if intf is null, or if an
exception occurs while trying constructing an MXBeanMappingFactory
based on an annotation. In the second case, the exception will appear
in the cause chain of the
IllegalArgumentException.
public abstract MXBeanMapping mappingForType(Type t,
MXBeanMappingFactory f)
throws OpenDataException
Return the mapping for the given Java type. Typically, a mapping factory will return mappings for types it handles, and forward other types to another mapping factory, most often the default one.
t - the Java type to be mapped.f - the original mapping factory that was consulted to do
the mapping. A mapping factory should pass this parameter intact
if it forwards a type to another mapping factory. In the example,
this is how MyLinkedListMappingFactory works for types
like MyLinkedList[] and List<MyLinkedList>.OpenDataException - if this type cannot be mapped. This
exception is appropriate if the factory is supposed to handle
all types of this sort (for example, all linked lists), but
cannot handle this particular type.
|
Java™ Platform Standard Ed. 7 DRAFT ea-b76 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.