KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > jotm > container > JotmContainer


1 /*
2  * $Id: JotmContainer.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2003 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * 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.jotm.container;
26
27 import java.util.Properties JavaDoc;
28
29 import org.ofbiz.base.container.Container;
30 import org.ofbiz.base.container.ContainerException;
31 import org.ofbiz.base.container.ContainerConfig;
32 import org.ofbiz.base.util.UtilProperties;
33 import org.ofbiz.base.util.Debug;
34
35 import org.objectweb.carol.util.configuration.RMIConfigurationException;
36 import org.objectweb.transaction.jta.TMService;
37 import org.objectweb.jotm.Jotm;
38
39 import javax.naming.InitialContext JavaDoc;
40 import javax.naming.NamingException JavaDoc;
41
42 /**
43  * JOTM Container
44  *
45  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
46  * @version $Rev: 5462 $
47  * @since 3.0
48  */

49 public class JotmContainer implements Container {
50
51     public static final String JavaDoc module = JotmContainer.class.getName();
52
53     protected String JavaDoc configFile = null;
54     protected TMService jotm = null;
55
56     /**
57      * @see org.ofbiz.base.container.Container#init(java.lang.String[], java.lang.String)
58      */

59     public void init(String JavaDoc[] args, String JavaDoc configFile) throws ContainerException {
60         this.configFile = configFile;
61         this.startJotm();
62     }
63
64     public boolean start() throws ContainerException {
65         return true;
66     }
67
68     private void startJotm() throws ContainerException {
69         // get the container config
70
ContainerConfig.Container cc = ContainerConfig.getContainer("jotm-container", configFile);
71         if (cc == null) {
72             throw new ContainerException("No jotm-container configuration found in container config!");
73         }
74
75         // locate the JNDI (carol) configuration file
76
String JavaDoc carolPropName = ContainerConfig.getPropertyValue(cc, "jndi-config", "iiop.properties");
77
78         // load the properties file
79
Properties JavaDoc carolProps = UtilProperties.getProperties(carolPropName);
80         // initialize Carol
81
try {
82             // default initialization
83
org.objectweb.carol.util.configuration.CarolConfiguration.init();
84             // load the defined properties file
85
org.objectweb.carol.util.configuration.CarolConfiguration.loadCarolConfiguration(carolProps);
86         } catch (RMIConfigurationException e) {
87             throw new ContainerException("Carol threw configuration exception", e);
88         }
89
90         // start JOTM
91
try {
92             jotm = new Jotm(true, false);
93         } catch (NamingException JavaDoc e) {
94             throw new ContainerException("Unable to load JOTM", e);
95         }
96
97         // bind UserTransaction and TransactionManager to JNDI
98
try {
99             InitialContext JavaDoc ic = new InitialContext JavaDoc();
100             ic.rebind("java:comp/UserTransaction", jotm.getUserTransaction());
101         } catch (NamingException JavaDoc e) {
102             throw new ContainerException("Unable to bind UserTransaction/TransactionManager to JNDI", e);
103         }
104
105         // check JNDI
106
try {
107             InitialContext JavaDoc ic = new InitialContext JavaDoc();
108             Object JavaDoc o = ic.lookup("java:comp/UserTransaction");
109             if (o == null) {
110                 throw new NamingException JavaDoc("Object came back null");
111             }
112         } catch (NamingException JavaDoc e) {
113             throw new ContainerException("Unable to lookup bound objects", e);
114         }
115         Debug.logInfo("JOTM is bound to JNDI - java:comp/UserTransaction", module);
116     }
117
118     public void stop() throws ContainerException {
119         jotm.stop();
120     }
121
122 }
123
Popular Tags