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; 26 import java.util.List; 27 import java.util.Iterator; 28 29 import javax.management.openmbean.TabularData; 30 import javax.management.openmbean.CompositeData; 31 import javax.management.openmbean.TabularType; 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 48 stringify( Object o ) 49 { 50 final StringBuffer buf = new StringBuffer(); 51 buf.append( "Tabular data:\n" ); 52 53 final TabularData data = (TabularData)o; 54 final TabularType type = data.getTabularType(); 55 56 final List indexNames = type.getIndexNames(); 57 final Set rowKeys = data.keySet(); 58 final Iterator rowIter = rowKeys.iterator(); 59 int rowIndex = 0; 60 while ( rowIter.hasNext() ) 61 { 62 final Object[] key = (Object[])rowIter.next(); 63 final CompositeData item = data.get( key ); 64 65 final String 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