001: /**
002: * $Id: ExportBean.java,v 1.12 2005/10/21 01:28:31 cathywu Exp $
003: * Copyright 2005 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.admin.console.fabric;
014:
015: import java.beans.*;
016: import java.io.Serializable;
017: import java.io.File;
018: import java.io.FileOutputStream;
019: import java.io.FileNotFoundException;
020: import java.io.IOException;
021:
022: import java.util.Map;
023: import java.util.ResourceBundle;
024: import java.util.Random;
025: import java.util.logging.Level;
026:
027: //JMX
028: import javax.management.Attribute;
029: import javax.management.AttributeNotFoundException;
030: import javax.management.InvalidAttributeValueException;
031: import javax.management.MBeanServerConnection;
032: import javax.management.ObjectName;
033: import javax.management.InstanceNotFoundException;
034: import javax.management.MBeanException;
035: import javax.management.ReflectionException;
036: import javax.management.RuntimeErrorException; //JSF
037: import javax.faces.context.FacesContext;
038: import javax.faces.el.VariableResolver;
039:
040: import com.sun.web.ui.model.Option;
041:
042: import com.sun.portal.admin.common.PSMBeanException;
043:
044: /**
045: * @author cathywu
046: */
047: public class ExportBean extends ImportExportBaseBean {
048:
049: private static final String FS_ONLY = "fsOnly";
050: private static final String DP_ONLY = "dpOnly";
051: private static final String ALL = "all";
052: private String exportParFileName;
053: private Object selected = (Object) ALL;
054: private String[] selectedDir = null;
055: private File currentDir = null;
056: private String currentDirPath = null;
057: private Option[] selections = {
058: new Option(ALL, "Include everything"),
059: new Option(FS_ONLY, "Include desktop file system data"),
060: new Option(DP_ONLY, "Include display profile") };
061:
062: public ExportBean() {
063: if (rbMap != null) {
064: titleStr = (String) rbMap.get("export.desktopPageTitle");
065: selections[0].setLabel((String) rbMap
066: .get("export.dataToInclude.all"));
067: selections[1].setLabel((String) rbMap
068: .get("export.dataToInclude.fsOnly"));
069: selections[2].setLabel((String) rbMap
070: .get("export.dataToInclude.dpOnly"));
071:
072: cancelText = (String) rbMap.get("cancel.button");
073: }
074:
075: setTitle(null);
076: }
077:
078: public String cancel() {
079: setDisplayError(Boolean.FALSE);
080: setLogMessage(null);
081: setCancelText((String) rbMap.get("cancel.button"));
082: setDisableExport(false);
083: setExportParFileName(null);
084: setSelected((Object) selections[0].getValue());
085: return "cancel";
086: }
087:
088: /**
089: * Par file name methods
090: */
091:
092: public String getExportParFileName() {
093: return exportParFileName;
094: }
095:
096: public void setExportParFileName(String value) {
097: exportParFileName = value;
098: }
099:
100: public File getCurrentDir() {
101: return currentDir;
102: }
103:
104: public void setCurrentDir(File value) {
105: currentDir = value;
106: }
107:
108: /**
109: * Data to inclue methods
110: */
111:
112: public Object[] getSelections() {
113: return (Object[]) selections;
114: }
115:
116: public void setSelected(Object value) {
117: selected = value;
118: }
119:
120: public Object getSelected() {
121: return selected;
122: }
123:
124: /**
125: * beginExport methods
126: */
127: public String beginExport() {
128:
129: if (inProgress == true) {
130: setupAlert(null, "error.export", "error.export.inProgress",
131: "information", null);
132: return "doneExport";
133: }
134:
135: inProgress = true;
136: new CreateThread(this , false).start();
137: return null;
138: }
139:
140: /**
141: * Export operation
142: */
143:
144: public String doExport(Thread t) {
145: FacesContext ctx = FacesContext.getCurrentInstance();
146: String parFileName = getExportParFileName();
147: String scope = DEFAULT_SCOPE;
148: Boolean fsOnly = new Boolean(false);
149: Boolean dpOnly = new Boolean(false);
150:
151: if (selected.equals(FS_ONLY)) {
152: fsOnly = new Boolean(true);
153: } else if (selected.equals(DP_ONLY)) {
154: dpOnly = new Boolean(true);
155: }
156:
157: log(Level.INFO, "ExportBean.doExport(), selected: "
158: + (String) selected);
159: log(Level.INFO, "ExportBean.doExport(), parFileName: "
160: + parFileName);
161:
162: try {
163: ObjectName cObjectName = getMBeanObjectName(getDomain(),
164: portalId);
165: if (cObjectName == null) {
166: setupAlert(null, "error.export",
167: "error.missing.backend.resource", "error", null);
168: return "doneExport";
169: }
170:
171: invokeExport(mbsc, cObjectName, parFileName, fsOnly,
172: dpOnly, scope);
173:
174: setupAlert(null, "export.summary", "export.completed",
175: "information", null);
176:
177: setCancelText((String) rbMap.get("close.button"));
178: setExportParFileName("");
179: setDisableExport(true);
180: } catch (MBeanException px) {
181: log(Level.SEVERE, "Exception in ExportBean.doExport()", px);
182: String errorKey = "error";
183: Object[] tokens = null;
184: String message = null;
185:
186: boolean pe = px.getCause() instanceof PSMBeanException;
187: if (pe) {
188: PSMBeanException me = (PSMBeanException) px.getCause();
189: String dbgMsg = null;
190:
191: if (me.getErrorKey() != null) {
192: errorKey = me.getErrorKey();
193: }
194: if (me.getTokens() != null) {
195: tokens = me.getTokens();
196: }
197: message = composeLogMessage(me);
198: } else {
199: message = composeLogMessage(px);
200: }
201:
202: if (inProgress == true) {
203: t.interrupt();
204: inProgress = false;
205: }
206: setupAlert(tokens, "error.export", errorKey, "error",
207: message);
208: } catch (Exception ex) {
209: log(Level.SEVERE, "ExportBean.doExport(), Exception", ex);
210: if (ex.getCause() != null) {
211: log(Level.SEVERE, "ImportBean.doImport(), Message:"
212: + ex.getCause().getMessage());
213: }
214: if (inProgress == true) {
215: t.interrupt();
216: inProgress = false;
217: }
218:
219: setupAlert(null, "error.export", "export.failed", "error",
220: composeLogMessage(ex));
221: }
222:
223: return "doneExport";
224: }
225:
226: /**
227: * Private methods
228: */
229: private void invokeExport(MBeanServerConnection msc,
230: ObjectName objName, String parFileName, Boolean fsOnly,
231: Boolean dpOnly, String scope) throws Exception {
232:
233: Object[] params = { parFileName, new Boolean(false), fsOnly,
234: dpOnly, scope };
235: String[] signature = { "java.lang.String", "java.lang.Boolean",
236: "java.lang.Boolean", "java.lang.Boolean",
237: "java.lang.String" };
238:
239: try {
240: msc.invoke(objName, "exportDesktop", params, signature);
241: } catch (InstanceNotFoundException ine) {
242: log(Level.SEVERE, "Exception in ExportBean.invokeExport()",
243: ine);
244: throw ine;
245: } catch (ReflectionException re) {
246: log(Level.SEVERE, "Exception in ExportBean.invokeExport()",
247: re);
248: throw re;
249: } catch (MBeanException me) {
250: log(Level.SEVERE, "Exception in ExportBean.invokeExport()",
251: me);
252: throw me;
253: } catch (Exception e) {
254: log(Level.SEVERE, "Exception in ExportBean.invokeExport()",
255: e);
256: throw e;
257: }
258:
259: }
260:
261: }
|