1 17 18 package org.apache.geronimo.naming.enc; 19 20 import java.util.HashMap ; 21 import java.util.Iterator ; 22 import java.util.Map ; 23 import java.util.Collections ; 24 25 import javax.naming.Context ; 26 import javax.naming.NamingException ; 27 import javax.transaction.UserTransaction ; 28 29 import org.apache.geronimo.kernel.Kernel; 30 import org.apache.geronimo.naming.reference.ClassLoaderAwareReference; 31 import org.apache.geronimo.naming.reference.KernelAwareReference; 32 import org.apache.xbean.naming.context.ImmutableContext; 33 34 37 public final class EnterpriseNamingContext { 38 39 public static Context createEnterpriseNamingContext(Map componentContext, UserTransaction userTransaction, Kernel kernel, ClassLoader classLoader) throws NamingException { 40 Map map = new HashMap (); 41 if (componentContext != null) { 42 map.putAll(componentContext); 43 } 44 45 boolean containsEnv = false; 46 for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) { 47 Map.Entry entry = (Map.Entry ) iterator.next(); 48 String name = (String ) entry.getKey(); 49 Object value = entry.getValue(); 50 51 if (name.startsWith("env/")) { 52 containsEnv = true; 53 } 54 if (value instanceof KernelAwareReference) { 55 ((KernelAwareReference) value).setKernel(kernel); 56 } 57 if (value instanceof ClassLoaderAwareReference) { 58 ((ClassLoaderAwareReference) value).setClassLoader(classLoader); 59 } 60 } 61 62 if (!containsEnv) { 63 Context env = new ImmutableContext("java:comp/env", Collections.EMPTY_MAP, false); 64 map.put("env", env); 65 } 66 67 if (userTransaction != null) { 68 map.put("UserTransaction", userTransaction); 69 } 70 71 return createEnterpriseNamingContext(map); 72 } 73 74 public static Context createEnterpriseNamingContext(Map context) throws NamingException { 75 return new ImmutableContext(context); 76 } 77 78 } 79 | Popular Tags |