001: /**
002: * $Id: ProducerBean.java,v 1.7 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.Collections;
017: import java.util.HashMap;
018: import java.util.HashSet;
019: import java.util.Iterator;
020: import java.util.List;
021: import java.util.Map;
022: import java.util.Set;
023: import java.util.logging.Level;
024:
025: import javax.management.ObjectName;
026:
027: import com.sun.data.provider.FieldKey;
028: import com.sun.data.provider.RowKey;
029: import com.sun.data.provider.impl.ObjectListDataProvider;
030: import com.sun.portal.admin.common.AttrOptionConstants;
031: import com.sun.portal.admin.common.util.AdminUtil;
032: import com.sun.web.ui.component.TableRowGroup;
033: import com.sun.web.ui.event.TableSelectPhaseListener;
034: import com.sun.web.ui.model.Option;
035:
036: public class ProducerBean extends ProducerBaseBean implements
037: ProducerAttributes {
038:
039: private String id = null;
040: private boolean dataLoaded = false;
041: private Option[] statusOptions = null;
042: private String status = null;
043: private String wsdlURL = null;
044: private Option[] allPortlets = null;
045: private String[] publishedPortlets = null;
046: private Option[] registrationOptions = null;
047: private String registration = null;
048: private Option[] inbandOptions = null;
049: private String inband = null;
050: private String registrationValidatorClassName = null;
051: private TableSelectPhaseListener tspl = null;
052: private TableRowGroup tableRowGroup = null;
053:
054: public ProducerBean() {
055: id = (String) getSessionAttribute(ATTR_SELECTED_PRODUCER);
056: tspl = new TableSelectPhaseListener();
057: loadData();
058: }
059:
060: private void loadData() {
061: Set names = new HashSet();
062: names.add(ENABLED);
063: names.add(WSDL_URL);
064: names.add(PUBLISHED_PORTLETS);
065: names.add(UNPUBLISHED_PORTLETS);
066: names.add(REGISTRATION_REQUIRED);
067: names.add(IN_BAND_REGISTRATION_SUPPORTED);
068: names.add(REGISTRATION_VALIDATOR_CLASS_NAME);
069: Map optionsMap = new HashMap();
070: optionsMap.put(AttrOptionConstants.OPT_COMPONENT, COMPONENT);
071: optionsMap.put("producer", id);
072: optionsMap.put(AttrOptionConstants.OPT_ATTR_NAMES, names);
073: String[] signature = { Map.class.getName() };
074: Object[] params = { optionsMap };
075:
076: try {
077: ObjectName objectName = AdminUtil.getPortalMBeanObjectName(
078: getDomain(), portalID);
079:
080: Map props = (Map) getMBeanServerConnection().invoke(
081: objectName, "getAttributes", params, signature);
082:
083: String enabledString = (String) ((List) props.get(ENABLED))
084: .get(0);
085: boolean enabled = Boolean.valueOf(enabledString)
086: .booleanValue();
087: status = enabled ? ENABLED : DISABLED;
088: wsdlURL = (String) ((List) props.get(WSDL_URL)).get(0);
089: List portlets = (List) props.get(PUBLISHED_PORTLETS);
090:
091: if (portlets.isEmpty()) {
092: status = DISABLED;
093: showAlert();
094: setAlertType(INFORMATION);
095: setAlertSummary(rb
096: .getString("producer.tab.general.message.enable"));
097: setAlertDetail("");
098: }
099:
100: publishedPortlets = (String[]) portlets
101: .toArray(new String[0]);
102: portlets.addAll((List) props.get(UNPUBLISHED_PORTLETS));
103: allPortlets = new Option[portlets.size()];
104:
105: for (int i = 0; i < portlets.size(); i++) {
106: String portlet = (String) portlets.get(i);
107: allPortlets[i] = new Option(portlet, portlet);
108: }
109:
110: String requiredString = (String) ((List) props
111: .get(REGISTRATION_REQUIRED)).get(0);
112: boolean required = Boolean.valueOf(requiredString)
113: .booleanValue();
114: registration = required ? REQUIRED : NOT_REQUIRED;
115: String supportedString = (String) ((List) props
116: .get(IN_BAND_REGISTRATION_SUPPORTED)).get(0);
117: boolean supported = Boolean.valueOf(supportedString)
118: .booleanValue();
119: inband = supported ? SUPPORTED : UNSUPPORTED;
120: registrationValidatorClassName = (String) ((List) props
121: .get(REGISTRATION_VALIDATOR_CLASS_NAME)).get(0);
122: } catch (Exception e) {
123: log(Level.SEVERE, "ProducerBean.loadData()", e);
124: showAlert();
125: setAlertType(ERROR);
126: setAlertSummary(rb
127: .getString("producer.tab.general.load.failed.summary"));
128: setAlertDetail(rb
129: .getString("producer.tab.general.load.failed.detail"));
130: }
131:
132: dataLoaded = true;
133: }
134:
135: private ObjectListDataProvider loadRegistrationPropertyDesc() {
136: List rpdList = new ArrayList();
137: Map optionsMap = new HashMap();
138: optionsMap.put(AttrOptionConstants.OPT_COMPONENT, COMPONENT);
139: optionsMap.put("producer", id);
140: optionsMap.put(AttrOptionConstants.OPT_ATTR_NAME,
141: REGISTRATION_PROPERTY_DESCRIPTION);
142: String[] signature = { Map.class.getName() };
143: Object[] params = { optionsMap };
144:
145: try {
146: ObjectName objectName = AdminUtil.getPortalMBeanObjectName(
147: getDomain(), portalID);
148:
149: List rpds = (List) getMBeanServerConnection().invoke(
150: objectName, "getAttribute", params, signature);
151:
152: for (int i = 0; i < rpds.size(); i++) {
153: String rpd = (String) rpds.get(i);
154: int index = rpd.indexOf("=");
155: String name = rpd.substring(0, index);
156: String description = rpd.substring(index + 1);
157: SimpleRPBean registrationProperty = new SimpleRPBean();
158: registrationProperty.setName(name);
159: registrationProperty.setDescription(description);
160: rpdList.add(registrationProperty);
161: }
162: } catch (Exception e) {
163: log(Level.SEVERE,
164: "ProducerBean.loadRegistrationPropertyDesc()", e);
165: showAlert();
166: setAlertType(ERROR);
167: setAlertSummary(rb
168: .getString("producer.tab.general.load.failed.summary"));
169: setAlertDetail(rb
170: .getString("producer.tab.general.load.failed.detail"));
171: }
172:
173: ObjectListDataProvider result = new ObjectListDataProvider(
174: rpdList);
175: result.setObjectType(SimpleRPBean.class);
176: return result;
177: }
178:
179: public String getId() {
180: return id;
181: }
182:
183: public Option[] getStatusOptions() {
184: if (statusOptions == null) {
185: statusOptions = getStatusOptionArray();
186: }
187:
188: return statusOptions;
189: }
190:
191: public String getStatus() {
192: if (!dataLoaded) {
193: loadData();
194: }
195:
196: return status;
197: }
198:
199: public void setStatus(String status) {
200: this .status = status;
201: }
202:
203: public String getWSDLURL() {
204: if (!dataLoaded) {
205: loadData();
206: }
207:
208: return wsdlURL;
209: }
210:
211: public Option[] getAllPortlets() {
212: if (!dataLoaded) {
213: loadData();
214: }
215:
216: return allPortlets;
217: }
218:
219: public boolean getHasNoPublishedPortlets() {
220: return getPublishedPortlets().length == 0;
221: }
222:
223: public String[] getPublishedPortlets() {
224: if (!dataLoaded) {
225: loadData();
226: }
227:
228: return publishedPortlets;
229: }
230:
231: public void setPublishedPortlets(String[] portlets) {
232: publishedPortlets = portlets;
233: }
234:
235: public Option[] getRegistrationOptions() {
236: if (registrationOptions == null) {
237: registrationOptions = getRegistrationOptionArray();
238: }
239:
240: return registrationOptions;
241: }
242:
243: public String getRegistration() {
244: if (!dataLoaded) {
245: loadData();
246: }
247:
248: return registration;
249: }
250:
251: public void setRegistration(String registration) {
252: this .registration = registration;
253: }
254:
255: public Option[] getInbandOptions() {
256: if (inbandOptions == null) {
257: inbandOptions = getSupportOptionArray();
258: }
259:
260: return inbandOptions;
261: }
262:
263: public String getInband() {
264: if (!dataLoaded) {
265: loadData();
266: }
267:
268: return inband;
269: }
270:
271: public void setInband(String inband) {
272: this .inband = inband;
273: }
274:
275: public String getRegistrationValidatorClassName() {
276: if (!dataLoaded) {
277: loadData();
278: }
279:
280: return registrationValidatorClassName;
281: }
282:
283: public void setRegistrationValidatorClassName(String rvcn) {
284: this .registrationValidatorClassName = rvcn;
285: }
286:
287: public TableRowGroup getTableRowGroup() {
288: return tableRowGroup;
289: }
290:
291: public void setTableRowGroup(TableRowGroup tableRowGroup) {
292: this .tableRowGroup = tableRowGroup;
293: }
294:
295: public Object getSelected() {
296: return tspl.getSelected(getTableRow());
297: }
298:
299: public void setSelected(Object object) {
300: RowKey rowKey = getTableRow();
301:
302: if (rowKey != null) {
303: tspl.setSelected(rowKey, object);
304: }
305: }
306:
307: public ObjectListDataProvider getRegistrationPropertyDesc() {
308: ObjectListDataProvider registrationPropertyDesc = (ObjectListDataProvider) getSessionAttribute(ATTR_RPDS);
309:
310: if (registrationPropertyDesc == null) {
311: registrationPropertyDesc = loadRegistrationPropertyDesc();
312: setSessionAttribute(ATTR_RPDS, registrationPropertyDesc);
313: }
314:
315: return registrationPropertyDesc;
316: }
317:
318: public void setRegistrationPropertyDesc(
319: ObjectListDataProvider registrationPropertyDesc) {
320: setSessionAttribute(ATTR_RPDS, registrationPropertyDesc);
321: }
322:
323: public void addRPD() {
324: ObjectListDataProvider registrationPropertyDesc = getRegistrationPropertyDesc();
325:
326: if (registrationPropertyDesc.canAppendRow()) {
327: registrationPropertyDesc.appendRow();
328: }
329:
330: registrationPropertyDesc.commitChanges();
331: }
332:
333: public void deleteRPDs() {
334: ObjectListDataProvider registrationPropertyDesc = getRegistrationPropertyDesc();
335: RowKey[] rowKeys = tableRowGroup.getRenderedRowKeys();
336:
337: if (rowKeys != null) {
338: for (int i = 0; i < rowKeys.length; i++) {
339: RowKey rowKey = rowKeys[i];
340:
341: if (tspl.isSelected(rowKey)
342: && registrationPropertyDesc
343: .isRowAvailable(rowKey)
344: && registrationPropertyDesc
345: .canRemoveRow(rowKey)) {
346:
347: registrationPropertyDesc.removeRow(rowKey);
348: }
349: }
350:
351: registrationPropertyDesc.commitChanges();
352: tableRowGroup.setFirst(0);
353: tspl.clear();
354: }
355: }
356:
357: public void save() {
358: Map optionsMap = new HashMap();
359: optionsMap.put(AttrOptionConstants.OPT_COMPONENT, COMPONENT);
360: optionsMap.put("producer", id);
361: Map nameValues = new HashMap();
362: String enabledString = Boolean.toString(ENABLED.equals(status));
363: nameValues.put(ENABLED, Collections
364: .singletonList(enabledString));
365: nameValues.put(PUBLISHED_PORTLETS,
366: arrayToList(publishedPortlets));
367: String requiredString = Boolean.toString(REQUIRED
368: .equals(registration));
369:
370: nameValues.put(REGISTRATION_REQUIRED, Collections
371: .singletonList(requiredString));
372:
373: String supportedString = Boolean.toString(SUPPORTED
374: .equals(inband));
375:
376: nameValues.put(IN_BAND_REGISTRATION_SUPPORTED, Collections
377: .singletonList(supportedString));
378:
379: nameValues.put(REGISTRATION_VALIDATOR_CLASS_NAME, Collections
380: .singletonList(registrationValidatorClassName));
381:
382: ObjectListDataProvider registrationPropertyDesc = getRegistrationPropertyDesc();
383: List rpds = new ArrayList();
384: registrationPropertyDesc.commitChanges();
385: List rpdList = registrationPropertyDesc.getList();
386:
387: for (int i = 0; i < rpdList.size(); i++) {
388: SimpleRPBean registrationProperty = (SimpleRPBean) rpdList
389: .get(i);
390: String name = registrationProperty.getName();
391: String description = registrationProperty.getDescription();
392: name = (name == null) ? "" : name.trim();
393: description = (description == null) ? "" : description
394: .trim();
395:
396: if (name.length() > 0) {
397: rpds.add(name + "=" + description);
398: }
399: }
400:
401: nameValues.put(REGISTRATION_PROPERTY_DESCRIPTION, rpds);
402: String[] signature = { Map.class.getName(), Map.class.getName() };
403: Object[] params = { nameValues, optionsMap };
404:
405: try {
406: ObjectName objectName = AdminUtil.getPortalMBeanObjectName(
407: getDomain(), portalID);
408:
409: getMBeanServerConnection().invoke(objectName,
410: "setAttributes", params, signature);
411:
412: showAlert();
413: setAlertType(INFORMATION);
414: setAlertSummary(rb
415: .getString("generic.save.success.summary"));
416: setAlertDetail("");
417: } catch (Exception e) {
418: log(Level.SEVERE, "ProducerBean.save()", e);
419: showAlert();
420: setAlertType(WARNING);
421: setAlertSummary(rb.getString("generic.save.failed.summary"));
422: setAlertDetail(rb.getString("generic.save.failed.detail"));
423: }
424: }
425:
426: public String reset() {
427: dataLoaded = false;
428: removeFromSession(ATTR_RPDS);
429: return "success";
430: }
431:
432: private RowKey getTableRow() {
433: return getTableRow("#{rpd.tableRow}");
434: }
435: }
|