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 MultiViewServer implements Server {
14: private int viewCount = 0;
15: private Map views;
16: private ViewQueue asynchronouslyUpdatedViews;
17: private String sessionID;
18: private Configuration configuration;
19: private SessionDispatcher.Listener.Monitor sessionMonitor;
20: private HttpSession session;
21: private Server server;
22:
23: public MultiViewServer(HttpSession session, String sessionID,
24: SessionDispatcher.Listener.Monitor sessionMonitor,
25: Map views, ViewQueue asynchronouslyUpdatedViews,
26: Configuration configuration) {
27: this .session = session;
28: this .sessionID = sessionID;
29: this .sessionMonitor = sessionMonitor;
30: this .views = views;
31: this .asynchronouslyUpdatedViews = asynchronouslyUpdatedViews;
32: this .configuration = configuration;
33: this .server = new PageServer();
34: }
35:
36: public void service(Request request) throws Exception {
37: //extract viewNumber if this request is from a redirect
38: View view;
39: if (request.containsParameter("rvn")) {
40: String redirectViewNumber = request.getParameter("rvn");
41: view = (View) views.get(redirectViewNumber);
42: if (view == null) {
43: view = new View(redirectViewNumber, sessionID, request,
44: asynchronouslyUpdatedViews, configuration,
45: sessionMonitor);
46: views.put(redirectViewNumber, view);
47: ContextEventRepeater
48: .viewNumberRetrieved(session, sessionID,
49: Integer.parseInt(redirectViewNumber));
50: } else {
51: view.updateOnRequest(request);
52: view.switchToNormalMode();
53: }
54: } else {
55: String viewNumber = String.valueOf(++viewCount);
56: view = new View(viewNumber, sessionID, request,
57: asynchronouslyUpdatedViews, configuration,
58: sessionMonitor);
59: views.put(viewNumber, view);
60: ContextEventRepeater.viewNumberRetrieved(session,
61: sessionID, Integer.parseInt(viewNumber));
62: }
63: sessionMonitor.touchSession();
64: server.service(request);
65: view.switchToPushMode();
66: view.release();
67: }
68:
69: public void shutdown() {
70: server.shutdown();
71: }
72: }
|