Package org.springframework.jndi
Class JndiTemplate
java.lang.Object
org.springframework.jndi.JndiTemplate
Helper class that simplifies JNDI operations. It provides methods to lookup and
 bind objects, and allows implementations of the 
JndiCallback interface
 to perform any operation they like with a JNDI naming context provided.- Author:
- Rod Johnson, Juergen Hoeller
- See Also:
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionCreate a new JndiTemplate instance.JndiTemplate(Properties environment) Create a new JndiTemplate instance, using the given environment.
- 
Method SummaryModifier and TypeMethodDescriptionvoidBind the given object to the current JNDI context, using the given name.protected ContextCreate a new JNDI initial context.<T> Texecute(JndiCallback<T> contextCallback) Execute the given JNDI context callback implementation.Obtain a JNDI context corresponding to this template's configuration.Return the environment for the JNDI InitialContext, if any.Look up the object with the given name in the current JNDI context.<T> TLook up the object with the given name in the current JNDI context.voidRebind the given object to the current JNDI context, using the given name.voidreleaseContext(Context ctx) Release a JNDI context as obtained fromgetContext().voidsetEnvironment(Properties environment) Set the environment for the JNDI InitialContext.voidRemove the binding for the given name from the current JNDI context.
- 
Field Details- 
logger
 
- 
- 
Constructor Details- 
JndiTemplatepublic JndiTemplate()Create a new JndiTemplate instance.
- 
JndiTemplateCreate a new JndiTemplate instance, using the given environment.
 
- 
- 
Method Details- 
setEnvironmentSet the environment for the JNDI InitialContext.
- 
getEnvironmentReturn the environment for the JNDI InitialContext, if any.
- 
executeExecute the given JNDI context callback implementation.- Parameters:
- contextCallback- the JndiCallback implementation to use
- Returns:
- a result object returned by the callback, or null
- Throws:
- NamingException- thrown by the callback implementation
- See Also:
 
- 
getContextObtain a JNDI context corresponding to this template's configuration. Called byexecute(org.springframework.jndi.JndiCallback<T>); may also be called directly.The default implementation delegates to createInitialContext().- Returns:
- the JNDI context (never null)
- Throws:
- NamingException- if context retrieval failed
- See Also:
 
- 
releaseContextRelease a JNDI context as obtained fromgetContext().- Parameters:
- ctx- the JNDI context to release (may be- null)
- See Also:
 
- 
createInitialContextCreate a new JNDI initial context. Invoked bygetContext().The default implementation use this template's environment settings. Can be subclassed for custom contexts, e.g. for testing. - Returns:
- the initial Context instance
- Throws:
- NamingException- in case of initialization errors
 
- 
lookupLook up the object with the given name in the current JNDI context.- Parameters:
- name- the JNDI name of the object
- Returns:
- object found (cannot be null; if a not so well-behaved JNDI implementations returns null, a NamingException gets thrown)
- Throws:
- NamingException- if there is no object with the given name bound to JNDI
 
- 
lookupLook up the object with the given name in the current JNDI context.- Parameters:
- name- the JNDI name of the object
- requiredType- type the JNDI object must match. Can be an interface or superclass of the actual class, or- nullfor any match. For example, if the value is- Object.class, this method will succeed whatever the class of the returned instance.
- Returns:
- object found (cannot be null; if a not so well-behaved JNDI implementations returns null, a NamingException gets thrown)
- Throws:
- NamingException- if there is no object with the given name bound to JNDI
 
- 
bindBind the given object to the current JNDI context, using the given name.- Parameters:
- name- the JNDI name of the object
- object- the object to bind
- Throws:
- NamingException- thrown by JNDI, mostly name already bound
 
- 
rebindRebind the given object to the current JNDI context, using the given name. Overwrites any existing binding.- Parameters:
- name- the JNDI name of the object
- object- the object to rebind
- Throws:
- NamingException- thrown by JNDI
 
- 
unbindRemove the binding for the given name from the current JNDI context.- Parameters:
- name- the JNDI name of the object
- Throws:
- NamingException- thrown by JNDI, mostly name not found
 
 
-