1    package com.instantbank.servicing.control.web;
2    
3    import java.io.Serializable;
4    import java.util.HashMap;
5    import java.util.ArrayList;
6    import java.util.Iterator;
7    import java.util.Enumeration;
8    import javax.servlet.http.HttpServletRequest;
9    import javax.servlet.http.HttpSession;
10   import javax.servlet.ServletContext;
11   
12   import com.instantbank.servicing.control.web.handlers.RequestHandler;
13   import com.instantbank.common.utilcomponents.Debug;
14   import com.instantbank.common.utilcomponents.ServicingExceptionMessage;
15   import com.instantbank.servicing.control.ServicingEventException;
16   import com.instantbank.servicing.control.event.ServicingEvent;
17   
18   /**
19    *  This class is auxiliary for RequestProcessor, generating necessary events
20    *  to modify the model data.
21    *
22    * @author Instant-bank (Consuelo Franky)
23    * @created September 2002
24    */
25   public class RequestToEventTranslator
26       implements Serializable {
27   
28     private RequestProcessor sessionClientController;
29     private ModelManager mm;
30     private ScreenFlowManager screenManager;
31     private Debug debug = null;
32   
33   
34     /**
35      *  constructor
36      *
37      * @param sessionClientController reference to RequestProcessor javabean
38      * @param screenManager reference to ScreenFlowManager javabean
39      */
40     public RequestToEventTranslator
41       (RequestProcessor sessionClientController,
42        ScreenFlowManager screenManager) {
43       debug = new Debug();
44       debug.setDebugginOn(true);
45       debug.setPreMessage("** RequestToEventTranslator: ");
46       this.sessionClientController = sessionClientController;
47       this.screenManager = screenManager;
48     }
49   
50   
51     /**
52      *  build event corresponding to user request using handler associated to event type
53      *
54      * @param request HTTP request
55      * @param context web context
56      * @return the event
57      * @exception ServicingEventException
58      */
59     public ServicingEvent processRequest(HttpServletRequest request,
60                                          ServletContext context)
61        throws ServicingEventException {
62   
63       // Process the request and get the necessary event
64       // depending on the URL
65       String selectedUrl = request.getPathInfo();
66       ServicingEvent event = null;
67       String requestProcessorString = null;
68   
69       // get urlMapping structure, associated to request url
70       URLMapping urlMapping
71          = screenManager.getURLMapping(request.getPathInfo());
72       debug.println("url=" + selectedUrl);
73   
74       if(urlMapping != null) {
75         requestProcessorString = urlMapping.getRequestHandler();
76         if(urlMapping.useRequestHandler()) {
77           RequestHandler handler = null;
78           try {
79             debug.println("loading handler");
80             handler = (RequestHandler)getClass()
81               .getClassLoader()
82               .loadClass
83               (requestProcessorString).newInstance();
84           }
85           catch(Exception e) {
86             debug.println(" Exception loading handler: " + e);
87             throw new ServicingEventException
88               (ServicingExceptionMessage.HANDLER_NOT_LOAD + e.getMessage());
89           }
90           handler.doStart(request);
91           event = handler.processRequest(request, context);
92           handler.doEnd(request);
93         }
94       }
95       return event;
96     }
97   }
98   
99