KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > cmdui > util > CommandUtils


1 /**
2  * Copyright 2004-2005 jManage.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 /**
25  *
26  * Date: Feb 23, 2005
27  * @author Rakesh Kalra
28  */

29 public class CommandUtils {
30
31     public static void printMBeans(List mbeanList){
32         /* first sort the list */
33         Collections.sort(mbeanList, new Comparator(){
34             public int compare(Object JavaDoc o1, Object JavaDoc 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         /* add header, if more than one attributeValues are present */
61         if(attributeValues.length > 1){
62             Object JavaDoc[] header = new Object JavaDoc[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 JavaDoc[] cols = new Object JavaDoc[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                     // todo: this should come out of display value - rk
82
cols[j+1] = "<unavailable>";
83                 }
84             }
85             table.add(cols);
86         }
87         table.print();
88     }
89 }
90
Popular Tags