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.search.admin;
007:
008: import java.io.*;
009: import java.text.NumberFormat;
010: import java.util.Properties;
011: import java.util.logging.Logger;
012: import java.util.logging.Level;
013:
014: import com.sun.portal.search.admin.model.DbStatModelImpl;
015: import com.sun.portal.log.common.PortalLogger;
016:
017: import javax.servlet.http.HttpServletRequest;
018: import javax.servlet.*;
019: import javax.servlet.http.*;
020:
021: import com.iplanet.jato.Log;
022: import com.iplanet.jato.RequestContext;
023: import com.iplanet.jato.RequestHandler;
024: import com.iplanet.jato.model.Model;
025: import com.iplanet.jato.model.DefaultModel;
026: import com.iplanet.jato.model.DatasetModel;
027: import com.iplanet.jato.ModelManager;
028:
029: import com.iplanet.jato.view.event.DisplayEvent;
030: import com.iplanet.jato.view.event.RequestInvocationEvent;
031:
032: import com.iplanet.jato.view.html.StaticTextField;
033: import com.iplanet.jato.view.html.TextField;
034: import com.iplanet.jato.view.html.Button;
035: import com.iplanet.jato.view.html.HREF;
036:
037: import com.iplanet.jato.view.View;
038: import com.iplanet.jato.view.ViewBean;
039: import com.iplanet.jato.view.ViewBeanBase;
040: import com.iplanet.jato.view.TiledView;
041: import com.iplanet.jato.view.RequestHandlingTiledViewBase;
042:
043: import com.iplanet.jato.ViewBeanManager;
044:
045: import com.iplanet.jato.model.ModelControlException;
046:
047: /**
048: * Tiled View that represents the DbStat per server
049: *
050: *
051: */
052: public class DbStatListProtocolView extends
053: RequestHandlingTiledViewBase implements TiledView,
054: RequestHandler {
055: // Create a logger for this class
056: private static Logger debugLogger = PortalLogger
057: .getLogger(DbStatListProtocolView.class);
058:
059: /**
060: *
061: *
062: */
063: public DbStatListProtocolView(View parent, String name) {
064: super (parent, name);
065: try {
066: // We set the primary model *class* here instead of setting
067: // the actual model instance via setPrimaryModel(). Thus, the
068: // model isn't created unnecessarily just because this view is
069: // instantiated.
070: setMaxDisplayTiles(100);
071: registerChildren();
072: } catch (Exception e) {
073: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
074: .getMessage());
075: }
076: }
077:
078: /**
079: *
080: *
081: */
082: protected void registerChildren() {
083: registerChild(DBSTAT_PROTOCOL_NAME, StaticTextField.class);
084: registerChild(DBSTAT_PROTOCOL_NB_RD, StaticTextField.class);
085: registerChild(DBSTAT_PROTOCOL_PERCENTAGE, StaticTextField.class);
086: }
087:
088: /**
089: *
090: *
091: */
092: protected View createChild(String name) {
093: if (name.equals(DBSTAT_PROTOCOL_NAME)) {
094: StaticTextField child = new StaticTextField(this ,
095: DBSTAT_PROTOCOL_NAME, "http");
096: if (child == null) {
097: debugLogger.finer("PSSH_CSPSA0030");
098: }
099: return child;
100: }
101:
102: if (name.equals(DBSTAT_PROTOCOL_NB_RD)) {
103: // This is the nb of RD for current server
104: StaticTextField child = new StaticTextField(this ,
105: DBSTAT_PROTOCOL_NB_RD, "3");
106: if (child == null) {
107: debugLogger.finer("PSSH_CSPSA0031");
108: }
109: return child;
110: }
111:
112: if (name.equals(DBSTAT_PROTOCOL_PERCENTAGE)) {
113: // This is the nb of RD for current server
114: StaticTextField child = new StaticTextField(this ,
115: DBSTAT_PROTOCOL_PERCENTAGE, "3%");
116: if (child == null) {
117: debugLogger.finer("PSSH_CSPSA0032");
118: }
119: return child;
120: }
121:
122: debugLogger.log(Level.INFO, "PSSH_CSPSA0002", name);
123: throw new IllegalArgumentException("Invalid child name ["
124: + name + "]");
125: }
126:
127: /**
128: *
129: */
130: public void beginDisplay(DisplayEvent event)
131: throws ModelControlException {
132: DbStatModelImpl dbModel = getDbStatModel();
133:
134: setPrimaryModel(dbModel);
135: // Ensure the primary model is non-null; if null, it would cause
136: // havoc with the various methods dependent on the primary model
137: if (getPrimaryModel() == null) {
138: debugLogger.info("PSSH_CSPSA0023");
139: throw new ModelControlException("Primary model is null");
140: }
141:
142: try {
143: // setting the size of tiledview
144: getPrimaryModel().setSize(dbModel.nbProtocols());
145:
146: super .beginDisplay(event);
147:
148: resetTileIndex();
149: dbModel.resetProtocols();
150: } catch (Exception e) {
151: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
152: .getMessage());
153: }
154: }
155:
156: /**
157: * return "false" when no more entries to display.
158: * return true to display the Tile, false don't display the tile
159: */
160: public boolean nextTile() throws ModelControlException {
161: try {
162: boolean movedToRow = super .nextTile();
163: if (movedToRow) {
164: DbStatModelImpl dbModel = getDbStatModel();
165:
166: if (dbModel.hasMoreProtocol()) {
167: // Server Href Field
168: String protocolName = dbModel.nextProtocolName();
169: setDisplayFieldValue(DBSTAT_PROTOCOL_NAME,
170: protocolName);
171: // Server RD counter Field
172: String rdCounter = dbModel.nextProtocolRDCounter();
173: setDisplayFieldValue(DBSTAT_PROTOCOL_NB_RD,
174: rdCounter);
175: // Server RD percentage
176: double div = (double) dbModel.getTotalNbRd();
177: double percentage;
178: if (div != 0.0) {
179: percentage = (new Double(rdCounter))
180: .doubleValue()
181: / div;
182: } else {
183: percentage = 0.0;
184: }
185: setDisplayFieldValue(DBSTAT_PROTOCOL_PERCENTAGE,
186: NumberFormat.getPercentInstance().format(
187: percentage));
188: return true;
189: } else {
190: return false;
191: }
192: }
193: return movedToRow;
194: } catch (Exception e) {
195: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
196: .getMessage());
197: return false;
198: }
199: }
200:
201: /**
202: *
203: *
204: */
205: public DbStatModelImpl getDbStatModel() {
206: DbStatListDBView p = (DbStatListDBView) getParent();
207: return (DbStatModelImpl) p.getDbStatModel();
208: }
209:
210: ////////////////////////////////////////////////////////////////////////////
211: // Event handling methods
212: ////////////////////////////////////////////////////////////////////////////
213:
214: ////////////////////////////////////////////////////////////////////////////
215: // Class variables
216: ////////////////////////////////////////////////////////////////////////////
217:
218: public static final String DBSTAT_PROTOCOL_NAME = "DbStatProtocolName";
219: public static final String DBSTAT_PROTOCOL_NB_RD = "DbStatProtocolNbRd";
220: public static final String DBSTAT_PROTOCOL_PERCENTAGE = "DbStatProtocolPercentage";
221:
222: ////////////////////////////////////////////////////////////////////////////
223: // Instance variables
224: ////////////////////////////////////////////////////////////////////////////
225: }
|