001: /**
002: * $Id: ConsumerRegistrationBean.java,v 1.6 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.List;
020: import java.util.Map;
021: import java.util.Set;
022: import java.util.logging.Level;
023:
024: import javax.management.ObjectName;
025:
026: import com.sun.data.provider.impl.ObjectListDataProvider;
027: import com.sun.portal.admin.common.AttrOptionConstants;
028: import com.sun.portal.admin.common.util.AdminUtil;
029: import com.sun.web.ui.model.Option;
030:
031: public class ConsumerRegistrationBean extends ProducerBaseBean
032: implements CRAttributes {
033:
034: private String producerID = null;
035: private String handle = null;
036: private boolean dataLoaded = false;
037: private String name = null;
038: private Option[] statusOptions = null;
039: private String status = null;
040: private String consumerAgent = null;
041: private Option[] methodGetOptions = null;
042: private String methodGet = null;
043: private Option[] standardModes = null;
044: private String[] consumerModes = null;
045: private Option[] standardWindowStates = null;
046: private String[] consumerWindowStates = null;
047: private Option[] standardUserScopes = null;
048: private String[] consumerUserScopes = null;
049: private String[] customUserProfileData = null;
050: private ObjectListDataProvider registrationProperties = null;
051:
052: public ConsumerRegistrationBean() {
053: producerID = (String) getSessionAttribute(ATTR_SELECTED_PRODUCER);
054: handle = (String) getSessionAttribute(ATTR_SELECTED_CONSUMER_REGISTRATION);
055: }
056:
057: private void loadData() {
058: Set names = new HashSet();
059: names.add(CONSUMER_NAME);
060: names.add(ENABLED);
061: names.add(CONSUMER_AGENT);
062: names.add(METHOD_GET_SUPPORTED);
063: names.add(CONSUMER_MODES);
064: names.add(CONSUMER_WINDOW_STATES);
065: names.add(CONSUMER_USER_SCOPES);
066: names.add(CUSTOM_USER_PROFILE_DATA);
067: names.add(REGISTRATION_PROPERTIES);
068: Map optionsMap = new HashMap();
069: optionsMap.put(AttrOptionConstants.OPT_COMPONENT, COMPONENT);
070: optionsMap.put("producer", producerID);
071: optionsMap.put("registrationhandle", handle);
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: name = (String) ((List) props.get(CONSUMER_NAME)).get(0);
084: String enabledString = (String) ((List) props.get(ENABLED))
085: .get(0);
086: boolean enabled = Boolean.valueOf(enabledString)
087: .booleanValue();
088: status = enabled ? ENABLED : DISABLED;
089: consumerAgent = (String) ((List) props.get(CONSUMER_AGENT))
090: .get(0);
091: String supportedString = (String) ((List) props
092: .get(METHOD_GET_SUPPORTED)).get(0);
093: boolean supported = Boolean.valueOf(supportedString)
094: .booleanValue();
095: methodGet = supported ? SUPPORTED : UNSUPPORTED;
096: List cm = (List) props.get(CONSUMER_MODES);
097: consumerModes = (String[]) cm.toArray(new String[0]);
098: List cws = (List) props.get(CONSUMER_WINDOW_STATES);
099: consumerWindowStates = (String[]) cws
100: .toArray(new String[0]);
101: List cus = (List) props.get(CONSUMER_USER_SCOPES);
102: consumerUserScopes = (String[]) cus.toArray(new String[0]);
103: List cupd = (List) props.get(CUSTOM_USER_PROFILE_DATA);
104: customUserProfileData = (String[]) cupd
105: .toArray(new String[0]);
106: optionsMap.remove("registrationhandle");
107: optionsMap.remove(AttrOptionConstants.OPT_ATTR_NAMES);
108:
109: optionsMap
110: .put(
111: AttrOptionConstants.OPT_ATTR_NAME,
112: ProducerAttributes.REGISTRATION_PROPERTY_DESCRIPTION);
113:
114: List rpds = (List) getMBeanServerConnection().invoke(
115: objectName, "getAttribute", params, signature);
116:
117: List rps = (List) props.get(REGISTRATION_PROPERTIES);
118: registrationProperties = getRPs(rpds, rps);
119: } catch (Exception e) {
120: log(Level.SEVERE, "ConsumerRegistrationBean.loadData()", e);
121: showAlert();
122: setAlertType(ERROR);
123: setAlertSummary(rb
124: .getString("consumerRegistration.load.failed.summary"));
125: setAlertDetail(rb
126: .getString("consumerRegistration.load.failed.detail"));
127: }
128:
129: dataLoaded = true;
130: }
131:
132: private ObjectListDataProvider getRPs(List rpds, List rps) {
133: List rpList = new ArrayList(rpds.size());
134:
135: for (int i = 0; i < rpds.size(); i++) {
136: String rpd = (String) rpds.get(i);
137: int index = rpd.indexOf("=");
138: String name = rpd.substring(0, index);
139: String description = rpd.substring(index + 1);
140: String namePlusEqualSign = name + "=";
141: String value = "";
142:
143: for (int j = 0; j < rps.size(); j++) {
144: String rp = (String) rps.get(j);
145:
146: if (rp.startsWith(namePlusEqualSign)) {
147: value = rp.substring(namePlusEqualSign.length());
148: break;
149: }
150: }
151:
152: SimpleRPBean registrationProperty = new SimpleRPBean();
153: registrationProperty.setName(name);
154: registrationProperty.setDescription(description);
155: registrationProperty.setPropValue(value);
156: rpList.add(registrationProperty);
157: }
158:
159: ObjectListDataProvider result = new ObjectListDataProvider(
160: rpList);
161: result.setObjectType(SimpleRPBean.class);
162: return result;
163: }
164:
165: public String getHandle() {
166: return handle;
167: }
168:
169: public String getName() {
170: if (!dataLoaded) {
171: loadData();
172: }
173:
174: return name;
175: }
176:
177: public void setName(String name) {
178: this .name = name;
179: }
180:
181: public Option[] getStatusOptions() {
182: if (statusOptions == null) {
183: statusOptions = getStatusOptionArray();
184: }
185:
186: return statusOptions;
187: }
188:
189: public String getStatus() {
190: if (!dataLoaded) {
191: loadData();
192: }
193:
194: return status;
195: }
196:
197: public void setStatus(String status) {
198: this .status = status;
199: }
200:
201: public String getConsumerAgent() {
202: if (!dataLoaded) {
203: loadData();
204: }
205:
206: return consumerAgent;
207: }
208:
209: public void setConsumerAgent(String consumerAgent) {
210: this .consumerAgent = consumerAgent;
211: }
212:
213: public Option[] getMethodGetOptions() {
214: if (methodGetOptions == null) {
215: methodGetOptions = getSupportOptionArray();
216: }
217:
218: return methodGetOptions;
219: }
220:
221: public String getMethodGet() {
222: if (!dataLoaded) {
223: loadData();
224: }
225:
226: return methodGet;
227: }
228:
229: public void setMethodGet(String methodGet) {
230: this .methodGet = methodGet;
231: }
232:
233: public Option[] getStandardModes() {
234: if (standardModes == null) {
235: standardModes = new Option[] { new Option("", ""),
236: new Option("wsrp:view", "wsrp:view"),
237: new Option("wsrp:edit", "wsrp:edit"),
238: new Option("wsrp:help", "wsrp:help"), };
239: }
240:
241: return standardModes;
242: }
243:
244: public String[] getConsumerModes() {
245: if (!dataLoaded) {
246: loadData();
247: }
248:
249: return consumerModes;
250: }
251:
252: public void setConsumerModes(String[] consumerModes) {
253: this .consumerModes = consumerModes;
254: }
255:
256: public Option[] getStandardWindowStates() {
257: if (standardWindowStates == null) {
258: standardWindowStates = new Option[] { new Option("", ""),
259: new Option("wsrp:normal", "wsrp:normal"),
260: new Option("wsrp:minimized", "wsrp:minimized"),
261: new Option("wsrp:maximized", "wsrp:maximized"), };
262: }
263:
264: return standardWindowStates;
265: }
266:
267: public String[] getConsumerWindowStates() {
268: if (!dataLoaded) {
269: loadData();
270: }
271:
272: return consumerWindowStates;
273: }
274:
275: public void setConsumerWindowStates(String[] consumerWindowStates) {
276: this .consumerWindowStates = consumerWindowStates;
277: }
278:
279: public Option[] getStandardUserScopes() {
280: if (standardUserScopes == null) {
281: standardUserScopes = new Option[] { new Option("", ""),
282: new Option("wsrp:perUser", "wsrp:perUser"),
283: new Option("wsrp:forAll", "wsrp:forAll"), };
284: }
285:
286: return standardUserScopes;
287: }
288:
289: public String[] getConsumerUserScopes() {
290: if (!dataLoaded) {
291: loadData();
292: }
293:
294: return consumerUserScopes;
295: }
296:
297: public void setConsumerUserScopes(String[] consumerUserScopes) {
298: this .consumerUserScopes = consumerUserScopes;
299: }
300:
301: public String[] getCustomUserProfileData() {
302: if (!dataLoaded) {
303: loadData();
304: }
305:
306: return customUserProfileData;
307: }
308:
309: public void setCustomUserProfileData(String[] customUserProfileData) {
310: this .customUserProfileData = customUserProfileData;
311: }
312:
313: public ObjectListDataProvider getRegistrationProperties() {
314: if (!dataLoaded) {
315: loadData();
316: }
317:
318: return registrationProperties;
319: }
320:
321: public void setRegistrationProperties(
322: ObjectListDataProvider registrationProperties) {
323: this .registrationProperties = registrationProperties;
324: }
325:
326: public String ok() {
327: Map optionsMap = new HashMap();
328: optionsMap.put(AttrOptionConstants.OPT_COMPONENT, COMPONENT);
329: optionsMap.put("producer", producerID);
330: optionsMap.put("registrationhandle", handle);
331: Map nameValues = new HashMap();
332: nameValues.put(CONSUMER_NAME, Collections.singletonList(name));
333: String enabledString = Boolean.toString(ENABLED.equals(status));
334: nameValues.put(ENABLED, Collections
335: .singletonList(enabledString));
336: nameValues.put(CONSUMER_AGENT, Collections
337: .singletonList(consumerAgent));
338: String supportedString = Boolean.toString(SUPPORTED
339: .equals(methodGet));
340: nameValues.put(METHOD_GET_SUPPORTED, Collections
341: .singletonList(supportedString));
342: nameValues.put(CONSUMER_MODES, arrayToList(consumerModes));
343: nameValues.put(CONSUMER_WINDOW_STATES,
344: arrayToList(consumerWindowStates));
345: nameValues.put(CONSUMER_USER_SCOPES,
346: arrayToList(consumerUserScopes));
347: nameValues.put(CUSTOM_USER_PROFILE_DATA,
348: arrayToList(customUserProfileData));
349:
350: if (registrationProperties.getRowCount() > 0) {
351: List rps = new ArrayList();
352: registrationProperties.commitChanges();
353: List rpList = registrationProperties.getList();
354:
355: for (int i = 0; i < rpList.size(); i++) {
356: SimpleRPBean registrationProperty = (SimpleRPBean) rpList
357: .get(i);
358: String name = registrationProperty.getName();
359: String value = registrationProperty.getPropValue();
360: rps.add(name + "=" + value);
361: }
362:
363: nameValues.put(REGISTRATION_PROPERTIES, rps);
364: }
365:
366: String[] signature = { Map.class.getName(), Map.class.getName() };
367: Object[] params = { nameValues, optionsMap };
368:
369: try {
370: ObjectName objectName = AdminUtil.getPortalMBeanObjectName(
371: getDomain(), portalID);
372:
373: getMBeanServerConnection().invoke(objectName,
374: "setAttributes", params, signature);
375:
376: return "success";
377: } catch (Exception e) {
378: log(Level.SEVERE, "ConsumerRegistrationBean.ok()", e);
379: showAlert();
380: setAlertType(WARNING);
381: setAlertSummary(rb.getString("generic.save.failed.summary"));
382: setAlertDetail(rb.getString("generic.save.failed.detail"));
383: return "failed";
384: }
385: }
386:
387: public String cancel() {
388: return "success";
389: }
390: }
|