KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > recover > bean > FrontEndBean


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.recover.bean;
23
24 import java.rmi.RemoteException JavaDoc;
25
26 import javax.ejb.EJBException JavaDoc;
27 import javax.ejb.FinderException JavaDoc;
28 import javax.naming.Context JavaDoc;
29 import javax.naming.InitialContext JavaDoc;
30 import javax.rmi.PortableRemoteObject JavaDoc;
31
32 import org.jboss.logging.Logger;
33 import org.jboss.test.recover.interfaces.Account;
34 import org.jboss.test.recover.interfaces.AccountHome;
35 import org.jboss.test.util.ejb.SessionSupport;
36
37 /**
38  * Implementation class for the FrontEnd stateful session bean.
39  *
40  * @author <a HREF="mailto:reverbel@ime.usp.br">Francisco Reverbel</a>
41  * @version $Revision: 58115 $
42  */

43 public class FrontEndBean
44    extends SessionSupport
45 {
46    private static transient Logger log =
47          Logger.getLogger(FrontEndBean.class);
48    
49    private String JavaDoc testName;
50    private Account account1JBRem, account2JBRem, account1IIOP, account2IIOP;
51
52    public void ejbCreate(String JavaDoc name)
53    {
54       ejbCreate(name, false);
55    }
56
57    public void ejbCreate(String JavaDoc name, boolean keepAccountBalances)
58    {
59       this.testName = name;
60       log = Logger.getLogger(FrontEndBean.class.getName() + "#" + testName);
61       log.debug("ejbCreate(" + name + "), ctx=" + sessionCtx);
62       findAccounts(keepAccountBalances);
63    }
64
65    public void setBalancesOverJBRem(int value1, int value2)
66    {
67       try
68       {
69          account1JBRem.setBalance(value1);
70          account2JBRem.setBalance(value2);
71       }
72       catch (RemoteException JavaDoc e)
73       {
74          throw new EJBException JavaDoc(e);
75       }
76    }
77    
78    public void setBalancesOverIIOP(int value1, int value2)
79    {
80       try
81       {
82          account1IIOP.setBalance(value1);
83          account2IIOP.setBalance(value2);
84       }
85       catch (RemoteException JavaDoc e)
86       {
87          throw new EJBException JavaDoc(e);
88       }
89    }
90    
91    public void setBalancesOverJBRemAndIIOP(int value1, int value2)
92    {
93       try
94       {
95          account1JBRem.setBalance(value1);
96          account2IIOP.setBalance(value2);
97       }
98       catch (RemoteException JavaDoc e)
99       {
100          throw new EJBException JavaDoc(e);
101       }
102    }
103    
104    public void setBalancesOverIIOPAndJBRem(int value1, int value2)
105    {
106       try
107       {
108          account1IIOP.setBalance(value1);
109          account2JBRem.setBalance(value2);
110       }
111       catch (RemoteException JavaDoc e)
112       {
113          throw new EJBException JavaDoc(e);
114       }
115    }
116    
117    public int[] getBalancesOverJBRem()
118    {
119       try
120       {
121          int[] balances = new int[2];
122          balances[0] = account1JBRem.getBalance();
123          balances[1] = account2JBRem.getBalance();
124          return balances;
125       }
126       catch (RemoteException JavaDoc e)
127       {
128          throw new EJBException JavaDoc(e);
129       }
130    }
131    
132    public int[] getBalancesOverIIOP()
133    {
134       try
135       {
136          int[] balances = new int[2];
137          balances[0] = account1IIOP.getBalance();
138          balances[1] = account2IIOP.getBalance();
139          return balances;
140       }
141       catch (RemoteException JavaDoc e)
142       {
143          throw new EJBException JavaDoc(e);
144       }
145    }
146    
147    public int[] getBalancesOverJBRemAndIIOP()
148    {
149       try
150       {
151          int[] balances = new int[2];
152          balances[0] = account1JBRem.getBalance();
153          balances[1] = account2IIOP.getBalance();
154          return balances;
155       }
156       catch (RemoteException JavaDoc e)
157       {
158          throw new EJBException JavaDoc(e);
159       }
160    }
161    
162    public int[] getBalancesOverIIOPAndJBRem()
163    {
164       try
165       {
166          int[] balances = new int[2];
167          balances[0] = account1IIOP.getBalance();
168          balances[1] = account2JBRem.getBalance();
169          return balances;
170       }
171       catch (RemoteException JavaDoc e)
172       {
173          throw new EJBException JavaDoc(e);
174       }
175    }
176    
177    public void addToBalancesOverJBRem(int value)
178    {
179       try
180       {
181          account1JBRem.addToBalance(value);
182          account2JBRem.addToBalance(value);
183       }
184       catch (RemoteException JavaDoc e)
185       {
186          throw new EJBException JavaDoc(e);
187       }
188    }
189
190    public void addToBalancesOverIIOP(int value)
191    {
192       try
193       {
194          account1IIOP.addToBalance(value);
195          account2IIOP.addToBalance(value);
196       }
197       catch (RemoteException JavaDoc e)
198       {
199          throw new EJBException JavaDoc(e);
200       }
201    }
202
203    public void addToBalancesOverJBRemAndIIOP(int value)
204    {
205       try
206       {
207          account1JBRem.addToBalance(value);
208          account2IIOP.addToBalance(value);
209       }
210       catch (RemoteException JavaDoc e)
211       {
212          throw new EJBException JavaDoc(e);
213       }
214    }
215
216    public void addToBalancesOverIIOPAndJBRem(int value)
217    {
218       try
219       {
220          account1IIOP.addToBalance(value);
221          account2JBRem.addToBalance(value);
222       }
223       catch (RemoteException JavaDoc e)
224       {
225          throw new EJBException JavaDoc(e);
226       }
227    }
228
229    public void setRollbackOnly()
230    {
231       sessionCtx.setRollbackOnly();
232    }
233    
234    public void tellFirstAccountToSetRollbackOnlyOverJBRem()
235    {
236       try
237       {
238          account1JBRem.setRollbackOnly();
239       }
240       catch (RemoteException JavaDoc e)
241       {
242          throw new EJBException JavaDoc(e);
243       }
244    }
245    
246    public void tellFirstAccountToSetRollbackOnlyOverIIOP()
247    {
248       try
249       {
250          account1IIOP.setRollbackOnly();
251       }
252       catch (RemoteException JavaDoc e)
253       {
254          throw new EJBException JavaDoc(e);
255       }
256    }
257    
258    public void tellSecondAccountToSetRollbackOnlyOverJBRem()
259    {
260       try
261       {
262          account2JBRem.setRollbackOnly();
263       }
264       catch (RemoteException JavaDoc e)
265       {
266          throw new EJBException JavaDoc(e);
267       }
268    }
269    
270    public void tellSecondAccountToSetRollbackOnlyOverIIOP()
271    {
272       try
273       {
274          account2IIOP.setRollbackOnly();
275       }
276       catch (RemoteException JavaDoc e)
277       {
278          throw new EJBException JavaDoc(e);
279       }
280    }
281    
282    private void findAccounts(boolean keepAccountBalances)
283    {
284       try
285       {
286          Object JavaDoc objref;
287          AccountHome home;
288          Context JavaDoc iniCtx = new InitialContext JavaDoc();
289          
290          objref = iniCtx.lookup("java:comp/env/ejb/Account1JBRem");
291          home = (AccountHome)
292             PortableRemoteObject.narrow(objref, AccountHome.class);
293          try
294          {
295             account1JBRem = home.findByPrimaryKey(testName + "#account1");
296             if (!keepAccountBalances)
297                account1JBRem.setBalance(0);
298          }
299          catch (FinderException JavaDoc e)
300          {
301             account1JBRem = home.create(testName + "#account1", 0);
302          }
303          
304          objref = iniCtx.lookup("java:comp/env/ejb/Account2JBRem");
305          home = (AccountHome)
306             PortableRemoteObject.narrow(objref, AccountHome.class);
307          try
308          {
309             account2JBRem = home.findByPrimaryKey(testName + "#account2");
310             if (!keepAccountBalances)
311                account2JBRem.setBalance(0);
312          }
313          catch (FinderException JavaDoc e)
314          {
315             account2JBRem = home.create(testName + "#account2", 0);
316          }
317
318          objref = iniCtx.lookup("java:comp/env/ejb/Account1IIOP");
319          home = (AccountHome)
320             PortableRemoteObject.narrow(objref, AccountHome.class);
321          try
322          {
323             account1IIOP = home.findByPrimaryKey(testName + "#account1");
324             // already done via JBRem:
325
// if (!keepAccountBalances)
326
// account1IIOP.setBalance(0);
327
}
328          catch (FinderException JavaDoc e)
329          {
330             // should never get here
331
account1IIOP = home.create(testName + "#account1", 0);
332          }
333          
334          objref = iniCtx.lookup("java:comp/env/ejb/Account2IIOP");
335          home = (AccountHome)
336             PortableRemoteObject.narrow(objref, AccountHome.class);
337          try
338          {
339             account2IIOP = home.findByPrimaryKey(testName + "#account2");
340             // already done via JBRem:
341
// if (!keepAccountBalances)
342
// account2IIOP.setBalance(0);
343
}
344          catch (FinderException JavaDoc e)
345          {
346             // should never get here
347
account2IIOP = home.create(testName + "#account2", 0);
348          }
349       }
350       catch (Exception JavaDoc e)
351       {
352          System.out.println("----------------------------------------");
353          e.printStackTrace();
354          System.out.println("----------------------------------------");
355          throw new EJBException JavaDoc(e);
356       }
357    }
358
359 }
360
Popular Tags