1    package com.instantbank.servicing.control.web.handlers;
2    
3    import java.util.HashMap;
4    import java.util.ArrayList;
5    import java.util.Enumeration;
6    import java.util.Hashtable;
7    import java.util.StringTokenizer;
8    
9    import javax.servlet.http.HttpServletRequest;
10   import javax.servlet.ServletContext;
11   import com.instantbank.common.utilcomponents.CodeDescription;
12   import com.instantbank.servicing.control.event.ParmLevelsNameEvent;
13   import com.instantbank.servicing.control.util.JSPUtil;
14   import com.instantbank.servicing.control.util.WebKeys;
15   import com.instantbank.common.utilcomponents.Debug;
16   import com.instantbank.common.utilcomponents.ServicingGlobals;
17   import com.instantbank.servicing.control.ServicingEventException;
18   
19   
20   /**
21    *  Parameter levels Name usecase: flow handler for deciding output screen after
22    *  processing an action
23    *
24    * @author Instant-bank (Jorge Cardenas)
25    * @created September 2002
26    */
27   public class ParmLevelsNameFlowHandler
28       implements FlowHandler {
29     private Debug debug = null;
30   
31   
32     /**
33      *  optional execution before processFlow method
34      *
35      * @param request HTTP request
36      */
37     public void doStart(HttpServletRequest request) { }
38   
39   
40     /**
41      *  principal method for deciding output screen after processing an action
42      *
43      * @param request of MainServlet
44      * @param answer of the action
45      * @param context web context
46      * @return String with the number of the  output screen
47      * @exception ServicingEventException
48      */
49     public String processFlow(HttpServletRequest request, Object answer,
50                               ServletContext context)
51        throws ServicingEventException {
52   
53       debug = new Debug();
54       debug.setDebugginOn(true);
55       debug.setPreMessage("** ParmLevelsNameFlowHandler: ");
56       debug.println("processFlow");
57   
58       String nextScreen = null;
59       ParmLevelsNameEvent ce = null;
60   
61       if(request.getAttribute(WebKeys.ParmLevelsNameEvent) != null) {
62         ce = (ParmLevelsNameEvent)request.getAttribute(WebKeys.ParmLevelsNameEvent);
63       }
64   
65       if(request.getAttribute(WebKeys.ExceptionOcurred) != null) {
66         nextScreen = "1";  // PARM_LEVELS_NAME_PROBLEM
67   
68       }
69       else if(ce.getActionType() == ParmLevelsNameEvent.LIST_PARM_LEVELS_NAME) {
70         // answer is the current parameter levels name: ArrayList()
71         // puts current parameter levels name  in the web request :
72   
73   
74         String list1 = (String)(((ArrayList)answer).get(0));
75         String list2 = (String)(((ArrayList)answer).get(1));
76   
77         request.setAttribute(WebKeys.ParmLevelsNameList, answer);
78         nextScreen = "2";  // PARM_LEVELS_NAME_MAIN
79   
80       }
81       else if(ce.getActionType() == ParmLevelsNameEvent.UPDATE_PARM_LEVELS_NAME) {
82         // answer is an ArrayList with 2 elements:
83         // 0: possible problem: String
84         // 1: current parameter levels name list: ArrayList()
85   
86         // puts current parameter levels name in the web request :
87         request.setAttribute
88           (WebKeys.ParmLevelsNameList, ((ArrayList)answer).get(1));
89   
90         String problem = (String)(((ArrayList)answer).get(0));
91         if(problem.equals(ServicingGlobals.STR_UNDEF)) {
92           nextScreen = "2";  // PARM_LEVELS_NAME_MAIN
93         }
94         else {  // problem is: theProblem|theStackTrace
95           JSPUtil.putProblemInRequest(request, problem);
96           nextScreen = "1";  // PARM_LEVELS_NAME_PROBLEM
97         }
98       }
99       return nextScreen;
100    }
101  
102  
103    /**
104     * optional execution after processFlow method
105     *
106     * @param request Description of the Parameter
107     */
108    public void doEnd(HttpServletRequest request) { }
109  }
110  
111