1 22 package org.jboss.tm.iiop.client; 23 24 import java.util.Hashtable ; 25 26 import javax.naming.Context ; 27 import javax.naming.InitialContext ; 28 import javax.naming.Name ; 29 import javax.naming.NamingException ; 30 import javax.naming.spi.ObjectFactory ; 31 import javax.transaction.UserTransaction ; 32 33 import org.omg.CORBA.BAD_PARAM ; 34 35 import org.jboss.logging.Logger; 36 import org.jboss.tm.iiop.TransactionFactoryExtHelper; 37 import org.jboss.tm.usertx.client.ServerVMClientUserTransaction; 38 39 47 public class IIOPClientUserTransactionObjectFactory 48 implements ObjectFactory 49 { 50 private static final Logger log = 51 Logger.getLogger(IIOPClientUserTransactionObjectFactory.class); 52 private static final boolean traceEnabled = log.isTraceEnabled(); 53 54 58 private static UserTransaction userTransaction = null; 59 60 64 private static UserTransaction getUserTransaction() 65 { 66 if (userTransaction == null) 67 { 68 try 70 { 71 new InitialContext ().lookup("java:/TransactionManager"); 72 73 userTransaction = ServerVMClientUserTransaction.getSingleton(); 75 } 76 catch (NamingException ex) 77 { 78 userTransaction = IIOPClientUserTransaction.getSingleton(); 80 } 81 } 82 return userTransaction; 83 } 84 85 public Object getObjectInstance(Object obj, Name name, 86 Context nameCtx, Hashtable environment) 87 throws Exception 88 { 89 90 if (traceEnabled) 91 log.trace("getObjectInstance: obj=" + obj + 92 "\n name=" + name + 93 "\n nameCtx= " + nameCtx); 94 95 if (!name.toString().equals("UserTransaction")) 96 return null; 97 try 98 { 99 TransactionFactoryExtHelper.narrow(obj); 100 } 101 catch (BAD_PARAM e) 102 { 103 return null; 104 } 105 return getUserTransaction(); 106 } 107 } 108 109 | Popular Tags |