DirectoryManagerpublic class DirectoryManager extends NamingManager This class contains methods for supporting DirContext
implementations.
This class is an extension of NamingManager. It contains methods
for use by service providers for accessing object factories and
state factories, and for getting continuation contexts for
supporting federation.
DirectoryManager is safe for concurrent access by multiple threads.
Except as otherwise noted,
a Name, Attributes, 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. |
Constructors Summary |
---|
DirectoryManager()
|
Methods Summary |
---|
private static java.lang.Object | createObjectFromFactories(java.lang.Object obj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable environment, javax.naming.directory.Attributes attrs)
FactoryEnumeration factories = ResourceManager.getFactories(
Context.OBJECT_FACTORIES, environment, nameCtx);
if (factories == null)
return null;
ObjectFactory factory;
Object answer = null;
// Try each factory until one succeeds
while (answer == null && factories.hasMore()) {
factory = (ObjectFactory)factories.next();
if (factory instanceof DirObjectFactory) {
answer = ((DirObjectFactory)factory).
getObjectInstance(obj, name, nameCtx, environment, attrs);
} else {
answer =
factory.getObjectInstance(obj, name, nameCtx, environment);
}
}
return answer;
| public static javax.naming.directory.DirContext | getContinuationDirContext(javax.naming.CannotProceedException cpe)Creates a context in which to continue a DirContext operation.
Operates just like NamingManager.getContinuationContext(),
only the continuation context returned is a DirContext.
Hashtable env = cpe.getEnvironment();
if (env == null) {
env = new Hashtable(7);
} else {
// Make a (shallow) copy of the environment.
env = (Hashtable) env.clone();
}
env.put(CPE, cpe);
return (new ContinuationDirContext(cpe, env));
| public static java.lang.Object | getObjectInstance(java.lang.Object refInfo, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable environment, javax.naming.directory.Attributes attrs)Creates an instance of an object for the specified object,
attributes, and environment.
This method is the same as NamingManager.getObjectInstance
except for the following differences:
-
It accepts an Attributes parameter that contains attributes
associated with the object. The DirObjectFactory might use these
attributes to save having to look them up from the directory.
-
The object factories tried must implement either
ObjectFactory or DirObjectFactory.
If it implements DirObjectFactory,
DirObjectFactory.getObjectInstance() is used, otherwise,
ObjectFactory.getObjectInstance() is used.
Service providers that implement the DirContext interface
should use this method, not NamingManager.getObjectInstance().
ObjectFactory factory;
ObjectFactoryBuilder builder = getObjectFactoryBuilder();
if (builder != null) {
// builder must return non-null factory
factory = builder.createObjectFactory(refInfo, environment);
if (factory instanceof DirObjectFactory) {
return ((DirObjectFactory)factory).getObjectInstance(
refInfo, name, nameCtx, environment, attrs);
} else {
return factory.getObjectInstance(refInfo, name, nameCtx,
environment);
}
}
// use reference if possible
Reference ref = null;
if (refInfo instanceof Reference) {
ref = (Reference) refInfo;
} else if (refInfo instanceof Referenceable) {
ref = ((Referenceable)(refInfo)).getReference();
}
Object answer;
if (ref != null) {
String f = ref.getFactoryClassName();
if (f != null) {
// if reference identifies a factory, use exclusively
factory = getObjectFactoryFromReference(ref, f);
if (factory instanceof DirObjectFactory) {
return ((DirObjectFactory)factory).getObjectInstance(
ref, name, nameCtx, environment, attrs);
} else if (factory != null) {
return factory.getObjectInstance(ref, name, nameCtx,
environment);
}
// No factory found, so return original refInfo.
// Will reach this point if factory class is not in
// class path and reference does not contain a URL for it
return refInfo;
} else {
// if reference has no factory, check for addresses
// containing URLs
// ignore name & attrs params; not used in URL factory
answer = processURLAddrs(ref, name, nameCtx, environment);
if (answer != null) {
return answer;
}
}
}
// try using any specified factories
answer = createObjectFromFactories(refInfo, name, nameCtx,
environment, attrs);
return (answer != null) ? answer : refInfo;
| public static javax.naming.spi.DirStateFactory$Result | getStateToBind(java.lang.Object obj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable environment, javax.naming.directory.Attributes attrs)Retrieves the state of an object for binding when given the original
object and its attributes.
This method is like NamingManager.getStateToBind except
for the following differences:
- It accepts an Attributes parameter containing attributes
that were passed to the DirContext.bind() method.
- It returns a non-null DirStateFactory.Result instance
containing the object to be bound, and the attributes to
accompany the binding. Either the object or the attributes may be null.
-
The state factories tried must each implement either
StateFactory or DirStateFactory.
If it implements DirStateFactory, then
DirStateFactory.getStateToBind() is called; otherwise,
StateFactory.getStateToBind() is called.
Service providers that implement the DirContext interface
should use this method, not NamingManager.getStateToBind().
See NamingManager.getStateToBind() for a description of how
the list of state factories to be tried is determined.
The object returned by this method is owned by the caller.
The implementation will not subsequently modify it.
It will contain either a new Attributes object that is
likewise owned by the caller, or a reference to the original
attrs parameter.
// Get list of state factories
FactoryEnumeration factories = ResourceManager.getFactories(
Context.STATE_FACTORIES, environment, nameCtx);
if (factories == null) {
// no factories to try; just return originals
return new DirStateFactory.Result(obj, attrs);
}
// Try each factory until one succeeds
StateFactory factory;
Object objanswer;
DirStateFactory.Result answer = null;
while (answer == null && factories.hasMore()) {
factory = (StateFactory)factories.next();
if (factory instanceof DirStateFactory) {
answer = ((DirStateFactory)factory).
getStateToBind(obj, name, nameCtx, environment, attrs);
} else {
objanswer =
factory.getStateToBind(obj, name, nameCtx, environment);
if (objanswer != null) {
answer = new DirStateFactory.Result(objanswer, attrs);
}
}
}
return (answer != null) ? answer :
new DirStateFactory.Result(obj, attrs); // nothing new
|
|