001: /**
002: * $Id: NewConsumerRegistrationBean.java,v 1.3 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.List;
019: import java.util.Map;
020: import java.util.Properties;
021: import java.util.logging.Level;
022:
023: import javax.faces.context.FacesContext;
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.event.WizardEvent;
030: import com.sun.web.ui.event.WizardEventListener;
031: import com.sun.web.ui.model.Option;
032:
033: public class NewConsumerRegistrationBean extends ProducerBaseBean
034: implements CRAttributes, WizardEventListener {
035:
036: private String name = "";
037: private Option[] statusOptions = null;
038: private String status = ENABLED;
039: private String consumerAgent = "";
040: private Option[] methodGetOptions = null;
041: private String methodGet = UNSUPPORTED;
042: private ObjectListDataProvider registrationProperties = null;
043:
044: public String getName() {
045: return name;
046: }
047:
048: public void setName(String name) {
049: this .name = name;
050: }
051:
052: public Option[] getStatusOptions() {
053: if (statusOptions == null) {
054: statusOptions = getStatusOptionArray();
055: }
056:
057: return statusOptions;
058: }
059:
060: public String getStatus() {
061: return status;
062: }
063:
064: public void setStatus(String status) {
065: this .status = status;
066: }
067:
068: public String getStatusText() {
069: return ENABLED.equals(status) ? rb
070: .getString("generic.label.enabled") : rb
071: .getString("generic.label.disabled");
072: }
073:
074: public String getConsumerAgent() {
075: return consumerAgent;
076: }
077:
078: public void setConsumerAgent(String consumerAgent) {
079: this .consumerAgent = consumerAgent;
080: }
081:
082: public Option[] getMethodGetOptions() {
083: if (methodGetOptions == null) {
084: methodGetOptions = getSupportOptionArray();
085: }
086:
087: return methodGetOptions;
088: }
089:
090: public String getMethodGet() {
091: return methodGet;
092: }
093:
094: public void setMethodGet(String methodGet) {
095: this .methodGet = methodGet;
096: }
097:
098: public String getMethodGetText() {
099: return SUPPORTED.equals(methodGet) ? rb
100: .getString("generic.label.supported") : rb
101: .getString("generic.label.unsupported");
102: }
103:
104: public ObjectListDataProvider getRegistrationProperties() {
105: if (registrationProperties == null) {
106: List rpds = loadRegistrationPropertyDescriptions();
107: List rpList = new ArrayList();
108:
109: for (int i = 0; i < rpds.size(); i++) {
110: String rpd = (String) rpds.get(i);
111: int index = rpd.indexOf("=");
112: String name = rpd.substring(0, index);
113: String description = rpd.substring(index + 1);
114: SimpleRPBean registrationProperty = new SimpleRPBean();
115: registrationProperty.setName(name);
116: registrationProperty.setDescription(description);
117: registrationProperty.setPropValue("");
118: rpList.add(registrationProperty);
119: }
120:
121: registrationProperties = new ObjectListDataProvider(rpList);
122: registrationProperties.setObjectType(SimpleRPBean.class);
123: }
124:
125: registrationProperties.commitChanges();
126: return registrationProperties;
127: }
128:
129: public void setRegistrationProperties(
130: ObjectListDataProvider registrationProperties) {
131: this .registrationProperties = registrationProperties;
132: }
133:
134: public boolean getHasRegistrationProperties() {
135: return getRegistrationProperties().getRowCount() > 0;
136: }
137:
138: public boolean handleEvent(WizardEvent event) {
139: switch (event.getNavigationEvent()) {
140: case WizardEvent.CANCEL:
141: case WizardEvent.CLOSE:
142: clearData();
143: break;
144: case WizardEvent.FINISH:
145: createConsumerRegistration();
146: break;
147: default:
148: break;
149: }
150:
151: return true;
152: }
153:
154: public boolean isTransient() {
155: return false;
156: }
157:
158: public void setTransient(boolean flag) {
159: }
160:
161: public Object saveState(FacesContext context) {
162: return null;
163: }
164:
165: public void restoreState(FacesContext context, Object state) {
166: }
167:
168: public void clearData() {
169: name = "";
170: status = ENABLED;
171: consumerAgent = "";
172: methodGet = UNSUPPORTED;
173: registrationProperties = null;
174: }
175:
176: private List loadRegistrationPropertyDescriptions() {
177: String producerID = (String) getSessionAttribute(ATTR_SELECTED_PRODUCER);
178: Map optionsMap = new HashMap();
179: optionsMap.put(AttrOptionConstants.OPT_COMPONENT, COMPONENT);
180: optionsMap.put("producer", producerID);
181:
182: optionsMap.put(AttrOptionConstants.OPT_ATTR_NAME,
183: ProducerAttributes.REGISTRATION_PROPERTY_DESCRIPTION);
184:
185: String[] signature = { Map.class.getName() };
186: Object[] params = { optionsMap };
187:
188: try {
189: ObjectName objectName = AdminUtil.getPortalMBeanObjectName(
190: getDomain(), portalID);
191:
192: return (List) getMBeanServerConnection().invoke(objectName,
193: "getAttribute", params, signature);
194: } catch (Exception e) {
195: // TODO: handle exception
196: log(
197: Level.SEVERE,
198: "NewConsumerRegistrationBean.loadRegistrationPropertyDescriptions()",
199: e);
200: return Collections.EMPTY_LIST;
201: }
202: }
203:
204: private void createConsumerRegistration() {
205: Properties registrationData = new Properties();
206: registrationData.setProperty(CONSUMER_NAME, name);
207: String enabledString = Boolean.toString(ENABLED.equals(status));
208: registrationData.setProperty(ENABLED, enabledString);
209: registrationData.setProperty(CONSUMER_AGENT, consumerAgent);
210: String supportedString = Boolean.toString(SUPPORTED
211: .equals(methodGet));
212: registrationData.setProperty(METHOD_GET_SUPPORTED,
213: supportedString);
214: registrationProperties.commitChanges();
215: List rpList = registrationProperties.getList();
216:
217: for (int i = 0; i < rpList.size(); i++) {
218: SimpleRPBean registrationProperty = (SimpleRPBean) rpList
219: .get(i);
220: String name = registrationProperty.getName();
221: String value = registrationProperty.getPropValue();
222: String key = "RegistrationProperties[" + name + "]";
223: registrationData.setProperty(key, value);
224: }
225:
226: // MBean path of Producer.
227: List path = getProducerPath();
228:
229: try {
230: // Object name of Producer.
231: ObjectName objectName = AdminUtil
232: .getResourceMBeanObjectName(PRODUCER_TYPE, path);
233:
234: String[] signature = { Properties.class.getName() };
235: Object[] params = { registrationData };
236:
237: getMBeanServerConnection().invoke(objectName,
238: "createConsumerRegistration", params, signature);
239:
240: setAlertType(INFORMATION);
241: setAlertSummary(rb
242: .getString("newConsumerRegistrationResult.success.summary"));
243: setAlertDetail(rb
244: .getString("newConsumerRegistrationResult.success.detail"));
245: } catch (Exception e) {
246: log(
247: Level.SEVERE,
248: "NewConsumerRegistrationBean.createConsumerRegistration()",
249: e);
250: setAlertType(ERROR);
251: setAlertSummary(rb
252: .getString("newConsumerRegistrationResult.failed.summary"));
253: setAlertDetail(rb
254: .getString("newConsumerRegistrationResult.failed.detail"));
255: }
256: }
257: }
|