KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jmx > IntrospectionMBean


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.jmx;
31
32 import javax.management.*;
33 import javax.management.openmbean.ArrayType JavaDoc;
34 import javax.management.openmbean.OpenType JavaDoc;
35 import javax.management.openmbean.SimpleType JavaDoc;
36 import java.lang.annotation.Annotation JavaDoc;
37 import java.lang.ref.SoftReference JavaDoc;
38 import java.lang.reflect.InvocationTargetException JavaDoc;
39 import java.lang.reflect.Method JavaDoc;
40 import java.lang.reflect.Modifier JavaDoc;
41 import java.util.ArrayList JavaDoc;
42 import java.util.Arrays JavaDoc;
43 import java.util.Collections JavaDoc;
44 import java.util.Comparator JavaDoc;
45 import java.util.HashMap JavaDoc;
46 import java.util.WeakHashMap JavaDoc;
47 import java.util.logging.Level JavaDoc;
48 import java.util.logging.Logger JavaDoc;
49
50 /**
51  * Resin implementation of StandardMBean.
52  */

53 public class IntrospectionMBean implements DynamicMBean {
54   private static final Logger JavaDoc log
55     = Logger.getLogger(IntrospectionMBean.class.getName());
56
57   private static final Class JavaDoc[] NULL_ARG = new Class JavaDoc[0];
58
59   private static final Class JavaDoc _descriptionAnn;
60   private static final Class JavaDoc _nameAnn;
61
62   private static final WeakHashMap JavaDoc<Class JavaDoc,SoftReference JavaDoc<MBeanInfo>> _cachedInfo
63     = new WeakHashMap JavaDoc<Class JavaDoc,SoftReference JavaDoc<MBeanInfo>>();
64
65   private final Object JavaDoc _impl;
66   private final Class JavaDoc _mbeanInterface;
67   private final boolean _isLowercaseAttributeNames;
68
69   private final MBeanInfo _mbeanInfo;
70
71   private final HashMap JavaDoc<String JavaDoc,OpenModelMethod> _attrGetMap
72     = new HashMap JavaDoc<String JavaDoc,OpenModelMethod>();
73
74   /**
75    * Makes a DynamicMBean.
76    */

77   public IntrospectionMBean(Object JavaDoc impl, Class JavaDoc mbeanInterface)
78     throws NotCompliantMBeanException
79   {
80     this(impl, mbeanInterface, false);
81   }
82
83   /**
84    * Makes a DynamicMBean.
85    *
86    * @param isLowercaseAttributeNames true if attributes should have first
87    * letter lowercased
88    */

89   public IntrospectionMBean(Object JavaDoc impl,
90                             Class JavaDoc mbeanInterface,
91                             boolean isLowercaseAttributeNames)
92     throws NotCompliantMBeanException
93   {
94     if (impl == null)
95       throw new NullPointerException JavaDoc();
96
97     _mbeanInterface = mbeanInterface;
98     _isLowercaseAttributeNames = isLowercaseAttributeNames;
99
100     _mbeanInfo = introspect(impl, mbeanInterface, isLowercaseAttributeNames);
101     _impl = impl;
102
103   }
104
105   /**
106    * Returns the implementation.
107    */

108   public Object JavaDoc getImplementation()
109   {
110     return _impl;
111   }
112
113   /**
114    * Returns an attribute value.
115    */

116   public Object JavaDoc getAttribute(String JavaDoc attribute)
117     throws AttributeNotFoundException, MBeanException, ReflectionException
118   {
119     try {
120       OpenModelMethod method = getGetMethod(attribute);
121
122       if (method != null)
123         return method.invoke(_impl, (Object JavaDoc []) null);
124       else
125         throw new AttributeNotFoundException(attribute);
126     } catch (IllegalAccessException JavaDoc e) {
127       throw new MBeanException(e);
128     } catch (InvocationTargetException JavaDoc e) {
129       if (e.getCause() instanceof Exception JavaDoc)
130         throw new ReflectionException((Exception JavaDoc) e.getCause());
131       else
132         throw (Error JavaDoc) e.getCause();
133     } catch (Throwable JavaDoc e) {
134       throw new RuntimeException JavaDoc(e);
135     }
136   }
137
138   /**
139    * Sets an attribute value.
140    */

141   public void setAttribute(Attribute attribute)
142     throws AttributeNotFoundException, InvalidAttributeValueException,
143            MBeanException, ReflectionException
144   {
145     try {
146       Method JavaDoc method = getSetMethod(attribute.getName(), attribute.getValue());
147
148       if (method != null)
149         method.invoke(_impl, new Object JavaDoc[] { attribute.getValue() });
150       else
151         throw new AttributeNotFoundException(attribute.getName());
152     } catch (IllegalAccessException JavaDoc e) {
153       throw new MBeanException(e);
154     } catch (InvocationTargetException JavaDoc e) {
155       throw new MBeanException(e);
156     } catch (Throwable JavaDoc e) {
157       throw new RuntimeException JavaDoc(e.toString());
158     }
159   }
160
161   /**
162    * Returns matching attribute values.
163    */

164   public AttributeList getAttributes(String JavaDoc []attributes)
165   {
166     AttributeList list = new AttributeList();
167
168     for (int i = 0; i < attributes.length; i++) {
169       try {
170         OpenModelMethod method = getGetMethod(attributes[i]);
171
172         if (method != null) {
173           Object JavaDoc value = method.invoke(_impl, (Object JavaDoc []) null);
174
175           list.add(new Attribute(attributes[i], value));
176         }
177       } catch (Throwable JavaDoc e) {
178         log.log(Level.WARNING, e.toString(), e);
179       }
180     }
181
182     return list;
183   }
184
185   /**
186    * Sets attribute values.
187    */

188   public AttributeList setAttributes(AttributeList attributes)
189   {
190     AttributeList list = new AttributeList();
191
192     for (int i = 0; i < attributes.size(); i++) {
193       try {
194         Attribute attr = (Attribute) attributes.get(i);
195         Method JavaDoc method = getSetMethod(attr.getName(), attr.getValue());
196
197         if (method != null) {
198           method.invoke(_impl, new Object JavaDoc[] { attr.getValue() });
199           list.add(new Attribute(attr.getName(), attr.getValue()));
200         }
201       } catch (Throwable JavaDoc e) {
202         log.log(Level.WARNING, e.toString(), e);
203       }
204     }
205
206     return list;
207   }
208
209   /**
210    * Returns the set method matching the name.
211    */

212   private OpenModelMethod getGetMethod(String JavaDoc name)
213   {
214     OpenModelMethod method = _attrGetMap.get(name);
215
216     if (method != null)
217       return method;
218
219     method = createGetMethod(name);
220
221     if (method != null)
222       _attrGetMap.put(name, method);
223
224     return method;
225   }
226
227   /**
228    * Returns the get or is method matching the name.
229    */

230   private OpenModelMethod createGetMethod(String JavaDoc name)
231   {
232     String JavaDoc methodName;
233
234     if (_isLowercaseAttributeNames) {
235       StringBuilder JavaDoc builder = new StringBuilder JavaDoc(name);
236       builder.setCharAt(0, Character.toUpperCase(builder.charAt(0)));
237       methodName = builder.toString();
238     }
239     else
240       methodName = name;
241
242     String JavaDoc getName = "get" + methodName;
243     String JavaDoc isName = "is" + methodName;
244
245     Method JavaDoc []methods = _mbeanInterface.getMethods();
246
247     for (int i = 0; i < methods.length; i++) {
248       if (! methods[i].getName().equals(getName) &&
249           ! methods[i].getName().equals(isName))
250         continue;
251
252       Class JavaDoc []args = methods[i].getParameterTypes();
253
254       if (args.length == 0 &&
255       ! methods[i].getReturnType().equals(void.class)) {
256     Class JavaDoc retType = methods[i].getReturnType();
257     
258         return new OpenModelMethod(methods[i], createUnmarshall(retType));
259       }
260     }
261
262     return null;
263   }
264
265   /**
266 v * Returns the open mbean unmarshaller for the given return type.
267    */

268   private Unmarshall createUnmarshall(Class JavaDoc cl)
269   {
270     Unmarshall mbean = getMBeanObjectName(cl);
271
272     if (mbean != null)
273       return mbean;
274
275     if (cl.isArray()) {
276       Class JavaDoc componentType = cl.getComponentType();
277       
278       mbean = getMBeanObjectName(componentType);
279
280       if (mbean != null)
281     return new UnmarshallArray(ObjectName.class, mbean);
282     }
283
284     return Unmarshall.IDENTITY;
285   }
286
287   private Unmarshall getMBeanObjectName(Class JavaDoc cl)
288   {
289     try {
290       Method JavaDoc method = cl.getMethod("getObjectName");
291
292       if (method != null
293       && ObjectName.class.equals(method.getReturnType()))
294     return new UnmarshallMBean(method);
295     } catch (NoSuchMethodException JavaDoc e) {
296     } catch (Exception JavaDoc e) {
297       log.log(Level.FINER, e.toString(), e);
298     }
299
300     return null;
301   }
302
303   /**
304    * Returns the set method matching the name.
305    */

306   private Method JavaDoc getSetMethod(String JavaDoc name, Object JavaDoc value)
307   {
308     String JavaDoc methodName;
309
310     if (_isLowercaseAttributeNames) {
311       StringBuilder JavaDoc builder = new StringBuilder JavaDoc(name);
312       builder.setCharAt(0, Character.toUpperCase(builder.charAt(0)));
313       methodName = builder.toString();
314     }
315     else
316       methodName = name;
317
318     String JavaDoc setName = "set" + methodName;
319
320     Method JavaDoc []methods = _mbeanInterface.getMethods();
321
322     for (int i = 0; i < methods.length; i++) {
323       if (! methods[i].getName().equals(setName))
324         continue;
325
326       Class JavaDoc []args = methods[i].getParameterTypes();
327
328       if (args.length != 1)
329         continue;
330
331       /*
332       if (value != null && ! args[0].isAssignableFrom(value.getClass()))
333     continue;
334       */

335
336       return methods[i];
337     }
338
339     return null;
340   }
341
342   /**
343    * Invokes a method on the bean.
344    */

345   public Object JavaDoc invoke(String JavaDoc actionName,
346                        Object JavaDoc []params,
347                        String JavaDoc []signature)
348     throws MBeanException, ReflectionException
349   {
350     try {
351       Method JavaDoc []methods = _mbeanInterface.getMethods();
352
353       int length = 0;
354       if (signature != null)
355         length = signature.length;
356       if (params != null)
357         length = params.length;
358
359       for (int i = 0; i < methods.length; i++) {
360         if (! methods[i].getName().equals(actionName))
361           continue;
362
363         Class JavaDoc []args = methods[i].getParameterTypes();
364
365         if (args.length != length)
366           continue;
367
368         boolean isMatch = true;
369         for (int j = length - 1; j >= 0; j--) {
370           if (! args[j].getName().equals(signature[j]))
371             isMatch = false;
372         }
373
374         if (isMatch)
375           return methods[i].invoke(_impl, params);
376       }
377
378       if (actionName.equals("hashCode") && signature.length == 0)
379         return _impl.hashCode();
380       else if (actionName.equals("toString") && signature.length == 0)
381         return _impl.toString();
382       else
383         return null;
384     } catch (IllegalAccessException JavaDoc e) {
385       throw new MBeanException(e);
386     } catch (InvocationTargetException JavaDoc e) {
387       if (e.getCause() instanceof Exception JavaDoc)
388         throw new ReflectionException((Exception JavaDoc) e.getCause());
389       else
390         throw (Error JavaDoc) e.getCause();
391     }
392   }
393
394   /**
395    * Returns the introspection information for the MBean.
396    */

397   public MBeanInfo getMBeanInfo()
398   {
399     return _mbeanInfo;
400   }
401
402   static MBeanInfo introspect(Object JavaDoc obj, Class JavaDoc cl, boolean isLowercaseAttributeNames)
403     throws NotCompliantMBeanException
404   {
405     try {
406       SoftReference JavaDoc<MBeanInfo> infoRef = _cachedInfo.get(cl);
407       MBeanInfo info = null;
408
409       if (infoRef != null && (info = infoRef.get()) != null)
410         return info;
411
412       String JavaDoc className = cl.getName();
413
414       HashMap JavaDoc<String JavaDoc,MBeanAttributeInfo> attributes
415         = new HashMap JavaDoc<String JavaDoc,MBeanAttributeInfo>();
416
417       ArrayList JavaDoc<MBeanConstructorInfo> constructors
418         = new ArrayList JavaDoc<MBeanConstructorInfo>();
419
420       ArrayList JavaDoc<MBeanOperationInfo> operations
421         = new ArrayList JavaDoc<MBeanOperationInfo>();
422
423       Method JavaDoc []methods = cl.getMethods();
424       for (int i = 0; i < methods.length; i++) {
425         Method JavaDoc method = methods[i];
426
427         if (method.getDeclaringClass() == Object JavaDoc.class)
428           continue;
429
430         if (Modifier.isStatic(method.getModifiers()))
431           continue;
432
433         String JavaDoc methodName = method.getName();
434         Class JavaDoc []args = method.getParameterTypes();
435         Class JavaDoc retType = method.getReturnType();
436
437         if (methodName.startsWith("get") && args.length == 0 &&
438             ! retType.equals(void.class)) {
439       Method JavaDoc getter = method;
440           String JavaDoc name = methodName.substring(3);
441
442           Method JavaDoc setter = getSetter(methods, name, retType);
443
444           String JavaDoc attributeName;
445
446           if (isLowercaseAttributeNames) {
447             StringBuilder JavaDoc builder = new StringBuilder JavaDoc(name);
448             builder.setCharAt(0, Character.toLowerCase(builder.charAt(0)));
449             attributeName = builder.toString();
450           }
451           else
452             attributeName = name;
453
454       Class JavaDoc type = method.getReturnType();
455
456       MBeanAttributeInfo attr;
457
458           attr = new MBeanAttributeInfo(attributeName,
459                     getDescription(method),
460                     getter,
461                     setter);
462
463       /*
464       Descriptor descriptor = attr.getDescriptor();
465
466       if (descriptor != null) {
467         Object openType = getOpenType(type);
468
469         if (openType != null)
470           descriptor.setField("openType", openType);
471       
472         descriptor.setField("originalType", getTypeName(type));
473
474         attr.setDescriptor(descriptor);
475       }
476       */

477
478       if (attributes.get(attributeName) == null)
479         attributes.put(attributeName, attr);
480         }
481         else if (methodName.startsWith("is") && args.length == 0 &&
482                  (retType.equals(boolean.class) ||
483                   retType.equals(Boolean JavaDoc.class))) {
484       Method JavaDoc getter = method;
485           String JavaDoc name = methodName.substring(2);
486
487           Method JavaDoc setter = getSetter(methods, name, retType);
488
489           String JavaDoc attributeName;
490
491           if (isLowercaseAttributeNames) {
492             StringBuilder JavaDoc builder = new StringBuilder JavaDoc(name);
493             builder.setCharAt(0, Character.toLowerCase(builder.charAt(0)));
494             attributeName = builder.toString();
495           }
496           else
497             attributeName = name;
498
499       if (attributes.get(attributeName) == null) {
500         attributes.put(attributeName,
501                new MBeanAttributeInfo(attributeName,
502                           getDescription(method),
503                           getter,
504                           setter));
505       }
506         }
507         else if (methodName.startsWith("set") && args.length == 1) {
508       Method JavaDoc setter = method;
509           String JavaDoc name = methodName.substring(3);
510
511           Method JavaDoc getter = getGetter(methods, name, args[0]);
512
513           if (getter == null) {
514             String JavaDoc attributeName;
515
516             if (isLowercaseAttributeNames) {
517               StringBuilder JavaDoc builder = new StringBuilder JavaDoc(name);
518               builder.setCharAt(0, Character.toLowerCase(builder.charAt(0)));
519               attributeName = builder.toString();
520             }
521             else
522               attributeName = name;
523
524         if (attributes.get(attributeName) == null) {
525           attributes.put(attributeName,
526                  new MBeanAttributeInfo(attributeName,
527                             getDescription(method),
528                             null,
529                             setter));
530         }
531       }
532     }
533         else {
534           operations.add(new MBeanOperationInfo(getName(method),
535                         getDescription(method),
536                         getSignature(method),
537                         method.getReturnType().getName(),
538                         MBeanOperationInfo.UNKNOWN));
539         }
540       }
541
542       ArrayList JavaDoc<MBeanNotificationInfo> notifications
543         = new ArrayList JavaDoc<MBeanNotificationInfo>();
544
545       if (obj instanceof NotificationBroadcaster) {
546         NotificationBroadcaster broadcaster;
547         broadcaster = (NotificationBroadcaster) obj;
548
549         MBeanNotificationInfo[] notifs = broadcaster.getNotificationInfo();
550
551         if (notifs != null) {
552           for (int i = 0; i < notifs.length; i++) {
553         MBeanNotificationInfo notif = notifs[i];
554
555         notifications.add((MBeanNotificationInfo) notifs[i].clone());
556       }
557         }
558       }
559
560       Collections.sort(notifications, MBEAN_FEATURE_INFO_COMPARATOR);
561
562       MBeanAttributeInfo []attrArray = new MBeanAttributeInfo[attributes.size()];
563       attributes.values().toArray(attrArray);
564       Arrays.sort(attrArray, MBEAN_FEATURE_INFO_COMPARATOR);
565       
566       MBeanConstructorInfo []conArray = new MBeanConstructorInfo[constructors.size()];
567       constructors.toArray(conArray);
568
569       MBeanOperationInfo []opArray = new MBeanOperationInfo[operations.size()];
570       operations.toArray(opArray);
571       Arrays.sort(opArray, MBEAN_FEATURE_INFO_COMPARATOR);
572       MBeanNotificationInfo []notifArray = new MBeanNotificationInfo[notifications.size()];
573       notifications.toArray(notifArray);
574       Arrays.sort(notifArray, MBEAN_FEATURE_INFO_COMPARATOR);
575
576       MBeanInfo modelInfo;
577
578       modelInfo = new MBeanInfo(cl.getName(),
579                      getDescription(cl),
580                      attrArray,
581                      conArray,
582                      opArray,
583                      notifArray);
584       /*
585       Descriptor descriptor = modelInfo.getMBeanDescriptor();
586       if (descriptor != null) {
587     descriptor.setField("mxbean", "true");
588     modelInfo.setMBeanDescriptor(descriptor);
589       }
590       */

591
592       info = modelInfo;
593
594       _cachedInfo.put(cl, new SoftReference JavaDoc<MBeanInfo>(info));
595
596       return info;
597     } catch (Exception JavaDoc e) {
598       NotCompliantMBeanException exn;
599       exn = new NotCompliantMBeanException(String.valueOf(e));
600
601       exn.initCause(e);
602
603       throw exn;
604     }
605   }
606
607   /**
608    * Returns the matching setter.
609    */

610   static Method JavaDoc getSetter(Method JavaDoc []methods, String JavaDoc property, Class JavaDoc type)
611   {
612     String JavaDoc name = "set" + property;
613
614     for (int i = 0; i < methods.length; i++) {
615       if (! methods[i].getName().equals(name))
616         continue;
617
618       Class JavaDoc []args = methods[i].getParameterTypes();
619
620       if (args.length != 1 || ! args[0].equals(type))
621         continue;
622
623       return methods[i];
624     }
625
626     return null;
627   }
628
629   /**
630    * Returns the matching getter.
631    */

632   static Method JavaDoc getGetter(Method JavaDoc []methods, String JavaDoc property, Class JavaDoc type)
633   {
634     String JavaDoc getName = "get" + property;
635     String JavaDoc isName = "is" + property;
636
637     for (int i = 0; i < methods.length; i++) {
638       if (! methods[i].getName().equals(getName) &&
639           ! methods[i].getName().equals(isName))
640         continue;
641
642       Class JavaDoc []args = methods[i].getParameterTypes();
643
644       if (args.length != 0)
645         continue;
646
647       Class JavaDoc retType = methods[i].getReturnType();
648
649       if (! retType.equals(type))
650         continue;
651
652       return methods[i];
653     }
654
655     return null;
656   }
657
658   /**
659    * Returns the class's description.
660    */

661   static String JavaDoc getDescription(Class JavaDoc cl)
662   {
663     try {
664       Description desc = (Description) cl.getAnnotation(_descriptionAnn);
665
666       if (desc != null)
667         return desc.value();
668       else
669         return "";
670     } catch (Throwable JavaDoc e) {
671       return "";
672     }
673   }
674
675   /**
676    * Returns the method's description.
677    */

678   static String JavaDoc getDescription(Method JavaDoc method)
679   {
680     try {
681       Description desc = (Description) method.getAnnotation(_descriptionAnn);
682
683       if (desc != null)
684         return desc.value();
685       else
686         return "";
687     } catch (Throwable JavaDoc e) {
688       return "";
689     }
690   }
691
692   /**
693    * Returns the method's name, the optional {@link Name} annotation overrides.
694    */

695   static String JavaDoc getName(Method JavaDoc method)
696   {
697     try {
698       Name name = (Name) method.getAnnotation(_nameAnn);
699
700       if (name != null)
701         return name.value();
702       else
703         return method.getName();
704     } catch (Throwable JavaDoc e) {
705       return method.getName();
706     }
707   }
708
709   private static MBeanParameterInfo[] getSignature(Method JavaDoc method)
710   {
711     Class JavaDoc[] params = method.getParameterTypes();
712     MBeanParameterInfo[] paramInfos = new MBeanParameterInfo[params.length];
713
714     for (int i = 0; i < params.length; i++) {
715       Class JavaDoc cl = params[i];
716
717       String JavaDoc name = getName(method, i);
718       String JavaDoc description = getDescription(method, i);
719
720       paramInfos[i] = new MBeanParameterInfo(name, cl.getName(), description);
721     }
722
723     return paramInfos;
724   }
725
726   private static String JavaDoc getName(Method JavaDoc method, int i)
727   {
728     try {
729       for (Annotation JavaDoc ann : method.getParameterAnnotations()[i]) {
730         if (ann instanceof Name)
731           return ((Name) ann).value();
732       }
733     } catch (Throwable JavaDoc e) {
734       log.log(Level.FINER, e.toString(), e);
735     }
736     
737     return "p" + i;
738   }
739
740   private static String JavaDoc getDescription(Method JavaDoc method, int i)
741   {
742     try {
743       for (Annotation JavaDoc ann : method.getParameterAnnotations()[i]) {
744     if (ann instanceof Description)
745           return ((Description) ann).value();
746       }
747     } catch (Throwable JavaDoc e) {
748       log.log(Level.FINER, e.toString(), e);
749     }
750     
751     return "";
752   }
753
754   private static String JavaDoc getTypeName(Class JavaDoc type)
755   {
756     if (type.isArray())
757       return getTypeName(type.getComponentType()) + "[]";
758     else
759       return type.getName();
760   }
761
762   private static OpenType JavaDoc getOpenType(Class JavaDoc type)
763   {
764     try {
765       if (type.isArray()) {
766     OpenType JavaDoc component = getOpenType(type.getComponentType());
767
768     if (component != null)
769       return new ArrayType JavaDoc(1, component);
770     else
771       return null;
772       }
773       else if (type.getName().endsWith("MXBean")
774            || type.getName().endsWith("MBean"))
775     return SimpleType.OBJECTNAME;
776       else if (void.class.equals(type))
777     return SimpleType.VOID;
778       else if (boolean.class.equals(type) || Boolean JavaDoc.class.equals(type))
779     return SimpleType.BOOLEAN;
780       else if (byte.class.equals(type) || Byte JavaDoc.class.equals(type))
781     return SimpleType.BYTE;
782       else if (short.class.equals(type) || Short JavaDoc.class.equals(type))
783     return SimpleType.SHORT;
784       else if (int.class.equals(type) || Integer JavaDoc.class.equals(type))
785     return SimpleType.INTEGER;
786       else if (long.class.equals(type) || Long JavaDoc.class.equals(type))
787     return SimpleType.LONG;
788       else if (float.class.equals(type) || Float JavaDoc.class.equals(type))
789     return SimpleType.FLOAT;
790       else if (double.class.equals(type) || Double JavaDoc.class.equals(type))
791     return SimpleType.DOUBLE;
792       else if (String JavaDoc.class.equals(type))
793     return SimpleType.STRING;
794       else if (char.class.equals(type) || Character JavaDoc.class.equals(type))
795     return SimpleType.CHARACTER;
796       else if (java.util.Date JavaDoc.class.equals(type))
797     return SimpleType.DATE;
798       else if (java.util.Calendar JavaDoc.class.equals(type))
799     return SimpleType.DATE;
800       else
801     return null; // can't deal with more complex at the moment
802
} catch (Exception JavaDoc e) {
803       log.log(Level.FINER, e.toString(), e);
804
805       return null;
806     }
807   }
808
809   private static Class JavaDoc findClass(String JavaDoc name)
810   {
811     try {
812       return Class.forName(name);
813     } catch (Throwable JavaDoc e) {
814       return null;
815     }
816   }
817
818   private static final Comparator JavaDoc<MBeanFeatureInfo> MBEAN_FEATURE_INFO_COMPARATOR
819     = new Comparator JavaDoc<MBeanFeatureInfo>() {
820
821     public int compare(MBeanFeatureInfo o1, MBeanFeatureInfo o2)
822     {
823       return o1.getName().compareTo(o2.getName());
824     }
825   };
826
827   static {
828     _descriptionAnn = findClass("com.caucho.jmx.Description");
829     _nameAnn = findClass("com.caucho.jmx.Name");
830   }
831 }
832
Popular Tags