1    package com.instantbank.lettertemplate.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.lettertemplate.control.GeneralFailureException;
16   import com.instantbank.lettertemplate.control.util.WebKeys;
17   import com.instantbank.common.utilcomponents.Debug;
18   import com.instantbank.lettertemplate.control.LetterTemplateEventException;
19   import com.instantbank.lettertemplate.control.ejb.LetterTemplateController;
20   import com.instantbank.lettertemplate.control.event.LetterTemplateEvent;
21   import com.instantbank.component.job.ejb.Job;
22   
23   /**
24    *  This class is essentially just a proxy object that calls methods on the EJB
25    *  tier using the LetterTemplateControllerEJB
26    *  object. All the methods that access the EJB are synchronized so that
27    *  concurrent requests do not happen to the stateful session bean.
28    *
29    * @author Instant-bank (Consuelo Franky)
30    * @created August 2002
31    * @see com.instantbank.lettertemplate.control.ejb.LetterTemplateController
32    * @see com.instantbank.lettertemplate.control.ejb.LetterTemplateControllerEJB
33    * @see com.instantbank.lettertemplate.control.event.LetterTemplateEvent
34    */
35   public class LetterTemplateControllerProxy
36       implements Serializable {
37   
38     private ModelManager mm;
39     private LetterTemplateController sccEjb;  // controller EJB
40     private HttpSession session;
41     private Debug debug = null;
42   
43   
44     /**
45      *  Constructor
46      */
47     public LetterTemplateControllerProxy() { }
48   
49   
50     /**
51      *  constructor for an HTTP client.
52      *
53      * @param session web session
54      */
55     public LetterTemplateControllerProxy(HttpSession session) {
56       debug = new Debug();
57       debug.setDebugginOn(true);
58       debug.setPreMessage("** LetterTemplateControllerProxy: ");
59       debug.println("constructor");
60   
61       this.session = session;
62       mm = (ModelManager)session.getAttribute(WebKeys.ModelManagerKey);
63       sccEjb = mm.getSCCEJB();
64     }
65   
66   
67     /**
68      *  get reference to Job EJB instance, valid for web session
69      *
70      * @param jobId Description of the Parameter
71      * @return The jobEJB value
72      */
73     public synchronized Job getJobEJB(Long jobId) {
74       try {
75         return sccEjb.getOldJob(jobId);
76       }
77       catch(RemoteException re) {
78         throw new GeneralFailureException(re.getMessage());
79       }
80     }
81   
82   
83     /**
84      *  feeds the specified event to the state machine of the business logic:
85      *  sends the event to the controller ejb and gets a list with names of
86      *  Model objects who were updated
87      *
88      * @param ese is the current event
89      * @return a list of models that got
90      *      updated because of the processing of this event. In addition, the
91      *      first element of the list contains the service answer
92      *      (or the "" string when this answer is not required)
93      * @exception LetterTemplateEventException
94      */
95     public synchronized Collection handleEvent(LetterTemplateEvent ese)
96        throws LetterTemplateEventException {
97       try {
98         debug.println("passing event from Application tier to Service tier");
99         debug.println("event=" + ese);
100        sccEjb = mm.getSCCEJB();
101        return sccEjb.handleEvent(ese);
102      }
103      catch(RemoteException re) {
104        throw new GeneralFailureException(re.getMessage());
105      }
106    }
107  
108  
109    /**
110     *  frees up all the resources associated with this controller and destroys
111     *  itself.
112     */
113    public synchronized void remove() {
114      // call ejb remove on self
115      try {
116        debug.println("before  sccEjb.remove()");
117        sccEjb.remove();
118      }
119      catch(RemoveException re) {
120        // ignore, after all its only a remove() call!
121        debug.println(re.toString());
122      }
123      catch(RemoteException rte) {
124        // ignore, after all its only a remove() call!
125        debug.println(rte.toString());
126      }
127    }
128  }
129  
130