KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > jmx > remote > internal > MBeanServerConnectionMethods


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * MBeanServerConnectionMethods.java
26  * $Id: MBeanServerConnectionMethods.java,v 1.3 2005/12/25 04:26:34 tcfujii Exp $
27  * $Revision: 1.3 $
28  * $Date: 2005/12/25 04:26:34 $
29  * Indentation Information:
30  * 0. Please (try to) preserve these settings.
31  * 1. Tabs are preferred over spaces.
32  * 2. In vi/vim -
33  * :set tabstop=4 :set shiftwidth=4 :set softtabstop=4
34  * 3. In S1 Studio -
35  * 1. Tools->Options->Editor Settings->Java Editor->Tab Size = 4
36  * 2. Tools->Options->Indentation Engines->Java Indentation Engine->Expand Tabs to Spaces = False.
37  * 3. Tools->Options->Indentation Engines->Java Indentation Engine->Number of Spaces per Tab = 4.
38  * Unit Testing Information:
39  * 0. Is Standard Unit Test Written (y/n):
40  * 1. Unit Test Location: (The instructions should be in the Unit Test Class itself).
41  */

42
43 package com.sun.enterprise.admin.jmx.remote.internal;
44 import java.lang.reflect.Method JavaDoc;
45 import javax.management.MBeanServerConnection JavaDoc;
46 import javax.management.ObjectName JavaDoc;
47 import javax.management.NotificationFilter JavaDoc;
48 import javax.management.NotificationListener JavaDoc;
49 import javax.management.remote.message.MBeanServerRequestMessage;
50
51 /** A class that links the class {@link MBeanServerRequestMessage} and interface {@link MBeanServerConnection}.
52  * The former of the two contains integers that has ids of the methods in the latter.
53  * Instead of designing an enum kind of construct I chose to take the reflection-oriented
54  * path because I did not want to worry about the internationalization etc. The cost
55  * is one-time and is bourne at the time of loading this class. The class is loaded
56  * as late as possible. Note that this class depends on the constant value fields from
57  * {@link MBeanServerRequestMessage}
58  * @author mailto:Kedar.Mhaswade@Sun.Com
59  * @since Sun Java System Application Server 8
60  */

61 class MBeanServerConnectionMethods {
62
63     private static String JavaDoc[] names = new String JavaDoc[0];
64     static {
65         initializeMethods();
66     }
67     
68     private MBeanServerConnectionMethods() {
69         //disallow
70
}
71     
72     private static void initializeMethods() {
73         try {
74             final Method JavaDoc[] methods = javax.management.MBeanServerConnection JavaDoc.class.getDeclaredMethods();
75             names = new String JavaDoc[methods.length];
76             for (int i = 0 ; i < methods.length ; i++) {
77                 indexMethod(methods[i]);
78             }
79         }
80         catch(final Exception JavaDoc e) {
81             throw new RuntimeException JavaDoc (e);
82         }
83     }
84     
85     private static void indexMethod(final Method JavaDoc am) {
86         final String JavaDoc 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 JavaDoc m) {
126         final Class JavaDoc[] params = m.getParameterTypes(); //this is ordered list, has to have 4 elements.
127
//indexing on the second parameter - it can either be ObjectName or NotificationListener
128
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 JavaDoc m) {
136         final Class JavaDoc[] params = m.getParameterTypes(); //this is ordered list, has to have 2, 3, 4 or 5 elements.
137
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 //has to be 5
145
names[MBeanServerRequestMessage.CREATE_MBEAN_LOADER_PARAMS] = m.toString();
146     }
147     private static void indexRemoveNotificationListenerMethod(final Method JavaDoc m) {
148         final Class JavaDoc[] params = m.getParameterTypes(); //this is ordered list, has to have 2, or 4 elements.
149
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 {// has to be 4
157
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 JavaDoc getName(final int id) {
164         return ( names[id] );
165     }
166 }
167
Popular Tags