001: /**
002: * $Id: ImportBean.java,v 1.14 2006/08/21 17:42:47 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.FileInputStream;
019: import java.io.FileNotFoundException;
020: import java.io.IOException;
021:
022: import java.util.LinkedList;
023: import java.util.ResourceBundle;
024: import java.util.MissingResourceException;
025: import java.util.Map;
026:
027: import java.util.logging.Level;
028:
029: import java.net.InetAddress;
030: import java.net.UnknownHostException;
031:
032: //JMX
033: import javax.management.Attribute;
034: import javax.management.AttributeNotFoundException;
035: import javax.management.InvalidAttributeValueException;
036: import javax.management.MBeanServerConnection;
037: import javax.management.ObjectName;
038: import javax.management.InstanceNotFoundException;
039: import javax.management.MBeanException;
040: import javax.management.ReflectionException;
041: import javax.management.MalformedObjectNameException;
042: import javax.management.RuntimeErrorException; //JFS
043: import javax.faces.context.FacesContext;
044: import javax.faces.el.VariableResolver;
045:
046: import com.sun.web.ui.model.Option;
047:
048: import com.sun.portal.admin.common.util.AdminClientUtil;
049: import com.sun.portal.admin.common.BackupVersion;
050: import com.sun.portal.admin.common.PSMBeanException;
051:
052: /**
053: * @author cathywu
054: */
055: public class ImportBean extends ImportExportBaseBean {
056: private static final String CANCEL = "cancel";
057: private static final String CONTINUE = "continue";
058: private static final String DESKTOP = "desktop";
059:
060: private String importParFileName = null;
061: private String importParFile = null;
062: private Object selected = (Object) CANCEL;
063: private Option[] selections = {
064: new Option(CANCEL, "Cancel the import action"),
065: new Option(CONTINUE, "Continue the import action") };
066: private File file = null;
067:
068: public ImportBean() {
069: if (rbMap != null) {
070: titleStr = (String) rbMap.get("import.desktopPageTitle");
071: selections[0].setLabel((String) rbMap
072: .get("import.storageStructureCancelOption"));
073: selections[1].setLabel((String) rbMap
074: .get("import.storageStructureContinueOption"));
075: cancelText = (String) rbMap.get("cancel.button");
076: }
077: setTitle(null);
078: }
079:
080: public String cancel() {
081: setDisplayError(Boolean.FALSE);
082: setLogMessage(null);
083: setCancelText((String) rbMap.get("cancel.button"));
084: setDisableImport(false);
085: setImportParFileName(null);
086: setSelected((Object) selections[0].getValue());
087: return "cancel";
088: }
089:
090: /**
091: * Par file name methods
092: */
093:
094: public String getImportParFileName() {
095: return importParFileName;
096: }
097:
098: public void setImportParFileName(String value) {
099: importParFileName = value;
100: }
101:
102: /**
103: * Par file name methods
104: */
105:
106: public File getFile() {
107: return file;
108: }
109:
110: public void setFile(File newFile) {
111: this .file = newFile;
112: }
113:
114: /**
115: * Storage Structure Collision Strategy methods
116: */
117:
118: public Object[] getSelections() {
119: return (Object[]) selections;
120: }
121:
122: public void setSelected(Object value) {
123: selected = value;
124: }
125:
126: public Object getSelected() {
127: return selected;
128: }
129:
130: /**
131: * beginImport methods
132: */
133: public String beginImport() {
134:
135: if (inProgress == true) {
136: setupAlert(null, "error.import", "error.import.inProgress",
137: "information", null);
138: return "doneImport";
139: }
140:
141: inProgress = true;
142: new CreateThread(this , true).start();
143: return null;
144: }
145:
146: /**
147: * Import operation
148: */
149:
150: public String doImport(Thread t) {
151: String parFileName = getImportParFileName();
152: //Object selected = getSelected();
153: String scope = DEFAULT_SCOPE;
154: Boolean cont = new Boolean(false);
155: if (selected.equals(CONTINUE)) {
156: cont = new Boolean(true);
157: }
158:
159: try {
160: ObjectName cObjectName = getMBeanObjectName(getDomain(),
161: portalId);
162: if (cObjectName == null) {
163: setupAlert(null, "error.import",
164: "error.missing.backend.resource", "error", null);
165: return "doneImport";
166: }
167:
168: Object[] params = { parFileName };
169: String[] signature = { "java.lang.String" };
170:
171: String backupVersion = (String) mbsc.invoke(cObjectName,
172: "getArchiveFileVersion", params, signature);
173: String type = null;
174: if (backupVersion != null) {
175: type = BackupVersion.getType(backupVersion);
176: }
177:
178: log(Level.SEVERE, "ImportBean.doImport(), type:" + type);
179: if (type == null || !type.equals(DESKTOP)) {
180: t.interrupt();
181: inProgress = false;
182: setupAlert(null, "error.import",
183: "error.archive.file.version", "error", null);
184: return "doneImport";
185: }
186:
187: invokeImport(mbsc, cObjectName, parFileName, cont, scope);
188:
189: setupAlert(null, "import.summary", "import.completed",
190: "information", null);
191: setCancelText((String) rbMap.get("close.button"));
192: setImportParFileName("");
193: setDisableImport(true);
194: } catch (MBeanException me) {
195: log(Level.SEVERE, "ImportBean.doImport(), MBeanException",
196: me);
197: String errorKey = "error";
198: Object[] tokens = null;
199: String message = null;
200:
201: boolean pe = me.getCause() instanceof PSMBeanException;
202: if (pe) {
203: PSMBeanException pme = (PSMBeanException) me.getCause();
204: String dbgMsg = null;
205:
206: if (pme.getErrorKey() != null) {
207: errorKey = pme.getErrorKey();
208: }
209: if (pme.getTokens() != null) {
210: tokens = pme.getTokens();
211: }
212: message = composeLogMessage(pme);
213: } else {
214: message = composeLogMessage(me);
215: }
216:
217: if (inProgress == true) {
218: t.interrupt();
219: inProgress = false;
220: }
221: setupAlert(tokens, "error.import", errorKey, "error",
222: message);
223:
224: } catch (Exception ex) {
225: log(Level.SEVERE, "ImportBean.doImport(), Exception:"
226: + ex.getMessage(), ex);
227:
228: if (inProgress == true) {
229: t.interrupt();
230: inProgress = false;
231: }
232:
233: setupAlert(null, "error.import", "import.failed", "error",
234: composeLogMessage(ex));
235: }
236:
237: return "doneImport";
238:
239: }
240:
241: //============================================================
242: // Private methods
243: //============================================================
244:
245: private void invokeImport(MBeanServerConnection msc,
246: ObjectName objName, String parFileName, Boolean cont,
247: String scope) throws Exception {
248:
249: try {
250: Object[] params = { new Boolean(false), new Boolean(false),
251: new Boolean(false), new Boolean(true),
252: new Boolean(true), parFileName, cont, scope, null,
253: new Boolean(false) };
254: String[] signature = { "java.lang.Boolean",
255: "java.lang.Boolean", "java.lang.Boolean",
256: "java.lang.Boolean", "java.lang.Boolean",
257: "java.lang.String", "java.lang.Boolean",
258: "java.lang.String", "java.lang.String",
259: "java.lang.Boolean" };
260:
261: msc.invoke(objName, "importDesktop", params, signature);
262: } catch (InstanceNotFoundException ine) {
263: log(Level.SEVERE, "ImportBean.invokeImport(), Exception",
264: ine);
265: throw ine;
266: } catch (MBeanException me) {
267: log(Level.SEVERE, "ImportBean.invokeImport(), Exception",
268: me);
269: throw me;
270: } catch (ReflectionException re) {
271: log(Level.SEVERE, "ImportBean.invokeImport(), Exception",
272: re);
273: throw re;
274: } catch (Exception e) {
275: log(Level.SEVERE, "ImportBean.invokeImport(), Exception", e);
276: throw e;
277: }
278: }
279:
280: }
|