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. 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 |
|---|---|
| public static final MXBeanMappingFactory | DEFAULT
Mapping factory that applies the default rules for MXBean mappings, as described in the MXBean specification. |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public abstract MXBeanMapping | Returns: the mapping for the given type.the Java type to be mapped. t, MXBeanMappingFactory 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 f)MyLinkedListMappingFactory works for types
like MyLinkedList[] and List<MyLinkedList>.Return the mapping for the given Java type. |
| DEFAULT | back to summary |
|---|---|
| public static final MXBeanMappingFactory DEFAULT Mapping factory that applies the default rules for MXBean mappings, as described in the MXBean specification. | |
| MXBeanMappingFactory | back to summary |
|---|---|
| protected MXBeanMappingFactory() Construct an instance of this class. | |
| mappingForType | back to summary |
|---|---|
| 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.
| |