001: /**
002: * $Id: ListPortalsBean.java,v 1.8 2005/09/23 04:05:54 pd109850 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.util.List;
016: import java.util.logging.Level;
017: import java.util.ArrayList;
018: import java.util.Set;
019: import java.util.Iterator;
020: import java.io.IOException;
021: import java.text.MessageFormat;
022:
023: import javax.faces.event.ActionEvent;
024: import javax.faces.context.FacesContext;
025: import javax.servlet.http.HttpServletRequest;
026:
027: import com.sun.data.provider.DataProvider;
028: import com.sun.data.provider.impl.ObjectListDataProvider;
029: import com.sun.web.ui.model.Option;
030: import com.sun.web.ui.component.RadioButton;
031:
032: import com.sun.portal.admin.common.util.AdminClientUtil;
033: import com.sun.portal.admin.common.PortalAttributes;
034:
035: import javax.management.ObjectName;
036:
037: public class ListPortalsBean extends FabricBaseBean {
038: private DataProvider portals = null;
039: private List portalsList = null;
040: private List names = null;
041:
042: public String currentPortal = null;
043:
044: /** Creates a new instance of ListPortalsBean*/
045: public ListPortalsBean() {
046: buildPortalList();
047: }
048:
049: private void buildPortalList() {
050: portalsList = new ArrayList();
051: names = getPortalNames();
052: Iterator iter = names.iterator();
053: while (iter.hasNext()) {
054: String name = (String) iter.next();
055: int nInstances = 0;
056: try {
057: nInstances = getInstanceObjectNames(name).size();
058: } catch (Exception e) {
059: log(
060: Level.INFO,
061: "ListPortalsBean.ListPortalsBean(): "
062: + "Failed to get number of instances for portal "
063: + name, e);
064: }
065: portalsList.add(new PortalBean(name, getPortalAttribute(
066: name, PortalAttributes.PORTAL_URI), nInstances));
067: }
068: portals = new ObjectListDataProvider(portalsList);
069: }
070:
071: public DataProvider getPortals() {
072: return portals;
073: }
074:
075: public void setPortals(DataProvider portals) {
076: this .portals = portals;
077: }
078:
079: public Option[] getPortalOptions() {
080: Option[] pOptions = new Option[names.size()];
081: Iterator iter = names.iterator();
082: int i = 0;
083: while (iter.hasNext()) {
084: String portalName = (String) iter.next();
085: Option portal = new Option(portalName, portalName);
086: pOptions[i] = portal;
087: i++;
088: }
089: return pOptions;
090: }
091:
092: public String getCurrentPortal() {
093: currentPortal = (String) getSessionAttribute(ATTR_SELECTED_PORTAL);
094: if (currentPortal == null) {
095: if (names != null && !names.isEmpty()) {
096: currentPortal = (String) names.get(0);
097: }
098: }
099: return currentPortal;
100: }
101:
102: public void setCurrentPortal(String portalId) {
103: setSessionAttribute(ATTR_SELECTED_PORTAL, portalId);
104: currentPortal = portalId;
105: }
106:
107: private List getPortalNames() {
108: List pNames = new ArrayList();
109: try {
110: ObjectName portalPat = AdminClientUtil
111: .getPortalsPattern(AdminClientUtil.DEFAULT_DOMAIN);
112: Set objNames = getMBeanServerConnection().queryNames(
113: portalPat, null);
114: Iterator iter = objNames.iterator();
115: while (iter.hasNext()) {
116: pNames
117: .add(getAttribute((ObjectName) iter.next(),
118: "ID"));
119: }
120: } catch (IOException ie) {
121: log(
122: Level.SEVERE,
123: "ListPortalsBean.getPortalNames: Exception when trying to get the list of portals",
124: ie);
125: } catch (Exception ex) {
126: log(
127: Level.SEVERE,
128: "ListPortalsBean.getPortalNames: Exception when trying to get the list of portals",
129: ex);
130: }
131: return pNames;
132: }
133:
134: public String gotoDesktopHome() {
135: HttpServletRequest req = (HttpServletRequest) FacesContext
136: .getCurrentInstance().getExternalContext().getRequest();
137: String portalId = (String) req
138: .getParameter(ATTR_SELECTED_PORTAL);
139: setSessionAttribute(ATTR_SELECTED_PORTAL, portalId);
140: return "gotoDesktopHome";
141: }
142:
143: public String exportPortal() {
144: return "export";
145: }
146:
147: public String importPortal() {
148: return "import";
149: }
150:
151: public String newPortal() {
152: return "newPortal";
153: }
154:
155: public String getSelectedPortal() {
156: String portalId = (String) RadioButton.getSelected("rb");
157: return portalId;
158: }
159:
160: public String deletePortal() {
161:
162: // Get the selected portal id
163: String name = (String) RadioButton.getSelected("rb");
164:
165: // Set the right params and signature
166: Object[] params = { name };
167: String[] signature = { "java.lang.String" };
168:
169: try {
170: // Get the MBean object for the newly created portal
171: ObjectName iObjName = AdminClientUtil
172: .getPortalDomainMBeanObjectName(AdminClientUtil.DEFAULT_DOMAIN);
173:
174: log(Level.FINEST, "Invoking Delete Portal for: " + name);
175: // Invoke the delete portal operation
176: getMBeanServerConnection().invoke(iObjName, "deletePortal",
177: params, signature);
178:
179: setAlertType("information");
180: setAlertSummary(getFabricI18N("message.deletePortal.success.summary"));
181: String ptrn = getFabricI18N("message.deletePortal.success.details");
182: MessageFormat mf = new MessageFormat(ptrn);
183: setAlertDetail(mf.format(params));
184: showAlert();
185: buildPortalList();
186: } catch (Exception e) {
187: log(
188: Level.SEVERE,
189: "ListPortalsBean.deletePortal(): Delete Portal operation failed",
190: e);
191: setAlertType("error");
192: setAlertSummary(getFabricI18N("message.deletePortal.failed.summary"));
193: String ptrn = getFabricI18N("message.deletePortal.failed.details");
194: MessageFormat mf = new MessageFormat(ptrn);
195: setAlertDetail(mf.format(params));
196: showAlert();
197: }
198: return null;
199: }
200:
201: }
|