01: /**
02: * Copyright 2004-2005 jManage.org
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: */package org.jmanage.cmdui.util;
16:
17: import org.jmanage.core.data.MBeanData;
18: import org.jmanage.core.data.AttributeListData;
19: import org.jmanage.core.management.ObjectAttribute;
20:
21: import java.util.*;
22:
23: /**
24: *
25: * Date: Feb 23, 2005
26: * @author Rakesh Kalra
27: */
28: public class CommandUtils {
29:
30: public static void printMBeans(List mbeanList) {
31: /* first sort the list */
32: Collections.sort(mbeanList, new Comparator() {
33: public int compare(Object o1, Object o2) {
34: MBeanData mbeanData1 = (MBeanData) o1;
35: MBeanData mbeanData2 = (MBeanData) o2;
36: return mbeanData1.getName().compareTo(
37: 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(
56: AttributeListData[] attributeValues) {
57: if (attributeValues.length == 0) {
58: return;
59: }
60: Table table = new Table(attributeValues.length + 1);
61: /* add header, if more than one attributeValues are present */
62: if (attributeValues.length > 1) {
63: Object[] header = new Object[attributeValues.length + 1];
64: header[0] = "Attributes";
65: for (int i = 0; i < attributeValues.length; i++) {
66: header[i + 1] = attributeValues[i].getAppName();
67: }
68: table.setHeader(header);
69: }
70:
71: List attrList = attributeValues[0].getAttributeList();
72: int numberOfAttrs = attrList.size();
73: for (int i = 0; i < numberOfAttrs; i++) {
74: Object[] cols = new Object[attributeValues.length + 1];
75: cols[0] = ((ObjectAttribute) attrList.get(i)).getName();
76: for (int j = 0; j < attributeValues.length; j++) {
77: if (!attributeValues[j].isError()) {
78: ObjectAttribute objAttribute = (ObjectAttribute) attributeValues[j]
79: .getAttributeList().get(i);
80: cols[j + 1] = objAttribute.getDisplayValue();
81: } else {
82: // todo: this should come out of display value - rk
83: cols[j + 1] = "<unavailable>";
84: }
85: }
86: table.add(cols);
87: }
88: table.print();
89: }
90: }
|