1 16 package org.jmanage.cmdui.util; 17 18 import org.jmanage.core.data.MBeanData; 19 import org.jmanage.core.data.AttributeListData; 20 import org.jmanage.core.management.ObjectAttribute; 21 22 import java.util.*; 23 24 29 public class CommandUtils { 30 31 public static void printMBeans(List mbeanList){ 32 33 Collections.sort(mbeanList, new Comparator(){ 34 public int compare(Object o1, Object o2) { 35 MBeanData mbeanData1 = (MBeanData)o1; 36 MBeanData mbeanData2 = (MBeanData)o2; 37 return mbeanData1.getName().compareTo(mbeanData2.getName()); 38 } 39 }); 40 41 if(mbeanList.size() > 0) 42 Out.println(); 43 44 for(Iterator it=mbeanList.iterator(); it.hasNext(); ){ 45 MBeanData mbeanData = (MBeanData)it.next(); 46 Out.print(mbeanData.getName()); 47 if(mbeanData.getConfiguredName() != null){ 48 Out.println(" [" + mbeanData.getConfiguredName() + "]"); 49 }else{ 50 Out.println(); 51 } 52 } 53 } 54 55 public static void printAttributeLists(AttributeListData[] attributeValues){ 56 if(attributeValues.length == 0){ 57 return; 58 } 59 Table table = new Table(attributeValues.length + 1); 60 61 if(attributeValues.length > 1){ 62 Object [] header = new Object [attributeValues.length + 1]; 63 header[0] = "Attributes"; 64 for(int i=0; i<attributeValues.length; i++){ 65 header[i+1] = attributeValues[i].getAppName(); 66 } 67 table.setHeader(header); 68 } 69 70 List attrList = attributeValues[0].getAttributeList(); 71 int numberOfAttrs = attrList.size(); 72 for(int i=0; i<numberOfAttrs; i++){ 73 Object [] cols = new Object [attributeValues.length + 1]; 74 cols[0] = ((ObjectAttribute)attrList.get(i)).getName(); 75 for(int j=0; j<attributeValues.length; j++){ 76 if(!attributeValues[j].isError()){ 77 ObjectAttribute objAttribute = 78 (ObjectAttribute)attributeValues[j].getAttributeList().get(i); 79 cols[j+1] = objAttribute.getDisplayValue(); 80 }else{ 81 cols[j+1] = "<unavailable>"; 83 } 84 } 85 table.add(cols); 86 } 87 table.print(); 88 } 89 } 90 | Popular Tags |