1 7 package org.jboss.jms.p2p.naming; 8 9 import java.util.Hashtable ; 10 import java.util.Map ; 11 import java.util.HashMap ; 12 import java.util.Iterator ; 13 14 import javax.naming.spi.InitialContextFactory ; 15 import javax.naming.Context ; 16 import javax.naming.NamingException ; 17 18 24 public class InitialContextFactoryImpl implements InitialContextFactory 25 { 26 private static final Map INITIAL_CONTEXT_MAP = new HashMap (); 27 28 public synchronized Context getInitialContext(Hashtable environment) throws NamingException 29 { 30 try 31 { 32 Integer key = new Integer (environment.hashCode()); 33 if (!INITIAL_CONTEXT_MAP.containsKey(key)) 34 { 35 Context context = new ContextImpl(environment); 36 INITIAL_CONTEXT_MAP.put(key, context); 37 return context; 38 } 39 else 40 { 41 return (Context ) INITIAL_CONTEXT_MAP.get(key); 42 } 43 } 44 catch (Exception exception) 45 { 46 throw new NamingException (exception.getMessage()); 47 } 48 } 49 50 static synchronized void unregisterInitialContext(Context context) 51 { 52 if (INITIAL_CONTEXT_MAP.containsValue(context)) 53 { 54 Iterator iterator = INITIAL_CONTEXT_MAP.keySet().iterator(); 55 while (iterator.hasNext()) 56 { 57 Object key = iterator.next(); 58 if (INITIAL_CONTEXT_MAP.get(key) == context) 59 { 60 INITIAL_CONTEXT_MAP.remove(key); 61 } 62 } 63 } 64 } 65 } 66 | Popular Tags |