org.springframework.jndi

## 类 JndiTemplate

- java.lang.Object
- - org.springframework.jndi.JndiTemplate

-     public class JndiTemplate
      extends Object

  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.
  作者:
    Rod Johnson, Juergen Hoeller
  另请参阅:
    `JndiCallback`, `execute(org.springframework.jndi.JndiCallback<T>)`

- - ### 字段概要

    字段
    限定符和类型 | 字段和说明
    --- | ---
    `protected Log` | `logger`

  - ### 构造器概要

    构造器
    构造器和说明
    `JndiTemplate()` Create a new JndiTemplate instance.
    `JndiTemplate(Properties environment)` Create a new JndiTemplate instance, using the given environment.

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `void` | `bind(String name, Object object)` Bind the given object to the current JNDI context, using the given name.
    `protected Context` | `createInitialContext()` Create a new JNDI initial context.
    `<T> T` | `execute(JndiCallback<T> contextCallback)` Execute the given JNDI context callback implementation.
    `Context` | `getContext()` Obtain a JNDI context corresponding to this template's configuration.
    `Properties` | `getEnvironment()` Return the environment for the JNDI InitialContext, if any.
    `Object` | `lookup(String name)` Look up the object with the given name in the current JNDI context.
    `<T> T` | `lookup(String name, Class<T> requiredType)` Look up the object with the given name in the current JNDI context.
    `void` | `rebind(String name, Object object)` Rebind the given object to the current JNDI context, using the given name.
    `void` | `releaseContext(Context ctx)` Release a JNDI context as obtained from `getContext()`.
    `void` | `setEnvironment(Properties environment)` Set the environment for the JNDI InitialContext.
    `void` | `unbind(String name)` Remove the binding for the given name from the current JNDI context.

    - ### 从类继承的方法 java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 字段详细资料

    - #### logger

          protected final Log logger

  - ### 构造器详细资料

    - #### JndiTemplate

          public JndiTemplate()

      Create a new JndiTemplate instance.

    - #### JndiTemplate

          public JndiTemplate(@Nullable
                              Properties environment)

      Create a new JndiTemplate instance, using the given environment.

  - ### 方法详细资料

    - #### setEnvironment

          public void setEnvironment(@Nullable
                                     Properties environment)

      Set the environment for the JNDI InitialContext.

    - #### getEnvironment

          @Nullable
          public Properties getEnvironment()

      Return the environment for the JNDI InitialContext, if any.

    - #### execute

          @Nullable
          public <T> T execute(JndiCallback<T> contextCallback)
                                   throws NamingException

      Execute the given JNDI context callback implementation.
      参数:
        `contextCallback` - JndiCallback implementation
      返回:
        a result object returned by the callback, or `null`
      抛出:
        `NamingException` - thrown by the callback implementation
      另请参阅:
        `createInitialContext()`

    - #### getContext

          public Context getContext()
                             throws NamingException

      Obtain a JNDI context corresponding to this template's configuration. Called by `execute(org.springframework.jndi.JndiCallback<T>)`; may also be called directly.

      The default implementation delegates to `createInitialContext()`.

      返回:
        the JNDI context (never `null`)
      抛出:
        `NamingException` - if context retrieval failed
      另请参阅:
        `releaseContext(javax.naming.Context)`

    - #### releaseContext

          public void releaseContext(@Nullable
                                     Context ctx)

      Release a JNDI context as obtained from `getContext()`.
      参数:
        `ctx` - the JNDI context to release (may be `null`)
      另请参阅:
        `getContext()`

    - #### createInitialContext

          protected Context createInitialContext()
                                          throws NamingException

      Create a new JNDI initial context. Invoked by `getContext()`.

      The default implementation use this template's environment settings. Can be subclassed for custom contexts, e.g. for testing.

      返回:
        the initial Context instance
      抛出:
        `NamingException` - in case of initialization errors

    - #### lookup

          public Object lookup(String name)
                        throws NamingException

      Look up the object with the given name in the current JNDI context.
      参数:
        `name` - the JNDI name of the object
      返回:
        object found (cannot be `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

    - #### lookup

          public <T> T lookup(String name,
                              @Nullable
                              Class<T> requiredType)
                       throws NamingException

      Look up the object with the given name in the current JNDI context.
      参数:
        `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.
      返回:
        object found (cannot be `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

    - #### bind

          public void bind(String name,
                           Object object)
                    throws NamingException

      Bind the given object to the current JNDI context, using the given name.
      参数:
        `name` - the JNDI name of the object
        `object` - the object to bind
      抛出:
        `NamingException` - thrown by JNDI, mostly name already bound

    - #### rebind

          public void rebind(String name,
                             Object object)
                      throws NamingException

      Rebind the given object to the current JNDI context, using the given name. Overwrites any existing binding.
      参数:
        `name` - the JNDI name of the object
        `object` - the object to rebind
      抛出:
        `NamingException` - thrown by JNDI

    - #### unbind

          public void unbind(String name)
                      throws NamingException

      Remove the binding for the given name from the current JNDI context.
      参数:
        `name` - the JNDI name of the object
      抛出:
        `NamingException` - thrown by JNDI, mostly name not found