001: /**
002: * Copyright 2002 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: *
013: * Author: Anurag Gupta
014: */package com.sun.portal.rproxy.admin;
015:
016: // JDK classes
017: import java.util.ArrayList;
018: import java.util.List;
019: import java.util.Set;
020:
021: import javax.servlet.http.HttpServletRequest;
022:
023: import com.iplanet.am.console.components.view.html.DynamicGUI;
024: import com.iplanet.am.console.components.view.html.DynamicGUIComp;
025: import com.iplanet.jato.RequestHandler;
026: import com.iplanet.jato.model.DatasetModel;
027: import com.iplanet.jato.model.ModelControlException;
028: import com.iplanet.jato.view.RequestHandlingTiledViewBase;
029: import com.iplanet.jato.view.TiledView;
030: import com.iplanet.jato.view.View;
031: import com.iplanet.jato.view.event.DisplayEvent;
032: import com.iplanet.jato.view.html.OptionList;
033: import com.sun.portal.rproxy.admin.model.GatewayModel;
034:
035: public class GatewayViewBase extends RequestHandlingTiledViewBase
036: implements TiledView, RequestHandler {
037:
038: public static final String CC_ATTR_SET = "ccAttrSet";
039:
040: public static final String ADD_BTN = "add.button";
041:
042: public static final String REMOVE_BTN = "remove.button";
043:
044: protected GatewayModel model = null;
045:
046: protected GatewayAdminModelManager modelManager = null;
047:
048: protected int viewType = 0;
049:
050: protected String[] attributeNameList;
051:
052: protected boolean attributeIndicesSet;
053:
054: protected int[] attributeIndicesList;
055:
056: /*
057: * @param parent The reference of the parent container @param name The name
058: * of this view.
059: */
060: public GatewayViewBase(View parent, String name) {
061: super (parent, name);
062: setPrimaryModel((DatasetModel) getDefaultModel());
063: registerChild(CC_ATTR_SET, DynamicGUIComp.class);
064: }
065:
066: protected View createChild(String name) {
067: if (name.equals(CC_ATTR_SET)) {
068: return new DynamicGUIComp(this , CC_ATTR_SET, null);
069: } else {
070: throw new IllegalArgumentException("Invalid child name: "
071: + name);
072: }
073: }
074:
075: public void beginDisplay(DisplayEvent event)
076: throws ModelControlException {
077: getPrimaryModel().setSize(getModel().getSize());
078: }
079:
080: protected GatewayModel getModel() {
081: if (model == null) {
082: GatewayAdminService viewBean = (GatewayAdminService) getParentViewBean();
083: model = viewBean.getModel();
084: }
085: return model;
086: }
087:
088: public GatewayAdminModelManager getGWModelMgr() {
089: if (modelManager == null) {
090: modelManager = (GatewayAdminModelManager) getRequestContext()
091: .getModelManager();
092: }
093: return modelManager;
094: }
095:
096: protected boolean isAttributeInList(int aIndex) {
097: boolean result = false;
098: int count;
099:
100: for (count = 0; count < attributeNameList.length; count++) {
101: if (aIndex == attributeIndicesList[count]) {
102: result = true;
103: break;
104: }
105: }
106: return result;
107: }
108:
109: protected boolean isAttributeInList(String aName) {
110: boolean result = false;
111: int count;
112:
113: for (count = 0; count < attributeNameList.length; count++) {
114: if (aName.equals(attributeNameList[count])) {
115: result = true;
116: break;
117: }
118: }
119: return result;
120: }
121:
122: public boolean nextTile() throws ModelControlException {
123: boolean movedToRow = super .nextTile();
124: GatewayModel m = getModel();
125: getGWModelMgr();
126:
127: if (!attributeIndicesSet) {
128: for (int i = 0; i < attributeNameList.length; i++) {
129: attributeIndicesList[i] = m
130: .getGWAttributeIndex(attributeNameList[i]);
131: }
132: attributeIndicesSet = true;
133: }
134:
135: boolean success = m.setCurrentRow(getTileIndex());
136: if (movedToRow && success) {
137: DynamicGUI dg = null;
138: // DynamicGUIComp dgc = (DynamicGUIComp)getChild(CC_ATTR_SET);
139: // Put row specific logic here
140: String name = m.getAttrName();
141: String label = m.getAttrLabel();
142: // None is a required attribute.
143: boolean required = false;
144: int attrType = m.getAttrType();
145: int attrSyntax = m.getAttrSyntax();
146: Set values = m.getAttrValues();
147:
148: while (!isAttributeInList(name)) {
149: movedToRow = super .nextTile();
150: success = m.setCurrentRow(getTileIndex());
151: if (movedToRow && success) {
152: name = m.getAttrName();
153: label = m.getAttrLabel();
154: attrType = m.getAttrType();
155: attrSyntax = m.getAttrSyntax();
156: values = m.getAttrValues();
157: } else {
158: return movedToRow;
159: }
160: }
161: /*
162: * dg = m.getDynamicGUI(); if(dg.getType == DynamicGUI.TYPE_LIST) {
163: * dg.setAddButtonStr(modelManager.getString(ADD_BTN));
164: * dg.setRemoveButtonStr(modelManager.getString(REMOVE_BTN)); }
165: */
166:
167: // Depending on the type and syntax, get value
168: if (attrType == DynamicGUI.TYPE_SINGLE) {
169: if (attrSyntax == DynamicGUI.SYNTAX_BOOLEAN) {
170: String trueValue = m.getAttrTrueValue();
171: String falseValue = m.getAttrFalseValue();
172: String value = "";
173: if (values != null) {
174: value = (String) values.iterator().next();
175: }
176:
177: // The Display text for this property has changed on the
178: // amconsole pages to
179: // Enable Null Ciphers. However, the property name and the
180: // meaning of these property
181: // are still maintained i.e it is disableNullCipher. Hence
182: // in the UI when you check the box
183: // for enable null ciphers, actually this property
184: // "sunPortalGatewayDisableNull" should be false.
185: // Hence the following code to toggle the value. Same case
186: // also applies to when we are rendering the page
187: // Fix for bug : #5011629 plus some previous half hearted
188: // fix by someone who made the text change
189: // but not the toggle of the value.
190: if (name.equals("sunPortalGatewayDisableNull"))
191: value = value.equals("true") ? "false" : "true";
192:
193: dg = new DynamicGUI(name, label, required,
194: attrType, attrSyntax, trueValue,
195: falseValue, value);
196: } else {
197: if (attrSyntax == DynamicGUI.SYNTAX_STRING) {
198: String value = "";
199: if (values != null) {
200: if (values.iterator().hasNext())
201: value = (String) values.iterator()
202: .next();
203: }
204: if (name
205: .equals("sunPortalGatewayRProxyPortTimeout")
206: || name
207: .equals("sunPortalGatewayBlockedSocketTimeout")) {
208: if (value != null && value != "") {// Converting
209: // milliseconds
210: // values to
211: // seconds for
212: // display
213: value = String.valueOf(Integer
214: .parseInt(value) / 1000);
215: values.clear();
216: values.add(value);
217: }
218: }
219: }
220: dg = new DynamicGUI(name, label, required,
221: attrType, attrSyntax, values);
222: }
223: } else if (attrType == DynamicGUI.TYPE_SINGLE_CHOICE
224: || attrType == DynamicGUI.TYPE_MULTIPLE_CHOICE) {
225: String[] choices = m.getAttrChoices();
226: OptionList optionList = new OptionList(choices, choices);
227: dg = new DynamicGUI(name, label, required, attrType,
228: attrSyntax, values, optionList);
229: } else if (attrType == DynamicGUI.TYPE_LIST) {
230: dg = new DynamicGUI(name, label, required, attrType,
231: attrSyntax, values);
232: dg.setAddButtonStr(modelManager.getString(ADD_BTN));
233: dg.setRemoveButtonStr(modelManager
234: .getString(REMOVE_BTN));
235: }
236: setDisplayFieldValue(CC_ATTR_SET, dg);
237: }
238: return movedToRow;
239: }
240:
241: /**
242: * re-creates dynamic gui components for saving purposes
243: *
244: * @return dynamic gui components for action value
245: */
246: public List getDynamicCompList() {
247: List dynamicGUIs = new ArrayList(10);
248: HttpServletRequest req = getRequestContext().getRequest();
249:
250: GatewayModel m = getModel();
251: for (int i = 0; i < attributeNameList.length; i++) {
252: attributeIndicesList[i] = m
253: .getGWAttributeIndex(attributeNameList[i]);
254: }
255:
256: int count = 0;
257: int componentsAdded = 0;
258: while (componentsAdded < attributeNameList.length) {
259: /*
260: * Skip if it is the index of Attributes not in this Bean's list
261: */
262: if (!isAttributeInList(count)) {
263: count++;
264: continue;
265: }
266:
267: DynamicGUI dGUI = DynamicGUIComp.createDynamicGUI(req,
268: getQualifiedName(), CC_ATTR_SET, count++);
269:
270: if (dGUI != null) {
271: dynamicGUIs.add(dGUI);
272: componentsAdded++;
273: } else {
274: break;
275: }
276: }
277: return dynamicGUIs;
278: }
279:
280: }
|