001: /**
002: * $Id: ChannelContainerBaseBean.java,v 1.15 2005/10/21 01:29:26 cathywu 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.desktop;
014:
015: import java.util.Map;
016: import java.util.LinkedList;
017: import java.util.logging.Level;
018:
019: import java.text.MessageFormat;
020:
021: import javax.management.MBeanServerConnection;
022: import javax.management.ObjectName;
023: import javax.management.InstanceNotFoundException;
024: import javax.management.MBeanException;
025: import javax.management.ReflectionException;
026:
027: import javax.faces.validator.ValidatorException;
028: import javax.faces.component.UIComponent;
029: import javax.faces.application.FacesMessage;
030: import javax.faces.context.FacesContext;
031: import javax.faces.el.VariableResolver;
032:
033: import com.sun.web.ui.model.Option;
034:
035: import com.sun.portal.admin.common.util.AdminClientUtil;
036: import com.sun.portal.admin.common.PSMBeanException;
037:
038: import com.sun.portal.admin.console.common.PSBaseBean;
039: import com.sun.portal.admin.console.fabric.ListPortalsBean;
040:
041: /**
042: * @author cathywu
043: */
044: public class ChannelContainerBaseBean extends PSBaseBean {
045: public static final String RB_NAME = "desktop";
046: public static final int CREATE_CHANNEL = 1;
047: public static final int DELETE_CHANNEL = 2;
048: public static final int CREATE_CONTAINER = 3;
049: public static final int DELETE_CONTAINER = 4;
050: public static final String CHANNEL = "Channel";
051: public static final String CONTAINER = "Container";
052:
053: protected Map rbMap;
054: protected String cancelText = "Cancel";
055: //protected Boolean disableDelete;
056:
057: //alert member variables
058: protected Boolean displayError;
059: protected String alertSummary;
060: protected String alertDetail;
061: protected String alertType;
062: protected String logMessage;
063:
064: //Member variables for JMX connection
065: protected MBeanServerConnection mbsc;
066: protected String portalId;
067: protected String dn;
068: protected String treeContainer = null;
069:
070: //flag to regenerate channel/container list to be deleted
071: protected Boolean regenerate = null;
072: protected Boolean disableCreate;
073: protected String channelOrContainer;
074:
075: protected Option[] channelContainerSelections = {
076: new Option(CHANNEL, "Channel"),
077: new Option(CONTAINER, "Container") };
078:
079: public ChannelContainerBaseBean() {
080: //setup initial screen
081: rbMap = getResourceStringMap(RB_NAME);
082: if (rbMap != null) {
083: cancelText = (String) rbMap.get("cancel.button");
084:
085: //initialize channel or container selections
086: channelContainerSelections[0].setLabel((String) rbMap
087: .get("createChannel.channelorContainer.channel"));
088: channelContainerSelections[0].setValue(CHANNEL);
089: channelContainerSelections[1].setLabel((String) rbMap
090: .get("createChannel.channelorContainer.container"));
091: channelContainerSelections[1].setValue(CONTAINER);
092: }
093:
094: //setup jmx connection, portal Id, and dn
095: mbsc = getMBeanServerConnection();
096: portalId = (String) getSessionAttribute(ATTR_SELECTED_PORTAL);
097: dn = (String) getCurrentDN();
098:
099: if (portalId == null) {
100: FacesContext context = FacesContext.getCurrentInstance();
101: VariableResolver vr = context.getApplication()
102: .getVariableResolver();
103: Object obj = (Object) vr.resolveVariable(context,
104: "ListPortalsBean");
105: if ((obj != null) && (obj instanceof ListPortalsBean)) {
106: ListPortalsBean epropsbean = (ListPortalsBean) obj;
107: portalId = epropsbean.getCurrentPortal();
108: setSessionAttribute(ATTR_SELECTED_PORTAL, portalId);
109: }
110: }
111:
112: if (dn == null) {
113: dn = GLOBAL_LOCATION_DN;
114: }
115:
116: log(Level.FINEST, "ChannelContainerBean(), current dn: " + dn);
117: log(Level.FINEST, "ChannelContainerBean(), portal: " + portalId);
118:
119: displayError = Boolean.FALSE;
120: }
121:
122: public void setChannelOrContainer(String value) {
123: channelOrContainer = value;
124: }
125:
126: public String getChannelOrContainer() {
127: return channelOrContainer;
128: }
129:
130: /**
131: * Channel or Container
132: */
133: public Object[] getChannelContainerSelections() {
134: if (getDisplayError() == Boolean.TRUE) {
135: setDisplayError(Boolean.FALSE);
136: }
137: return (Object[]) channelContainerSelections;
138: }
139:
140: /**
141: * validator for channel and container name
142: */
143: public void validateChannelName(FacesContext ctx, UIComponent comp,
144: Object value) {
145:
146: String sm = (String) rbMap.get("error.validation.summary");
147: String dm = (String) rbMap.get("error.letterordigit");
148: String cn = (String) value;
149: for (int i = 0; i < cn.length(); i++) {
150: char c = cn.charAt(i);
151: if (!Character.isLetterOrDigit(c) && (c != '_')) {
152: throw new ValidatorException(new FacesMessage(sm, dm));
153: }
154: }
155: }
156:
157: /**
158: * Regenerate flag
159: */
160: public void setRegenerate(boolean val) {
161: regenerate = new Boolean(val);
162: setSessionAttribute(ATTR_REGENERATE_CHANNELS, regenerate);
163: }
164:
165: public boolean getRegenerate() {
166: regenerate = (Boolean) getSessionAttribute(ATTR_REGENERATE_CHANNELS);
167: if (regenerate != null) {
168: return regenerate.booleanValue();
169: } else {
170: return false;
171: }
172:
173: }
174:
175: /**
176: * This method figures out which container is being selected in
177: * the tree view. If the selected item is not a container, set
178: * treeContainer to null.
179: */
180: public void setupTreeContainer() {
181: // Get EditPropertiesBean
182: FacesContext fc = FacesContext.getCurrentInstance();
183: VariableResolver vr = fc.getApplication().getVariableResolver();
184: Object obj = (EditPropertiesBean) vr.resolveVariable(fc,
185: "EditPropertiesBean");
186: EditPropertiesBean epb = null;
187: if (obj == null) {
188: setupAlert(null, "error.createChannel.summary",
189: "error.createChannel.failed.checkLogs.noToken",
190: "error", null, null);
191: return;
192: } else if ((obj instanceof EditPropertiesBean)) {
193: epb = (EditPropertiesBean) obj;
194: }
195: // Get Current selected container name, if the
196: // selected node is a container, set the value, else
197: // set value null.
198: log(Level.INFO,
199: "CreateChannelBean.setupTreeContainer(), isContainer: "
200: + epb.isContainer() + " channel name: "
201: + epb.getChannelName());
202:
203: treeContainer = (epb.isContainer() == true) ? epb
204: .getChannelName() : null;
205:
206: }
207:
208: public String getTreeContainer() {
209: setupTreeContainer();
210:
211: if ((treeContainer != null && treeContainer.equals("_root"))) {
212: treeContainer = null;
213: }
214:
215: return treeContainer;
216: }
217:
218: public void setTreeContainer(String val) {
219: treeContainer = val;
220: }
221:
222: /**
223: * Cancel operation
224: */
225: public String getCancelText() {
226: return cancelText;
227: }
228:
229: public void setCancelText(String val) {
230: cancelText = val;
231: }
232:
233: public String cancel() {
234: setCancelText((String) rbMap.get("cancel.button"));
235: return "goDesktopManager";
236: }
237:
238: /**
239: * disable delete
240: */
241: public boolean isDisableCreate() {
242: if (disableCreate == null) {
243: disableCreate = new Boolean(false);
244: }
245: return disableCreate.booleanValue();
246: }
247:
248: public void setDisableCreate(boolean val) {
249: disableCreate = new Boolean(val);
250: }
251:
252: /**
253: * Alert methods
254: */
255: public Boolean getDisplayError() {
256: return displayError;
257: }
258:
259: public void setDisplayError(Boolean value) {
260: displayError = value;
261: }
262:
263: public String getAlertSummary() {
264: return alertSummary;
265: }
266:
267: public void setAlertSummary(String summary) {
268: alertSummary = summary;
269: }
270:
271: public String getAlertDetail() {
272: return alertDetail;
273: }
274:
275: public void setAlertDetail(String detail) {
276: alertDetail = detail;
277: }
278:
279: public String getAlertType() {
280: return alertType;
281: }
282:
283: public void setAlertType(String type) {
284: alertType = type;
285: }
286:
287: public String getLogMessage() {
288: return logMessage;
289: }
290:
291: public void setLogMessage(String val) {
292: logMessage = val;
293: }
294:
295: protected String composeLogMessage(Exception e) {
296: StringBuffer msg = new StringBuffer();
297: msg.append(e.getMessage());
298: msg.append('\n');
299: msg.append(getStackTrace(e));
300: return msg.toString();
301: }
302:
303: /**
304: * Alert Utility methods
305: */
306:
307: public void setupAlert(Object[] tokens, String summary,
308: String detail, String type, String defaultKey,
309: String message) {
310:
311: String sm = (String) rbMap.get(summary);
312: String dm = (String) rbMap.get(detail);
313:
314: //if it was not possible to localize the message from the
315: //mbean then show a generic message
316: if (dm == null || dm.startsWith("???")) {
317: dm = (String) rbMap.get(defaultKey);
318: }
319:
320: if (tokens != null) {
321: String pattern = dm;
322: MessageFormat mf = new MessageFormat(pattern);
323: dm = mf.format(tokens);
324: }
325:
326: if (message != null) {
327: dm = dm + " "
328: + (String) rbMap.get("general.error.viewSource");
329: setLogMessage(message);
330: } else {
331: setLogMessage("");
332: }
333:
334: setDisplayError(Boolean.TRUE);
335: setAlertSummary(sm);
336: setAlertDetail(dm);
337: setAlertType(type);
338: }
339:
340: }
|