001: /**
002: * $Id: CRsTabBean.java,v 1.4 2005/09/21 15:30:01 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.wsrp.producer;
014:
015: import java.util.ArrayList;
016: import java.util.Iterator;
017: import java.util.List;
018: import java.util.Set;
019: import java.util.StringTokenizer;
020: import java.util.logging.Level;
021:
022: import javax.management.ObjectName;
023:
024: import com.sun.data.provider.FieldKey;
025: import com.sun.data.provider.RowKey;
026: import com.sun.data.provider.impl.ObjectListDataProvider;
027: import com.sun.portal.admin.common.util.AdminUtil;
028: import com.sun.web.ui.component.TableRowGroup;
029: import com.sun.web.ui.event.TableSelectPhaseListener;
030:
031: public class CRsTabBean extends ProducerBaseBean {
032: public static final String TAB = "\t";
033: public static final FieldKey HANDLE = new FieldKey("handle");
034: private TableSelectPhaseListener tspl = null;
035: private TableRowGroup tableRowGroup = null;
036: private ObjectListDataProvider consumerRegistrations = null;
037:
038: public CRsTabBean() {
039: tspl = new TableSelectPhaseListener();
040: removeFromSession(ATTR_RPDS);
041:
042: NewConsumerRegistrationBean newConsumerRegistrationBean = (NewConsumerRegistrationBean) getSessionAttribute("NewConsumerRegistrationBean");
043:
044: if (newConsumerRegistrationBean != null) {
045: newConsumerRegistrationBean.clearData();
046: }
047: }
048:
049: public TableRowGroup getTableRowGroup() {
050: return tableRowGroup;
051: }
052:
053: public void setTableRowGroup(TableRowGroup tableRowGroup) {
054: this .tableRowGroup = tableRowGroup;
055: }
056:
057: public Object getSelected() {
058: return tspl.getSelected(getTableRow());
059: }
060:
061: public void setSelected(Object object) {
062: RowKey rowKey = getTableRow();
063:
064: if (rowKey != null) {
065: tspl.setSelected(rowKey, object);
066: }
067: }
068:
069: public ObjectListDataProvider getConsumerRegistrations() {
070: if (consumerRegistrations == null) {
071: List regs = new ArrayList();
072:
073: // MBean path of Producer.
074: List path = getProducerPath();
075:
076: try {
077: // Object name of Producer.
078: ObjectName objectName = AdminUtil
079: .getResourceMBeanObjectName(PRODUCER_TYPE, path);
080:
081: Set registrations = (Set) getMBeanServerConnection()
082: .invoke(objectName,
083: "listConsumerRegistrations", null, null);
084:
085: for (Iterator i = registrations.iterator(); i.hasNext();) {
086: String registration = (String) i.next();
087: StringTokenizer st = new StringTokenizer(
088: registration, TAB);
089: String handle = st.hasMoreTokens() ? st.nextToken()
090: : null;
091: String enabledString = st.hasMoreTokens() ? st
092: .nextToken() : null;
093: boolean enabled = Boolean.valueOf(enabledString)
094: .booleanValue();
095:
096: String status = enabled ? rb
097: .getString("generic.label.enabled") : rb
098: .getString("generic.label.disabled");
099:
100: String name = st.hasMoreTokens() ? st.nextToken()
101: : null;
102: SimpleCRBean cr = new SimpleCRBean();
103: cr.setHandle(handle);
104: cr.setStatus(status);
105: cr.setName(name);
106: regs.add(cr);
107: }
108: } catch (Exception e) {
109: log(Level.SEVERE,
110: "CRsTabBean.getConsumerRegistrations()", e);
111: showAlert();
112: setAlertType(ERROR);
113: setAlertSummary(rb
114: .getString("producer.tab.crs.load.failed.summary"));
115: setAlertDetail(rb
116: .getString("producer.tab.crs.load.failed.detail"));
117: }
118:
119: consumerRegistrations = new ObjectListDataProvider(regs);
120: consumerRegistrations.setObjectType(SimpleCRBean.class);
121: }
122:
123: return consumerRegistrations;
124: }
125:
126: public void setConsumerRegistrations(
127: ObjectListDataProvider consumerRegistrations) {
128: this .consumerRegistrations = consumerRegistrations;
129: }
130:
131: public String deleteConsumerRegistrations() {
132: RowKey[] rowKeys = tableRowGroup.getRenderedRowKeys();
133:
134: if (rowKeys != null) {
135: List path = getProducerPath();
136: String[] signature = { String.class.getName() };
137:
138: for (int i = 0; i < rowKeys.length; i++) {
139: RowKey rowKey = rowKeys[i];
140:
141: if (tspl.isSelected(rowKey)) {
142: String handle = (String) consumerRegistrations
143: .getValue(HANDLE, rowKey);
144: Object[] params = { handle };
145:
146: try {
147: ObjectName objectName = AdminUtil
148: .getResourceMBeanObjectName(
149: PRODUCER_TYPE, path);
150:
151: getMBeanServerConnection().invoke(objectName,
152: "deleteConsumerRegistration", params,
153: signature);
154:
155: if (consumerRegistrations
156: .isRowAvailable(rowKey)
157: && consumerRegistrations
158: .canRemoveRow(rowKey)) {
159:
160: consumerRegistrations.removeRow(rowKey);
161: }
162: } catch (Exception e) {
163: log(
164: Level.SEVERE,
165: "CRsTabBean.deleteConsumerRegistrations()",
166: e);
167: showAlert();
168: setAlertType(WARNING);
169: setAlertSummary(rb
170: .getString("producer.tab.crs.deleteCRs.failed.summary"));
171: setAlertDetail(rb
172: .getString("producer.tab.crs.deleteCRs.failed.detail"));
173: }
174: }
175: }
176:
177: consumerRegistrations.commitChanges();
178: tableRowGroup.setFirst(0);
179: tspl.clear();
180: }
181:
182: return "success";
183: }
184:
185: public String editConsumerRegistration() {
186: setRequestAttributeInSession(ATTR_SELECTED_CONSUMER_REGISTRATION);
187: return "editConsumerRegistration";
188: }
189:
190: private RowKey getTableRow() {
191: return getTableRow("#{consumerRegistration.tableRow}");
192: }
193: }
|