001: /*
002: * CmdExport.java
003: *
004: * Created on November 14, 2001, 1:27 PM
005: */
006:
007: package com.sun.portal.desktop.deployment;
008:
009: import java.util.Set;
010: import java.util.List;
011: import java.util.Iterator;
012:
013: import java.io.PrintStream;
014: import java.io.FileOutputStream;
015:
016: import com.sun.portal.desktop.dp.DPNode;
017: import com.sun.portal.desktop.dp.DPChannel;
018: import com.sun.portal.desktop.dp.DPContainerChannel;
019:
020: /**
021: *
022: * @author yabob
023: * @version
024: */
025: public class CmdContainers {
026:
027: public static void doContainers(DPRootSpecifier dpr, boolean debug,
028: PrintStream out) throws ParFileException {
029: if (debug) {
030: try {
031: FileOutputStream oxf = new FileOutputStream("dn.xml");
032: StringBuffer sb = new StringBuffer(256);
033: dpr.getRoot().toXML(sb, 0);
034: oxf.write(sb.toString().getBytes());
035: oxf.flush();
036: out.println(Par.getLocalizedString("msgDPDebugDoc"));
037: } catch (Exception ex) {
038: Object tok[] = { ex };
039: out.println(Par.getLocalizedString("msgDPDebugDocFail",
040: tok));
041: }
042: }
043: doContainers(0, dpr.getRoot(), out);
044: }
045:
046: private static void doContainers(int indent, DPNode node,
047: PrintStream out) throws ParFileException {
048:
049: String nm = null;
050:
051: try {
052: Set set = node.getChannelNames();
053:
054: Iterator it = set.iterator();
055: while (it.hasNext()) {
056: nm = (String) it.next();
057: DPChannel ch = node.getChannel(nm);
058:
059: StringBuffer buf = indentedBuffer(indent);
060: buf.append(nm);
061: buf.append(" (");
062: if (ch.getProvider() != null) {
063: buf.append(ch.getProvider().getClassName());
064: buf.append(" ");
065: }
066: String pnm = ch.getProviderName();
067: buf.append(pnm == null ? "?" : pnm);
068: buf.append(")");
069: out.println(buf.toString());
070:
071: if (ch instanceof DPContainerChannel) {
072: doContainers(indent + 1, ch, out);
073: DPContainerChannel cch = (DPContainerChannel) ch;
074: doList("Available", cch.getAvailable().getNames(),
075: indent + 1, out);
076: doList("Selected", cch.getSelected().getNames(),
077: indent + 1, out);
078: }
079: }
080: } catch (Exception ex) {
081: throw new ParFileException(
082: "Exception describing channel - " + nm, ex);
083: }
084: }
085:
086: private static void doList(String pfx, Set set, int indent,
087: PrintStream out) {
088: StringBuffer buf = indentedBuffer(indent);
089: buf.append(pfx);
090: buf.append(":");
091: Iterator it = set.iterator();
092: while (it.hasNext()) {
093: buf.append(" ");
094: buf.append(it.next().toString());
095: }
096: out.println(buf.toString());
097: }
098:
099: private static StringBuffer indentedBuffer(int indent) {
100: StringBuffer buf = new StringBuffer();
101: for (int i = 0; i < indent; ++i) {
102: buf.append(" ");
103: }
104: return buf;
105: }
106:
107: /**
108: * @param args the command line arguments
109: */
110: public static void main(String args[]) {
111:
112: CmdOpts opts = CmdOpts.parseOpts(args, CmdOpts.STD_DPONLY,
113: CmdOpts.REM_NONE, Par
114: .getLocalizedString("usageContainers"), "rpd");
115:
116: if (opts != null) {
117: try {
118: doContainers(opts.dproot(), opts.debug(), System.out);
119: } catch (Exception ex) {
120: opts.produceErrorMessage(ex);
121: }
122: }
123: System.exit(0);
124: }
125: }
|