001: /**
002: * $Id: DPAdminWrapper.java,v 1.14 2005/10/21 07:15:09 dg154973 Exp $
003: * Copyright 2004 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: */package com.sun.portal.desktop.admin.mbeans;
014:
015: import java.io.*;
016: import java.util.List;
017: import java.util.logging.Level;
018: import java.util.logging.Logger;
019:
020: import com.sun.portal.log.common.PortalLogger;
021:
022: import com.sun.portal.desktop.admin.mbeans.tasks.DPAException;
023: import com.sun.portal.desktop.context.AdminDPContext;
024: import com.sun.portal.desktop.admin.mbeans.tasks.DPHelper;
025: import com.sun.portal.desktop.admin.mbeans.tasks.DesktopDataException;
026:
027: import com.sun.portal.admin.common.context.PSConfigContext;
028: import com.sun.portal.admin.common.PSConfigConstants;
029: import com.sun.portal.admin.common.context.PortalDomainContext;
030: import com.sun.portal.admin.common.PSMBeanException;
031: import com.sun.portal.admin.server.mbeans.PSResource;
032: import com.sun.portal.admin.server.AdminServerUtil;
033:
034: //DP operations
035: import com.sun.portal.desktop.admin.mbeans.tasks.DPAAdd;
036: import com.sun.portal.desktop.admin.mbeans.tasks.DPAList;
037: import com.sun.portal.desktop.admin.mbeans.tasks.DPAMerge;
038: import com.sun.portal.desktop.admin.mbeans.tasks.DPAModify;
039: import com.sun.portal.desktop.admin.mbeans.tasks.DPARemove;
040:
041: //This class implements DPAdminWrapperMBean interface and implements methods
042: //to interact with existing dpadmin cli for dp manipulation.
043:
044: public class DPAdminWrapper extends PSResource implements
045: DPAdminWrapperMBean {
046: private static final String MSG_PREFIX = "desktop.";
047: private String psPortalID;
048: private PSConfigContext cc = null;
049: private static Logger logger = PortalLogger
050: .getLogger(DPAdminWrapper.class);
051:
052: public DPAdminWrapper() {
053: ;
054: }
055:
056: public void init(PSConfigContext cc, PortalDomainContext pdc,
057: List path) {
058: super .init(cc, pdc, path);
059:
060: this .cc = cc;
061: this .psPortalID = (String) path.get(1);
062:
063: }
064:
065: //Method for dp Add
066: public void dpAdd(String dn, String parent,
067: byte[][] arrayByteArray, Boolean global, Boolean dryrun,
068: Boolean verbose) throws PSMBeanException {
069:
070: AdminDPContext adpContext = getAdminDPContext();
071: //get xml byte stream
072: InputStream[] xmlByteStreams;
073: xmlByteStreams = getXMLInputFromByteArray(arrayByteArray);
074:
075: DPAAdd dpaadd = new DPAAdd();
076: try {
077: dpaadd.process(adpContext, dn, global.booleanValue(),
078: parent, xmlByteStreams, verbose.booleanValue(),
079: dryrun.booleanValue(), logger);
080: } catch (DPAException dpae) {
081: logger.log(Level.SEVERE, "PSDT_CSPDAMB0005", dpae
082: .getOrigEx());
083: throw new PSMBeanException(MSG_PREFIX + dpae.getKey(), dpae
084: .getOrigEx(), dpae.getTokens());
085: } finally {
086: try {
087: for (int i = 0; i < xmlByteStreams.length; i++) {
088: xmlByteStreams[i].close();
089: }
090: } catch (IOException ioe) {
091: throw new PSMBeanException(MSG_PREFIX
092: + "errorStreamClose", ioe);
093: }
094: }
095:
096: };
097:
098: //Method for dp list
099: public String dpList(String dn, String name, Boolean global,
100: Boolean verbose) throws PSMBeanException {
101:
102: //get the admin dp context ;
103: AdminDPContext adpContext = getAdminDPContext();
104:
105: DPAList dpalist = new DPAList();
106: String dp;
107: try {
108: dp = dpalist.process(adpContext, dn, global.booleanValue(),
109: name, verbose.booleanValue(), logger);
110: if (dp != null) {
111: return dp;
112: } else {
113: logger.log(Level.INFO, "PSDT_CSPDAMB0007");
114: throw new PSMBeanException(MSG_PREFIX + "errorNodp");
115: }
116: } catch (DPAException dpae) {
117:
118: logger.log(Level.SEVERE, "PSDT_CSPDAMB0005"
119: + dpae.getOrigEx());
120: throw new PSMBeanException(MSG_PREFIX + dpae.getKey(), dpae
121: .getOrigEx(), dpae.getTokens());
122: }
123: };
124:
125: public String dpMerge(String dn, String name, Boolean global,
126: Boolean verbose) throws PSMBeanException {
127:
128: //get the admin dp context ;
129: AdminDPContext adpContext = getAdminDPContext();
130: DPAMerge dpamerge = new DPAMerge();
131: try {
132: String dp = dpamerge.process(adpContext, dn, global
133: .booleanValue(), name, verbose.booleanValue(),
134: logger);
135: if (dp != null) {
136: return dp;
137: } else {
138: logger.log(Level.INFO, "PSDT_CSPDAMB0007");
139: throw new PSMBeanException(MSG_PREFIX + "errorNodp");
140: }
141: } catch (DPAException dpae) {
142: logger.log(Level.SEVERE, "PSDT_CSPDAMB0005"
143: + dpae.getOrigEx());
144: throw new PSMBeanException(MSG_PREFIX + dpae.getKey(), dpae
145: .getOrigEx(), dpae.getTokens());
146: }
147: };
148:
149: public void dpModify(String dn, String parent, Boolean global,
150: byte[][] arrayByteArray, Boolean combine, Boolean dryrun,
151: Boolean verbose) throws PSMBeanException {
152:
153: //get the admin dp context ;
154: AdminDPContext adpContext = getAdminDPContext();
155: //get xml byte stream
156: InputStream[] xmlByteStreams;
157: xmlByteStreams = getXMLInputFromByteArray(arrayByteArray);
158:
159: DPAModify dpamodify = new DPAModify();
160: try {
161: dpamodify.process(adpContext, dn, global.booleanValue(),
162: parent, combine.booleanValue(), xmlByteStreams,
163: verbose.booleanValue(), dryrun.booleanValue(),
164: logger);
165:
166: } catch (DPAException dpae) {
167:
168: logger.log(Level.SEVERE, "PSDT_CSPDAMB0005"
169: + dpae.getOrigEx());
170: throw new PSMBeanException(MSG_PREFIX + dpae.getKey(), dpae
171: .getOrigEx(), dpae.getTokens());
172:
173: } finally {
174: try {
175: for (int i = 0; i < xmlByteStreams.length; i++) {
176: xmlByteStreams[i].close();
177: }
178: } catch (IOException ioe) {
179: throw new PSMBeanException(MSG_PREFIX
180: + "errorStreamClose", ioe);
181: }
182: }
183:
184: };
185:
186: public void dpRemove(String dn, String parent, String name,
187: String type, Boolean global, Boolean dryrun, Boolean verbose)
188: throws PSMBeanException {
189:
190: //get the admin dp context ;
191: AdminDPContext adpContext = getAdminDPContext();
192: DPARemove dparemove = new DPARemove();
193: try {
194: dparemove.process(adpContext, dn, global.booleanValue(),
195: parent, name, type, verbose.booleanValue(), dryrun
196: .booleanValue(), logger);
197:
198: } catch (DPAException dpae) {
199:
200: logger.log(Level.SEVERE, "PSDT_CSPDAMB0005"
201: + dpae.getOrigEx());
202: throw new PSMBeanException(MSG_PREFIX + dpae.getKey(), dpae
203: .getOrigEx(), dpae.getTokens());
204:
205: }
206: };
207:
208: //-----------------common methods-----------------------------------------------------------------------------//
209: //utlity method to get Stream of byte arrays
210: private InputStream[] getXMLInputFromByteArray(
211: byte[][] arrayByteArray) {
212: InputStream[] streams = null;
213: streams = new InputStream[arrayByteArray.length];
214: for (int i = 0; i < arrayByteArray.length; i++) {
215: streams[i] = new ByteArrayInputStream(arrayByteArray[i]);
216: }
217: return streams;
218: }
219:
220: //method to get admin dp context
221: private AdminDPContext getAdminDPContext() throws PSMBeanException {
222: AdminDPContext adpContext = null;
223: try {
224: DPHelper dpHelper = DPHelper.getDPHelper(
225: getPSConfigContext(),
226: AdminServerUtil.getSSOToken(), psPortalID);
227: adpContext = (AdminDPContext) dpHelper
228: .getAdminDPContext(psPortalID);
229: adpContext.init(AdminServerUtil.getSSOToken(), null,
230: psPortalID);
231: } catch (DesktopDataException de) {
232: logger.log(Level.SEVERE, "PSDT_CSPDAMB0006" + de);
233: throw new PSMBeanException(MSG_PREFIX + "errorDesktopData",
234: de);
235: }
236: return adpContext;
237: }
238: }
|