APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.naming.spi

public Class NamingManager

extends Object
Class Inheritance
Known Direct Subclasses
javax.naming.spi.DirectoryManager
Imports
java.util.*, javax.naming.*, com.sun.naming.internal.NamingManagerHelper, .ObjectFactoriesFilter, .VersionHelper, .ResourceManager, .FactoryEnumeration, jdk.internal.loader.ClassLoaderValue

This class contains methods for creating context objects and objects referred to by location information in the naming or directory service.

This class cannot be instantiated. It has only static methods.

The mention of URL in the documentation for this class refers to a URL string as defined by RFC 1738 and its related RFCs. It is any string that conforms to the syntax described therein, and may not always have corresponding support in the java.net.URL class or Web browsers.

NamingManager is safe for concurrent access by multiple threads.

Except as otherwise noted, a Name or environment parameter passed to any method is owned by the caller. The implementation will not modify the object or keep a reference to it, although it may keep a reference to a clone or copy.

Authors
Rosanna Lee, Scott Seligman
Since
1.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
NamingManager.FactoryInitializationError

Thrown when an error is encountered while loading and instantiating the context factory classes.

Field Summary

Modifier and TypeField and Description
public static final String
CPE

Constant that holds the name of the environment property into which getContinuationContext() stores the value of its CannotProceedException parameter.

private static final String
private static final ClassLoaderValue<InitialContextFactory>
pack-priv static final VersionHelper
private static InitialContextFactoryBuilder

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv static Context

Returns:

A context identified by obj.
getContext
(Object
The object identifying the context.
obj
,
Name
The name of the context being returned, relative to nameCtx, or null if no name is being specified. See the getObjectInstance method for details.
name
,
Context
The context relative to which name is specified, or null for the default initial context. See the getObjectInstance method for details.
nameCtx
,
Hashtable<?, ?>
Environment specifying characteristics of the resulting context.
environment
)

Retrieves a context identified by obj, using the specified environment.

public static Context

Returns:

A non-null Context object for continuing the operation.
getContinuationContext
(CannotProceedException
The non-null exception that triggered this continuation.
cpe
)

Creates a context in which to continue a context operation.

private static InitialContextFactory
getFactory(String className)

public static Context

Returns:

A non-null initial context.
getInitialContext
(Hashtable<?, ?>
The possibly null environment properties used when creating the context.
env
)

Creates an initial context using the specified environment properties.

private static synchronized InitialContextFactoryBuilder
getInitialContextFactoryBuilder()

Use this method for accessing initctx_factory_builder while inside an unsynchronized method.

pack-priv static ObjectFactoryBuilder
getObjectFactoryBuilder()

Used for accessing object factory builder.

public static Object

Returns:

An object created using refInfo; or refInfo if an object cannot be created using the algorithm described above.
getObjectInstance
(Object
The possibly null object for which to create an object.
refInfo
,
Name
The name of this object relative to nameCtx. Specifying a name is optional; if it is omitted, name should be null.
name
,
Context
The context relative to which the name parameter is specified. If null, name is relative to the default initial context.
nameCtx
,
Hashtable<?, ?>
The possibly null environment to be used in the creation of the object factory and the object.
environment
)

Creates an instance of an object for the specified object and environment.

pack-priv static Resolver
getResolver(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment)

public static Object

Returns:

The non-null object representing obj's state for binding. It could be the object (obj) itself.
getStateToBind
(Object
The non-null object for which to get state to bind.
obj
,
Name
The name of this object relative to nameCtx, or null if no name is specified.
name
,
Context
The context relative to which the name parameter is specified, or null if name is relative to the default initial context.
nameCtx
,
Hashtable<?, ?>
The possibly null environment to be used in the creation of the state factory and the object's state.
environment
)

Retrieves the state of an object for binding.

public static Context

Returns:

A context for resolving URLs with the scheme id scheme; null if the factory for creating the context is not found.
getURLContext
(String
The non-null scheme-id of the URLs supported by the context.
scheme
,
Hashtable<?, ?>
The possibly null environment properties to be used in the creation of the object factory and the context.
environment
)

Creates a context for the given URL scheme id.

The resulting context is for resolving URLs of the scheme scheme.

private static Object
getURLObject(String
the URL scheme id for the context
scheme
,
Object
information used to create the context
urlInfo
,
Name
name of this object relative to nameCtx
name
,
Context
Context whose provider resource file will be searched for package prefix values (or null if none)
nameCtx
,
Hashtable<?, ?>
Environment properties for creating the context
environment
)

Creates an object for the given URL scheme id using the supplied urlInfo.

public static boolean

Returns:

true if an initial context factory builder has been set; false otherwise.
hasInitialContextFactoryBuilder
()

Determines whether an initial context factory builder has been set.

public static synchronized void
setInitialContextFactoryBuilder(InitialContextFactoryBuilder
The initial context factory builder to install. If null, no builder is set.
builder
)

Sets the InitialContextFactory builder to be builder.

public static void
setObjectFactoryBuilder(ObjectFactoryBuilder
The factory builder to install. If null, no builder is installed.
builder
)

The ObjectFactoryBuilder determines the policy used when trying to load object factories.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CPEback to summary
public static final String CPE

Constant that holds the name of the environment property into which getContinuationContext() stores the value of its CannotProceedException parameter. This property is inherited by the continuation context, and may be used by that context's service provider to inspect the fields of the exception.

The value of this constant is "java.naming.spi.CannotProceedException".

Since
1.3
See Also
getContinuationContext
defaultPkgPrefixback to summary
private static final String defaultPkgPrefix
FACTORIES_CACHEback to summary
private static final ClassLoaderValue<InitialContextFactory> FACTORIES_CACHE
helperback to summary
pack-priv static final VersionHelper helper
initctx_factory_builderback to summary
private static InitialContextFactoryBuilder initctx_factory_builder

Constructor Detail

NamingManagerback to summary
pack-priv NamingManager()

Method Detail

getContextback to summary
pack-priv static Context getContext(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws NamingException

Retrieves a context identified by obj, using the specified environment. Used by ContinuationContext.

Parameters
obj:Object

The object identifying the context.

name:Name

The name of the context being returned, relative to nameCtx, or null if no name is being specified. See the getObjectInstance method for details.

nameCtx:Context

The context relative to which name is specified, or null for the default initial context. See the getObjectInstance method for details.

environment:Hashtable<?, ?>

Environment specifying characteristics of the resulting context.

Returns:Context

A context identified by obj.

See Also
getObjectInstance
getContinuationContextback to summary
public static Context getContinuationContext(CannotProceedException cpe) throws NamingException

Creates a context in which to continue a context operation.

In performing an operation on a name that spans multiple namespaces, a context from one naming system may need to pass the operation on to the next naming system. The context implementation does this by first constructing a CannotProceedException containing information pinpointing how far it has proceeded. It then obtains a continuation context from JNDI by calling getContinuationContext. The context implementation should then resume the context operation by invoking the same operation on the continuation context, using the remainder of the name that has not yet been resolved.

Before making use of the cpe parameter, this method updates the environment associated with that object by setting the value of the property CPE to cpe. This property will be inherited by the continuation context, and may be used by that context's service provider to inspect the fields of this exception.

Parameters
cpe:CannotProceedException

The non-null exception that triggered this continuation.

Returns:Context

A non-null Context object for continuing the operation.

Annotations
@SuppressWarnings:unchecked
Exceptions
NamingException:
If a naming exception occurred.
getFactoryback to summary
private static InitialContextFactory getFactory(String className)
getInitialContextback to summary
public static Context getInitialContext(Hashtable<?, ?> env) throws NamingException

Creates an initial context using the specified environment properties.

This is done as follows:

  • If an InitialContextFactoryBuilder has been installed, it is used to create the factory for creating the initial context
  • Otherwise, the class specified in the Context.INITIAL_CONTEXT_FACTORY environment property is used
    • First, the ServiceLoader mechanism tries to locate an InitialContextFactory provider using the current thread's context class loader
    • Failing that, this implementation tries to locate a suitable InitialContextFactory using a built-in mechanism
      (Note that an initial context factory (an object that implements the InitialContextFactory interface) must be public and must have a public constructor that accepts no arguments. In cases where the factory is in a named module then it must be in a package which is exported by that module to the java.naming module.)
Parameters
env:Hashtable<?, ?>

The possibly null environment properties used when creating the context.

Returns:Context

A non-null initial context.

Exceptions
NamingException:
If some other naming exception was encountered.
NoInitialContextException:
If the Context.INITIAL_CONTEXT_FACTORY property is not found or names a nonexistent class or a class that cannot be instantiated, or if the initial context could not be created for some other reason.
See Also
javax.naming.InitialContext, javax.naming.directory.InitialDirContext
getInitialContextFactoryBuilderback to summary
private static synchronized InitialContextFactoryBuilder getInitialContextFactoryBuilder()

Use this method for accessing initctx_factory_builder while inside an unsynchronized method.

getObjectFactoryBuilderback to summary
pack-priv static ObjectFactoryBuilder getObjectFactoryBuilder()

Used for accessing object factory builder.

getObjectInstanceback to summary
public static Object getObjectInstance(Object refInfo, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception

Creates an instance of an object for the specified object and environment.

If an object factory builder has been installed, it is used to create a factory for creating the object. Otherwise, the following rules are used to create the object:

  1. If refInfo is a Reference or Referenceable containing a factory class name, use the named factory to create the object. Return refInfo if the factory cannot be created. Downloading a factory class from a location specified in the reference can be supported by a custom implementation of ObjectFactoryBuilder. The factory class location, if present, is ignored. A custom ObjectFactoryBuilder may be used if a different policy is desired. If an exception is encountered while creating the factory, it is passed up to the caller.
  2. If refInfo is a Reference or Referenceable with no factory class name, and the address or addresses are StringRefAddrs with address type "URL", try the URL context factory corresponding to each URL's scheme id to create the object (see getURLContext()). If that fails, continue to the next step.
  3. Use the object factories specified in the Context.OBJECT_FACTORIES property of the environment, and of the provider resource file associated with nameCtx, in that order. The value of this property is a colon-separated list of factory class names that are tried in order, and the first one that succeeds in creating an object is the one used. If none of the factories can be loaded, return refInfo. If an exception is encountered while creating the object, the exception is passed up to the caller.

Service providers that implement the DirContext interface should use DirectoryManager.getObjectInstance(), not this method. Service providers that implement only the Context interface should use this method.

Note that an object factory (an object that implements the ObjectFactory interface) must be public and must have a public constructor that accepts no arguments. In cases where the factory is in a named module then it must be in a package which is exported by that module to the java.naming module.

The name and nameCtx parameters may optionally be used to specify the name of the object being created. name is the name of the object, relative to context nameCtx. This information could be useful to the object factory or to the object implementation. If there are several possible contexts from which the object could be named -- as will often be the case -- it is up to the caller to select one. A good rule of thumb is to select the "deepest" context available. If nameCtx is null, name is relative to the default initial context. If no name is being specified, the name parameter should be null.

Parameters
refInfo:Object

The possibly null object for which to create an object.

name:Name

The name of this object relative to nameCtx. Specifying a name is optional; if it is omitted, name should be null.

nameCtx:Context

The context relative to which the name parameter is specified. If null, name is relative to the default initial context.

environment:Hashtable<?, ?>

The possibly null environment to be used in the creation of the object factory and the object.

Returns:Object

An object created using refInfo; or refInfo if an object cannot be created using the algorithm described above.

Exceptions
Exception:
if one of the factories accessed throws an exception, or if an error was encountered while loading and instantiating the factory and object classes. A factory should only throw an exception if it does not want other factories to be used in an attempt to create an object. See ObjectFactory.getObjectInstance().
NamingException:
if a naming exception was encountered while attempting to get a URL context, or if one of the factories accessed throws a NamingException.
See Also
getURLContext, ObjectFactory, ObjectFactory#getObjectInstance
getResolverback to summary
pack-priv static Resolver getResolver(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws NamingException
getStateToBindback to summary
public static Object getStateToBind(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws NamingException

Retrieves the state of an object for binding.

Service providers that implement the DirContext interface should use DirectoryManager.getStateToBind(), not this method. Service providers that implement only the Context interface should use this method.

This method uses the specified state factories in the Context.STATE_FACTORIES property from the environment properties, and from the provider resource file associated with nameCtx, in that order. The value of this property is a colon-separated list of factory class names that are tried in order, and the first one that succeeds in returning the object's state is the one used. If no object's state can be retrieved in this way, return the object itself. If an exception is encountered while retrieving the state, the exception is passed up to the caller.

Note that a state factory (an object that implements the StateFactory interface) must be public and must have a public constructor that accepts no arguments. In cases where the factory is in a named module then it must be in a package which is exported by that module to the java.naming module.

The name and nameCtx parameters may optionally be used to specify the name of the object being created. See the description of "Name and Context Parameters" in ObjectFactory.getObjectInstance() for details.

This method may return a Referenceable object. The service provider obtaining this object may choose to store it directly, or to extract its reference (using Referenceable.getReference()) and store that instead.

Parameters
obj:Object

The non-null object for which to get state to bind.

name:Name

The name of this object relative to nameCtx, or null if no name is specified.

nameCtx:Context

The context relative to which the name parameter is specified, or null if name is relative to the default initial context.

environment:Hashtable<?, ?>

The possibly null environment to be used in the creation of the state factory and the object's state.

Returns:Object

The non-null object representing obj's state for binding. It could be the object (obj) itself.

Exceptions
NamingException:
If one of the factories accessed throws an exception, or if an error was encountered while loading and instantiating the factory and object classes. A factory should only throw an exception if it does not want other factories to be used in an attempt to create an object. See StateFactory.getStateToBind().
Since
1.3
See Also
StateFactory, StateFactory#getStateToBind, DirectoryManager#getStateToBind
getURLContextback to summary
public static Context getURLContext(String scheme, Hashtable<?, ?> environment) throws NamingException

Creates a context for the given URL scheme id.

The resulting context is for resolving URLs of the scheme scheme. The resulting context is not tied to a specific URL. It is able to handle arbitrary URLs with the specified scheme.

The class name of the factory that creates the resulting context has the naming convention scheme-idURLContextFactory (e.g. "ftpURLContextFactory" for the "ftp" scheme-id), in the package specified as follows. The Context.URL_PKG_PREFIXES environment property (which may contain values taken from system properties, or application resource files) contains a colon-separated list of package prefixes. Each package prefix in the property is tried in the order specified to load the factory class. The default package prefix is "com.sun.jndi.url" (if none of the specified packages work, this default is tried). The complete package name is constructed using the package prefix, concatenated with the scheme id.

For example, if the scheme id is "ldap", and the Context.URL_PKG_PREFIXES property contains "com.widget:com.wiz.jndi", the naming manager would attempt to load the following classes until one is successfully instantiated:

  • com.widget.ldap.ldapURLContextFactory
  • com.wiz.jndi.ldap.ldapURLContextFactory
  • com.sun.jndi.url.ldap.ldapURLContextFactory
If none of the package prefixes work, null is returned.

If a factory is instantiated, it is invoked with the following parameters to produce the resulting context.

factory.getObjectInstance(null, environment);

For example, invoking getObjectInstance() as shown above on a LDAP URL context factory would return a context that can resolve LDAP urls (e.g. "ldap://ldap.wiz.com/o=wiz,c=us", "ldap://ldap.umich.edu/o=umich,c=us", ...).

Note that an object factory (an object that implements the ObjectFactory interface) must be public and must have a public constructor that accepts no arguments. In cases where the factory is in a named module then it must be in a package which is exported by that module to the java.naming module.

Parameters
scheme:String

The non-null scheme-id of the URLs supported by the context.

environment:Hashtable<?, ?>

The possibly null environment properties to be used in the creation of the object factory and the context.

Returns:Context

A context for resolving URLs with the scheme id scheme; null if the factory for creating the context is not found.

Exceptions
NamingException:
If a naming exception occurs while creating the context.
See Also
getObjectInstance, ObjectFactory#getObjectInstance
getURLObjectback to summary
private static Object getURLObject(String scheme, Object urlInfo, Name name, Context nameCtx, Hashtable<?, ?> environment) throws NamingException

Creates an object for the given URL scheme id using the supplied urlInfo.

If urlInfo is null, the result is a context for resolving URLs with the scheme id 'scheme'. If urlInfo is a URL, the result is a context named by the URL. Names passed to this context is assumed to be relative to this context (i.e. not a URL). For example, if urlInfo is "ldap://ldap.wiz.com/o=Wiz,c=us", the resulting context will be that pointed to by "o=Wiz,c=us" on the server 'ldap.wiz.com'. Subsequent names that can be passed to this context will be LDAP names relative to this context (e.g. cn="Barbs Jensen"). If urlInfo is an array of URLs, the URLs are assumed to be equivalent in terms of the context to which they refer. The resulting context is like that of the single URL case. If urlInfo is of any other type, that is handled by the context factory for the URL scheme.

Parameters
scheme:String

the URL scheme id for the context

urlInfo:Object

information used to create the context

name:Name

name of this object relative to nameCtx

nameCtx:Context

Context whose provider resource file will be searched for package prefix values (or null if none)

environment:Hashtable<?, ?>

Environment properties for creating the context

See Also
javax.naming.InitialContext
hasInitialContextFactoryBuilderback to summary
public static boolean hasInitialContextFactoryBuilder()

Determines whether an initial context factory builder has been set.

Returns:boolean

true if an initial context factory builder has been set; false otherwise.

See Also
setInitialContextFactoryBuilder
setInitialContextFactoryBuilderback to summary
public static synchronized void setInitialContextFactoryBuilder(InitialContextFactoryBuilder builder) throws NamingException

Sets the InitialContextFactory builder to be builder.

Parameters
builder:InitialContextFactoryBuilder

The initial context factory builder to install. If null, no builder is set.

Exceptions
NamingException:
builder cannot be installed for a non-security-related reason.
IllegalStateException:
If a builder was previous installed.
See Also
hasInitialContextFactoryBuilder
setObjectFactoryBuilderback to summary
public static void setObjectFactoryBuilder(ObjectFactoryBuilder builder) throws NamingException

The ObjectFactoryBuilder determines the policy used when trying to load object factories. See getObjectInstance() and class ObjectFactory for a description of the default policy. setObjectFactoryBuilder() overrides this default policy by installing an ObjectFactoryBuilder. Subsequent object factories will be loaded and created using the installed builder.

Parameters
builder:ObjectFactoryBuilder

The factory builder to install. If null, no builder is installed.

Exceptions
NamingException:
builder cannot be installed for a non-security-related reason.
IllegalStateException:
If a factory has already been installed.
See Also
getObjectInstance, ObjectFactory, ObjectFactoryBuilder
javax.naming.spi back to summary

private Class NamingManager.FactoryInitializationError

extends Error
Class Inheritance

Thrown when an error is encountered while loading and instantiating the context factory classes.

Field Summary

Modifier and TypeField and Description
pack-priv static final long

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public NoInitialContextException
getCause()

Overrides java.lang.Throwable.getCause.

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Field Detail

serialVersionUIDback to summary
pack-priv static final long serialVersionUID

Hides java.lang.Error.serialVersionUID.

Annotations
@Serial

Constructor Detail

FactoryInitializationErrorback to summary
private FactoryInitializationError(NoInitialContextException cause)

Method Detail

getCauseback to summary
public NoInitialContextException getCause()

Overrides java.lang.Throwable.getCause.

Doc from java.lang.Throwable.getCause.

Returns the cause of this throwable or null if the cause is nonexistent or unknown. (The cause is the throwable that caused this throwable to get thrown.)

This implementation returns the cause that was supplied via one of the constructors requiring a Throwable, or that was set after creation with the initCause(Throwable) method. While it is typically unnecessary to override this method, a subclass can override it to return a cause set by some other means. This is appropriate for a "legacy chained throwable" that predates the addition of chained exceptions to Throwable. Note that it is not necessary to override any of the PrintStackTrace methods, all of which invoke the getCause method to determine the cause of a throwable.

Annotations
@Override