public static Object getObjectInstance(Object refInfo,
Name name,
Context nameCtx,
Hashtable<?, ?> environment,
Attributes attrs) throws Exception {
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 Result getStateToBind(Object obj,
Name name,
Context nameCtx,
Hashtable<?, ?> environment,
Attributes attrs) throws NamingException {
// 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
}
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. |