NamingContext (Apache Tomcat 11.0.5 API Documentation)
Description: declaration: package: org.apache.naming, class: NamingContext

# Class NamingContext

java.lang.Object
org.apache.naming.NamingContext

All Implemented Interfaces:
  `Context`

public class NamingContext extends Object implements Context
Catalina JNDI Context implementation.

Author:
  Remy Maucherat

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final HashMap<String,NamingEntry>`
  `bindings`
  Bindings in this Context.
  `protected final Hashtable<String,Object>`
  `env`
  Environment.
  `protected final String`
  `name`
  Name of the associated Catalina Context.
  `protected static final NameParser`
  `nameParser`
  Name parser for this context.
  `protected static final StringManager`
  `sm`
  The string manager for this package.

  ### Fields inherited from interface javax.naming.Context

  `APPLET, AUTHORITATIVE, BATCHSIZE, DNS_URL, INITIAL_CONTEXT_FACTORY, LANGUAGE, OBJECT_FACTORIES, PROVIDER_URL, REFERRAL, SECURITY_AUTHENTICATION, SECURITY_CREDENTIALS, SECURITY_PRINCIPAL, SECURITY_PROTOCOL, STATE_FACTORIES, URL_PKG_PREFIXES`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `NamingContext(Hashtable<String,Object> env, String name)`
  Builds a naming context.
  `NamingContext(Hashtable<String,Object> env, String name, HashMap<String,NamingEntry> bindings)`
  Builds a naming context.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Object`
  `addToEnvironment(String propName, Object propVal)`
  `void`
  `bind(String name, Object obj)`
  `void`
  `bind(Name name, Object obj)`
  `protected void`
  `bind(Name name, Object obj, boolean rebind)`
  Binds a name to an object.
  `protected boolean`
  `checkWritable()`
  Throws a naming exception is Context is not writable.
  `void`
  `close()`
  `String`
  `composeName(String name, String prefix)`
  `Name`
  `composeName(Name name, Name prefix)`
  `Context`
  `createSubcontext(String name)`
  `Context`
  `createSubcontext(Name name)`
  `void`
  `destroySubcontext(String name)`
  `void`
  `destroySubcontext(Name name)`
  `Hashtable<?,?>`
  `getEnvironment()`
  `boolean`
  `getExceptionOnFailedWrite()`
  `String`
  `getNameInNamespace()`
  `NameParser`
  `getNameParser(String name)`
  `NameParser`
  `getNameParser(Name name)`
  `protected boolean`
  `isWritable()`
  `NamingEnumeration<NameClassPair>`
  `list(String name)`
  `NamingEnumeration<NameClassPair>`
  `list(Name name)`
  `NamingEnumeration<Binding>`
  `listBindings(String name)`
  `NamingEnumeration<Binding>`
  `listBindings(Name name)`
  `Object`
  `lookup(String name)`
  `Object`
  `lookup(Name name)`
  `protected Object`
  `lookup(Name name, boolean resolveLinks)`
  Retrieves the named object.
  `Object`
  `lookupLink(String name)`
  `Object`
  `lookupLink(Name name)`
  `void`
  `rebind(String name, Object obj)`
  `void`
  `rebind(Name name, Object obj)`
  `Object`
  `removeFromEnvironment(String propName)`
  `void`
  `rename(String oldName, String newName)`
  `void`
  `rename(Name oldName, Name newName)`
  `void`
  `setExceptionOnFailedWrite(boolean exceptionOnFailedWrite)`
  `void`
  `unbind(String name)`
  `void`
  `unbind(Name name)`

  ### Methods inherited from class java.lang.Object

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

- ## Field Details

  - ### nameParser

    protected static final NameParser nameParser
    Name parser for this context.

  - ### env

    protected final Hashtable<String,Object> env
    Environment.

  - ### sm

    protected static final StringManager sm
    The string manager for this package.

  - ### bindings

    protected final HashMap<String,NamingEntry> bindings
    Bindings in this Context.

  - ### name

    protected final String name
    Name of the associated Catalina Context.

- ## Constructor Details

  - ### NamingContext

    public NamingContext(Hashtable<String,Object> env, String name)
    Builds a naming context.
    Parameters:
      `env` - The environment to use to construct the naming context
      `name` - The name of the associated Catalina Context

  - ### NamingContext

    public NamingContext(Hashtable<String,Object> env, String name, HashMap<String,NamingEntry> bindings)
    Builds a naming context.
    Parameters:
      `env` - The environment to use to construct the naming context
      `name` - The name of the associated Catalina Context
      `bindings` - The initial bindings for the naming context

- ## Method Details

  - ### getExceptionOnFailedWrite

    public boolean getExceptionOnFailedWrite()

  - ### setExceptionOnFailedWrite

    public void setExceptionOnFailedWrite(boolean exceptionOnFailedWrite)

  - ### lookup

    public Object lookup(Name name) throws NamingException
    Specified by:
      `lookup` in interface `Context`
    Throws:
      `NamingException`

  - ### lookup

    public Object lookup(String name) throws NamingException
    Specified by:
      `lookup` in interface `Context`
    Throws:
      `NamingException`

  - ### bind

    public void bind(Name name, Object obj) throws NamingException
    Specified by:
      `bind` in interface `Context`
    Throws:
      `NamingException`

  - ### bind

    public void bind(String name, Object obj) throws NamingException
    Specified by:
      `bind` in interface `Context`
    Throws:
      `NamingException`

  - ### rebind

    public void rebind(Name name, Object obj) throws NamingException
    Specified by:
      `rebind` in interface `Context`
    Throws:
      `NamingException`

  - ### rebind

    public void rebind(String name, Object obj) throws NamingException
    Specified by:
      `rebind` in interface `Context`
    Throws:
      `NamingException`

  - ### unbind

    public void unbind(Name name) throws NamingException
    Specified by:
      `unbind` in interface `Context`
    Throws:
      `NamingException`

  - ### unbind

    public void unbind(String name) throws NamingException
    Specified by:
      `unbind` in interface `Context`
    Throws:
      `NamingException`

  - ### rename

    public void rename(Name oldName, Name newName) throws NamingException
    Specified by:
      `rename` in interface `Context`
    Throws:
      `NamingException`

  - ### rename

    public void rename(String oldName, String newName) throws NamingException
    Specified by:
      `rename` in interface `Context`
    Throws:
      `NamingException`

  - ### list

    public NamingEnumeration<NameClassPair> list(Name name) throws NamingException
    Specified by:
      `list` in interface `Context`
    Throws:
      `NamingException`

  - ### list

    public NamingEnumeration<NameClassPair> list(String name) throws NamingException
    Specified by:
      `list` in interface `Context`
    Throws:
      `NamingException`

  - ### listBindings

    public NamingEnumeration<Binding> listBindings(Name name) throws NamingException
    Specified by:
      `listBindings` in interface `Context`
    Throws:
      `NamingException`

  - ### listBindings

    public NamingEnumeration<Binding> listBindings(String name) throws NamingException
    Specified by:
      `listBindings` in interface `Context`
    Throws:
      `NamingException`

  - ### destroySubcontext

    public void destroySubcontext(Name name) throws NamingException
    Specified by:
      `destroySubcontext` in interface `Context`
    Throws:
      `NamingException`

  - ### destroySubcontext

    public void destroySubcontext(String name) throws NamingException
    Specified by:
      `destroySubcontext` in interface `Context`
    Throws:
      `NamingException`

  - ### createSubcontext

    public Context createSubcontext(Name name) throws NamingException
    Specified by:
      `createSubcontext` in interface `Context`
    Throws:
      `NamingException`

  - ### createSubcontext

    public Context createSubcontext(String name) throws NamingException
    Specified by:
      `createSubcontext` in interface `Context`
    Throws:
      `NamingException`

  - ### lookupLink

    public Object lookupLink(Name name) throws NamingException
    Specified by:
      `lookupLink` in interface `Context`
    Throws:
      `NamingException`

  - ### lookupLink

    public Object lookupLink(String name) throws NamingException
    Specified by:
      `lookupLink` in interface `Context`
    Throws:
      `NamingException`

  - ### getNameParser

    public NameParser getNameParser(Name name) throws NamingException
    Specified by:
      `getNameParser` in interface `Context`
    Throws:
      `NamingException`

  - ### getNameParser

    public NameParser getNameParser(String name) throws NamingException
    Specified by:
      `getNameParser` in interface `Context`
    Throws:
      `NamingException`

  - ### composeName

    public Name composeName(Name name, Name prefix) throws NamingException
    Specified by:
      `composeName` in interface `Context`
    Throws:
      `NamingException`

  - ### composeName

    public String composeName(String name, String prefix)
    Specified by:
      `composeName` in interface `Context`

  - ### addToEnvironment

    public Object addToEnvironment(String propName, Object propVal)
    Specified by:
      `addToEnvironment` in interface `Context`

  - ### removeFromEnvironment

    public Object removeFromEnvironment(String propName)
    Specified by:
      `removeFromEnvironment` in interface `Context`

  - ### getEnvironment

    public Hashtable<?,?> getEnvironment()
    Specified by:
      `getEnvironment` in interface `Context`

  - ### close

    public void close() throws NamingException
    Specified by:
      `close` in interface `Context`
    Throws:
      `NamingException`

  - ### getNameInNamespace

    public String getNameInNamespace() throws NamingException
    Specified by:
      `getNameInNamespace` in interface `Context`
    Throws:
      `NamingException`

  - ### lookup

    protected Object lookup(Name name, boolean resolveLinks) throws NamingException
    Retrieves the named object.
    Parameters:
      `name` - the name of the object to look up
      `resolveLinks` - If true, the links will be resolved
    Returns:
      the object bound to name
    Throws:
      `NamingException` - if a naming exception is encountered

  - ### bind

    protected void bind(Name name, Object obj, boolean rebind) throws NamingException
    Binds a name to an object. All intermediate contexts and the target context (that named by all but terminal atomic component of the name) must already exist.
    Parameters:
      `name` - the name to bind; may not be empty
      `obj` - the object to bind; possibly null
      `rebind` - if true, then perform a rebind (ie, overwrite)
    Throws:
      `NameAlreadyBoundException` - if name is already bound
      `InvalidAttributesException` - if object did not supply all mandatory attributes
      `NamingException` - if a naming exception is encountered

  - ### isWritable

    protected boolean isWritable()
    Returns:
      `true` if writing is allowed on this context.

  - ### checkWritable

    protected boolean checkWritable() throws NamingException
    Throws a naming exception is Context is not writable.
    Returns:
      `true` if the Context is writable
    Throws:
      `NamingException` - if the Context is not writable and `exceptionOnFailedWrite` is `true`