001: /**
002: * Copyright 2003 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.wsrp.consumer.cli;
013:
014: import java.util.Set;
015: import java.util.Iterator;
016: import java.util.logging.Level;
017: import java.util.logging.Logger;
018:
019: import java.net.URL;
020: import java.net.MalformedURLException;
021:
022: import com.sun.portal.wsrp.common.stubs.ServiceDescription;
023:
024: import com.sun.portal.wsrp.common.WSRPFactory;
025: import com.sun.portal.wsrp.WSRPException;
026:
027: import com.sun.portal.wsrp.common.stubs.PortletDescription;
028: import com.sun.portal.wsrp.consumer.common.WSRPConsumerException;
029:
030: import com.sun.portal.wsrp.consumer.producermanager.ProducerEntityManager;
031: import com.sun.portal.wsrp.consumer.producermanager.ProducerEntity;
032: import com.sun.portal.log.common.PortalLogger;
033:
034: class PEAList {
035:
036: private static Logger logger = PortalLogger
037: .getLogger(PEAList.class);
038:
039: public String process(ProducerEntityManager pem, String dn,
040: String pid, String purl, boolean verbose)
041: throws PEAException {
042:
043: //
044: // sanity check: either pid or purl has to be specified
045: //
046: if (pid != null && purl != null) {
047: throw new PEAException("errorBothPIDPURL");
048: }
049:
050: if (verbose) {
051: if (pid != null) {
052: if (logger.isLoggable(Level.FINEST)) {
053: Object[] tokens = { pid };
054: logger
055: .log(Level.FINEST, "PSWS_CSPWCCL0015",
056: tokens);
057: }
058: } else if (purl != null) {
059: if (logger.isLoggable(Level.FINEST)) {
060: Object[] tokens = { purl };
061: logger
062: .log(Level.FINEST, "PSWS_CSPWCCL0016",
063: tokens);
064: }
065: } else {
066: if (logger.isLoggable(Level.FINEST)) {
067: logger.log(Level.FINEST, "PSWS_CSPWCCL0017");
068: }
069: }
070: }
071:
072: StringBuffer buf = new StringBuffer();
073: if (pid != null) {
074: ProducerEntity pe = null;
075: try {
076: pe = pem.getProducerEntity(pid);
077: } catch (WSRPConsumerException wce) {
078: Object[] tokens = { dn, pid };
079: throw new PEAException("errorGetPE", wce, tokens);
080: }
081: if (pe != null) {
082: buf.append(pe.toString());
083: } else {
084: Object[] tokens = { dn, pid };
085: throw new PEAException("errorInvalidPID", tokens);
086: }
087:
088: } else if (purl != null) {
089: URL url = null;
090: try {
091: url = new URL(purl);
092: } catch (MalformedURLException mue) {
093: Object[] tokens = { purl };
094: throw new PEAException("errorInvalidURL", mue, tokens);
095: }
096:
097: String sdXML = null;
098: try {
099: WSRPFactory factory = WSRPFactory.getInstance();
100: ServiceDescription sd = pem.getServiceDescription(url);
101: sdXML = factory.getServiceDescriptionXML(sd, true);
102: } catch (WSRPConsumerException wce) {
103: Object[] tokens = { purl };
104: throw new PEAException("errorGetSD", wce, tokens);
105: } catch (WSRPException we) {
106: Object[] tokens = { purl };
107: throw new PEAException("errorGetSD", we, tokens);
108: }
109: buf.append(sdXML);
110:
111: } else {
112: Set peIds = null;
113: try {
114: peIds = pem.getProducerEntityIds();
115: } catch (WSRPConsumerException wce) {
116: Object[] tokens = { dn };
117: throw new PEAException("errorGetPEs", wce, tokens);
118: }
119: if (peIds != null && peIds.size() > 0) {
120: for (Iterator i = peIds.iterator(); i.hasNext();) {
121: ProducerEntity pe = null;
122: String peId = (String) i.next();
123: try {
124: pe = pem.getProducerEntity(peId);
125: } catch (WSRPConsumerException wce) {
126: Object[] tokens = { dn, peId };
127: throw new PEAException("errorGetPE", wce,
128: tokens);
129: }
130:
131: if (pe == null) {
132: Object[] tokens = { dn, peId };
133: throw new PEAException("errorGetPE", tokens);
134: }
135:
136: buf.append(pe.getId()).append("|").append(
137: pe.getName()).append("|").append(
138: pe.getURL()).append("|").append(
139: pe.getStatus().toString()).append("\n");
140: }
141: }
142: }
143: return buf.toString();
144: }
145: }
|