|
JNDI 1.1.1 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.naming.InitialContext
This class is the starting context for performing naming operations.
All naming operations are relative to a context. The initial context implements the Context interface and provides the starting point for resolution of names.
The initial context implementation is determined at runtime.
The default policy uses the environment or system property
"java.naming.factory.initial"
,
which contains the class name of the initial context factory.
(If both are present, the environment property takes precedence).
If a URL string (with syntax scheme_id:rest_of_name) is passed
to methods in InitialContext
, either as a String
argument or as the first component of Name
, the URL's
scheme id is used to locate the context factory for handling that
scheme. If none is found, the initial context specified by
"java.naming.factory.initial"
is used.
See jndi.naming.spi.NamingManager.getURLContext()
for
details on how URL context factories are located.
This default policy of locating the initial context can be overridden
by calling
javax.naming.spi.NamingManager.setInitialContextFactoryBuilder()
.
NoInitialContextException is thrown when an initial context cannot be instantiated. This exception can be thrown during any interaction with the InitialContext, not only when the InitialContext is constructed. For example, the implementation of the initial context might lazily retrieve the context only when actual methods are invoked on it. The application should not have any dependency on when the existence of an initial context is determined.
When the environment or system property java.naming.factory.initial is non-null, the InitialContext constructor will attempt to create the initial context specified therein. At that time, the initial context factory involved might throw an exception if a problem is encountered. However, it is provider implementation-dependent when it verifies and indicates to the users of the initial context any environment property- or connection- related problems. It can do so lazily--delaying until an operation is performed on the context, or eagerly, at the time the context is constructed.
An InitialContext instance is not synchronized against concurrent access by multiple threads. Multiple threads each manipulating their own InitialContext instances need not synchronize. Threads that need to access a single InitialContext instance concurrently should synchronize amongst themselves and provide the necessary locking.
Context
,
NamingManager.setInitialContextFactoryBuilder(javax.naming.spi.InitialContextFactoryBuilder)
Field Summary | |
protected Context |
defaultInitCtx
Field holding the result of calling NamingManager.getInitialContext(). |
protected boolean |
gotDefault
Field indicating whether the initial context has been obtained by calling NamingManager.getInitialContext(). |
protected java.util.Hashtable |
myProps
The environment associated with this InitialContext. |
Constructor Summary | |
InitialContext()
Constructs an initial context. |
|
InitialContext(java.util.Hashtable environment)
Constructs an initial context using information supplied in 'environment'. |
Method Summary | |
java.lang.Object |
addToEnvironment(java.lang.String propName,
java.lang.Object propVal)
Adds a new environment property to the environment of this context. |
void |
bind(Name name,
java.lang.Object obj)
Binds 'name' to the object 'obj'. |
void |
bind(java.lang.String name,
java.lang.Object obj)
Binds the string name 'name' to the object 'obj'. |
void |
close()
Closes this initial context. |
Name |
composeName(Name name,
Name prefix)
Composes the name of this context with a name relative to this context. |
java.lang.String |
composeName(java.lang.String name,
java.lang.String prefix)
Composes the name of this context with a name relative to this context. |
Context |
createSubcontext(Name name)
Creates and binds a new context. |
Context |
createSubcontext(java.lang.String name)
Creates and binds a new context. |
void |
destroySubcontext(Name name)
Destroys the named context and removes it from the namespace. |
void |
destroySubcontext(java.lang.String name)
Destroys the named context and removes it from the namespace. |
protected Context |
getDefaultInitCtx()
Retrieves the initial context by calling NamingManager.getInitialContext()
and cache it in defaultInitCtx. |
java.util.Hashtable |
getEnvironment()
Retrieves the environment in effect for the initial context. |
NameParser |
getNameParser(Name name)
Retrieves the parser associated with the named context. |
NameParser |
getNameParser(java.lang.String name)
Retrieves the parser associated with the named context. |
protected Context |
getURLOrDefaultInitCtx(Name name)
Retrieves a context for resolving name . |
protected Context |
getURLOrDefaultInitCtx(java.lang.String name)
Retrieves a context for resolving the string name name . |
NamingEnumeration |
list(Name name)
Enumerates the names and the class names of their bound objects in the context named relative to this initial context. |
NamingEnumeration |
list(java.lang.String name)
Enumerates the names and the class names of their bound objects in the context named relative to this initial context. |
NamingEnumeration |
listBindings(Name name)
Enumerates the names and their bound objects in the context named relative to this initial context. |
NamingEnumeration |
listBindings(java.lang.String name)
Enumerates the names and their bound objects in the context named relative to this initial context. |
java.lang.Object |
lookup(Name name)
Retrieves the object bound to name resolved relative to the
initial context. |
java.lang.Object |
lookup(java.lang.String name)
Retrieves the object bound to name resolved relative to the
initial context. |
java.lang.Object |
lookupLink(Name name)
Retrieve the object named relative to this initial context, following links except for the terminal atomic component of name. |
java.lang.Object |
lookupLink(java.lang.String name)
Retrieve the object named relative to this initial context, following links except for the terminal atomic component of name. |
void |
rebind(Name name,
java.lang.Object obj)
Binds 'name' to the object 'obj', overwrite any existing binding. |
void |
rebind(java.lang.String name,
java.lang.Object obj)
Binds the string name 'name' to the object 'obj', overwrite any existing binding. |
java.lang.Object |
removeFromEnvironment(java.lang.String propName)
Removes an environment property from the environment of this context. |
void |
rename(Name oldName,
Name newName)
Binds 'newName' to the object bound to 'oldName', and unbinds 'oldName'. |
void |
rename(java.lang.String oldName,
java.lang.String newName)
Binds 'newName' to the object bound to 'oldName', and unbinds 'oldName'. |
void |
unbind(Name name)
Unbinds 'name' resolved relative to this initial context. |
void |
unbind(java.lang.String name)
Unbinds 'name' resolved relative to this initial context. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
protected java.util.Hashtable myProps
addToEnvironment(java.lang.String, java.lang.Object)
,
removeFromEnvironment(java.lang.String)
,
getEnvironment()
protected Context defaultInitCtx
getDefaultInitCtx()
protected boolean gotDefault
defaultInitCtx
.Constructor Detail |
public InitialContext() throws NamingException
public InitialContext(java.util.Hashtable environment) throws NamingException
environment
- The possibly null environment
used for creating the initial context
(such as user name, password, etc.)Method Detail |
protected Context getDefaultInitCtx() throws NamingException
NamingManager.getInitialContext()
and cache it in defaultInitCtx.
Set gotDefault
so that we know we've tried this before.protected Context getURLOrDefaultInitCtx(java.lang.String name) throws NamingException
name
.
If name
name is a URL string, then attempt
to find a URL context for it. If none is found, or if
name
is not a URL string, then return
getDefaultInitCtx()
.
See getURLOrDefaultInitCtx(Name) for description of how a subclass should use this method.
name
- The non-null name for which to get the context.name
or the cached
initial context. The result cannot be null.NamingManager.getURLContext(java.lang.String, java.util.Hashtable)
protected Context getURLOrDefaultInitCtx(Name name) throws NamingException
name
.
If the first component of name
name is a URL string,
then attempt to find a URL context for it. If none is found, or if
the first component of name
is not a URL string,
then return getDefaultInitCtx()
.
When creating a subclass of InitialContext, use this method as follows. Define a new method that uses this method to get an initial context of the desired subclass.
When providing implementations for the new methods in the subclass, use this newly defined method to get the initial context.protected XXXContext getURLOrDefaultInitXXXCtx(Name name) throws NamingException { Context answer = getURLOrDefaultInitCtx(name); if (!(answer instanceof XXXContext)) { if (answer == null) { throw new NoInitialContextException(); } else { throw new NotContextException("Not an XXXContext"); } } return (XXXContext)answer; }
public Object XXXMethod1(Name name, ...) { throws NamingException { return getURLOrDefaultInitXXXCtx(name).XXXMethod1(name, ...); }
name
- The non-null name for which to get the context.name
or the cached
initial context. The result cannot be null.NamingManager.getURLContext(java.lang.String, java.util.Hashtable)
public java.lang.Object lookup(java.lang.String name) throws NamingException
name
resolved relative to the
initial context.name
- The non-null string name of the object to lookup.Context.lookup(javax.naming.Name)
public java.lang.Object lookup(Name name) throws NamingException
name
resolved relative to the
initial context.name
- The non-null name of the object to lookup.Context.lookup(javax.naming.Name)
public void bind(java.lang.String name, java.lang.Object obj) throws NamingException
name
- The non-null name to bind. It cannot be empty.obj
- The non-null object to bind.Context.bind(javax.naming.Name, java.lang.Object)
public void bind(Name name, java.lang.Object obj) throws NamingException
name
- The non-null name to bind. It cannot be empty.obj
- The non-null object to bind.Context.bind(javax.naming.Name, java.lang.Object)
public void rebind(java.lang.String name, java.lang.Object obj) throws NamingException
name
- The non-null name to bind. It cannot be empty.obj
- The non-null object to bind. If obj is a DirContext,Context.rebind(javax.naming.Name, java.lang.Object)
public void rebind(Name name, java.lang.Object obj) throws NamingException
name
- The non-null name to bind. It cannot be empty.obj
- The non-null object to bind. If obj is a DirContext,Context.rebind(javax.naming.Name, java.lang.Object)
public void unbind(java.lang.String name) throws NamingException
name
- The non-null name to unbind. It cannot be empty.Context.unbind(Name)
public void unbind(Name name) throws NamingException
name
- The non-null name to unbind. It cannot be empty.Context.unbind(Name)
public void rename(java.lang.String oldName, java.lang.String newName) throws NamingException
oldName
- The non-null name of the existing binding,newName
- The non-null name of the new binding,Context.rename(Name, Name)
public void rename(Name oldName, Name newName) throws NamingException
oldName
- The non-null name of the existing binding,newName
- The non-null name of the new binding,Context.rename(Name, Name)
public NamingEnumeration list(java.lang.String name) throws NamingException
name
- The non-null name of the context to list.Context.list(Name)
public NamingEnumeration list(Name name) throws NamingException
name
- The non-null name of the context to list.Context.list(Name)
public NamingEnumeration listBindings(java.lang.String name) throws NamingException
name
- The non-null name of the context to list.Context.listBindings(Name)
public NamingEnumeration listBindings(Name name) throws NamingException
name
- The non-null name of the context to list.Context.listBindings(Name)
public void destroySubcontext(java.lang.String name) throws NamingException
name
- The non-null name of the context to be destroyed.Context.destroySubcontext(Name)
public void destroySubcontext(Name name) throws NamingException
name
- The non-null name of the context to be destroyed.Context.destroySubcontext(Name)
public Context createSubcontext(java.lang.String name) throws NamingException
name
- The non-null name of the context to create.
It cannot be empty.Context.createSubcontext(Name)
public Context createSubcontext(Name name) throws NamingException
name
- The non-null name of the context to create.
It cannot be empty.Context.createSubcontext(Name)
public java.lang.Object lookupLink(java.lang.String name) throws NamingException
name
- The non-null name to look up.Context.lookupLink(Name)
public java.lang.Object lookupLink(Name name) throws NamingException
name
- The non-null name to look up.Context.lookupLink(Name)
public NameParser getNameParser(java.lang.String name) throws NamingException
name
- The non-null name of the context from which to
get the parser.Context.getNameParser(Name)
public NameParser getNameParser(Name name) throws NamingException
name
- The non-null name of the context from which to
get the parser.Context.getNameParser(Name)
public java.lang.String composeName(java.lang.String name, java.lang.String prefix) throws NamingException
name
- A non-null name relative to this context.prefix
- The non-null name of this context relative to one of
its ancestors.prefix
and
name
.Context.composeName(Name, Name)
public Name composeName(Name name, Name prefix) throws NamingException
name
- A non-null name relative to this context.prefix
- The non-null name of this context relative to one of
its ancestors.prefix
and
name
.Context.composeName(Name, Name)
public java.lang.Object addToEnvironment(java.lang.String propName, java.lang.Object propVal) throws NamingException
propName
- The non-null name of the environment property to add.
If already exists in environment, overwrite and return old value.propVal
- The non-null value.Context.addToEnvironment(java.lang.String, java.lang.Object)
public java.lang.Object removeFromEnvironment(java.lang.String propName) throws NamingException
propName
- The non-null name of the environment property to remove.Context.removeFromEnvironment(java.lang.String)
public java.util.Hashtable getEnvironment() throws NamingException
Context.getEnvironment()
public void close() throws NamingException
This method is idempotent. Invoking close() on an already closed context does not do anything. However, invoking any other method on a closed context results in undefined behavior.
|
JNDI 1.1.1 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |