FileDocCategorySizeDatePackage
MBeanServerConnectionMethods.javaAPI DocGlassfish v2 API8862Fri May 04 22:36:24 BST 2007com.sun.enterprise.admin.jmx.remote.internal

MBeanServerConnectionMethods

public class MBeanServerConnectionMethods extends Object
A class that links the class {@link MBeanServerRequestMessage} and interface {@link MBeanServerConnection}. The former of the two contains integers that has ids of the methods in the latter. Instead of designing an enum kind of construct I chose to take the reflection-oriented path because I did not want to worry about the internationalization etc. The cost is one-time and is bourne at the time of loading this class. The class is loaded as late as possible. Note that this class depends on the constant value fields from {@link MBeanServerRequestMessage}
author
mailto:Kedar.Mhaswade@Sun.Com
since
Sun Java System Application Server 8

Fields Summary
private static String[]
names
Constructors Summary
private MBeanServerConnectionMethods()

     
        initializeMethods();
    
        //disallow
    
Methods Summary
java.lang.StringgetName(int id)

        return ( names[id] );
    
private static voidindexAddNotificationListenerMethod(java.lang.reflect.Method m)

        final Class[] params = m.getParameterTypes(); //this is ordered list, has to have 4 elements.
        //indexing on the second parameter - it can either be ObjectName or NotificationListener
        if (params[1].getName().indexOf("ObjectName") != -1)
            names[MBeanServerRequestMessage.ADD_NOTIFICATION_LISTENER_OBJECTNAME] = m.toString();
        else {
            assert (params[1].getName().indexOf("NotificationListener")) != -1;
            names[MBeanServerRequestMessage.ADD_NOTIFICATION_LISTENERS] = m.toString();
        }
    
private static voidindexCreateMBeanMethod(java.lang.reflect.Method m)

        final Class[] params = m.getParameterTypes(); //this is ordered list, has to have 2, 3, 4 or 5 elements.
        final int n = params.length;
        if (n == 2)
            names[MBeanServerRequestMessage.CREATE_MBEAN] = m.toString();
        else if (n == 3)
            names[MBeanServerRequestMessage.CREATE_MBEAN_LOADER] = m.toString();
        else if (n == 4)
            names[MBeanServerRequestMessage.CREATE_MBEAN_PARAMS] = m.toString();
        else //has to be 5
            names[MBeanServerRequestMessage.CREATE_MBEAN_LOADER_PARAMS] = m.toString();
    
private static voidindexMethod(java.lang.reflect.Method am)

        final String m = am.getName();
        if ("getAttribute".equals(m))
            names[MBeanServerRequestMessage.GET_ATTRIBUTE] = am.toString();
        else if ("getAttributes".equals(m))
            names[MBeanServerRequestMessage.GET_ATTRIBUTES] = am.toString();
        else if ("getDefaultDomain".equals(m))
            names[MBeanServerRequestMessage.GET_DEFAULT_DOMAIN] = am.toString();
        else if ("getDomains".equals(m))
            names[MBeanServerRequestMessage.GET_DOMAINS] = am.toString();
        else if ("getMBeanCount".equals(m))
            names[MBeanServerRequestMessage.GET_MBEAN_COUNT] = am.toString();
        else if ("getMBeanInfo".equals(m))
            names[MBeanServerRequestMessage.GET_MBEAN_INFO] = am.toString();
        else if ("getObjectInstance".equals(m))
            names[MBeanServerRequestMessage.GET_OBJECT_INSTANCE] = am.toString();
        else if ("invoke".equals(m))
            names[MBeanServerRequestMessage.INVOKE] = am.toString();
        else if ("isInstanceOf".equals(m))
            names[MBeanServerRequestMessage.IS_INSTANCE_OF] = am.toString();
        else if ("isRegistered".equals(m))
            names[MBeanServerRequestMessage.IS_REGISTERED] = am.toString();
        else if ("queryMBeans".equals(m))
            names[MBeanServerRequestMessage.QUERY_MBEANS] = am.toString();
        else if ("queryNames".equals(m))
            names[MBeanServerRequestMessage.QUERY_NAMES] = am.toString();
        else if ("setAttribute".equals(m))
            names[MBeanServerRequestMessage.SET_ATTRIBUTE] = am.toString();
        else if ("setAttributes".equals(m))
            names[MBeanServerRequestMessage.SET_ATTRIBUTES] = am.toString();
        else if ("unregisterMBean".equals(m))
            names[MBeanServerRequestMessage.UNREGISTER_MBEAN] = am.toString();
        else if ("addNotificationListener".equals(m))
            indexAddNotificationListenerMethod(am);
        else if ("createMBean".equals(m))
            indexCreateMBeanMethod(am);
        else if ("removeNotificationListener".equals(m))
            indexRemoveNotificationListenerMethod(am);
    
private static voidindexRemoveNotificationListenerMethod(java.lang.reflect.Method m)

        final Class[] params = m.getParameterTypes(); //this is ordered list, has to have 2, or 4 elements.
        final int n = params.length;
        if (n == 2) {
            if (params[1].getName().indexOf("ObjectName") != -1)
                names[MBeanServerRequestMessage.REMOVE_NOTIFICATION_LISTENER_OBJECTNAME] = m.toString();
            else
                names[MBeanServerRequestMessage.REMOVE_NOTIFICATION_LISTENER] = m.toString();
        }
        else {// has to be 4
            if (params[1].getName().indexOf("ObjectName") != -1)
                names[MBeanServerRequestMessage.REMOVE_NOTIFICATION_LISTENER_OBJECTNAME_FILTER_HANDBACK] = m.toString();
            else
                names[MBeanServerRequestMessage.REMOVE_NOTIFICATION_LISTENER_FILTER_HANDBACK] = m.toString();            
        }
    
private static voidinitializeMethods()

        try {
            final Method[] methods = javax.management.MBeanServerConnection.class.getDeclaredMethods();
            names = new String[methods.length];
            for (int i = 0 ; i < methods.length ; i++) {
                indexMethod(methods[i]);
            }    
        }
        catch(final Exception e) {
            throw new RuntimeException (e);
        }