001: /**
002: * $Id: ListInstancesBean.java,v 1.9 2006/05/15 23:27:46 ru111118 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.HashSet;
020: import java.util.Map;
021: import java.util.Iterator;
022: import java.io.IOException;
023: import java.text.MessageFormat;
024:
025: import javax.management.ObjectName;
026:
027: import javax.faces.context.FacesContext;
028: import javax.faces.event.ValueChangeEvent;
029: import javax.faces.el.VariableResolver;
030:
031: import com.sun.data.provider.DataProvider;
032: import com.sun.data.provider.impl.ObjectListDataProvider;
033: import com.sun.web.ui.component.RadioButton;
034: import com.sun.web.ui.model.Option;
035:
036: import com.sun.portal.admin.common.util.AdminClientUtil;
037: import com.sun.portal.admin.common.InstanceAttributes;
038:
039: public class ListInstancesBean extends FabricBaseBean {
040:
041: private DataProvider instances = null;
042: private List instanceList = null;
043: private List names = null;
044: private String portalId = null;
045: private Option[] instanceNames = null;
046:
047: /** Creates a new instance of ListPortalsBean*/
048: public ListInstancesBean() {
049: portalId = (String) getSessionAttribute(ATTR_SELECTED_PORTAL);
050: if (portalId == null) {
051: FacesContext context = FacesContext.getCurrentInstance();
052: VariableResolver vr = context.getApplication()
053: .getVariableResolver();
054: Object obj = (Object) vr.resolveVariable(context,
055: "ListPortalsBean");
056: if ((obj != null) && (obj instanceof ListPortalsBean)) {
057: ListPortalsBean listportalsbean = (ListPortalsBean) obj;
058: portalId = listportalsbean.getCurrentPortal();
059: setSessionAttribute(ATTR_SELECTED_PORTAL, portalId);
060: }
061: }
062: // Initialize the list of Portal Server instances
063: buildInstanceList();
064: }
065:
066: private void buildInstanceList() {
067:
068: instanceList = new ArrayList();
069: names = getInstanceNames();
070: Iterator iter = names.iterator();
071: instanceNames = new Option[names.size()];
072: int count = 0;
073: while (iter.hasNext()) {
074: String name = (String) iter.next();
075: Set names = new HashSet();
076: names.add(InstanceAttributes.HOST);
077: names.add(InstanceAttributes.PORT);
078: names.add(InstanceAttributes.WEB_CONTAINER_TYPE);
079: Map attrs = (Map) getInstanceAttributes(portalId, name,
080: names);
081: Set values = (Set) attrs.get(InstanceAttributes.HOST);
082: String host = values == null ? "" : (String) (values
083: .iterator().next());
084: values = (Set) attrs.get(InstanceAttributes.PORT);
085: String port = values == null ? "" : (String) (values
086: .iterator().next());
087: values = (Set) attrs
088: .get(InstanceAttributes.WEB_CONTAINER_TYPE);
089: String wcType = values == null ? "" : (String) (values
090: .iterator().next());
091: instanceList
092: .add(new InstanceBean(name, host, port, wcType));
093: instanceNames[count] = new Option(name);
094: if (count == 0) {
095: setSessionAttribute(ATTR_SELECTED_INSTANCE, name);
096: }
097: count++;
098: }
099: instances = new ObjectListDataProvider(instanceList);
100: }
101:
102: public DataProvider getInstances() {
103: return instances;
104: }
105:
106: public Option[] getInstancesForDropDown() {
107: return instanceNames;
108: }
109:
110: public Object getCurrentInstance() {
111: return getSessionAttribute(ATTR_SELECTED_INSTANCE);
112: }
113:
114: public void setCurrentInstance(Object currentInstance) {
115: setSessionAttribute(ATTR_SELECTED_INSTANCE, currentInstance);
116: }
117:
118: private List getInstanceNames() {
119: List iNames = new ArrayList();
120: try {
121: Set objNames = getInstanceObjectNames(portalId);
122: Iterator iter = objNames.iterator();
123: while (iter.hasNext()) {
124: iNames
125: .add(getAttribute((ObjectName) iter.next(),
126: "ID"));
127: }
128: } catch (IOException ie) {
129: log(
130: Level.SEVERE,
131: "ListInstancesBean.getInstanceNames(): Exception while trying to get the list of portal instances for portalId = "
132: + portalId, ie);
133: } catch (Exception ex) {
134: log(
135: Level.SEVERE,
136: "ListInstancesBean.getInstanceNames(): Exception while trying to get the list of portal instances for portalId = "
137: + portalId, ex);
138: }
139: return iNames;
140: }
141:
142: public String newInstance() {
143: return "newInstance";
144: }
145:
146: public String deleteInstance() {
147:
148: String status = "";
149: String name = (String) RadioButton.getSelected("rb");
150: // Set the right params and signature
151: Object[] iParams = { name };
152: String[] iSignature = { "java.lang.String" };
153:
154: try {
155: // Get the MBean object for the newly created portal
156: ObjectName iObjName = AdminClientUtil
157: .getPortalMBeanObjectName(
158: AdminClientUtil.DEFAULT_DOMAIN, portalId);
159:
160: log(Level.FINEST, "Invoking deleteInstance for: "
161: + portalId);
162: // Invoke the delete instance operation
163: getMBeanServerConnection().invoke(iObjName,
164: "deleteInstance", iParams, iSignature);
165: setAlertType("information");
166: setAlertSummary(getFabricI18N("message.deleteInstance.success.summary"));
167: String ptrn = getFabricI18N("message.deleteInstance.success.details");
168: MessageFormat mf = new MessageFormat(ptrn);
169: setAlertDetail(mf.format(iParams));
170: showAlert();
171: buildInstanceList();
172: } catch (Exception e) {
173: log(
174: Level.SEVERE,
175: "ListInstancesBean.deleteInstance(): Delete Instance operation failed",
176: e);
177: setAlertType("error");
178: setAlertSummary(getFabricI18N("message.deleteInstance.failed.summary"));
179: String ptrn = getFabricI18N("message.deleteInstance.failed.details");
180: MessageFormat mf = new MessageFormat(ptrn);
181: setAlertDetail(mf.format(iParams));
182: showAlert();
183: }
184: return status;
185: }
186:
187: public String gotoInstanceInfo() {
188: return "instanceInfo";
189: }
190:
191: public void processInstanceChange(ValueChangeEvent evt) {
192: Object currentInstance = evt.getNewValue();
193: log(Level.FINEST,
194: "Processing Value Change for Instance: New Instance="
195: + currentInstance);
196: setCurrentInstance(currentInstance);
197: }
198:
199: }
|