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.net.*;
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.ModelManager;
026:
027: import com.iplanet.jato.view.event.DisplayEvent;
028: import com.iplanet.jato.view.event.RequestInvocationEvent;
029:
030: import com.iplanet.jato.view.html.StaticTextField;
031: import com.iplanet.jato.view.html.TextField;
032: import com.iplanet.jato.view.html.Button;
033: import com.iplanet.jato.view.html.HREF;
034:
035: import com.iplanet.jato.view.View;
036: import com.iplanet.jato.view.ViewBean;
037: import com.iplanet.jato.view.ViewBeanBase;
038: import com.iplanet.jato.view.TiledView;
039: import com.iplanet.jato.view.RequestHandlingTiledViewBase;
040:
041: import com.iplanet.jato.ViewBeanManager;
042:
043: import com.iplanet.jato.model.ModelControlException;
044:
045: /**
046: * Tiled View that represents the DbStat per server
047: *
048: *
049: */
050: public class DbStatListServerView extends RequestHandlingTiledViewBase
051: implements TiledView, RequestHandler {
052: // Create a logger for this class
053: private static Logger debugLogger = PortalLogger
054: .getLogger(DbStatListServerView.class);
055:
056: /**
057: *
058: *
059: */
060: public DbStatListServerView(View parent, String name) {
061: super (parent, name);
062:
063: try {
064: // We set the primary model *class* here instead of setting
065: // the actual model instance via setPrimaryModel(). Thus, the
066: // model isn't created unnecessarily just because this view is
067: // instantiated.
068: setMaxDisplayTiles(1000);
069: registerChildren();
070: } catch (Exception e) {
071: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
072: .getMessage());
073: }
074: }
075:
076: /**
077: *
078: *
079: */
080: protected void registerChildren() {
081: registerChild(DBSTAT_SERVER_HREF, StaticTextField.class);
082: registerChild(DBSTAT_SERVER_NB_RD, StaticTextField.class);
083: }
084:
085: /**
086: *
087: *
088: */
089: protected View createChild(String name) {
090: if (name.equals(DBSTAT_SERVER_HREF)) {
091: StaticTextField child = new StaticTextField(this ,
092: DBSTAT_SERVER_HREF, "http://www.gnu.org:80");
093: if (child == null) {
094: debugLogger.finer("PSSH_CSPSA0033");
095: }
096: return child;
097: }
098:
099: if (name.equals(DBSTAT_SERVER_NB_RD)) {
100: // This is the nb of RD for current server
101: StaticTextField child = new StaticTextField(this ,
102: DBSTAT_SERVER_NB_RD, "2");
103: if (child == null) {
104: debugLogger.finer("PSSH_CSPSA0034");
105: }
106: return child;
107: }
108: debugLogger.log(Level.INFO, "PSSH_CSPSA0002", name);
109: throw new IllegalArgumentException("Invalid child name ["
110: + name + "]");
111: }
112:
113: /**
114: *
115: *
116: */
117: public void beginDisplay(DisplayEvent event)
118: throws ModelControlException {
119: DbStatModelImpl dbModel = getDbStatModel();
120: setPrimaryModel(dbModel);
121: // Ensure the primary model is non-null; if null, it would cause
122: // havoc with the various methods dependent on the primary model
123: if (getPrimaryModel() == null) {
124: debugLogger.info("PSSH_CSPSA0023");
125: throw new ModelControlException(
126: "DbStatModel Primary model is null");
127: }
128:
129: try {
130: // setting the size of tiledview
131: getPrimaryModel().setSize(dbModel.nbServers());
132:
133: super .beginDisplay(event);
134:
135: resetTileIndex();
136: dbModel.resetServers();
137:
138: } catch (Exception e) {
139: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
140: .getMessage());
141: }
142:
143: }
144:
145: /**
146: * return "false" when no more entries to display.
147: * return true to display the Tile, false don't display the tile
148: */
149: public boolean nextTile() throws ModelControlException {
150: try {
151: boolean movedToRow = super .nextTile();
152: if (movedToRow) {
153: DbStatModelImpl dbModel = getDbStatModel();
154:
155: if (dbModel.hasMoreServer()) {
156:
157: // Server Href Field
158: String serverHref = dbModel.nextServerHref();
159:
160: setDisplayFieldValue(DBSTAT_SERVER_HREF, serverHref);
161: // Server RD counter Field
162: String rdCounter = dbModel.nextServerRDCounter();
163:
164: setDisplayFieldValue(DBSTAT_SERVER_NB_RD, rdCounter);
165: return true;
166: } else {
167: return false;
168: }
169: }
170: return movedToRow;
171: } catch (Exception e) {
172: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
173: .getMessage());
174: return false;
175: }
176: }
177:
178: /**
179: *
180: *
181: */
182: public DbStatModelImpl getDbStatModel() {
183: DbStatListDBView p = (DbStatListDBView) getParent();
184: return (DbStatModelImpl) p.getDbStatModel();
185: }
186:
187: ////////////////////////////////////////////////////////////////////////////
188: // Event handling methods
189: ////////////////////////////////////////////////////////////////////////////
190:
191: ////////////////////////////////////////////////////////////////////////////
192: // Class variables
193: ////////////////////////////////////////////////////////////////////////////
194:
195: public static final String DBSTAT_SERVER_HREF = "DbStatServerHref";
196: public static final String DBSTAT_SERVER_NB_RD = "DbStatServerNbRd";
197:
198: ////////////////////////////////////////////////////////////////////////////
199: // Instance variables
200: ////////////////////////////////////////////////////////////////////////////
201: }
|