APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.naming.internal

public final Class ResourceManager

extends Object
Class Inheritance
Imports
java.io.InputStream, .IOException, java.lang.ref.WeakReference, java.util.HashMap, .Hashtable, .Map, .Properties, .StringTokenizer, .List, .ArrayList, .WeakHashMap, javax.naming.*

The ResourceManager class facilitates the reading of JNDI resource files.
Authors
Rosanna Lee, Scott Seligman

Field Summary

Modifier and TypeField and Description
private static final String
private static final String
private static final WeakHashMap<ClassLoader, Map<String, List<NamedWeakReference<Object>>>>
private static final VersionHelper
private static final String
private static final String[]
private static final WeakReference<Object>
private static final WeakHashMap<Object, Hashtable<? super String, Object>>
private static final String
private static final WeakHashMap<ClassLoader, Map<String, WeakReference<Object>>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static Hashtable<? super String, Object>
public static FactoryEnumeration

Returns:

An enumeration of factory classes/objects; null if none.
getFactories
(String
The non-null property name
propName
,
Hashtable<?, ?>
The possibly null environment properties
env
,
Context
The possibly null context
ctx
)

Retrieves an enumeration of factory classes/object specified by a property.

public static Object

Returns:

An factory object; null if none.
getFactory
(String
The non-null property name
propName
,
Hashtable<?, ?>
The possibly null environment properties
env
,
Context
The possibly null context
ctx
,
String
The non-null class name (e.g. ".ldap.ldapURLContextFactory).
classSuffix
,
String
The non-null default package prefix. (e.g., "com.sun.jndi.url").
defaultPkgPrefix
)

Retrieves a factory from a list of packages specified in a property.

public static Hashtable<?, ?>
getInitialEnvironment(Hashtable<?, ?>
environment passed to initial context constructor. Null indicates an empty environment.
env
)

Given the environment parameter passed to the initial context constructor, returns the full environment for that initial context (never null).

public static String

Returns:

the property value, or null is there is none.
getProperty
(String
The non-null property name
propName
,
Hashtable<?, ?>
The possibly null environment properties
env
,
Context
The possibly null context
ctx
,
boolean
True if multiple values should be concatenated
concat
)

Retrieves the property from the environment, or from the provider resource file associated with the given context.

private static Hashtable<? super String, Object>
private static boolean
private static void
mergeTables(Hashtable<? super String, Object> props1, Hashtable<? super String, Object> props2)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

APP_RESOURCE_FILE_NAMEback to summary
private static final String APP_RESOURCE_FILE_NAME
DISABLE_APP_RESOURCE_FILESback to summary
private static final String DISABLE_APP_RESOURCE_FILES
factoryCacheback to summary
private static final WeakHashMap<ClassLoader, Map<String, List<NamedWeakReference<Object>>>> factoryCache
helperback to summary
private static final VersionHelper helper
JRE_CONF_PROPERTY_FILE_NAMEback to summary
private static final String JRE_CONF_PROPERTY_FILE_NAME
listPropertiesback to summary
private static final String[] listProperties
NO_FACTORYback to summary
private static final WeakReference<Object> NO_FACTORY
propertiesCacheback to summary
private static final WeakHashMap<Object, Hashtable<? super String, Object>> propertiesCache
PROVIDER_RESOURCE_FILE_NAMEback to summary
private static final String PROVIDER_RESOURCE_FILE_NAME
urlFactoryCacheback to summary
private static final WeakHashMap<ClassLoader, Map<String, WeakReference<Object>>> urlFactoryCache

Constructor Detail

ResourceManagerback to summary
private ResourceManager()

Method Detail

getApplicationResourcesback to summary
private static Hashtable<? super String, Object> getApplicationResources() throws NamingException
getFactoriesback to summary
public static FactoryEnumeration getFactories(String propName, Hashtable<?, ?> env, Context ctx) throws NamingException

Retrieves an enumeration of factory classes/object specified by a property. The property is gotten from the environment and the provider resource file associated with the given context and concatenated. See getProperty(). The resulting property value is a list of class names.

This method then loads each class using the current thread's context class loader and keeps them in a list. Any class that cannot be loaded is ignored. The resulting list is then cached in a two-level hash table, keyed first by the context class loader and then by the property's value. The next time threads of the same context class loader call this method, they can use the cached list.

After obtaining the list either from the cache or by creating one from the property value, this method then creates and returns a FactoryEnumeration using the list. As the FactoryEnumeration is traversed, the cached Class object in the list is instantiated and replaced by an instance of the factory object itself. Both class objects and factories are wrapped in weak references so as not to prevent GC of the class loader.

Note that multiple threads can be accessing the same cached list via FactoryEnumeration, which locks the list during each next(). The size of the list will not change, but a cached Class object might be replaced by an instantiated factory object.

Parameters
propName:String

The non-null property name

env:Hashtable<?, ?>

The possibly null environment properties

ctx:Context

The possibly null context

Returns:FactoryEnumeration

An enumeration of factory classes/objects; null if none.

Exceptions
NamingException:
If encounter problem while reading the provider property file.
See Also
javax.naming.spi.NamingManager#getObjectInstance, javax.naming.spi.NamingManager#getStateToBind, javax.naming.spi.DirectoryManager#getObjectInstance, javax.naming.spi.DirectoryManager#getStateToBind, javax.naming.ldap.ControlFactory#getControlInstance
getFactoryback to summary
public static Object getFactory(String propName, Hashtable<?, ?> env, Context ctx, String classSuffix, String defaultPkgPrefix) throws NamingException

Retrieves a factory from a list of packages specified in a property. The property is gotten from the environment and the provider resource file associated with the given context and concatenated. classSuffix is added to the end of this list. See getProperty(). The resulting property value is a list of package prefixes.

This method then constructs a list of class names by concatenating each package prefix with classSuffix and attempts to load and instantiate the class until one succeeds. Any class that cannot be loaded is ignored. The resulting object is then cached in a two-level hash table, keyed first by the context class loader and then by the property's value and classSuffix. The next time threads of the same context class loader call this method, they use the cached factory. If no factory can be loaded, NO_FACTORY is recorded in the table so that next time it'll return quickly.

Parameters
propName:String

The non-null property name

env:Hashtable<?, ?>

The possibly null environment properties

ctx:Context

The possibly null context

classSuffix:String

The non-null class name (e.g. ".ldap.ldapURLContextFactory).

defaultPkgPrefix:String

The non-null default package prefix. (e.g., "com.sun.jndi.url").

Returns:Object

An factory object; null if none.

Exceptions
NamingException:
If encounter problem while reading the provider property file, or problem instantiating the factory.
See Also
javax.naming.spi.NamingManager#getURLContext, javax.naming.spi.NamingManager#getURLObject
getInitialEnvironmentback to summary
public static Hashtable<?, ?> getInitialEnvironment(Hashtable<?, ?> env) throws NamingException

Given the environment parameter passed to the initial context constructor, returns the full environment for that initial context (never null). This is based on the environment parameter, the system properties, and all application resource files.

This method will modify env and save a reference to it. The caller may no longer modify it.

Parameters
env:Hashtable<?, ?>

environment passed to initial context constructor. Null indicates an empty environment.

Annotations
@SuppressWarnings:unchecked
Exceptions
NamingException:
if an error occurs while reading a resource file
getPropertyback to summary
public static String getProperty(String propName, Hashtable<?, ?> env, Context ctx, boolean concat) throws NamingException

Retrieves the property from the environment, or from the provider resource file associated with the given context. The environment may in turn contain values that come from system properties, or application resource files. If concat is true and both the environment and the provider resource file contain the property, the two values are concatenated (with a ':' separator). Returns null if no value is found.

Parameters
propName:String

The non-null property name

env:Hashtable<?, ?>

The possibly null environment properties

ctx:Context

The possibly null context

concat:boolean

True if multiple values should be concatenated

Returns:String

the property value, or null is there is none.

Exceptions
NamingException:
if an error occurs while reading the provider resource file.
getProviderResourceback to summary
private static Hashtable<? super String, Object> getProviderResource(Object obj) throws NamingException
isListPropertyback to summary
private static boolean isListProperty(String prop)
mergeTablesback to summary
private static void mergeTables(Hashtable<? super String, Object> props1, Hashtable<? super String, Object> props2)