01: package com.icesoft.faces.webapp.http.core;
02:
03: import com.icesoft.faces.context.View;
04: import com.icesoft.faces.util.event.servlet.ContextEventRepeater;
05: import com.icesoft.faces.webapp.http.common.Configuration;
06: import com.icesoft.faces.webapp.http.common.Request;
07: import com.icesoft.faces.webapp.http.common.Server;
08: import com.icesoft.faces.webapp.http.servlet.SessionDispatcher;
09:
10: import javax.servlet.http.HttpSession;
11: import java.util.Map;
12:
13: public class SingleViewServer implements Server {
14: private static final String viewNumber = "1";
15: private Map views;
16: private String sessionID;
17: private ViewQueue allUpdatedViews;
18: private Configuration configuration;
19: private SessionDispatcher.Listener.Monitor sessionMonitor;
20: private HttpSession session;
21: private Server server;
22:
23: public SingleViewServer(HttpSession session, String sessionID,
24: SessionDispatcher.Listener.Monitor sessionMonitor,
25: Map views, ViewQueue allUpdatedViews,
26: Configuration configuration) {
27: this .session = session;
28: this .sessionID = sessionID;
29: this .sessionMonitor = sessionMonitor;
30: this .views = views;
31: this .allUpdatedViews = allUpdatedViews;
32: this .configuration = configuration;
33: this .server = new PageServer();
34: }
35:
36: public void service(Request request) throws Exception {
37: //create single view or re-create view if the request is the result of a redirect
38: View view = (View) views.get(viewNumber);
39: if (view == null) {
40: view = new View(viewNumber, sessionID, request,
41: allUpdatedViews, configuration, sessionMonitor);
42: views.put(viewNumber, view);
43: ContextEventRepeater.viewNumberRetrieved(session,
44: sessionID, Integer.parseInt(viewNumber));
45: } else {
46: view.updateOnRequest(request);
47: }
48:
49: view.switchToNormalMode();
50: sessionMonitor.touchSession();
51: server.service(request);
52: view.switchToPushMode();
53: view.release();
54: }
55:
56: public void shutdown() {
57: server.shutdown();
58: }
59: }
|