java.lang.Objectjavax.naming.InitialContext
All Implemented Interfaces:
Context
Direct Known Subclasses:
InitialLdapContext, InitialDirContext
InitialContext object is required as the starting context
for any naming operations. Other contexts and subcontexts may be created
later. Contexts may consist of different implementations according to the
needs of the application. All naming operations are performed relative to a
context and names are resolved beginning with the initial context.
When constructing an initial context, environment properties from a range of sources may be used to initialize the environment. See the specification of the Context interface for further details of environment properties.
The environment at runtime determines the initial context implementation. By
default, the naming frameworks look for the initial context factory class
name in the property Context.INITIAL_CONTEXT_FACTORY. When
URL strings must be resolved, a different policy is used which is described
below.
A NoInitialContextException is thrown when it cannot create an
initial context. The exception may occur not only during constructor
invocation, but may occur later. For example, when a subclass of
InitialContext
uses the lazy initialization option,
InitialContext methods
may be invoked later which require the initialization to be completed at that
time using the init protected method. In these circumstances,
NoInitialContextException
may be thrown some time after the
constructor was invoked. JNDI applications should be written to be
independent of when initial context is actually initialized.
If environment property Context.INITIAL_CONTEXT_FACTORY has a
non-null value, then the specified initial context factory may experience a
problem trying to instantiate an initial context and so throw an exception.
It is a responsibility of the service provider implementation as to when an
exception is thrown to report the problem to the JNDI application.
URL names comprising a String format described by RFC1738 may be components
of names passed to naming operations. Typically, the URL is composed of the
"scheme" - such as one of http, ldap, dns - followed by additional text. If
the JNDI can identify the URL scheme from the specified name, then it is used
to construct a classname suffix in the following form:
<package_prefix> . <scheme> . <scheme>URLContextFactory
Several variants of the classname are constructed using each element of the
Context.URL_PACKAGE_PREFIXES environment property. Note that
an additional package prefix - "com.sun.jndi.url" - is always considered to
be at the end of those already present in the value of that environment
property. Although a service provider may also provide a URL context
implementation as well as a context implementation, it is not required to do
so, and so an arbitrary service provider might not provide for creating URL
contexts.
If a URL context is successfully created for a specified URL scheme, the
factory can create contexts for arbitrary URLs of the same scheme.
NamingManager.setInitialContextFactoryBuilder may be used to
specify an alternate policy for locating factories for initial contexts and
URL contexts.
On successful completion of InitialContext initialization, the
service provider implementation will have returned an appropriate
Context
object which can be used for looking up and manipulating names which may or
may not be URL names. InitialContext methods other than those
dealing with environments should delegate context operations to that
Context object.
| Field Summary | ||
|---|---|---|
| protected Context | defaultInitCtx | Set to the result of the first successful invocation of
NamingManager.getInitialContext
by getDefaultInitCtx
. Initially null. |
| protected boolean | gotDefault | Set to true when NamingManager.getInitialContext has been
invoked to obtain an initial context. Initially false. |
| protected Hashtable<Object, Object> | myProps | Contains all those JNDI environment properties that were found in any of the the sources of JNDI environment properties. Initially null. |
| Constructor: |
|---|
InitialContext instance without using any
environment properties. This constructor is effectively the same as using
constructor InitialContext((Hashtable)null).
|
InitialContext instance using environment
properties in the supplied parameter which may be null.
|
InitialContext instance by indicating
whether a lazy initialization is desired. Effectively, this is the same
as using constructor InitialContext()
if lazy
initialization is not indicated.
This constructor may be invoked with a parameter value of true and the
implementation will defer initialization of the instance. This may be
used in an
|
| Method from javax.naming.InitialContext Summary: |
|---|
| addToEnvironment, bind, bind, close, composeName, composeName, createSubcontext, createSubcontext, destroySubcontext, destroySubcontext, doLookup, doLookup, getDefaultInitCtx, getEnvironment, getNameInNamespace, getNameParser, getNameParser, getURLOrDefaultInitCtx, getURLOrDefaultInitCtx, init, list, list, listBindings, listBindings, lookup, lookup, lookupLink, lookupLink, rebind, rebind, removeFromEnvironment, rename, rename, unbind, unbind |
| Methods from java.lang.Object: |
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from javax.naming.InitialContext Detail: |
|---|
|
|
|
|
prefix is expected to be the name of one
or more of the immediate parent contexts of this context, so should be an
empty name for an InitialContext. name is
a name relative to this context. Neither prefix nor
name may be null. |
prefix is expected to be the name of one
or more of the immediate parent contexts of this context, so should be an
empty string for an InitialContext. name
is a name relative to this context. |
|
|
|
|
Name.
It is equivalent to
InitialContext icxt = new InitialContext(); T obj = icxt.lookup();
Returns a new instance of this context when |
String. |
Context implementation. If
gotDefault is true, returns the value of
defaultInitCtx.
Otherwise, calls NamingManager.getInitialContext
to return
an initial context for the current environment into
defaultInitCtx, then gotDefault is set
true. If the resulting context object is null, a
NoInitialContextException
is thrown, otherwise the value
of defaultInitCtx is returned. |
|
|
|
|
If an initial context factory builder has been defined, then the
specified |
If an initial context factory builder has been defined, then the
specified name parameter is ignored and the result of |
InitialContext object. The
myProps field will be filled with found JNDI properties.
If JNDI standard property "java.naming.factory.initial" has a non-null
value, then getDefaultInitCtx is invoked to try to
initialize fields gotDefault and
defaultInitCtx of the InitialContext
object. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|