panmx.model
Class ModelMBeanFactory

java.lang.Object
  extended by panmx.model.ModelMBeanFactory

public class ModelMBeanFactory
extends java.lang.Object

Utility class to create ModelMBeans and their associated MBeanInfo objects from annotated Java classes.

The user can expose a java object as a ModelMBean by annotating the java class using the Java 1.5 Annotations defined in the package 'panmx.annotations'. The ModelMBeanFactory class currently supports the all of the annotations except for MxConstructor.

Following are some code examples and a description of the corresponding ModelMBeanInfo that could be created from the class.

Example 1: ModelMBeanInfo with a description "Component to measure and clean out toxins" but 0 attributes and 0 operations.

 @MBean(description = "Component to measure and clean out toxins")
   public class Liver
 {
 }
 

Example 2: ModelMBeanInfo with 0 attributes and 1 operation 'clean'

 @MBean()
   public class Liver
 {
    private float m_toxicity;

    @MxOperation(description = "Clean out the toxins")
      public void clean()
    {
      m_toxicity = 0;
    }
 }
 

Example 3: ModelMBeanInfo with 1 read-only attribute 'toxicity', with a description "Level of toxicity" and display name of "Toxicity Level". Corresponding operation for accessor 'getToxicity'.

 @MBean()
   public class Liver
 {
    private float m_toxicity;

    @MxAttribute(description = "Level of toxicity", displayName = "Toxicity Level")
      public float getToxicity()
    {
      return m_toxicity;
    }
 }
 

Example 4: ModelMBeanInfo with 1 attribute named 'toxicity', with a description "Level of toxicity" and display name of "Toxicity Level". Corresponding operations for accessor 'getToxicity' and mutator 'setToxicity'.

 @MBean()
   public class Liver
 {
    private float m_toxicity;

    @MxAttribute()
      public float getToxicity()
    {
      return m_toxicity;
    }

    @MxAttribute(description = "Level of toxicity", displayName = "Toxicity Level")
      public void setToxicity(final float toxicity)
    {
      m_toxicity = toxicity;
    }
 }
 

Example 5: ModelMBeanInfo with 0 attributes and 1 operation 'clean'.

 public interface LiverRMXBean
 {
   @MxOperation(description = "Clean out the toxins")
   void clean();
 }

 @MBean(interfaces = {LiverMBean.class})
   public class Liver
 {
    private float m_toxicity;

      public void clean()
    {
      m_toxicity = 0;
    }
 }
 

Some points to note;


Constructor Summary
ModelMBeanFactory()
           
 
Method Summary
static void clearCache()
          Clear the cache of all MBeanInfos currently loaded into the system.
static javax.management.modelmbean.ModelMBean createAnnotatedModelMBean(java.lang.Object object)
          Create ModelMBean for annotated object.
static javax.management.modelmbean.ModelMBeanInfo getMBeanInfo(java.lang.Class<?> type)
          Return the MBeanInfo for type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModelMBeanFactory

public ModelMBeanFactory()
Method Detail

createAnnotatedModelMBean

public static javax.management.modelmbean.ModelMBean createAnnotatedModelMBean(java.lang.Object object)
                                                                        throws javax.management.NotCompliantMBeanException,
                                                                               javax.management.JMException,
                                                                               javax.management.modelmbean.InvalidTargetObjectTypeException
Create ModelMBean for annotated object.

Parameters:
object - the object.
Returns:
the ModelMBean.
Throws:
javax.management.NotCompliantMBeanException - if the object does not conform to ModelMBean specification.
javax.management.JMException - if there is an error creating RequiredModelMBean.
javax.management.modelmbean.InvalidTargetObjectTypeException

clearCache

public static final void clearCache()
                             throws java.lang.SecurityException
Clear the cache of all MBeanInfos currently loaded into the system.

Note that the caller must have been granted the "panmx.model.ModelMBeanFactory.clearCache" RuntimePermission or a security exception will be thrown.

Throws:
java.lang.SecurityException - if the caller does not have permission to clear cache.

getMBeanInfo

public static final javax.management.modelmbean.ModelMBeanInfo getMBeanInfo(java.lang.Class<?> type)
                                                                     throws javax.management.NotCompliantMBeanException
Return the MBeanInfo for type.

Parameters:
type - the type.
Returns:
the MBeanInfo for specified type.
Throws:
javax.management.NotCompliantMBeanException - if malformed type.


Copyright © 2005-2006 . All Rights Reserved.