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.admin.mbeans.tasks;
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:
020: import java.util.logging.Logger;
021: import java.util.logging.Level;
022:
023: public class DPAMerge {
024:
025: // XML DP Factory
026: XMLDPFactory dpf = XMLDPFactory.getInstance();
027:
028: public String process(AdminDPContext adc, String dn,
029: boolean global, String name, boolean verbose, Logger logger)
030: throws DPAException {
031:
032: String doc = null;
033: if (verbose) {
034: Object[] tokens = { global ? DPAUtil
035: .getLocalizedString("msgGlobal") : dn };
036: logger.log(Level.INFO, "PSDT_CSPDAMT0020", tokens);
037: }
038:
039: try {
040: if (global) {
041: doc = adc.getGlobalDPDocument();
042: if (doc == null || doc.length() == 0) {
043: return null;
044: }
045: if (name == null) {
046: return doc.toString();
047: }
048: } else {
049: doc = adc.getDPDocument(dn);
050: }
051: } catch (Throwable ex) {
052: Object[] tokens = { global ? "<global>" : dn };
053: throw new DPAException("errorRetrieveDP", ex, tokens);
054: }
055:
056: if (verbose) {
057: Object[] tokens = { global ? DPAUtil
058: .getLocalizedString("msgGlobal") : dn };
059: logger.log(Level.INFO, "PSDT_CSPDAMT0021", tokens);
060: }
061: DPRoot dpr = null;
062: try {
063: if (doc != null && doc.length() > 0) {
064: dpr = dpf.createRoot(adc, doc);
065: } else {
066: //
067: // if doc is empty, create an empty dproot
068: //
069: dpr = dpf.createRoot(adc);
070: }
071: if (!global) {
072: Set names = adc.getDPDocumentNames(dn);
073: dpr = dpf.addMergers(adc, dpr, names, new HashMap());
074: if (name == null) {
075: return dpr.toMergedXML();
076: }
077: }
078: } catch (Throwable ex) {
079: Object[] tokens = { global ? "<global>" : dn };
080: throw new DPAException("errorCreateDPRoot", ex, tokens);
081: }
082:
083: if (verbose) {
084: Object[] tokens = { name };
085: logger.log(Level.INFO, "PSDT_CSPDAMT0022", tokens);
086: }
087:
088: DPPropertyHolder ph = null;
089: try {
090: ph = dpr.getChannel(name);
091: if (ph == null) {
092: ph = dpr.getProvider(name);
093: }
094:
095: if (ph != null) {
096: return ph.toMergedXML();
097: } else {
098: return null;
099: }
100: } catch (Throwable ex) {
101: Object[] tokens = { name };
102: throw new DPAException("errorFindPropertyHolder", ex,
103: tokens);
104: }
105:
106: }
107:
108: }
|