01: /*
02: * $Id: JotmContainer.java,v 1.2 2003/12/02 01:18:38 ajzeneski Exp $
03: *
04: * Copyright (c) 2003 The Open For Business Project - www.ofbiz.org
05: *
06: * Permission is hereby granted, free of charge, to any person obtaining a
07: * copy of this software and associated documentation files (the "Software"),
08: * to deal in the Software without restriction, including without limitation
09: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10: * and/or sell copies of the Software, and to permit persons to whom the
11: * Software is furnished to do so, subject to the following conditions:
12: *
13: * The above copyright notice and this permission notice shall be included
14: * in all copies or substantial portions of the Software.
15: *
16: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23: *
24: */
25: package org.ofbiz.entity.transaction;
26:
27: import org.ofbiz.base.container.Container;
28: import org.ofbiz.base.container.ContainerException;
29: import org.objectweb.carol.util.configuration.RMIConfigurationException;
30: import org.objectweb.transaction.jta.TMService;
31: import org.objectweb.jotm.Jotm;
32:
33: import javax.naming.InitialContext;
34: import javax.naming.NamingException;
35:
36: /**
37: * JOTM Container
38: *
39: * @author <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
40: * @version $Revision: 1.2 $
41: * @since 3.0
42: */
43: public class JotmContainer implements Container {
44:
45: public static final String module = JotmContainer.class.getName();
46:
47: protected TMService jotm = null;
48:
49: public boolean start(String configFileLocation)
50: throws ContainerException {
51:
52: // initialize Carol
53: try {
54: org.objectweb.carol.util.configuration.CarolConfiguration
55: .init();
56: } catch (RMIConfigurationException e) {
57: throw new ContainerException(
58: "Carol threw configuration exception", e);
59: }
60:
61: // start JOTM
62: try {
63: jotm = new Jotm(true, false);
64: } catch (NamingException e) {
65: throw new ContainerException("Unable to load JOTM", e);
66: }
67:
68: // bind UserTransaction and TransactionManager to JNDI
69: try {
70: InitialContext ic = new InitialContext();
71: ic.rebind("java:comp/UserTransaction", jotm
72: .getUserTransaction());
73: } catch (NamingException e) {
74: throw new ContainerException(
75: "Unable to bind UserTransaction/TransactionManager to JNDI",
76: e);
77: }
78:
79: // check JNDI
80: try {
81: InitialContext ic = new InitialContext();
82: Object o = ic.lookup("java:comp/UserTransaction");
83: if (o == null) {
84: throw new NamingException("Object came back null");
85: }
86: } catch (NamingException e) {
87: throw new ContainerException(
88: "Unable to lookup bound objects", e);
89: }
90:
91: return true;
92: }
93:
94: public void stop() throws ContainerException {
95: MinervaConnectionFactory.closeAll();
96: jotm.stop();
97: }
98:
99: }
|