KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > server > core > jmx > tester > MBeanIntrospectorTester


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 package com.sun.enterprise.admin.server.core.jmx.tester;
25
26 import java.io.*;
27 import javax.management.NotCompliantMBeanException JavaDoc;
28 import com.sun.enterprise.admin.util.Debug;
29 import com.sun.enterprise.admin.server.core.jmx.MBeanIntrospector;
30
31 public class MBeanIntrospectorTester
32 {
33     public static void main(String JavaDoc[] args) throws Exception JavaDoc
34     {
35         BufferedReader reader = new BufferedReader(new FileReader(args[0]));
36         String JavaDoc str;
37         long begin = System.currentTimeMillis();
38         while ((str = reader.readLine()) != null)
39         {
40             str = str.trim();
41             if (isPrimitive(str))
42             {
43                 try
44                 {
45                     checkPrimitive(str);
46                     Debug.println("Test failed : " + str);
47                 }
48                 catch (NotCompliantMBeanException JavaDoc e)
49                 {
50                 }
51             }
52             else
53             {
54                 try
55                 {
56                     checkNonPrimitive(str);
57                 }
58                 catch (NotCompliantMBeanException JavaDoc e)
59                 {
60                     Debug.println("Not Compliant : " + str);
61                 }
62             }
63         }
64         long end = System.currentTimeMillis();
65         //Debug.println("Time lapse = " + (end - begin));
66
reader.close();
67     }
68
69     private static boolean isPrimitive(String JavaDoc str)
70     {
71         return (str.equals("int") ||
72                 str.equals("boolean") ||
73                 str.equals("short") ||
74                 str.equals("byte") ||
75                 str.equals("char") ||
76                 str.equals("float") ||
77                 str.equals("long") ||
78                 str.equals("double"));
79     }
80
81     private static void checkPrimitive(String JavaDoc str)
82         throws NotCompliantMBeanException JavaDoc
83     {
84         Class JavaDoc c = null;
85         if (str.equals("int")) { c = int.class; }
86         else if (str.equals("boolean")) { c = boolean.class; }
87         else if (str.equals("short")) { c = short.class; }
88         else if (str.equals("byte")) { c = byte.class; }
89         else if (str.equals("char")) { c = char.class; }
90         else if (str.equals("float")) { c = float.class; }
91         else if (str.equals("long")) { c = long.class; }
92         else if (str.equals("double")) { c = double.class; }
93
94         new MBeanIntrospector(c);
95     }
96     
97     private static void checkNonPrimitive(String JavaDoc str)
98         throws ClassNotFoundException JavaDoc, NotCompliantMBeanException JavaDoc
99     {
100         Class JavaDoc c = Class.forName(str);
101         MBeanIntrospector intr = new MBeanIntrospector(c);
102         String JavaDoc msg = " Type = ";
103         msg += intr.isStandardMBean() ? "isStandard" :
104                         intr.isDynamicMBean() ? "isDynamic" : "Don't know";
105         Debug.println(str + msg);
106         Debug.println("Management interface = " +
107             intr.getMBeanInterfaceClass().getName());
108     }
109 }
Popular Tags