001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.subscriptions.admin;
007:
008: import java.util.*;
009: import java.util.logging.Level;
010: import java.util.logging.Logger;
011:
012: import javax.servlet.http.HttpServletRequest;
013:
014: import com.iplanet.jato.view.View;
015: import com.iplanet.jato.view.html.StaticTextField;
016: import com.iplanet.jato.CompleteRequestException;
017: import com.iplanet.jato.view.event.DisplayEvent;
018: import com.iplanet.jato.view.event.ChildDisplayEvent;
019: import com.iplanet.jato.view.event.RequestInvocationEvent;
020: import com.iplanet.jato.model.ModelControlException;
021: import com.iplanet.jato.view.html.RadioButtonGroup;
022: import com.iplanet.jato.view.html.OptionList;
023: import com.iplanet.jato.view.html.TextField;
024:
025: import com.iplanet.am.console.base.AMMessageViewBean;
026: import com.iplanet.am.console.base.model.AMConsoleException;
027: import com.iplanet.am.console.service.SMDataViewBean;
028: import com.iplanet.am.console.service.model.SMDataModel;
029: import com.iplanet.am.console.components.view.html.DynamicGUI;
030: import com.iplanet.am.console.components.view.html.DynamicGUIComp;
031: import com.iplanet.am.console.components.view.html.MessageBox;
032: import com.iplanet.am.console.components.view.html.IPlanetButton;
033:
034: import com.sun.portal.subscriptions.admin.model.SubscriptionsAdminServiceModelImpl;
035: import com.sun.portal.log.common.PortalLogger;
036:
037: public class SubscriptionsAdminServiceViewBean extends SMDataViewBean {
038: public static final String PAGE_NAME = "SubscriptionsAdminService";
039:
040: public static final String DEFAULT_DISPLAY_URL = "/ps/subsadmin/SubscriptionsAdminService.jsp";
041: public static final String CHILD_TITLE = "title";
042: public static final String CHILD_SUBS_DESCRIPTION = "subs.description";
043: public static final String CHILD_PROF_DESCRIPTION = "prof.description";
044: public static final String START_VIEW = "StartProfiler";
045: public static final String STOP_VIEW = "StopProfiler";
046:
047: // used for debugging
048: public static final String CLASS_NAME = "SubscriptionsAdminServiceViewBean.";
049: public static final String GET_MODEL = CLASS_NAME + "getModel(): ";
050: private static ResourceBundle rb = null;
051: public SMDataModel model = null;
052: public String organization = null;
053: private static Logger logger = PortalLogger
054: .getLogger(SubscriptionsAdminServiceViewBean.class);
055:
056: public SubscriptionsAdminServiceViewBean() {
057: super (PAGE_NAME);
058: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
059: registerChildren();
060: }
061:
062: public void registerChildren() {
063: registerChild(CHILD_TITLE, StaticTextField.class);
064: registerChild(CHILD_SUBS_DESCRIPTION, StaticTextField.class);
065: super .registerChildren();
066: }
067:
068: /**
069: * creates child view/component
070: *
071: * @param name of view/component
072: * @return child view/component
073: */
074: protected View createChild(String name) {
075: if (name.equals(CHILD_SUBS_DESCRIPTION)) {
076: return new StaticTextField(this , CHILD_SUBS_DESCRIPTION,
077: getLocalizedString(CHILD_SUBS_DESCRIPTION));
078: } else if (name.equals(START_VIEW)) {
079: return new ScheduleView(this , START_VIEW);
080: } else if (name.equals(STOP_VIEW)) {
081: return new ScheduleView(this , STOP_VIEW);
082: } else if (name.equals(CHILD_TITLE)) {
083: return new StaticTextField(this , CHILD_TITLE,
084: getLocalizedString(CHILD_TITLE));
085: } else if (name.equals(ORG_DATA_VIEW)) {
086: return new SubscriptionsAdminServiceView(this ,
087: ORG_DATA_VIEW, SMDataModel.ORG_TYPE);
088: } else {
089: logger.log(Level.WARNING, "PSSS_CSPSA0001", name);
090: return super .createChild(name);
091: }
092: }
093:
094: public void beginDisplay(DisplayEvent event)
095: throws ModelControlException {
096: model = getModel();
097: super .beginDisplay(event);
098: }
099:
100: /**
101: * Handles the Submit button click event.
102: *
103: * @param event The Request Invocation Event
104: * @overrides handleSubmitButtonRequest in SMDataViewBean
105: */
106: public void handleBtnSaveRequest(RequestInvocationEvent event)
107: throws ModelControlException {
108: try {
109: if (isTemplate()) {
110: ScheduleView child = (ScheduleView) getChild(this .START_VIEW);
111: child.store();
112: child = (ScheduleView) getChild(this .STOP_VIEW);
113: child.store();
114: }
115: model.process();
116: } catch (AMConsoleException amce) {
117: logger.log(Level.SEVERE, "PSSS_CSPSA0005");
118: }
119: super .handleBtnSaveRequest(event);
120: }
121:
122: public void handleBtnResetRequest(RequestInvocationEvent event)
123: throws ModelControlException {
124: if (isTemplate()) {
125: ScheduleView child = (ScheduleView) getChild(this .START_VIEW);
126: child.reset();
127: child = (ScheduleView) getChild(this .STOP_VIEW);
128: child.reset();
129: }
130: super .handleBtnResetRequest(event);
131: }
132:
133: public void handleDeleteButtonRequest(RequestInvocationEvent event)
134: throws ModelControlException {
135: if (isTemplate()) {
136: ScheduleView child = (ScheduleView) getChild(this .START_VIEW);
137: child.delete();
138: child = (ScheduleView) getChild(this .STOP_VIEW);
139: child.delete();
140: }
141: super .handleDeleteButtonRequest(event);
142: }
143:
144: /**
145: * Creates and returns the model instance. This method is an implementation
146: * of the SMData interface. It is called by the DesktopAdminServiceView.
147: *
148: * @return Instance of model
149: */
150: public SMDataModel getModel() {
151: if (model == null) {
152: HttpServletRequest req = getRequestContext().getRequest();
153: String locationDN = req.getParameter("Location");
154:
155: if (locationDN != null) {
156: setPageSessionAttribute(CONSOLE_LOCATION_DN, locationDN);
157: } else {
158: locationDN = (String) getPageSessionAttribute(CONSOLE_LOCATION_DN);
159: }
160: String svcName = getServiceName();
161:
162: //if svcName not in either, then its an error.
163: if (svcName != null && svcName.length() > 0) {
164: model = new SubscriptionsAdminServiceModelImpl(
165: req,
166: SubscriptionsAdminConstants.RESOURCE_BUNDLE_FILE,
167: getPageSessionAttributes(), svcName,
168: isTemplate());
169: }
170: if (svcName == null || model == null) {
171: //No model, so get debug and send error.
172: AMMessageViewBean vb = (AMMessageViewBean) getViewBean(com.iplanet.am.console.base.AMMessageViewBean.class);
173: //Localization not possible as model creation has failed.
174: vb.setTitle("Error - ");
175: vb
176: .setMessage("An error occurred while processing this request."
177: + " Please contact your administrator.");
178: vb.forwardTo(getRequestContext());
179: throw new CompleteRequestException();
180: }
181: try {
182: ((SubscriptionsAdminServiceModelImpl) model)
183: .initData(locationDN);
184: } catch (Exception e) {
185: if (logger.isLoggable(Level.SEVERE))
186: logger.log(Level.SEVERE, "PSSS_CSPSA0002", e);
187: }
188: }
189: return model;
190: }
191:
192: public String getLocalizedString(String key) {
193: try {
194: return model.getLocalizedString(key);
195: } catch (MissingResourceException e) {
196: if (logger.isLoggable(Level.SEVERE))
197: logger
198: .log(
199: Level.SEVERE,
200: "PSSS_CSPSA0003",
201: SubscriptionsAdminConstants.RESOURCE_BUNDLE_FILE);
202: return key;
203: } catch (Exception e) {
204:
205: String[] param = { key,
206: SubscriptionsAdminConstants.RESOURCE_BUNDLE_FILE };
207:
208: if (logger.isLoggable(Level.SEVERE))
209: logger.log(Level.SEVERE, "PSSS_CSPSA0004", param);
210: return key;
211: }
212: }
213: }
|