001: /**
002: * $Id: ListConfigurationsBean.java,v 1.4 2005/09/21 15:29:57 fo160993 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.ssoa;
014:
015: import java.util.*;
016: import java.util.logging.Level;
017: import java.io.IOException;
018:
019: import javax.faces.application.FacesMessage;
020: import javax.faces.context.FacesContext;
021: import javax.faces.validator.ValidatorException;
022:
023: import javax.management.ObjectName;
024: import javax.management.MBeanServerConnection;
025: import javax.management.MalformedObjectNameException;
026:
027: import javax.servlet.http.HttpServletRequest;
028:
029: import com.sun.data.provider.DataProvider;
030: import com.sun.data.provider.impl.ObjectListDataProvider;
031: import com.sun.web.ui.component.Checkbox;
032:
033: import com.sun.portal.admin.common.util.AdminClientUtil;
034:
035: import com.sun.portal.admin.console.common.PSBaseBean;
036:
037: public abstract class ListConfigurationsBean extends PSBaseBean {
038:
039: // public static final String ATTR_SELECTED_TEMPLATE = "ssoa.template.selected";
040: // public static final String ATTR_SELECTED_CONFIG = "ssoa.config.selected";
041: // public static final String ATTR_CURRENT_LOCATION_DN = "ssoa.dn.selected";
042:
043: public static final String RB_NAME = "ssoa";
044: // public static final String GLOBAL_LOCATION_DN = "_!global!_";
045:
046: protected Map rbMap;
047:
048: protected DataProvider configurations;
049: protected ObjectName objectName = null;
050:
051: /** Creates a new instance of ListConfigurationsBean*/
052: public ListConfigurationsBean() {
053: log(Level.FINEST, "ListConfigurationsBean.constructor start");
054: // Get resource bundle
055: rbMap = getResourceStringMap(RB_NAME);
056:
057: // MBean path of SSOAdapter.
058: LinkedList path = new LinkedList();
059: path.addFirst(getDomain());
060: path.addFirst("ssoadapter");
061:
062: try {
063: objectName = AdminClientUtil.getResourceMBeanObjectName(
064: AdminClientUtil.SSOADAPTER_MBEAN_TYPE, path);
065: } catch (MalformedObjectNameException e) {
066: log(
067: Level.SEVERE,
068: "ListConfigurationsBean.constructor: Exception when getting MBean object name",
069: e);
070: }
071: //resetConfigurations();
072: }
073:
074: public DataProvider getConfigurations() {
075: return configurations;
076: }
077:
078: // Do the mbean server connection to pull the configurations. Will also reset the data
079: // object to reflect the configurations.
080: // If session attribute ATTR_SELECTED_TEMPLATE is set, pull configurations for selected template.
081: // If session attribute ATTR_CURRENT_LOCATION_DN is set, pull configurations for selected dn.
082: // public abstract void resetConfigurations();
083:
084: public abstract String gotoConfigurationHome();
085:
086: public void createConfiguration() {
087: log(Level.FINEST,
088: "ListConfigurationsBean.createConfiguration start");
089: }
090:
091: public void deleteConfigurations() {
092: log(Level.FINEST,
093: "ListConfigurationsBean.deleteConfigurations start");
094: // RadioButton.getSelected(String groupName) is
095: // a static convenience method that obtains the
096: // selected radio button value from the request map
097: // ONLY when the radio button is part of a group.
098: //
099: List selectedcbs = Checkbox.getSelected("cb");
100: for (Iterator i = selectedcbs.iterator(); i.hasNext();) {
101: deleteConfiguration((String) i.next());
102: }
103: // This will tell the configuration list by dn bean to re-query the list from the MBean
104: setSessionAttribute("resetSSOA", "true");
105: }
106:
107: public void deleteConfiguration(String id) {
108: //String id = (String)RadioButton.getSelected("rb");
109: // The id is in the form of dn|name
110: int sepindex = id.indexOf(ConfigurationBean.ID_SEPARATOR);
111: String dn = id.substring(0, sepindex);
112: String name = id.substring(sepindex + 1);
113: // String dn = (String) getSessionAttribute(ATTR_CURRENT_LOCATION_DN);
114: if ((dn == null) || (dn.length() == 0))
115: dn = GLOBAL_LOCATION_DN;
116: log(Level.FINEST,
117: "ListConfigurationsBean.deleteConfiguration: Deleting config "
118: + name + " from dn " + dn);
119: if ((name == null) || (name.length() == 0)) {
120: log(Level.WARNING,
121: "ListConfigurationsBean.deleteConfiguration: Configuration name is invalid");
122: return;
123: }
124: try {
125: String[] signature = { String.class.getName(),
126: String.class.getName() };
127: Object[] params = { dn, name };
128: MBeanServerConnection connection = getMBeanServerConnection();
129: // This can throw AttributeNotFoundException, MBeanException, InstanceNotFoundException
130: // ReflectionException, RuntimeOperationsException, or IOException
131: connection.invoke(objectName, "deleteConfiguration",
132: params, signature);
133: } catch (Exception ex) {
134: log(
135: Level.SEVERE,
136: "ListConfigurationsBean.deleteConfiguration: Exception when attempting to delete "
137: + name, ex);
138: }
139: //resetConfigurations();
140: }
141:
142: }
|