KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > util > j2ee > stringifier > StatsStringifier


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 package com.sun.appserv.management.util.j2ee.stringifier;
24
25 import java.util.Arrays JavaDoc;
26
27 import javax.management.j2ee.statistics.Stats JavaDoc;
28 import javax.management.j2ee.statistics.Statistic JavaDoc;
29
30 import com.sun.appserv.management.util.stringifier.Stringifier;
31 import com.sun.appserv.management.util.stringifier.SmartStringifier;
32 import com.sun.appserv.management.util.stringifier.ArrayStringifier;
33
34 /**
35     Stringifier for javax.management.j2ee.statistics
36  */

37 public class StatsStringifier implements Stringifier
38 {
39     public static final StatsStringifier DEFAULT = new StatsStringifier();
40     
41         public
42     StatsStringifier( )
43     {
44     }
45     
46         public String JavaDoc
47     stringify( Object JavaDoc o )
48     {
49         final Stats JavaDoc stats = (Stats JavaDoc)o;
50         final String JavaDoc [] names = stats.getStatisticNames();
51         
52         Arrays.sort( names );
53         
54         final StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
55         
56         buf.append( "Stats: " + ArrayStringifier.stringify( names, ", " ) + "\n" );
57         
58         for( int i = 0; i < names.length; ++i )
59         {
60             final Object JavaDoc statistic = stats.getStatistic( names[ i ] );
61             
62             buf.append( SmartStringifier.toString( statistic ) );
63             buf.append( "---\n" );
64         }
65         buf.append( "\n" );
66         
67         return( buf.toString() );
68     }
69 }
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
Popular Tags