001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.desktop.dp.cli;
006:
007: import java.util.Set;
008: import java.util.HashMap;
009: import java.util.logging.Level;
010: import java.util.logging.Logger;
011:
012: import com.sun.portal.desktop.context.AdminDPContext;
013: import com.sun.portal.desktop.context.DPContext;
014:
015: import com.sun.portal.desktop.dp.DPRoot;
016: import com.sun.portal.desktop.dp.DPPropertyHolder;
017:
018: import com.sun.portal.desktop.dp.xml.XMLDPFactory;
019: import com.sun.portal.log.common.PortalLogger;
020:
021: import java.util.logging.Logger;
022: import java.util.logging.Level;
023:
024: class DPAMerge {
025:
026: // XML DP Factory
027: XMLDPFactory dpf = XMLDPFactory.getInstance();
028:
029: private static Logger logger = PortalLogger
030: .getLogger(DPAMerge.class);
031:
032: public String process(AdminDPContext adc, String dn,
033: boolean global, String name, boolean verbose, Logger logger)
034: throws DPAException {
035:
036: String doc = null;
037: if (verbose) {
038: Object[] tokens = { global ? DPAUtil
039: .getLocalizedString("msgGlobal") : dn };
040: logger.log(Level.FINEST, "PSDT_CSPDDC0020", tokens);
041: }
042:
043: try {
044: if (global) {
045: doc = adc.getGlobalDPDocument();
046: if (doc == null || doc.length() == 0) {
047: return null;
048: }
049: if (name == null) {
050: return doc.toString();
051: }
052: } else {
053: doc = adc.getDPDocument(dn);
054: }
055: } catch (Throwable ex) {
056: Object[] tokens = { DPAUtil.getLocalizedString("msgGlobal") };
057: throw new DPAException("errorRetrieveDP", ex, tokens);
058: }
059:
060: if (verbose) {
061: Object[] tokens = { global ? DPAUtil
062: .getLocalizedString("msgGlobal") : dn };
063: logger.log(Level.FINEST, "PSDT_CSPDDC0021", tokens);
064: }
065: DPRoot dpr = null;
066: try {
067: if (doc != null && doc.length() > 0) {
068: dpr = dpf.createRoot(adc, doc);
069: } else {
070: //
071: // if doc is empty, create an empty dproot
072: //
073: dpr = dpf.createRoot(adc);
074: }
075: if (!global) {
076: Set names = adc.getDPDocumentNames(dn);
077: dpr = dpf.addMergers(adc, dpr, names, new HashMap());
078: if (name == null) {
079: return dpr.toMergedXML();
080: }
081: }
082: } catch (Throwable ex) {
083: Object[] tokens = { global ? DPAUtil
084: .getLocalizedString("msgGlobal") : dn };
085: throw new DPAException("errorCreateDPRoot", ex, tokens);
086: }
087:
088: if (verbose) {
089: Object[] tokens = { name };
090: logger.log(Level.FINEST, "PSDT_CSPDDC0022", tokens);
091: }
092:
093: DPPropertyHolder ph = null;
094: try {
095: ph = dpr.getChannel(name);
096: if (ph == null) {
097: ph = dpr.getProvider(name);
098: }
099:
100: if (ph != null) {
101: return ph.toMergedXML();
102: } else {
103: return null;
104: }
105: } catch (Throwable ex) {
106: Object[] tokens = { name };
107: throw new DPAException("errorFindPropertyHolder", ex,
108: tokens);
109: }
110:
111: }
112:
113: }
|