1 25 26 package org.objectweb.easybeans.injection; 27 28 import javax.naming.InitialContext ; 29 import javax.naming.NamingException ; 30 31 import org.objectweb.easybeans.log.JLog; 32 import org.objectweb.easybeans.log.JLogFactory; 33 34 38 public final class JNDILookupHelper { 39 40 43 public enum JndiType { REGISTRY, JAVA_COMP, JAVA_COMP_ENV} 44 45 48 private static final String JAVA_COMP = "java:comp/"; 49 50 53 private static final String JAVA_COMP_ENV = JAVA_COMP + "env/"; 54 55 58 private static JLog logger = JLogFactory.getLog(JNDILookupHelper.class); 59 60 61 62 65 private JNDILookupHelper() { 66 67 } 68 69 74 public static Object getJndiName(final String name) { 75 InitialContext ictx; 76 try { 77 ictx = new InitialContext (); 78 } catch (NamingException e) { 79 logger.error("Cannot instantiate an initial context", e); 80 return null; 81 } 82 83 Object o = null; 84 try { 85 o = ictx.lookup(name); 86 } catch (NamingException e) { 87 logger.error("Cannot find the JNDI name {0}", name, e); 88 } 89 if (o == null) { 90 logger.error("No object was found for JNDI name {0}", name); 91 } 92 return o; 93 } 94 95 100 public static Object getEnvJndiName(final String name) { 101 return getJndiName(JAVA_COMP_ENV + name); 102 } 103 104 109 public static Object getCompJndiName(final String name) { 110 return getJndiName(JAVA_COMP + name); 111 } 112 113 } 114 | Popular Tags |