KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mchange > v2 > management > ManagementUtils


1 /*
2  * Distributed as part of c3p0 v.0.9.1
3  *
4  * Copyright (C) 2005 Machinery For Change, Inc.
5  *
6  * Author: Steve Waldman <swaldman@mchange.com>
7  *
8  * This library is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License version 2.1, as
10  * published by the Free Software Foundation.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this software; see the file LICENSE. If not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */

22
23
24 package com.mchange.v2.management;
25
26 import javax.management.*;
27 import java.util.Comparator JavaDoc;
28
29 public class ManagementUtils
30 {
31     public final static Comparator JavaDoc PARAM_INFO_COMPARATOR = new Comparator JavaDoc()
32     {
33         public int compare(Object JavaDoc a, Object JavaDoc b)
34         {
35             MBeanParameterInfo aa = (MBeanParameterInfo) a;
36             MBeanParameterInfo bb = (MBeanParameterInfo) b;
37             int out = aa.getType().compareTo(bb.getType());
38             if (out == 0)
39             {
40                 out = aa.getName().compareTo(bb.getName());
41                 if (out == 0)
42                 {
43                     String JavaDoc aDesc = aa.getDescription();
44                     String JavaDoc bDesc = bb.getDescription();
45                     if (aDesc == null && bDesc == null)
46                         out = 0;
47                     else if (aDesc == null)
48                         out = -1;
49                     else if (bDesc == null)
50                         out = 1;
51                     else
52                         out = aDesc.compareTo(bDesc);
53                 }
54             }
55             return out;
56         }
57     };
58     
59     public final static Comparator JavaDoc OP_INFO_COMPARATOR = new Comparator JavaDoc()
60     {
61         public int compare(Object JavaDoc a, Object JavaDoc b)
62         {
63             MBeanOperationInfo aa = (MBeanOperationInfo) a;
64             MBeanOperationInfo bb = (MBeanOperationInfo) b;
65             String JavaDoc aName = aa.getName();
66             String JavaDoc bName = bb.getName();
67             int out = String.CASE_INSENSITIVE_ORDER.compare(aName, bName);
68             if (out == 0)
69             {
70                 if (aName.equals(bName))
71                 {
72                     MBeanParameterInfo[] aParams = aa.getSignature();
73                     MBeanParameterInfo[] bParams = bb.getSignature();
74                     if (aParams.length < bParams.length)
75                         out = -1;
76                     else if (aParams.length > bParams.length)
77                         out = 1;
78                     else
79                     {
80                         for (int i = 0, len = aParams.length; i < len; ++i)
81                         {
82                             out = PARAM_INFO_COMPARATOR.compare(aParams[i], bParams[i]);
83                             if (out != 0)
84                                 break;
85                         }
86                     }
87                 }
88                 else
89                 {
90                     out = aName.compareTo(bName);
91                 }
92             }
93             return out;
94         }
95     };
96 }
97
Popular Tags