1    package com.instantbank.servicing.control.web;
2    
3    import java.io.Serializable;
4    import java.util.Collection;
5    import java.util.ArrayList;
6    import java.util.HashMap;
7    import java.util.Locale;
8    import javax.servlet.ServletContext;
9    import javax.servlet.http.HttpServletRequest;
10   import javax.servlet.http.HttpServletResponse;
11   import javax.servlet.http.HttpSession;
12   import javax.naming.NamingException;
13   import javax.naming.InitialContext;
14   import com.instantbank.servicing.control.util.WebKeys;
15   import com.instantbank.common.utilcomponents.Debug;
16   import com.instantbank.servicing.control.ServicingEventException;
17   import com.instantbank.servicing.control.event.ServicingEvent;
18   
19   /**
20    *  This class is responsible for processing all user requests and
21    *  generating necessary events to modify data which are sent to the
22    *  ServicingControllerProxy
23    *
24    * @author Instant-bank (Consuelo Franky)
25    * @created September 2002
26    */
27   public class RequestProcessor
28       implements Serializable {
29   
30     private ScreenFlowManager screenManager;
31     private ServletContext context;
32     private RequestToEventTranslator eventTranslator;
33     private Debug debug = null;
34   
35   
36     /**
37      *  Empty constructor for use by the JSP engine.
38      */
39     public RequestProcessor() {
40       debug = new Debug();
41       debug.setDebugginOn(true);
42       debug.setPreMessage("** RequestProcessor: ");
43     }
44   
45   
46     /**
47      *  get references to some controller javabeans:
48      *  ScreenFlowManager y RequestToEventTranslator
49      *
50      * @param context web context
51      */
52     public void init(ServletContext context) {
53       debug.println("init");
54       this.context = context;
55       screenManager
56         = (ScreenFlowManager)context.getAttribute
57         (WebKeys.ScreenManagerKey);
58       eventTranslator
59         = new RequestToEventTranslator(this, screenManager);
60     }
61   
62   
63     /**
64      *  This method is the core of the RequestProcessor. It receives all service
65      *  requests and generates the necessary update events.
66      *
67      * @param request HTTP request
68      * @return the service answer(or the ""  string when this answer is not required)
69      * @exception ServicingEventException
70      */
71     public Object processRequest(HttpServletRequest request)
72        throws ServicingEventException {
73       ServicingEvent event = null;
74       Object answer = "";
75   
76       ModelManager mm
77          = (ModelManager)request.getSession()
78         .getAttribute(WebKeys.ModelManagerKey);
79       ServicingControllerProxy scc
80          = (ServicingControllerProxy)request.getSession()
81         .getAttribute(WebKeys.WebControllerKey);
82       if(scc == null) {
83         scc = new ServicingControllerProxy(request.getSession());
84         mm.setSCC(scc);
85         request.getSession().setAttribute
86           (WebKeys.WebControllerKey, scc);
87       }
88   
89       // getting associated event to user request:
90       event = eventTranslator.processRequest(request, context);
91       // sending event to controller EJB through web proxy:
92       if(event != null) {
93         ArrayList updatedModelList = (ArrayList)scc.handleEvent(event);
94         debug.println("answer received from Services tier to Application tier");
95         answer = updatedModelList.get(0);
96         updatedModelList.remove(0);
97         mm.notifyListeners(updatedModelList);
98       }
99       return answer;
100    }
101  }
102  
103