01: package applis.ejb.perfs;
02:
03: import javax.rmi.PortableRemoteObject;
04: import javax.transaction.UserTransaction;
05: import javax.naming.InitialContext;
06: import java.util.Properties;
07:
08: /**
09: * A litlle class that helps clients to lookup UserTransaction. Indeed the InitialContext
10: * requires different properties if we are using David or RMI
11: */
12: public class Transaction {
13:
14: static private InitialContext ictx = null;
15:
16: static public UserTransaction getUserTransaction()
17: throws javax.naming.NamingException {
18:
19: if (ictx == null) {
20: String registryPort = System
21: .getProperty("jonas.registryport");
22:
23: if (registryPort != null) {
24: // it means we are using David
25: Properties prop = new Properties();
26: prop
27: .put("java.naming.factory.initial",
28: "com.sun.jndi.rmi.registry.RegistryContextFactory");
29: prop.put("java.naming.provider.url", "rmi://localhost:"
30: + registryPort);
31: ictx = new InitialContext(prop);
32: } else {
33: ictx = new InitialContext();
34: }
35: }
36:
37: return (UserTransaction) PortableRemoteObject.narrow(ictx
38: .lookup("javax.transaction.UserTransaction"),
39: UserTransaction.class);
40: }
41: }
|