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.servicing.control.event.ParmLevel2ValuesEvent;
12   import com.instantbank.servicing.control.util.JSPUtil;
13   import com.instantbank.servicing.control.util.WebKeys;
14   import com.instantbank.common.utilcomponents.Debug;
15   import com.instantbank.common.utilcomponents.ServicingGlobals;
16   import com.instantbank.servicing.control.ServicingEventException;
17   
18   
19   /**
20    *  Parameter Level2 Values usecase: flow handler for deciding output screen after
21    *  processing an action
22    *
23    * @author Instant-bank (Jorge Cardenas)
24    * @created September 2002
25    */
26   public class ParmLevel2ValuesFlowHandler
27       implements FlowHandler {
28     private Debug debug = null;
29   
30   
31     /**
32      *  optional execution before processFlow method
33      *
34      * @param request HTTP request
35      */
36     public void doStart(HttpServletRequest request) { }
37   
38   
39     /**
40      *  principal method for deciding output screen after processing an action
41      *
42      * @param request of MainServlet
43      * @param answer of the action
44      * @param context web context
45      * @return String with the number of the  output screen
46      * @exception ServicingEventException
47      */
48     public String processFlow(HttpServletRequest request, Object answer,
49                               ServletContext context)
50        throws ServicingEventException {
51   
52       debug = new Debug();
53       debug.setDebugginOn(true);
54       debug.setPreMessage("** ParmLevel2ValuesFlowHandler: ");
55       debug.println("processFlow");
56   
57       String nextScreen = null;
58       ParmLevel2ValuesEvent ce = null;
59   
60       String companyNumber = (String)request.getSession()
61         .getAttribute(WebKeys.CompanyNumber);
62   
63       if(request.getAttribute(WebKeys.ParmLevel2ValuesEvent) != null) {
64         ce = (ParmLevel2ValuesEvent)request.getAttribute(WebKeys.ParmLevel2ValuesEvent);
65       }
66   
67       if(request.getAttribute(WebKeys.ExceptionOcurred) != null) {
68         nextScreen = "1";  // PARM_LEVEL2_VALUES_PROBLEM
69   
70       }
71       else if(ce.getActionType() == ParmLevel2ValuesEvent.LIST_PARM_LEVEL2_VALUES) {
72         // answer is an ArrayList with 2 elements:
73         // 0: current parameter levels name list: ArrayList()
74         // 1: current parameter Level2 values list: CodeDescription[]
75   
76         // puts current parameter Level2 values list in the web request :
77         request.setAttribute(WebKeys.ParmLevel2ValuesList, ((ArrayList)answer).get(1));
78   
79         // puts current parameter levels name list in the web request :
80         request.setAttribute
81           (WebKeys.ParmLevelsNameList, ((ArrayList)answer).get(0));
82   
83         nextScreen = "2";  // PARM_LEVEL2_VALUES_MAIN
84   
85       }
86       else if(ce.getActionType() == ParmLevel2ValuesEvent.UPDATE_PARM_LEVEL2_VALUES) {
87         // answer is an ArrayList with 3 elements:
88         // 0: possible problem: String
89         // 1: current parameter levels name list: ArrayList()
90         // 2: current parameter Level2 values list: CodeDescription[]
91   
92         // puts current parameter Level2 values list in the web request :
93         request.setAttribute
94           (WebKeys.ParmLevel2ValuesList, ((ArrayList)answer).get(2));
95   
96         // puts current parameter levels name in the web request :
97         request.setAttribute
98           (WebKeys.ParmLevelsNameList, ((ArrayList)answer).get(1));
99   
100        String problem = (String)(((ArrayList)answer).get(0));
101        if(problem.equals(ServicingGlobals.STR_UNDEF)) {
102          nextScreen = "2";  // PARM_LEVEL2_VALUES_MAIN
103        }
104        else {  // problem is: theProblem|theStackTrace
105          JSPUtil.putProblemInRequest(request, problem);
106          nextScreen = "1";  // PARM_LEVEL2_VALUES_PROBLEM
107        }
108      }
109      return nextScreen;
110    }
111  
112  
113    /**
114     * optional execution after processFlow method
115     *
116     * @param request Description of the Parameter
117     */
118    public void doEnd(HttpServletRequest request) { }
119  }
120  
121