1    package com.instantbank.servicing.control.web;
2    
3    import java.util.Locale;
4    import java.util.Collection;
5    import java.io.Serializable;
6    import java.rmi.RemoteException;
7    
8    import javax.rmi.PortableRemoteObject;
9    import javax.naming.InitialContext;
10   import javax.servlet.http.HttpSession;
11   import javax.ejb.FinderException;
12   import javax.ejb.CreateException;
13   import javax.ejb.RemoveException;
14   import javax.naming.NamingException;
15   import com.instantbank.servicing.control.GeneralFailureException;
16   import com.instantbank.servicing.control.util.WebKeys;
17   import com.instantbank.common.utilcomponents.Debug;
18   import com.instantbank.servicing.control.ServicingEventException;
19   import com.instantbank.servicing.control.ejb.ServicingController;
20   import com.instantbank.servicing.control.event.ServicingEvent;
21   
22   /**
23    *  This class is essentially just a proxy object that calls methods on the EJB
24    *  tier using the ServicingControllerEJB object.
25    *  All the methods that access the EJB are synchronized so that
26    *  concurrent requests do not happen to the stateful session bean.
27    *
28    * @author Instant-bank (Consuelo Franky)
29    * @created September 2002
30    * @see com.instantbank.servicing.control.ejb.ServicingController
31    * @see com.instantbank.servicing.control.ejb.ServicingControllerEJB
32    * @see com.instantbank.servicing.control.event.ServicingEvent
33    */
34   public class ServicingControllerProxy
35       implements Serializable {
36   
37     private ServicingController sccEjb;  // controller EJB
38     private HttpSession session;
39     private Debug debug = null;
40   
41   
42     /**
43      *  Constructor
44      */
45     public ServicingControllerProxy() { }
46   
47   
48     /**
49      *  constructor for an HTTP client.
50      *
51      * @param session web session
52      */
53     public ServicingControllerProxy(HttpSession session) {
54       debug = new Debug();
55       debug.setDebugginOn(true);
56       debug.setPreMessage("** ServicingControllerProxy: ");
57       debug.println("constructor");
58   
59       this.session = session;
60       ModelManager mm =
61         (ModelManager)session.getAttribute(WebKeys.ModelManagerKey);
62       sccEjb = mm.getSCCEJB();
63     }
64   
65   
66   
67     /**
68      *  feeds the specified event to the state machine of the business logic:
69      *  sends the event to the controller ejb and gets a list with names of
70      *  Model objects who were updated
71      *
72      * @param ese is the current event
73      * @return a list of models that got
74      *      updated because of the processing of this event. In addition, the
75      *      first element of the list contains the service answer
76      *      (or the "" string when this answer is not required)
77      * @exception ServicingEventException
78      */
79     public synchronized Collection handleEvent(ServicingEvent ese)
80        throws ServicingEventException {
81       try {
82         debug.println("passing event from Application tier to Service tier ");
83         return sccEjb.handleEvent(ese);
84       }
85       catch(RemoteException re) {
86         throw new GeneralFailureException(re.getMessage());
87       }
88     }
89   
90   
91     /**
92      *  frees up all the resources associated with this controller and destroys
93      *  itself.
94      */
95     public synchronized void remove() {
96       // call ejb remove on self
97       try {
98         sccEjb.remove();
99       }
100      catch(RemoveException re) {
101        // ignore, after all its only a remove() call!
102        debug.println(re.toString());
103      }
104      catch(RemoteException rte) {
105        // ignore, after all its only a remove() call!
106        debug.println(rte.toString());
107      }
108    }
109  }
110  
111