1 22 package org.jboss.ejb3; 23 24 import java.util.Hashtable ; 25 import java.util.LinkedList ; 26 import javax.naming.Context ; 27 import javax.naming.Name ; 28 import javax.naming.spi.ObjectFactory ; 29 import org.jnp.interfaces.NamingContext; 30 import org.jnp.server.NamingServer; 31 32 39 public class ThreadLocalENCFactory 40 implements ObjectFactory 41 { 42 private static ThreadLocal enc = new ThreadLocal (); 43 private static ThreadLocal stack = new ThreadLocal (); 44 45 public static Context create(Context parent) throws Exception 46 { 47 NamingServer srv = new NamingServer(); 48 return new NamingContext(parent.getEnvironment(), null, srv); 49 } 50 51 public static void push(Context ctx) 52 { 53 if (enc.get() == null) 54 { 55 enc.set(ctx); 56 return; 57 } 58 LinkedList currentStack = (LinkedList ) stack.get(); 59 if (currentStack == null) 60 { 61 currentStack = new LinkedList (); 62 stack.set(currentStack); 63 } 64 currentStack.addLast(enc.get()); 65 enc.set(ctx); 66 } 67 68 public static void pop() 69 { 70 LinkedList currentStack = (LinkedList ) stack.get(); 71 if (currentStack == null) 72 { 73 enc.set(null); 74 return; 75 } 76 if (currentStack.size() == 0) 77 { 78 enc.set(null); 79 return; 80 } 81 Object previous = currentStack.removeLast(); 82 enc.set(previous); 83 } 84 86 88 public Object getObjectInstance(Object obj, Name name, Context nameCtx, 90 Hashtable environment) 91 throws Exception 92 { 93 return enc.get(); 94 } 95 96 } 97 | Popular Tags |