KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > util > jmx > stringifier > TabularDataStringifier


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.jmx.stringifier;
24
25 import java.util.Set JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29 import javax.management.openmbean.TabularData JavaDoc;
30 import javax.management.openmbean.CompositeData JavaDoc;
31 import javax.management.openmbean.TabularType JavaDoc;
32
33 import com.sun.appserv.management.util.misc.StringUtil;
34 import com.sun.appserv.management.util.stringifier.Stringifier;
35 import com.sun.appserv.management.util.stringifier.SmartStringifier;
36
37
38 public class TabularDataStringifier implements Stringifier
39 {
40     public static final TabularDataStringifier DEFAULT = new TabularDataStringifier();
41     
42         public
43     TabularDataStringifier( )
44     {
45     }
46     
47         public String JavaDoc
48     stringify( Object JavaDoc o )
49     {
50         final StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
51         buf.append( "Tabular data:\n" );
52         
53         final TabularData JavaDoc data = (TabularData JavaDoc)o;
54         final TabularType JavaDoc type = data.getTabularType();
55         
56         final List JavaDoc indexNames = type.getIndexNames();
57         final Set JavaDoc rowKeys = data.keySet();
58         final Iterator JavaDoc rowIter = rowKeys.iterator();
59         int rowIndex = 0;
60         while ( rowIter.hasNext() )
61         {
62             final Object JavaDoc[] key = (Object JavaDoc[])rowIter.next();
63             final CompositeData JavaDoc item = data.get( key );
64             
65             final String JavaDoc s = SmartStringifier.toString( item );
66             
67             // emit the row index followed by the row
68
buf.append( "[" + rowIndex + "] " );
69             buf.append( s + "\n" );
70             
71             ++rowIndex;
72         }
73         
74         return( buf.toString() );
75     }
76 }
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
Popular Tags