public class JndiTemplate extends Object
JndiCallback interface to perform any operation they like with a JNDI naming context provided.
Note that this implementation is an almost exact copy of the Spring Framework's identically named class from their 2.5.4 distribution - we didn't want to re-invent the wheel, but not require a full dependency on the Spring framework, nor does Spring make available only its JNDI classes in a small jar, or we would have used that. Since Shiro is also Apache 2.0 licensed, all regular licenses and conditions and authors have remained in tact.
| Constructor and Description |
|---|
JndiTemplate()
Create a new JndiTemplate instance.
|
JndiTemplate(Properties
Create a new JndiTemplate instance, using the given environment.
|
| Modifier and Type | Method and Description |
|---|---|
void |
bind(String
Bind the given object to the current JNDI context, using the given name.
|
protected Context |
createInitialContext()
Create a new JNDI initial context.
|
Object |
execute(JndiCallback
Execute the given JNDI context callback implementation.
|
Properties |
getEnvironment()
Return the environment for the JNDI InitialContext, or
null if none should be used.
|
Object |
lookup(String
Look up the object with the given name in the current JNDI context.
|
Object |
lookup(String
Look up the object with the given name in the current JNDI context.
|
void |
rebind(String
Rebind the given object to the current JNDI context, using the given name.
|
void |
setEnvironment(Properties
Set the environment for the JNDI InitialContext.
|
void |
unbind(String
Remove the binding for the given name from the current JNDI context.
|
public JndiTemplate()
public JndiTemplate(Propertiesenvironment)
environment - the Properties to initialize with
public void setEnvironment(Propertiesenvironment)
environment - the Properties to initialize with
public PropertiesgetEnvironment()
null if none should be used.
null if none should be used.
public Objectexecute(JndiCallback contextCallback) throws NamingException
contextCallback - JndiCallback implementation
null
NamingException - thrown by the callback implementation
createInitialContext()
protected ContextcreateInitialContext() throws NamingException
execute(org.apache.shiro.jndi.JndiCallback).
The default implementation use this template's environment settings. Can be subclassed for custom contexts, e.g. for testing.
NamingException - in case of initialization errors
public Objectlookup(String name) throws NamingException
name - the JNDI name of the object
null; if a not so well-behaved JNDI implementations returns null, a NamingException gets thrown)
NamingException - if there is no object with the given name bound to JNDI
public Objectlookup(String name, Class requiredType) throws NamingException
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
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)
NamingException - if there is no object with the given name bound to JNDI
public void bind(Stringname, Object object) throws NamingException
name - the JNDI name of the object
object - the object to bind
NamingException - thrown by JNDI, mostly name already bound
public void rebind(Stringname, Object object) throws NamingException
name - the JNDI name of the object
object - the object to rebind
NamingException - thrown by JNDI
public void unbind(Stringname) throws NamingException
name - the JNDI name of the object
NamingException - thrown by JNDI, mostly name not found