An
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 {@link 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.
@see Context