001: /**
002: * Copyright 2004 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.admin.cli.commands.search;
013:
014: import java.util.*;
015:
016: // JMX
017: import javax.management.MBeanServerConnection;
018: import javax.management.ObjectName;
019: import javax.management.InstanceNotFoundException;
020: import javax.management.MBeanException;
021: import javax.management.ReflectionException;
022: import javax.management.MalformedObjectNameException;
023: import javax.management.RuntimeOperationsException;
024:
025: // PS Admin Common
026: import com.sun.portal.admin.common.util.AdminClientUtil;
027:
028: // CLI framework
029: import com.sun.enterprise.cli.framework.*;
030:
031: // Base Class
032: import com.sun.portal.admin.cli.commands.GenericCommand;
033:
034: /**
035: * This class implements the psadmin list-search-resourcedescriptions
036: * subcommand. The list-search-resourcedescriptions subcommand calls
037: * the SearchServerMBean and shows a list of resource descriptions.
038: */
039: public class ListResourceDescriptionsCommand extends GenericCommand {
040:
041: private static final String HIT_LABEL = "psadmin.subcommand.resource.list-search-resourcedescriptions.hit.label";
042: private static final String PAGE_LABEL = "psadmin.subcommand.resource.list-search-resourcedescriptions.page.label";
043:
044: /**
045: * process return value from MBean
046: * @param object
047: */
048: protected void handleReturnValue(Object object) {
049: StringBuffer sb = new StringBuffer();
050:
051: ArrayList data = (ArrayList) object;
052:
053: Integer totalHits = (Integer) data.get(0);
054: sb.append(getLocalizedString(HIT_LABEL,
055: new Object[] { totalHits.toString() }));
056:
057: Integer currentPage = (Integer) data.get(1);
058: Integer totalPages = (Integer) data.get(2);
059: sb.append(getLocalizedString(PAGE_LABEL, new Object[] {
060: currentPage.toString(), totalPages.toString() }));
061:
062: sb.append("\n");
063:
064: ArrayList values = (ArrayList) data.get(3);
065: for (int index1 = 0; index1 < values.size(); index1++) {
066: HashMap hm = (HashMap) values.get(index1);
067: Iterator i = hm.keySet().iterator();
068: while (i.hasNext()) {
069: String attribute = (String) i.next();
070: ArrayList al = (ArrayList) hm.get(attribute);
071: for (int index2 = 0; index2 < al.size(); index2++) {
072: appendColumn(sb, attribute + " - ", (String) al
073: .get(index2));
074: }
075: }
076: sb.append("\n");
077: }
078:
079: CLILogger.getInstance().printMessage(sb.toString());
080: }
081:
082: private void appendColumn(StringBuffer sb, String label,
083: String value) {
084: String lead = null;
085:
086: StringTokenizer st1 = new StringTokenizer(value.trim(), "\n");
087: while (st1.hasMoreTokens()) {
088: String line = (String) st1.nextToken();
089:
090: if (lead != null) {
091: sb.append(lead);
092: } else {
093: sb.append(label);
094:
095: lead = "";
096: for (int i = 0; i < label.length(); i++) {
097: lead = lead + " ";
098: }
099: }
100: int lineLength = lead.length();
101:
102: StringTokenizer st2 = new StringTokenizer(line, " ");
103: if (st2.countTokens() == 1) {
104: sb.append((String) st2.nextToken() + " ");
105: } else {
106: while (st2.hasMoreTokens()) {
107: String word = (String) st2.nextToken();
108: lineLength += word.length();
109: if (lineLength > 60) {
110: sb.append("\n" + lead);
111: lineLength = lead.length() + word.length();
112: }
113: sb.append(word + " ");
114: }
115: }
116: sb.append("\n");
117: }
118: }
119:
120: }
|