1 25 package org.ofbiz.jotm.container; 26 27 import java.util.Properties ; 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 ; 40 import javax.naming.NamingException ; 41 42 49 public class JotmContainer implements Container { 50 51 public static final String module = JotmContainer.class.getName(); 52 53 protected String configFile = null; 54 protected TMService jotm = null; 55 56 59 public void init(String [] args, String 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 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 String carolPropName = ContainerConfig.getPropertyValue(cc, "jndi-config", "iiop.properties"); 77 78 Properties carolProps = UtilProperties.getProperties(carolPropName); 80 try { 82 org.objectweb.carol.util.configuration.CarolConfiguration.init(); 84 org.objectweb.carol.util.configuration.CarolConfiguration.loadCarolConfiguration(carolProps); 86 } catch (RMIConfigurationException e) { 87 throw new ContainerException("Carol threw configuration exception", e); 88 } 89 90 try { 92 jotm = new Jotm(true, false); 93 } catch (NamingException e) { 94 throw new ContainerException("Unable to load JOTM", e); 95 } 96 97 try { 99 InitialContext ic = new InitialContext (); 100 ic.rebind("java:comp/UserTransaction", jotm.getUserTransaction()); 101 } catch (NamingException e) { 102 throw new ContainerException("Unable to bind UserTransaction/TransactionManager to JNDI", e); 103 } 104 105 try { 107 InitialContext ic = new InitialContext (); 108 Object o = ic.lookup("java:comp/UserTransaction"); 109 if (o == null) { 110 throw new NamingException ("Object came back null"); 111 } 112 } catch (NamingException 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 |