Iterator iterator;
if (value instanceof Iterator) {
return (Iterator) value;
}
if (value instanceof Map) {
value = ((Map) value).entrySet();
}
if (value == null) {
return null;
}
if (value instanceof Collection) {
iterator = ((Collection) value).iterator();
} else if (value.getClass().isArray()) {
//need ability to support primitives; therefore, cannot
//use Object[] casting.
ArrayList list = new ArrayList(Array.getLength(value));
for (int j = 0; j < Array.getLength(value); j++) {
list.add(Array.get(value, j));
}
iterator = list.iterator();
} else if (value instanceof Enumeration) {
Enumeration enumeration = (Enumeration) value;
ArrayList list = new ArrayList();
while (enumeration.hasMoreElements()) {
list.add(enumeration.nextElement());
}
iterator = list.iterator();
} else {
List list = new ArrayList(1);
list.add(value);
iterator = list.iterator();
}
return iterator;