1 23 24 42 43 package com.sun.enterprise.admin.jmx.remote.internal; 44 import java.lang.reflect.Method ; 45 import javax.management.MBeanServerConnection ; 46 import javax.management.ObjectName ; 47 import javax.management.NotificationFilter ; 48 import javax.management.NotificationListener ; 49 import javax.management.remote.message.MBeanServerRequestMessage; 50 51 61 class MBeanServerConnectionMethods { 62 63 private static String [] names = new String [0]; 64 static { 65 initializeMethods(); 66 } 67 68 private MBeanServerConnectionMethods() { 69 } 71 72 private static void initializeMethods() { 73 try { 74 final Method [] methods = javax.management.MBeanServerConnection .class.getDeclaredMethods(); 75 names = new String [methods.length]; 76 for (int i = 0 ; i < methods.length ; i++) { 77 indexMethod(methods[i]); 78 } 79 } 80 catch(final Exception e) { 81 throw new RuntimeException (e); 82 } 83 } 84 85 private static void indexMethod(final Method am) { 86 final String m = am.getName(); 87 if ("getAttribute".equals(m)) 88 names[MBeanServerRequestMessage.GET_ATTRIBUTE] = am.toString(); 89 else if ("getAttributes".equals(m)) 90 names[MBeanServerRequestMessage.GET_ATTRIBUTES] = am.toString(); 91 else if ("getDefaultDomain".equals(m)) 92 names[MBeanServerRequestMessage.GET_DEFAULT_DOMAIN] = am.toString(); 93 else if ("getDomains".equals(m)) 94 names[MBeanServerRequestMessage.GET_DOMAINS] = am.toString(); 95 else if ("getMBeanCount".equals(m)) 96 names[MBeanServerRequestMessage.GET_MBEAN_COUNT] = am.toString(); 97 else if ("getMBeanInfo".equals(m)) 98 names[MBeanServerRequestMessage.GET_MBEAN_INFO] = am.toString(); 99 else if ("getObjectInstance".equals(m)) 100 names[MBeanServerRequestMessage.GET_OBJECT_INSTANCE] = am.toString(); 101 else if ("invoke".equals(m)) 102 names[MBeanServerRequestMessage.INVOKE] = am.toString(); 103 else if ("isInstanceOf".equals(m)) 104 names[MBeanServerRequestMessage.IS_INSTANCE_OF] = am.toString(); 105 else if ("isRegistered".equals(m)) 106 names[MBeanServerRequestMessage.IS_REGISTERED] = am.toString(); 107 else if ("queryMBeans".equals(m)) 108 names[MBeanServerRequestMessage.QUERY_MBEANS] = am.toString(); 109 else if ("queryNames".equals(m)) 110 names[MBeanServerRequestMessage.QUERY_NAMES] = am.toString(); 111 else if ("setAttribute".equals(m)) 112 names[MBeanServerRequestMessage.SET_ATTRIBUTE] = am.toString(); 113 else if ("setAttributes".equals(m)) 114 names[MBeanServerRequestMessage.SET_ATTRIBUTES] = am.toString(); 115 else if ("unregisterMBean".equals(m)) 116 names[MBeanServerRequestMessage.UNREGISTER_MBEAN] = am.toString(); 117 else if ("addNotificationListener".equals(m)) 118 indexAddNotificationListenerMethod(am); 119 else if ("createMBean".equals(m)) 120 indexCreateMBeanMethod(am); 121 else if ("removeNotificationListener".equals(m)) 122 indexRemoveNotificationListenerMethod(am); 123 } 124 125 private static void indexAddNotificationListenerMethod(final Method m) { 126 final Class [] params = m.getParameterTypes(); if (params[1].getName().indexOf("ObjectName") != -1) 129 names[MBeanServerRequestMessage.ADD_NOTIFICATION_LISTENER_OBJECTNAME] = m.toString(); 130 else { 131 assert (params[1].getName().indexOf("NotificationListener")) != -1; 132 names[MBeanServerRequestMessage.ADD_NOTIFICATION_LISTENERS] = m.toString(); 133 } 134 } 135 private static void indexCreateMBeanMethod(final Method m) { 136 final Class [] params = m.getParameterTypes(); final int n = params.length; 138 if (n == 2) 139 names[MBeanServerRequestMessage.CREATE_MBEAN] = m.toString(); 140 else if (n == 3) 141 names[MBeanServerRequestMessage.CREATE_MBEAN_LOADER] = m.toString(); 142 else if (n == 4) 143 names[MBeanServerRequestMessage.CREATE_MBEAN_PARAMS] = m.toString(); 144 else names[MBeanServerRequestMessage.CREATE_MBEAN_LOADER_PARAMS] = m.toString(); 146 } 147 private static void indexRemoveNotificationListenerMethod(final Method m) { 148 final Class [] params = m.getParameterTypes(); final int n = params.length; 150 if (n == 2) { 151 if (params[1].getName().indexOf("ObjectName") != -1) 152 names[MBeanServerRequestMessage.REMOVE_NOTIFICATION_LISTENER_OBJECTNAME] = m.toString(); 153 else 154 names[MBeanServerRequestMessage.REMOVE_NOTIFICATION_LISTENER] = m.toString(); 155 } 156 else { if (params[1].getName().indexOf("ObjectName") != -1) 158 names[MBeanServerRequestMessage.REMOVE_NOTIFICATION_LISTENER_OBJECTNAME_FILTER_HANDBACK] = m.toString(); 159 else 160 names[MBeanServerRequestMessage.REMOVE_NOTIFICATION_LISTENER_FILTER_HANDBACK] = m.toString(); 161 } 162 } 163 String getName(final int id) { 164 return ( names[id] ); 165 } 166 } 167 | Popular Tags |