Please note that this documentation is not final and is subject to change.

Java™ Platform
Standard Ed. 7

DRAFT ea-b76

javax.management.openmbean
Class MXBeanMappingFactory

java.lang.Object
  extended by javax.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.

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

Field Summary
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.
 
Constructor Summary
Modifier Constructor and Description
protected MXBeanMappingFactory()
          Construct an instance of this class.
 
Method Summary
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

DEFAULT

public static final MXBeanMappingFactory DEFAULT

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

Constructor Detail

MXBeanMappingFactory

protected MXBeanMappingFactory()

Construct an instance of this class.

Method Detail

forInterface

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.

Parameters:
intf - the MXBean interface for which to determine the MXBeanMappingFactory.
Returns:
the MXBeanMappingFactory for the given MXBean interface.
Throws:
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.

mappingForType

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 - 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>.
Returns:
the mapping for the given type.
Throws:
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

Submit a bug or feature

Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. Use is subject to license terms.