public abstract class

JndiLocatorSupport

extends JndiAccessor
java.lang.Object
   ↳ org.springframework.jndi.JndiAccessor
     ↳ org.springframework.jndi.JndiLocatorSupport
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Convenient superclass for classes that can locate any number of JNDI objects. Derives from JndiAccessor to inherit the "jndiTemplate" and "jndiEnvironment" bean 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 (e.g. "java:") is given.

Summary

Constants
String CONTAINER_PREFIX JNDI prefix used in a J2EE container
[Expand]
Inherited Fields
From class org.springframework.jndi.JndiAccessor
Public Constructors
JndiLocatorSupport()
Public Methods
boolean isResourceRef()
Return whether the lookup occurs in a J2EE container.
void setResourceRef(boolean resourceRef)
Set whether the lookup occurs in a J2EE container, i.e.
Protected Methods
String convertJndiName(String jndiName)
Convert the given JNDI name into the actual JNDI name to use.
<T> T lookup(String jndiName, Class<T> requiredType)
Perform an actual JNDI lookup for the given name via the JndiTemplate.
Object lookup(String jndiName)
Perform an actual JNDI lookup for the given name via the JndiTemplate.
[Expand]
Inherited Methods
From class org.springframework.jndi.JndiAccessor
From class java.lang.Object

Constants

public static final String CONTAINER_PREFIX

JNDI prefix used in a J2EE container

Constant Value: "java:comp/env/"

Public Constructors

public JndiLocatorSupport ()

Public Methods

public boolean isResourceRef ()

Return whether the lookup occurs in a J2EE container.

public void setResourceRef (boolean resourceRef)

Set whether 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 (e.g. "java:") is given.

Protected Methods

protected String convertJndiName (String jndiName)

Convert the given JNDI name into the actual JNDI name to use.

The default implementation applies the "java:comp/env/" prefix if "resourceRef" is "true" and no other scheme (e.g. "java:") is given.

Parameters
jndiName the original JNDI name
Returns
  • the JNDI name to use

protected T lookup (String jndiName, Class<T> requiredType)

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
requiredType the required type of the object
Returns
  • the obtained object
Throws
NamingException if the JNDI lookup failed

protected Object lookup (String jndiName)

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
Returns
  • the obtained object
Throws
NamingException if the JNDI lookup failed