public class JndiTemplate
extends java.lang.Object
JndiCallback
interface
to perform any operation they like with a JNDI naming context provided.JndiCallback
,
execute(org.springframework.jndi.JndiCallback<T>)
Constructor and Description |
---|
JndiTemplate()
Create a new JndiTemplate instance.
|
JndiTemplate(java.util.Properties environment)
Create a new JndiTemplate instance, using the given environment.
|
Modifier and Type | Method and Description |
---|---|
void |
bind(java.lang.String name,
java.lang.Object object)
Bind the given object to the current JNDI context, using the given name.
|
protected javax.naming.Context |
createInitialContext()
Create a new JNDI initial context.
|
<T> T |
execute(JndiCallback<T> contextCallback)
Execute the given JNDI context callback implementation.
|
javax.naming.Context |
getContext()
Obtain a JNDI context corresponding to this template's configuration.
|
java.util.Properties |
getEnvironment()
Return the environment for the JNDI InitialContext, if any.
|
java.lang.Object |
lookup(java.lang.String name)
Look up the object with the given name in the current JNDI context.
|
<T> T |
lookup(java.lang.String name,
java.lang.Class<T> requiredType)
Look up the object with the given name in the current JNDI context.
|
void |
rebind(java.lang.String name,
java.lang.Object object)
Rebind the given object to the current JNDI context, using the given name.
|
void |
releaseContext(javax.naming.Context ctx)
Release a JNDI context as obtained from
getContext() . |
void |
setEnvironment(java.util.Properties environment)
Set the environment for the JNDI InitialContext.
|
void |
unbind(java.lang.String name)
Remove the binding for the given name from the current JNDI context.
|
protected final Log logger
public JndiTemplate()
public JndiTemplate(@Nullable java.util.Properties environment)
public void setEnvironment(@Nullable java.util.Properties environment)
@Nullable public java.util.Properties getEnvironment()
@Nullable public <T> T execute(JndiCallback<T> contextCallback) throws javax.naming.NamingException
contextCallback
- the JndiCallback implementation to usenull
javax.naming.NamingException
- thrown by the callback implementationcreateInitialContext()
public javax.naming.Context getContext() throws javax.naming.NamingException
execute(org.springframework.jndi.JndiCallback<T>)
; may also be called directly.
The default implementation delegates to createInitialContext()
.
null
)javax.naming.NamingException
- if context retrieval failedreleaseContext(javax.naming.Context)
public void releaseContext(@Nullable javax.naming.Context ctx)
getContext()
.ctx
- the JNDI context to release (may be null
)getContext()
protected javax.naming.Context createInitialContext() throws javax.naming.NamingException
getContext()
.
The default implementation use this template's environment settings. Can be subclassed for custom contexts, e.g. for testing.
javax.naming.NamingException
- in case of initialization errorspublic java.lang.Object lookup(java.lang.String name) throws javax.naming.NamingException
name
- the JNDI name of the objectnull
; if a not so well-behaved
JNDI implementations returns null, a NamingException gets thrown)javax.naming.NamingException
- if there is no object with the given
name bound to JNDIpublic <T> T lookup(java.lang.String name, @Nullable java.lang.Class<T> requiredType) throws javax.naming.NamingException
name
- the JNDI name of the objectrequiredType
- type the JNDI object must match. Can be an interface or
superclass of the actual class, or null
for any match. For example,
if the value is Object.class
, this method will succeed whatever
the class of the returned instance.null
; if a not so well-behaved
JNDI implementations returns null, a NamingException gets thrown)javax.naming.NamingException
- if there is no object with the given
name bound to JNDIpublic void bind(java.lang.String name, java.lang.Object object) throws javax.naming.NamingException
name
- the JNDI name of the objectobject
- the object to bindjavax.naming.NamingException
- thrown by JNDI, mostly name already boundpublic void rebind(java.lang.String name, java.lang.Object object) throws javax.naming.NamingException
name
- the JNDI name of the objectobject
- the object to rebindjavax.naming.NamingException
- thrown by JNDIpublic void unbind(java.lang.String name) throws javax.naming.NamingException
name
- the JNDI name of the objectjavax.naming.NamingException
- thrown by JNDI, mostly name not found