javax.naming
Class InitialContext

java.lang.Object
  extended by javax.naming.InitialContext
All Implemented Interfaces:
Context
Direct Known Subclasses:
InitialDirContext

public class InitialContext
extends Object
implements Context

The starting context for performing naming operations. All naming operations are performed in the scope of some context. The initial context is the starting point for the name resolution.


Field Summary
protected  Context defaultInitCtx
          Contains the default initial context.
protected  boolean gotDefault
          Indicates if the initial context was obtained by calling NamingManager.getInitialContext(java.util.Hashtable).
protected  Hashtable<Object,Object> myProps
          The environment, associated with this initial context.
 
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
  InitialContext()
          Creates teh new initial context with no properties.
protected InitialContext(boolean lazy)
          Creates the initial context with the possibility to delay its initialisation.
  InitialContext(Hashtable<?,?> environment)
          Creates the new initial context with the given properties.
 
Method Summary
 Object addToEnvironment(String propName, Object propVal)
          Add new environment property to the environment of this context.
 void bind(Name name, Object obj)
          Give the specified name for the specified object.
 void bind(String name, Object obj)
          Give the specified name for the specified object.
 void close()
          Releases all resources, associated with this context.
 Name composeName(Name name, Name prefix)
          Composes the name of this context together with another name, related to this context.
 String composeName(String name, String prefix)
          Composes the name of this context together with another name, related to this context.
 Context createSubcontext(Name name)
          Creates the new naming subcontext and binds it to the current (this) context.
 Context createSubcontext(String name)
          Creates the new naming subcontext and binds it to the current (this) context.
 void destroySubcontext(Name name)
          Removes the naming subcontext from this naming context.
 void destroySubcontext(String name)
          Removes the naming subcontext from this naming context.
protected  Context getDefaultInitCtx()
          Get the default initial context.
 Hashtable<?,?> getEnvironment()
          Returns the environment, associated with this naming context.
 String getNameInNamespace()
          This operation is not supported for the initial naming context.
 NameParser getNameParser(Name name)
          Obtains the name parser for parsing the names of the given naming subcontext.
 NameParser getNameParser(String name)
          Obtains the name parser for parsing the names of the given naming subcontext.
protected  Context getURLOrDefaultInitCtx(Name name)
          Obtains the context for resolving the given name.
protected  Context getURLOrDefaultInitCtx(String name)
          Obtains the context for resolving the given name.
protected  void init(Hashtable<?,?> environment)
           Initialises the context, using the properties, specified in the passed table.
 NamingEnumeration<NameClassPair> list(Name name)
          Creates and returns the enumeration over the name bindings that are present the given subcontext.
 NamingEnumeration<NameClassPair> list(String name)
          Creates and returns the enumeration over the name bindings that are present the given subcontext.
 NamingEnumeration<Binding> listBindings(Name name)
          Creates and returns the enumeration over the name - object bindings that are present the given subcontext.
 NamingEnumeration<Binding> listBindings(String name)
          Creates and returns the enumeration over the name - object bindings that are present the given subcontext.
 Object lookup(Name name)
          Gets the previously named object by name.
 Object lookup(String name)
          Gets the previously named object by name.
 Object lookupLink(Name name)
          Retrieves the named object, not following the link of the terminal atomic component of the name.
 Object lookupLink(String name)
          Retrieves the named object, not following the link of the terminal atomic component of the name.
 void rebind(Name name, Object obj)
          Give the specified name for the specified object.
 void rebind(String name, Object obj)
          Give the specified name for the specified object.
 Object removeFromEnvironment(String propName)
          Removes the property with the given name from the environment.
 void rename(Name oldName, Name newName)
          Renames the existing binding, removing the existing and giving the new name for the same object.
 void rename(String oldName, String newName)
          Renames the existing binding, removing the existing and giving the new name for the same object.
 void unbind(Name name)
          Removes the name - object mapping from the current context.
 void unbind(String name)
          Removes the name - object mapping from the current context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultInitCtx

protected Context defaultInitCtx
Contains the default initial context. This value is returned by NamingManager.getInitialContext(java.util.Hashtable). It is set by this method when calling it first time. The subsequent calls return the value of this field.


gotDefault

protected boolean gotDefault
Indicates if the initial context was obtained by calling NamingManager.getInitialContext(java.util.Hashtable).


myProps

protected Hashtable<Object,Object> myProps
The environment, associated with this initial context.

Constructor Detail

InitialContext

public InitialContext(Hashtable<?,?> environment)
               throws NamingException
Creates the new initial context with the given properties.

Parameters:
environment - the properties, used by the initial context being created.
Throws:
NamingException

InitialContext

protected InitialContext(boolean lazy)
                  throws NamingException
Creates the initial context with the possibility to delay its initialisation.

Parameters:
lazy - specified if the initialization should not be performed by this constructor (true). If the valueis false, it works the same way as the parameterless constructor.
Throws:
NamingException

InitialContext

public InitialContext()
               throws NamingException
Creates teh new initial context with no properties. Same as InitialContext(null).

Throws:
NamingException
Method Detail

init

protected void init(Hashtable<?,?> environment)
             throws NamingException

Initialises the context, using the properties, specified in the passed table.

The missing properties are additionally obtained (in order) from the following locations:

Parameters:
environment - the table of the properties, may be null. The method modifies the table and stores the reference to it. The caller must not later reuse this structure for other purposes.
Throws:
NamingException
Since:
1.3

getDefaultInitCtx

protected Context getDefaultInitCtx()
                             throws NamingException
Get the default initial context. If gotDefault == false, this method obtains the initial context from the naming manager and sets gotDefault to true. Otherwise the cached value (defaultInitCtx is returned.

Returns:
the default initial context
Throws:
NamingException

getURLOrDefaultInitCtx

protected Context getURLOrDefaultInitCtx(Name name)
                                  throws NamingException
Obtains the context for resolving the given name. If the first component of the name is the URL string, this method tries to find the corressponding URL naming context. If it is not an URL string, or the URL context is not found, the default initial context is returned.

Parameters:
name - the name, for that it is required to obtain the context.
Returns:
the context for resolving the name.
Throws:
NamingException

getURLOrDefaultInitCtx

protected Context getURLOrDefaultInitCtx(String name)
                                  throws NamingException
Obtains the context for resolving the given name. If the first component of the name is the URL string, this method tries to find the corressponding URL naming context. If it is not an URL string, or the URL context is not found, the default initial context is returned.

Parameters:
name - the name, for that it is required to obtain the context.
Returns:
the context for resolving the name.
Throws:
NamingException

bind

public void bind(Name name,
                 Object obj)
          throws NamingException
Description copied from interface: Context
Give the specified name for the specified object. The passed name must not be already bound to some other object.

Specified by:
bind in interface Context
Parameters:
name - the name that will be given to the object (in the scope of this context).
obj - the object being named.
Throws:
NameAlreadyBoundException - if this name is already used to name some object.
InvalidAttributesException - if the object does not supply all required attributes.
NamingException - if the naming operation has failed due other reasons.

bind

public void bind(String name,
                 Object obj)
          throws NamingException
Description copied from interface: Context
Give the specified name for the specified object. The passed name must not be already bound to some other object.

Specified by:
bind in interface Context
Parameters:
name - the name that will be given to the object (in the scope of this context).
obj - the object being named.
Throws:
NameAlreadyBoundException - if this name is already used to name some object.
InvalidAttributesException - if the object does not supply all required attributes.
NamingException - if the naming operation has failed due other reasons.

lookup

public Object lookup(Name name)
              throws NamingException
Description copied from interface: Context
Gets the previously named object by name. If the passed name is empty, the method should return a cloned instance of this naming context.

Specified by:
lookup in interface Context
Parameters:
name - the name of the object being searched in this context
Returns:
the named object
Throws:
NamingException - if the naming fails.

lookup

public Object lookup(String name)
              throws NamingException
Description copied from interface: Context
Gets the previously named object by name. If the passed name is empty, the method should return a cloned instance of this naming context.

Specified by:
lookup in interface Context
Parameters:
name - the name of the object being searched in this context
Returns:
the named object
Throws:
NamingException - if the naming fails.

rebind

public void rebind(Name name,
                   Object obj)
            throws NamingException
Description copied from interface: Context
Give the specified name for the specified object. Unlike bind, this method silently replaces the existing binding for this name, if one exists.

Specified by:
rebind in interface Context
Parameters:
name - the name that will be given to the object (in the scope of this context).
obj - the object being named.
Throws:
InvalidAttributesException - if the object does not supply all required attributes.
NamingException - if the naming operation has failed due other reasons.

rebind

public void rebind(String name,
                   Object obj)
            throws NamingException
Description copied from interface: Context
Give the specified name for the specified object. Unlike bind, this method silently replaces the existing binding for this name, if one exists.

Specified by:
rebind in interface Context
Parameters:
name - the name that will be given to the object (in the scope of this context).
obj - the object being named.
Throws:
InvalidAttributesException - if the object does not supply all required attributes.
NamingException - if the naming operation has failed due other reasons.

unbind

public void unbind(Name name)
            throws NamingException
Description copied from interface: Context
Removes the name - object mapping from the current context. This method returns without action if the name is not bound to an object in the terminal context, but throws NameNotFoundException if one of the intermadiate contexts does not exist.

Specified by:
unbind in interface Context
Parameters:
name - the name to be removed
Throws:
NameNotFoundException - if one of the intermediate naming contexts does not exist. Will not be thrown if just the terminal binding is missing.
NamingException - if the naming operation has failed due other reasons.

unbind

public void unbind(String name)
            throws NamingException
Description copied from interface: Context
Removes the name - object mapping from the current context. This method returns without action if the name is not bound to an object in the terminal context, but throws NameNotFoundException if one of the intermadiate contexts does not exist.

Specified by:
unbind in interface Context
Parameters:
name - the name to be removed
Throws:
NameNotFoundException - if one of the intermediate naming contexts does not exist. Will not be thrown if just the terminal binding is missing.
NamingException - if the naming operation has failed due other reasons.

rename

public void rename(Name oldName,
                   Name newName)
            throws NamingException
Description copied from interface: Context
Renames the existing binding, removing the existing and giving the new name for the same object.

Specified by:
rename in interface Context
Parameters:
oldName - the existing name of the known object
newName - the new name of the same object
Throws:
NameNotFoundException - if the oldName is unknown for this context
NamingException - if the naming operation has failed due other reasons.

rename

public void rename(String oldName,
                   String newName)
            throws NamingException
Description copied from interface: Context
Renames the existing binding, removing the existing and giving the new name for the same object.

Specified by:
rename in interface Context
Parameters:
oldName - the existing name of the known object
newName - the new name of the same object
Throws:
NameNotFoundException - if the oldName is unknown for this context
NamingException - if the naming operation has failed due other reasons.

list

public NamingEnumeration<NameClassPair> list(Name name)
                                      throws NamingException
Description copied from interface: Context
Creates and returns the enumeration over the name bindings that are present the given subcontext. The enumeration elements have the type of NameClassPair, providing also information about the class of the bound object. The behaviour in the case if the bindings are added or removed later is not defined. The contents of the subcontexts are not included.

Specified by:
list in interface Context
Parameters:
name - the name of the subcontext
Returns:
the enumeration over the names, known for the given subcontext.
Throws:
NamingException

list

public NamingEnumeration<NameClassPair> list(String name)
                                      throws NamingException
Description copied from interface: Context
Creates and returns the enumeration over the name bindings that are present the given subcontext. The enumeration elements have the type of NameClassPair, providing also information about the class of the bound object. The behaviour in the case if the bindings are added or removed later is not defined. The contents of the subcontexts are not included.

Specified by:
list in interface Context
Parameters:
name - the name of the subcontext
Returns:
the enumeration over the names, known for the given subcontext.
Throws:
NamingException

listBindings

public NamingEnumeration<Binding> listBindings(Name name)
                                        throws NamingException
Description copied from interface: Context
Creates and returns the enumeration over the name - object bindings that are present the given subcontext. The enumeration elements have the type of Binding, providing also information about the class of the bound object. The behaviour in the case if the bindings are added or removed later is not defined. The contents of the subcontexts are not included.

Specified by:
listBindings in interface Context
Parameters:
name - the name of the subcontext
Returns:
the enumeration over the names, known for the given subcontext.
Throws:
NamingException

listBindings

public NamingEnumeration<Binding> listBindings(String name)
                                        throws NamingException
Description copied from interface: Context
Creates and returns the enumeration over the name - object bindings that are present the given subcontext. The enumeration elements have the type of Binding, providing also information about the class of the bound object. The behaviour in the case if the bindings are added or removed later is not defined. The contents of the subcontexts are not included.

Specified by:
listBindings in interface Context
Parameters:
name - the name of the subcontext
Returns:
the enumeration over the names, known for the given subcontext.
Throws:
NamingException

destroySubcontext

public void destroySubcontext(Name name)
                       throws NamingException
Description copied from interface: Context
Removes the naming subcontext from this naming context. Returns without action if such subcontext does not exist. The context being destroyed must be empty.

Specified by:
destroySubcontext in interface Context
Parameters:
name - the name of the subcontext beig removed.
Throws:
ContextNotEmptyException - if the named context is not empty.
NamingException

destroySubcontext

public void destroySubcontext(String name)
                       throws NamingException
Description copied from interface: Context
Removes the naming subcontext from this naming context. Returns without action if such subcontext does not exist. The context being destroyed must be empty.

Specified by:
destroySubcontext in interface Context
Parameters:
name - the name of the subcontext beig removed.
Throws:
ContextNotEmptyException - if the named context is not empty.
NamingException

createSubcontext

public Context createSubcontext(Name name)
                         throws NamingException
Description copied from interface: Context
Creates the new naming subcontext and binds it to the current (this) context.

Specified by:
createSubcontext in interface Context
Parameters:
name - the name of the new context being created
Returns:
the newly created context, bound to the instance of the context on that the method has been called
Throws:
NameAlreadyBoundException - if this name is already bound
InvalidAttributesException - if the creation of the new context requires the missing mandatory attributes
NamingException

createSubcontext

public Context createSubcontext(String name)
                         throws NamingException
Description copied from interface: Context
Creates the new naming subcontext and binds it to the current (this) context.

Specified by:
createSubcontext in interface Context
Parameters:
name - the name of the new context being created
Returns:
the newly created context, bound to the instance of the context on that the method has been called
Throws:
NameAlreadyBoundException - if this name is already bound
InvalidAttributesException - if the creation of the new context requires the missing mandatory attributes
NamingException

lookupLink

public Object lookupLink(Name name)
                  throws NamingException
Description copied from interface: Context
Retrieves the named object, not following the link of the terminal atomic component of the name. If the object, named by the passed name, is not a link, returns that object itself. The intermediate links, if present, are followed.

Specified by:
lookupLink in interface Context
Parameters:
name - the name of the object that may be a link, leading to another object.
Returns:
the named object, not following the terminal link (if present).
Throws:
NamingException

lookupLink

public Object lookupLink(String name)
                  throws NamingException
Description copied from interface: Context
Retrieves the named object, not following the link of the terminal atomic component of the name. If the object, named by the passed name, is not a link, returns that object itself. The intermediate links, if present, are followed.

Specified by:
lookupLink in interface Context
Parameters:
name - the name of the object that may be a link, leading to another object.
Returns:
the named object, not following the terminal link (if present).
Throws:
NamingException

getNameParser

public NameParser getNameParser(Name name)
                         throws NamingException
Description copied from interface: Context
Obtains the name parser for parsing the names of the given naming subcontext.

Specified by:
getNameParser in interface Context
Parameters:
name - the name of the subcontext for that the parser must be obtained
Returns:
the parser to parse the names of that context
Throws:
NamingException

getNameParser

public NameParser getNameParser(String name)
                         throws NamingException
Description copied from interface: Context
Obtains the name parser for parsing the names of the given naming subcontext.

Specified by:
getNameParser in interface Context
Parameters:
name - the name of the subcontext for that the parser must be obtained
Returns:
the parser to parse the names of that context
Throws:
NamingException

composeName

public Name composeName(Name name,
                        Name prefix)
                 throws NamingException
Description copied from interface: Context
Composes the name of this context together with another name, related to this context.

Specified by:
composeName in interface Context
Parameters:
name - a name, defined in the scope of this context
prefix - a name of this context itself, defined in the scope of some ancestor
Returns:
the name of the same object as named by the first parameter, but related to the context of the specified ancestor.
Throws:
NamingException

composeName

public String composeName(String name,
                          String prefix)
                   throws NamingException
Description copied from interface: Context
Composes the name of this context together with another name, related to this context.

Specified by:
composeName in interface Context
Parameters:
name - a name, defined in the scope of this context
prefix - a name of this context itself, defined in the scope of some ancestor
Returns:
the name of the same object as named by the first parameter, but related to the context of the specified ancestor.
Throws:
NamingException

addToEnvironment

public Object addToEnvironment(String propName,
                               Object propVal)
                        throws NamingException
Description copied from interface: Context
Add new environment property to the environment of this context. Both name and value of the new property must not be null. If the property is already defined, is current value is replaced by the propVal.

Specified by:
addToEnvironment in interface Context
Parameters:
propName - the name of the new property
propVal - the value of the new property
Returns:
the previous value of this property or null if the property has not been previously defined
Throws:
NamingException

removeFromEnvironment

public Object removeFromEnvironment(String propName)
                             throws NamingException
Description copied from interface: Context
Removes the property with the given name from the environment. Returns without action if this property is not defined.

Specified by:
removeFromEnvironment in interface Context
Parameters:
propName - the name of the property being removed.
Returns:
the value of the property that has been removed or null if the property was not defined.
Throws:
NamingException

getEnvironment

public Hashtable<?,?> getEnvironment()
                              throws NamingException
Description copied from interface: Context
Returns the environment, associated with this naming context. The returned table should never be modified by the caller. Use Context.addToEnvironment(java.lang.String, java.lang.Object) and Context.removeFromEnvironment(java.lang.String) to modify the environement, if needed.

Specified by:
getEnvironment in interface Context
Returns:
the table, representing the environment of this context
Throws:
NamingException

close

public void close()
           throws NamingException
Description copied from interface: Context
Releases all resources, associated with this context. The close() method can be called several times, but after it has been once invoked, it is not allowed to call any other method of this context,

Specified by:
close in interface Context
Throws:
NamingException

getNameInNamespace

public String getNameInNamespace()
                          throws NamingException
This operation is not supported for the initial naming context.

Specified by:
getNameInNamespace in interface Context
Returns:
the full name of this naming context, in its own namespace.
Throws:
OperationNotSupportedException - always, unless the method is overridden in the derived class.
NamingException