KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ebank > web > BeanManager


1 /*
2  * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved. U.S.
3  * Government Rights - Commercial software. Government users are subject
4  * to the Sun Microsystems, Inc. standard license agreement and
5  * applicable provisions of the FAR and its supplements. Use is subject
6  * to license terms.
7  *
8  * This distribution may include materials developed by third parties.
9  * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks
10  * or registered trademarks of Sun Microsystems, Inc. in the U.S. and
11  * other countries.
12  *
13  * Copyright (c) 2004 Sun Microsystems, Inc. Tous droits reserves.
14  *
15  * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel
16  * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de
17  * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions
18  * en vigueur de la FAR (Federal Acquisition Regulations) et des
19  * supplements a celles-ci. Distribue par des licences qui en
20  * restreignent l'utilisation.
21  *
22  * Cette distribution peut comprendre des composants developpes par des
23  * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE
24  * sont des marques de fabrique ou des marques deposees de Sun
25  * Microsystems, Inc. aux Etats-Unis et dans d'autres pays.
26  */

27
28
29 package com.sun.ebank.web;
30
31 import javax.ejb.*;
32 import javax.naming.*;
33 import javax.rmi.PortableRemoteObject JavaDoc;
34 import java.rmi.RemoteException JavaDoc;
35 import com.sun.ebank.ejb.exception.*;
36 import com.sun.ebank.util.*;
37 import com.sun.ebank.ejb.account.*;
38 import com.sun.ebank.ejb.customer.*;
39 import com.sun.ebank.ejb.tx.*;
40 import java.util.*;
41
42
43 public class BeanManager {
44     private CustomerController custctl = null;
45     private AccountController acctctl = null;
46     private TxController txctl = null;
47
48     public BeanManager() {
49         if (custctl == null) {
50             try {
51                 CustomerControllerHome home =
52                     EJBGetter.getCustomerControllerHome();
53                 custctl = home.create();
54             } catch (RemoteException JavaDoc ex) {
55                 Debug.print("Couldn't create customer bean." + ex.getMessage());
56             } catch (CreateException ex) {
57                 Debug.print("Couldn't create customer bean." + ex.getMessage());
58             } catch (NamingException ex) {
59                 Debug.print("Unable to look up home: " +
60                     CodedNames.CUSTOMER_CONTROLLER_EJBHOME + ex.getMessage());
61             }
62         }
63
64         if (acctctl == null) {
65             try {
66                 AccountControllerHome home =
67                     EJBGetter.getAccountControllerHome();
68                 acctctl = home.create();
69             } catch (RemoteException JavaDoc ex) {
70                 Debug.print("Couldn't create account bean." + ex.getMessage());
71             } catch (CreateException ex) {
72                 Debug.print("Couldn't create account bean." + ex.getMessage());
73             } catch (NamingException ex) {
74                 Debug.print("Unable to look up home: " +
75                     CodedNames.ACCOUNT_CONTROLLER_EJBHOME + ex.getMessage());
76             }
77         }
78
79         if (txctl == null) {
80             try {
81                 TxControllerHome home = EJBGetter.getTxControllerHome();
82                 txctl = home.create();
83             } catch (RemoteException JavaDoc ex) {
84                 Debug.print("Couldn't create transaction bean." +
85                     ex.getMessage());
86             } catch (CreateException ex) {
87                 Debug.print("Couldn't create transaction bean." +
88                     ex.getMessage());
89             } catch (NamingException ex) {
90                 Debug.print("Unable to look up home: " +
91                     CodedNames.TX_CONTROLLER_EJBHOME + ex.getMessage());
92             }
93         }
94     }
95
96     public CustomerController getCustomerController() {
97         return custctl;
98     }
99
100     public AccountController getAccountController() {
101         return acctctl;
102     }
103
104     public TxController getTxController() {
105         return txctl;
106     }
107
108     public void destroy() {
109         custctl = null;
110         acctctl = null;
111         txctl = null;
112     }
113 }
114
Popular Tags