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.Collection;
7    import java.util.Iterator;
8    import java.rmi.RemoteException;
9    import javax.servlet.http.HttpSession;
10   import javax.servlet.ServletContext;
11   import javax.ejb.CreateException;
12   import javax.ejb.FinderException;
13   import com.instantbank.servicing.control.GeneralFailureException;
14   import com.instantbank.servicing.control.util.EJBUtil;
15   import com.instantbank.servicing.control.util.WebKeys;
16   
17   import com.instantbank.common.utilcomponents.Debug;
18   import com.instantbank.common.utilcomponents.ServicingExceptionMessage;
19   import com.instantbank.servicing.control.ejb.ServicingController;
20   
21   /**
22    *  This class provides a convenient set of methods for the web tier
23    *  components to access all the model objects. This class also insures that
24    *  only one copy of the model objects are created for web tier access by
25    *  placing a reference to the model objects in the session.
26    *
27    * @author Instant-bank (Consuelo Franky)
28    * @created September 2002
29    */
30   public class ModelManager extends ModelUpdateNotifier
31       implements Serializable {
32   
33     private ServletContext context;
34     private HttpSession session;
35     private ServicingController sccEjb = null;
36     private ServicingControllerProxy scc = null;
37     private Debug debug = null;
38   
39   
40     /**
41      *  constructor
42      */
43     public ModelManager() {
44       debug = new Debug();
45       debug.setDebugginOn(true);
46       debug.setPreMessage("** ModelManager");
47     }
48   
49   
50     /**
51      *  Here it should instances all the javabeans that are view of Model.
52      *  a) only one view copy in the user web session for each EJB in the user Service Layer session
53      *  b) only one view copy in the web context for each EJB shared between all users
54      *
55      * @param context HTTP context
56      * @param session HTTP session
57      */
58     public void init(ServletContext context, HttpSession session) {
59       debug.println("init");
60       this.session = session;
61       this.context = context;
62       //TODO: instances javabeans that are view of Model
63     }
64   
65   
66     /**
67      *  sets to scc attribute the web proxy reference
68      *
69      * @param scc web proxy reference
70      */
71     public void setSCC(ServicingControllerProxy scc) {
72       this.scc = scc;
73       debug.println("scc assigned");
74     }
75   
76   
77   
78     /**
79      *  sets to sccEjb attribute the controller ejb reference
80      *
81      * @return The sCCEJB value
82      */
83     public ServicingController getSCCEJB() {
84       if(sccEjb == null) {
85         try {
86           sccEjb = EJBUtil.getServicingControllerHome().create();
87         }
88         catch(CreateException ce) {
89           throw new GeneralFailureException(ce.getMessage());
90         }
91         catch(RemoteException re) {
92           throw new GeneralFailureException(re.getMessage());
93         }
94         catch(javax.naming.NamingException ne) {
95           throw new GeneralFailureException(ne.getMessage());
96         }
97         catch(Exception e) {
98           throw new GeneralFailureException(e.getMessage());
99         }
100      }
101      return sccEjb;
102    }
103  
104  
105  }
106  
107