001: /*
002: * RegistrySearchCommand.java
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */
014:
015: package com.sun.portal.admin.cli.commands.wsrp;
016:
017: import com.sun.portal.admin.cli.commands.GenericCommand;
018: import java.util.Iterator;
019: import java.util.Map;
020: import java.util.Set;
021: import com.sun.enterprise.cli.framework.*;
022:
023: public class RegistrySearchCommand extends GenericCommand {
024:
025: //TODO : Specify a proper usage string
026: public static final String OPT_SEARCH_PRODUCER = "searchproducerdata";
027: public static final String OPT_SEARCH_PORTLET = "searchportletdata";
028: public static final String OPT_SEARCH_ORG = "searchorgdata";
029: public static final String OPERATION_SEARCH_PRODUCER = "searchProducer";
030: public static final String OPERATION_SEARCH_PORTLET = "searchPortlet";
031: public static final String OPERATION_SEARCH_ORG = "searchOrganization";
032: public static final String OPT_COMPONENT = "component";
033: public static final String OPT_COMPONENT_VALUE = "consumer";
034: public static final String SEPARATOR = " : ";
035:
036: public String getOperationName() throws CommandException {
037: String operationNameStr = super .getOperationName();
038: String searchPortlet = getOption(OPT_SEARCH_PORTLET);
039: String searchOrg = getOption(OPT_SEARCH_ORG);
040: if (searchPortlet != null) {
041: operationNameStr = OPERATION_SEARCH_PORTLET;
042: } else if (searchOrg != null) {
043: operationNameStr = OPERATION_SEARCH_ORG;
044: }
045: CLILogger.getInstance().printDebugMessage(
046: "OperationName = " + operationNameStr);
047: return operationNameStr;
048: }
049:
050: public boolean validateOptions() throws CommandValidationException {
051: if (super .validateOptions() == false) {
052: return false;
053: }
054: String component = getOption(OPT_COMPONENT);
055: String searchProducer = getOption(OPT_SEARCH_PRODUCER);
056: String searchPortlet = getOption(OPT_SEARCH_PORTLET);
057: String searchOrg = getOption(OPT_SEARCH_ORG);
058:
059: if (!component.equals(OPT_COMPONENT_VALUE)) {
060: return false;
061: }
062:
063: if (searchProducer == null && searchPortlet == null
064: && searchOrg == null) {
065: throw new CommandValidationException(
066: getLocalizedString("wsrp.consumer.error.search-registry.file.required"));
067: }
068:
069: if (searchProducer != null) {
070: if (searchPortlet != null || searchOrg != null) {
071: return false;
072: }
073: }
074:
075: if (searchPortlet != null) {
076: if (searchProducer != null || searchOrg != null) {
077: return false;
078: }
079: }
080:
081: if (searchOrg != null) {
082: if (searchProducer != null || searchPortlet != null) {
083: return false;
084: }
085: }
086: return true;
087: }
088:
089: protected Object[] getParamsInfo() throws CommandException,
090: CommandValidationException {
091:
092: Object[] params = super .getParamsInfo();
093: String searchPortlet = getOption(OPT_SEARCH_PORTLET);
094: String searchOrg = getOption(OPT_SEARCH_ORG);
095:
096: if (searchPortlet != null) {
097: params = new Object[1];
098: params[0] = createPropertiesParam(searchPortlet);
099: } else if (searchOrg != null) {
100: params = new Object[1];
101: params[0] = createPropertiesParam(searchOrg);
102: }
103: return params;
104: }
105:
106: protected void handleReturnValue(Object returnval) {
107: String searchProducer = getOption(OPT_SEARCH_PRODUCER);
108: if (searchProducer != null) {
109: formatSearchProducerResults(returnval);
110: }
111:
112: String searchPortlet = getOption(OPT_SEARCH_PORTLET);
113:
114: if (searchPortlet != null) {
115: formatSearchPortletResults(returnval);
116: }
117:
118: String searchOrg = getOption(OPT_SEARCH_ORG);
119:
120: if (searchOrg != null) {
121: formatSearchOrgResults(returnval);
122: }
123: }
124:
125: private void formatSearchOrgResults(Object returnval) {
126: StringBuffer formatted = new StringBuffer();
127: Set output = (Set) returnval;
128: Iterator it = output.iterator();
129: String key = getLocalizedString("wsrp.registry.object.key")
130: + SEPARATOR;
131: String name = getLocalizedString("wsrp.registry.organization.name")
132: + SEPARATOR;
133: String desc = getLocalizedString("wsrp.registry.organization.description")
134: + SEPARATOR;
135: String records = getLocalizedString("wsrp.registry.result.summary")
136: + SEPARATOR;
137: Map record = null;
138:
139: formatted.append(records + output.size());
140:
141: if (output.size() > 0) {
142: formatted.append("\n\n");
143: }
144:
145: while (it.hasNext()) {
146: record = (Map) it.next();
147: formatted.append(key + record.get("organization.key")
148: + "\n");
149: formatted.append(name + record.get("organization.name")
150: + "\n");
151: formatted.append(desc
152: + record.get("organization.description"));
153: if (it.hasNext()) {
154: formatted.append("\n\n");
155: }
156: }
157: CLILogger.getInstance().printMessage(formatted.toString());
158: }
159:
160: private void formatSearchPortletResults(Object returnval) {
161: StringBuffer formatted = new StringBuffer();
162: Set output = (Set) returnval;
163: Iterator it = output.iterator();
164: String key = getLocalizedString("wsrp.registry.object.key")
165: + SEPARATOR;
166: String name = getLocalizedString("wsrp.registry.portlet.name")
167: + SEPARATOR;
168: String desc = getLocalizedString("wsrp.registry.portlet.description")
169: + SEPARATOR;
170: String urls = getLocalizedString("wsrp.registry.producer.urls")
171: + SEPARATOR;
172: String records = getLocalizedString("wsrp.registry.result.summary")
173: + SEPARATOR;
174: Map record = null;
175:
176: formatted.append(records + output.size());
177:
178: if (output.size() > 0) {
179: formatted.append("\n\n");
180: }
181:
182: while (it.hasNext()) {
183: record = (Map) it.next();
184: formatted.append(key + record.get("portlet.key") + "\n");
185: formatted.append(name + record.get("portlet.name") + "\n");
186: formatted.append(desc + record.get("portlet.description")
187: + "\n");
188: formatted
189: .append(urls + record.get("portlet.producer.urls"));
190: if (it.hasNext()) {
191: formatted.append("\n\n");
192: }
193: }
194: CLILogger.getInstance().printMessage(formatted.toString());
195: }
196:
197: private void formatSearchProducerResults(Object returnval) {
198: StringBuffer formatted = new StringBuffer();
199: Set output = (Set) returnval;
200: Iterator it = output.iterator();
201: String key = getLocalizedString("wsrp.registry.object.key")
202: + SEPARATOR;
203: String name = getLocalizedString("wsrp.registry.producer.name")
204: + SEPARATOR;
205: String desc = getLocalizedString("wsrp.registry.producer.description")
206: + SEPARATOR;
207: String urls = getLocalizedString("wsrp.registry.producer.urls")
208: + SEPARATOR;
209: String records = getLocalizedString("wsrp.registry.result.summary")
210: + SEPARATOR;
211: Map record = null;
212:
213: formatted.append(records + output.size());
214:
215: if (output.size() > 0) {
216: formatted.append("\n\n");
217: }
218:
219: while (it.hasNext()) {
220: record = (Map) it.next();
221: formatted.append(key + record.get("producer.key") + "\n");
222: formatted.append(name + record.get("producer.name") + "\n");
223: formatted.append(desc + record.get("producer.description")
224: + "\n");
225: formatted.append(urls + record.get("producer.urls"));
226: if (it.hasNext()) {
227: formatted.append("\n\n");
228: }
229: }
230: CLILogger.getInstance().printMessage(formatted.toString());
231: }
232: }
|