1 14 package org.jmanage.core.management.data; 15 16 import org.jmanage.util.display.Table; 17 18 import javax.management.openmbean.CompositeData ; 19 import javax.management.openmbean.CompositeType ; 20 import java.util.Iterator ; 21 import java.util.Set ; 22 23 29 public abstract class CompositeDataFormat implements DataFormat { 30 31 public String format(Object data){ 32 CompositeData compositeData = (CompositeData )data; 33 CompositeType type = compositeData.getCompositeType(); 34 35 Set itemNamesSet = type.keySet(); 36 String [] itemNames = new String [itemNamesSet.size() + 1]; 37 String [] itemValues = new String [itemNamesSet.size() + 1]; 38 39 itemNames[0] = "CompositeType"; 40 itemValues[0] = type.getTypeName(); 41 42 int index = 1; 43 for(Iterator it=itemNamesSet.iterator();it.hasNext();){ 44 itemNames[index] = (String )it.next(); 45 Object value = compositeData.get(itemNames[index]); 46 itemValues[index] = DataFormatUtil.format(value); 47 index ++; 48 } 49 50 51 Table table = getTable(); 52 table.setHeader(itemNames); 53 table.addRow(itemValues); 54 return table.draw(); 55 } 56 57 protected abstract Table getTable(); 58 } 59 | Popular Tags |