KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > transaction > JTransactionManager


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: JTransactionManager.java 1022 2006-08-04 11:02:28Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.transaction;
27
28 import javax.naming.InitialContext JavaDoc;
29 import javax.naming.NamingException JavaDoc;
30 import javax.transaction.TransactionManager JavaDoc;
31
32 import org.objectweb.easybeans.component.itf.TMComponent;
33
34 /**
35  * Allows to get a transaction manager.
36  * @author Florent Benoit
37  */

38 public final class JTransactionManager {
39
40     /**
41      * Utility class, no public constructor.
42      */

43     private JTransactionManager() {
44
45     }
46
47     /**
48      * Internal tm.
49      */

50     private static TransactionManager JavaDoc tm = null;
51
52     /**
53      * Allow to get a transaction manager.
54      * @return a transaction manager.
55      */

56     public static TransactionManager JavaDoc getTransactionManager() {
57         if (tm != null) {
58             return tm;
59         }
60
61         // get it.
62
try {
63             tm = (TransactionManager JavaDoc) new InitialContext JavaDoc().lookup(TMComponent.JNDI_NAME);
64         } catch (NamingException JavaDoc e) {
65             throw new IllegalStateException JavaDoc("Cannot get transaction manager", e);
66         }
67         return tm;
68     }
69 }
70
Popular Tags