| java.lang.Object javax.naming.InitialContext
All known Subclasses: javax.naming.directory.InitialDirContext,
InitialContext | public class InitialContext implements Context(Code) | | 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
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 Also: Context |
Field Summary | |
protected Context | defaultInitCtx Set to the result of the first successful invocation of
NamingManager.getInitialContext
by getDefaultInitCtx
. | protected boolean | gotDefault Set to true when NamingManager.getInitialContext has been
invoked to obtain an initial context. | protected Hashtable<Object, Object> | myProps Contains all those JNDI environment properties that were found in any of
the the sources of JNDI environment properties. |
Constructor Summary | |
public | InitialContext() Constructs an InitialContext instance without using any
environment properties. | public | InitialContext(Hashtable, ?> environment) Constructs an InitialContext instance using environment
properties in the supplied parameter which may be null. | protected | InitialContext(boolean doNotInit) Constructs an InitialContext instance by indicating
whether a lazy initialization is desired. |
Method Summary | |
public Object | addToEnvironment(String propName, Object propVal) | public void | bind(Name name, Object obj) | public void | bind(String name, Object obj) | public void | close() | public Name | composeName(Name name, Name prefix) Combines two names into a composite name according to the syntax for this
context. | public String | composeName(String name, String prefix) Combines two names into a composite name according to the syntax for this
context. | public Context | createSubcontext(Name name) | public Context | createSubcontext(String name) | public void | destroySubcontext(Name name) | public void | destroySubcontext(String name) | protected Context | getDefaultInitCtx() Gets the default underlying Context implementation. | public Hashtable, ?> | getEnvironment() | public String | getNameInNamespace() | public NameParser | getNameParser(Name name) | public NameParser | getNameParser(String name) | protected Context | getURLOrDefaultInitCtx(Name name) Returns a non-null context for the specified name of Name representation.
If an initial context factory builder has been defined, then the
specified Name parameter is ignored and the result of
getDefaultInitCtx is returned. | protected Context | getURLOrDefaultInitCtx(String name) Returns a non-null context for the specified name of string
representation.
If an initial context factory builder has been defined, then the
specified name parameter is ignored and the result of
getDefaultInitCtx
is returned. | protected void | init(Hashtable, ?> env) Uses the specified environment parameter together with other JNDI
properties to initialize this InitialContext object. | public NamingEnumeration<NameClassPair> | list(Name name) | public NamingEnumeration<NameClassPair> | list(String name) | public NamingEnumeration<Binding> | listBindings(Name name) | public NamingEnumeration<Binding> | listBindings(String name) | public Object | lookup(Name name) | public Object | lookup(String name) | public Object | lookupLink(Name name) | public Object | lookupLink(String name) | public void | rebind(Name name, Object obj) | public void | rebind(String name, Object obj) | public Object | removeFromEnvironment(String propName) | public void | rename(Name oldName, Name newName) | public void | rename(String oldName, String newName) | public void | unbind(Name name) | public void | unbind(String name) |
defaultInitCtx | protected Context defaultInitCtx(Code) | | Set to the result of the first successful invocation of
NamingManager.getInitialContext
by getDefaultInitCtx
. Initially null.
|
gotDefault | protected boolean gotDefault(Code) | | Set to true when NamingManager.getInitialContext has been
invoked to obtain an initial context. Initially false.
|
myProps | protected Hashtable<Object, Object> myProps(Code) | | Contains all those JNDI environment properties that were found in any of
the the sources of JNDI environment properties. Initially null.
|
InitialContext | public InitialContext() throws NamingException(Code) | | Constructs an InitialContext instance without using any
environment properties. This constructor is effectively the same as using
constructor InitialContext((Hashtable)null) .
throws: NamingException - If failed to create an InitialContext . |
InitialContext | public InitialContext(Hashtable, ?> environment) throws NamingException(Code) | | Constructs an InitialContext instance using environment
properties in the supplied parameter which may be null.
Parameters: environment - the JNDI environment properties used to create the context throws: NamingException - If failed to create an InitialContext . |
InitialContext | protected InitialContext(boolean doNotInit) throws NamingException(Code) | | Constructs an 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 InitialContext subclass constructor in which
later action will set up a Hashtable object with
appropriate environment properties and pass that to the init
method to complete initialization of the InitialContext
object.
Parameters: doNotInit - Specifies whether to initialize the new instance. throws: NamingException - If failed to create an InitialContext . |
composeName | public Name composeName(Name name, Name prefix) throws NamingException(Code) | | Combines two names into a composite name according to the syntax for this
context. The name 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.
Parameters: name - a Name , may not be null Parameters: prefix - a Name serves as prefix, may not be null the combined name throws: NamingException - if an error occurs. |
composeName | public String composeName(String name, String prefix) throws NamingException(Code) | | Combines two names into a composite name according to the syntax for this
context. The name 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.
Parameters: name - a Name , may not be null Parameters: prefix - a Name serves as prefix, may not be null the combined name throws: NamingException - if an error occurs. |
getDefaultInitCtx | protected Context getDefaultInitCtx() throws NamingException(Code) | | Gets the default underlying 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.
the default context throws: NoInitialContextException - If NamingManager.getInitialContext returnsnull. throws: NamingException - If failed to create the default context. |
getURLOrDefaultInitCtx | protected Context getURLOrDefaultInitCtx(Name name) throws NamingException(Code) | | Returns a non-null context for the specified name of Name representation.
If an initial context factory builder has been defined, then the
specified Name parameter is ignored and the result of
getDefaultInitCtx is returned. Otherwise, if the first
component of the name is not a URL string, then it returns the result of
invoking getDefaultInitCtx . Otherwise, it attempts to
return a URL context
javax.naming.spi.NamingManager.getURLContext(StringHashtable) ,
but if unsuccessful, returns the result of invoking
getDefaultInitCtx .
Parameters: name - a name used in a naming operation which may not be null a context which may be a URL context throws: NamingException - If failed to get the desired context. |
getURLOrDefaultInitCtx | protected Context getURLOrDefaultInitCtx(String name) throws NamingException(Code) | | Returns a non-null context for the specified name of string
representation.
If an initial context factory builder has been defined, then the
specified name parameter is ignored and the result of
getDefaultInitCtx
is returned. Otherwise, if the name is not a URL string, then it returns
the result of invoking getDefaultInitCtx
. Otherwise, it
attempts to return a URL context
javax.naming.spi.NamingManager.getURLContext(StringHashtable) ,
but if unsuccessful, returns the result of invoking
getDefaultInitCtx .
Parameters: name - a name used in a naming operation which may not be null a context which may be a URL context throws: NamingException - If failed to get the desired context. |
init | protected void init(Hashtable, ?> env) throws NamingException(Code) | | Uses the specified environment parameter together with other JNDI
properties to initialize this 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.
Parameters: env - the JNDI environment properties supplied to create the context throws: NamingException - If naming problems are encountered during initialization ofthese fields. |
|
|