APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.jmx.mbeanserver

public abstract Class MXBeanMappingFactory

extends Object
Class Inheritance
Known Direct Subclasses
com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory
Imports
javax.management.openmbean.*, com.sun.jmx.mbeanserver.MXBeanMapping, .DefaultMXBeanMappingFactory, java.lang.reflect.Type

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.

See Also
MXBean specification, section "Custom MXBean type mappings"

Field Summary

Modifier and TypeField and Description
public static final MXBeanMappingFactory
DEFAULT

Mapping factory that applies the default rules for MXBean mappings, as described in the MXBean specification.

Constructor Summary

AccessConstructor and Description
protected
MXBeanMappingFactory()

Construct an instance of this class.

Method Summary

Modifier and TypeMethod and Description
public abstract MXBeanMapping

Returns:

the mapping for the given type.
mappingForType
(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 MyLinkedListMappingFactory works for types like MyLinkedList[] and List<MyLinkedList>.
f
)

Return the mapping for the given Java type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULTback to summary
public static final MXBeanMappingFactory DEFAULT

Mapping factory that applies the default rules for MXBean mappings, as described in the MXBean specification.

Constructor Detail

MXBeanMappingFactoryback to summary
protected MXBeanMappingFactory()

Construct an instance of this class.

Method Detail

mappingForTypeback 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.

Parameters
t:Type

the Java type to be mapped.

f: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 MyLinkedListMappingFactory works for types like MyLinkedList[] and List<MyLinkedList>.

Returns:MXBeanMapping

the mapping for the given type.

Exceptions
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.