1 16 17 package org.springframework.jndi; 18 19 import javax.naming.NamingException ; 20 21 import org.springframework.util.Assert; 22 23 40 public abstract class JndiLocatorSupport extends JndiAccessor { 41 42 43 public static final String CONTAINER_PREFIX = "java:comp/env/"; 44 45 46 private boolean resourceRef = false; 47 48 49 56 public void setResourceRef(boolean resourceRef) { 57 this.resourceRef = resourceRef; 58 } 59 60 63 public boolean isResourceRef() { 64 return this.resourceRef; 65 } 66 67 68 76 protected Object lookup(String jndiName) throws NamingException { 77 return lookup(jndiName, null); 78 } 79 80 88 protected Object lookup(String jndiName, Class requiredType) throws NamingException { 89 Assert.notNull(jndiName, "'jndiName' must not be null"); 90 String jndiNameToUse = convertJndiName(jndiName); 91 Object jndiObject = getJndiTemplate().lookup(jndiNameToUse, requiredType); 92 if (logger.isDebugEnabled()) { 93 logger.debug("Located object with JNDI name [" + jndiNameToUse + "]"); 94 } 95 return jndiObject; 96 } 97 98 107 protected String convertJndiName(String jndiName) { 108 if (isResourceRef() && !jndiName.startsWith(CONTAINER_PREFIX) && jndiName.indexOf(':') == -1) { 110 jndiName = CONTAINER_PREFIX + jndiName; 111 } 112 return jndiName; 113 } 114 115 } 116 | Popular Tags |