src/share/classes/com/sun/naming/internal/FactoryEnumeration.java
Print this page
@@ -35,11 +35,12 @@
* @author Scott Seligman
*/
// no need to implement Enumeration since this is only for internal use
public final class FactoryEnumeration {
- private List factories;
+ // 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,19 +58,20 @@
* 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) {
+ FactoryEnumeration(List<NamedWeakReference<Object>> factories,
+ ClassLoader loader) {
this.factories = factories;
this.loader = loader;
}
public Object next() throws NamingException {
synchronized (factories) {
- NamedWeakReference ref = (NamedWeakReference) factories.get(posn++);
+ NamedWeakReference<Object> ref = factories.get(posn++);
Object answer = ref.get();
if ((answer != null) && !(answer instanceof Class)) {
return answer;
}
@@ -79,11 +81,11 @@
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);
+ 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);