src/share/classes/com/sun/naming/internal/FactoryEnumeration.java
Print this page
*** 35,45 ****
* @author Scott Seligman
*/
// no need to implement Enumeration since this is only for internal use
public final class FactoryEnumeration {
! private List factories;
private int posn = 0;
private ClassLoader loader;
/**
* Records the input list and uses it directly to satisfy
--- 35,46 ----
* @author Scott Seligman
*/
// no need to implement Enumeration since this is only for internal use
public final class FactoryEnumeration {
! // List<NamedWeakReference<Class | Object>>
! private List<NamedWeakReference<Object>> factories;
private int posn = 0;
private ClassLoader loader;
/**
* Records the input list and uses it directly to satisfy
*** 57,75 ****
* class can be reloaded if the reference is cleared.
* @param factories A non-null list
* @param loader The class loader of the list's contents
*/
! FactoryEnumeration(List factories, ClassLoader loader) {
this.factories = factories;
this.loader = loader;
}
public Object next() throws NamingException {
synchronized (factories) {
! NamedWeakReference ref = (NamedWeakReference) factories.get(posn++);
Object answer = ref.get();
if ((answer != null) && !(answer instanceof Class)) {
return answer;
}
--- 58,77 ----
* class can be reloaded if the reference is cleared.
* @param factories A non-null list
* @param loader The class loader of the list's contents
*/
! FactoryEnumeration(List<NamedWeakReference<Object>> factories,
! ClassLoader loader) {
this.factories = factories;
this.loader = loader;
}
public Object next() throws NamingException {
synchronized (factories) {
! NamedWeakReference<Object> ref = factories.get(posn++);
Object answer = ref.get();
if ((answer != null) && !(answer instanceof Class)) {
return answer;
}
*** 79,89 ****
if (answer == null) { // reload class if weak ref cleared
answer = Class.forName(className, true, loader);
}
// Instantiate Class to get factory
answer = ((Class) answer).newInstance();
! ref = new NamedWeakReference(answer, className);
factories.set(posn-1, ref); // replace Class object or null
return answer;
} catch (ClassNotFoundException e) {
NamingException ne =
new NamingException("No longer able to load " + className);
--- 81,91 ----
if (answer == null) { // reload class if weak ref cleared
answer = Class.forName(className, true, loader);
}
// Instantiate Class to get factory
answer = ((Class) answer).newInstance();
! ref = new NamedWeakReference<>(answer, className);
factories.set(posn-1, ref); // replace Class object or null
return answer;
} catch (ClassNotFoundException e) {
NamingException ne =
new NamingException("No longer able to load " + className);