FileDocCategorySizeDatePackage
MBeanIntrospector.javaAPI DocGlassfish v2 API8661Fri May 04 22:33:48 BST 2007com.sun.enterprise.admin.server.core.jmx

MBeanIntrospector

public class MBeanIntrospector extends Introspector
Class which has convinience routines to introspect an MBean. The parameter passed in constructor should be an MBean, otherwise it throws an exception. Provides routines to check whether the MBean is JMX compliant.

Fields Summary
private boolean
mIsStandard
private boolean
mIsDynamic
private Class
mMBeanInterfaceClass
Constructors Summary
public MBeanIntrospector(Class c)
Creates new MBeanIntrospector

        super(c);
        checkBasic(c);
        checkMBeanType(c);
        checkCompliance();
    
Methods Summary
private voidcheckBasic(java.lang.Class c)

        if (!isInstantiableJavaClass(c))
        {
            throw new NotCompliantMBeanException();
        }
    
private voidcheckCompliance()

        if (!(mIsStandard || mIsDynamic) || // (A U B)' = A' ^ B'
            (mIsStandard && mIsDynamic))
        {
            throw new NotCompliantMBeanException();
        }
    
private voidcheckMBeanType(java.lang.Class c)

        /*
         * StandardMBean Checks :-
         * 1. It is neither primitive type, nor an interface nor an 
         * abstract class.
         * 2. Implements <className>MBean interface. If not, 
         * 3. A nearest superclass (can omit java.lang.Object) is a 
         * standard mbean.
         *
         * DynamicMBean Checks :-
         * 1. It is neither primitive type, nor an interface nor an 
         * abstract class.
         * 2. It implements DynamicMBean interface. If not,
         * 3. Any of its superclasses implements DynamicMBean interface.
         */

        boolean isStandard  = isStandard(c);
        boolean isDynamic   = isDynamic(c);
        if (!(isStandard || isDynamic)) // (A U B)' = A' ^ B'
        {
            Class superClass = c.getSuperclass();
            //Can omit java.lang.Object.
            if ((superClass != null) && 
                (superClass != java.lang.Object.class))
            {
                checkMBeanType(superClass);
            }
        }
        /**
         * Need to check both conditions even though it is either or.
         * A class that is both standard &  dynamic is not compliant
         * and will be raised in checkCompliance()
         */
        if (isStandard)
        {
            mIsStandard = true;
            setStandardMBeanInterface(c);
        }
        if (isDynamic)
        {
            mIsDynamic = true;
            setDynamicMBeanInterface();
        }
    
private final java.lang.StringconvertToCamelCase(java.lang.String str)

        String camelCase = "";
        char c = str.charAt(0);
        camelCase += Character.toUpperCase(c);
        if (str.length() > 1)
        {
            camelCase += str.substring(1);
        }
        return camelCase;
    
private java.lang.StringderiveStandardMBeanIntfClassName(java.lang.Class c)
If class name is foo.bar, this method returns barMBean

        String className = truncateClassName(c);
        return (className + "MBean");
    
private java.lang.ClassgetImplementedMBeanClass(java.lang.Class c, java.lang.String intfName)

        Class implementedMBean = null;
        Class[] interfaces = c.getInterfaces();
        /* No need to check for null as c.getInterfaces() javadoc claims to
         * return an array of 0 length if the class does not implement any
         * interfaces or if the class is a primitive type.
         */
        for (int i = 0; i < interfaces.length; i++)
        {
            String className = truncateClassName(interfaces[i]);
            if (className.equals(intfName))
            {
                implementedMBean = interfaces[i];
                break;
            }
        }
        return implementedMBean;
    
public java.lang.ClassgetMBeanInterfaceClass()

        return mMBeanInterfaceClass;
    
private booleanisDynamic(java.lang.Class c)

        boolean isDynamic = false;
        Class[] interfaces = c.getInterfaces();
        /* No need to check for null as c.getInterfaces() javadoc claims to
         * return an array of 0 length if the class does not implement any
         * interfaces or if the class is a primitive type.
         */
        int length = interfaces.length;
        for (int i = 0; i < length; i++)
        {
            if (interfaces[i] == javax.management.DynamicMBean.class)
            {
                isDynamic = true;
                break;
            }
        }
        return isDynamic;
    
public booleanisDynamicMBean()

        return mIsDynamic;
    
private booleanisInstantiableJavaClass(java.lang.Class c)

        boolean isInstantiable = false;
        if (!c.isPrimitive() && !c.isArray())
        {
            int modifiers = c.getModifiers();
            boolean isInterface = Modifier.isInterface(modifiers);
            boolean isAbstract  = Modifier.isAbstract(modifiers);
            isInstantiable = !(isInterface || isAbstract);
        }
        return isInstantiable;
    
private booleanisStandard(java.lang.Class c)

        boolean isStandard = false;
        /**
         * Note that mbean impl & mbean interface can be in different
         * packages.
         */
        String  className = deriveStandardMBeanIntfClassName(c);
        if (getImplementedMBeanClass(c, className) != null)
        {
            isStandard = true;
        }
        return isStandard;
    
public booleanisStandardMBean()

        return mIsStandard;
    
public booleanisSupported(java.lang.String methodName, java.lang.Class[] signature)

        boolean isSupported = false;
        try
        {
            Method m = mMBeanInterfaceClass.getMethod(methodName, signature);
            isSupported = (m != null);
        }
        catch (Exception e)
        {
        }
        return isSupported;
    
private voidsetDynamicMBeanInterface()

        mMBeanInterfaceClass = javax.management.DynamicMBean.class;
    
private voidsetStandardMBeanInterface(java.lang.Class c)

        String className = deriveStandardMBeanIntfClassName(c);
        mMBeanInterfaceClass = getImplementedMBeanClass(c, className);
    
private java.lang.StringtruncateClassName(java.lang.Class c)
If class name is foo.bar, this method returns bar

        String className = c.getName();
        int lastDot = className.lastIndexOf('.");
        className = className.substring(lastDot + 1);
        return className;