1 package com.instantbank.servicing.control.ejb;
2
3 import java.util.Collection;
4 import java.util.HashMap;
5 import java.rmi.RemoteException;
6 import javax.ejb.CreateException;
7 import javax.ejb.EJBException;
8 import javax.ejb.RemoveException;
9 import javax.ejb.SessionBean;
10 import javax.ejb.SessionContext;
11 import javax.ejb.FinderException;
12 import com.instantbank.servicing.control.util.EJBUtil;
13
14 import com.instantbank.common.utilcomponents.Debug;
15 import com.instantbank.component.parameter.ejb.Parameter;
16 import com.instantbank.component.parameter.ejb.ParameterHome;
17 import com.instantbank.servicing.control.ServicingEventException;
18 import com.instantbank.servicing.control.event.ServicingEvent;
19
20
32 public class ServicingControllerEJB
33 implements SessionBean {
34
35
36 private StateMachine sm;
37 private Parameter parameter;
38
39
40 private SessionContext sc;
41 private Debug debug = null;
42
43
44
45
46
49 public ServicingControllerEJB() { }
50
51
52
53
54
60 public void setSessionContext(SessionContext sc) {
61 this.sc = sc;
62 debug = new Debug();
63 debug.setDebugginOn(true);
64 debug.setPreMessage("** ServicingControllerEJB");
65 }
66
67
68
71 public void ejbActivate() { }
72
73
74
77 public void ejbPassivate() { }
78
79
80
81
82
85 public void ejbCreate() {
86 sm = new StateMachine(this, sc);
87 }
88
89
90
93 public void ejbRemove() {
94 sm = null;
95
96
97
98
99 if(parameter != null) {
100 try {
101 parameter.remove();
102 }
103 catch(RemoteException re) {
104 throw new EJBException(re);
105 }
106 catch(RemoveException re) {
107 throw new EJBException(re);
108 }
109 }
110
111
112 }
113
114
115
116
117
128 public Collection handleEvent(ServicingEvent ese)
129 throws ServicingEventException {
130 debug.println("handleEvent ");
131 try {
132 return (sm.handleEvent(ese));
133 }
134 catch(RemoteException re) {
135 throw new EJBException(re);
136 }
137 }
138
139
140
146 public Parameter getParameter(String companyId, Long userId) {
147 if(parameter == null) {
148 try {
149 ParameterHome home = EJBUtil.getParameterHome();
150 parameter = home.create(companyId, userId);
151 }
152 catch(CreateException ce) {
153 throw new EJBException(ce);
154 }
155 catch(RemoteException re) {
156 throw new EJBException(re);
157 }
158 catch(javax.naming.NamingException ne) {
159 throw new EJBException(ne);
160 }
161 catch(Exception e) {
162 throw new EJBException(e);
163 }
164 }
165 return parameter;
166 }
167
168
169
170
174 public String getW() {
175 String w = (String)sm.getAttribute("w");
176 if(w != null) {
177 return w;
178 }
179 else {
180 throw new EJBException("session w variable doesn't exist");
181 }
182 }
183
184 }
185
186