org.springframework.jndi
Class JndiLocatorSupport

java.lang.Object
  extended byorg.springframework.jndi.JndiAccessor
      extended byorg.springframework.jndi.JndiLocatorSupport
Direct Known Subclasses:
JndiDestinationResolver, JndiObjectLocator

public abstract class JndiLocatorSupport
extends JndiAccessor

Convenient superclass for classes that can locate any number of JNDI objects. Derives from JndiAccessor to inherit jndiTemplate and jndiEnvironment properties.

JNDI names may or may not include the "java:comp/env/" prefix expected by J2EE applications when accessing a locally mapped (ENC - Environmental Naming Context) resource. If it doesn't, the "java:comp/env/" prefix will be prepended if the "resourceRef" property is true (the default is false) and no other scheme like "java:" is given.

Since:
1.1
Author:
Juergen Hoeller
See Also:
JndiAccessor.setJndiTemplate(org.springframework.jndi.JndiTemplate), JndiAccessor.setJndiEnvironment(java.util.Properties), setResourceRef(boolean)

Field Summary
static String CONTAINER_PREFIX
          JNDI prefix used in a J2EE container
 
Fields inherited from class org.springframework.jndi.JndiAccessor
logger
 
Constructor Summary
JndiLocatorSupport()
           
 
Method Summary
protected  String convertJndiName(String jndiName)
          Convert the given JNDI name to the actual JNDI name to use.
 boolean isResourceRef()
          Return if the lookup occurs in a J2EE container.
protected  Object lookup(String jndiName)
          Perform an actual JNDI lookup for the given name via the JndiTemplate.
 void setResourceRef(boolean resourceRef)
          Set if the lookup occurs in a J2EE container, i.e. if the prefix "java:comp/env/" needs to be added if the JNDI name doesn't already contain it.
 
Methods inherited from class org.springframework.jndi.JndiAccessor
getJndiEnvironment, getJndiTemplate, setJndiEnvironment, setJndiTemplate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTAINER_PREFIX

public static String CONTAINER_PREFIX
JNDI prefix used in a J2EE container

Constructor Detail

JndiLocatorSupport

public JndiLocatorSupport()
Method Detail

setResourceRef

public void setResourceRef(boolean resourceRef)
Set if the lookup occurs in a J2EE container, i.e. if the prefix "java:comp/env/" needs to be added if the JNDI name doesn't already contain it. Default is false.

Note: Will only get applied if no other scheme like "java:" is given.


isResourceRef

public boolean isResourceRef()
Return if the lookup occurs in a J2EE container.


lookup

protected Object lookup(String jndiName)
                 throws NamingException
Perform an actual JNDI lookup for the given name via the JndiTemplate. If the name doesn't begin with "java:comp/env/", this prefix is added if resourceRef is set to true.

Parameters:
jndiName - the JNDI name to look up
Throws:
NamingException - if the JNDI lookup failed
See Also:
setResourceRef(boolean)

convertJndiName

protected String convertJndiName(String jndiName)
Convert the given JNDI name to the actual JNDI name to use. Default implementation applies the "java:comp/env/" prefix if resourceRef is true and no other scheme like "java:" is given.

Parameters:
jndiName - the original JNDI name
Returns:
the JNDI name to use
See Also:
CONTAINER_PREFIX, setResourceRef(boolean)


Copyright (C) 2003-2004 The Spring Framework Project.