coded this method in bean. The intent was for the bean to run
all the setters using the values in a vector argument. here's
the code:
public void loadSelf(Vector v) throws Exception {
String[] parms = new String[1];
Class cls = getClass();
java.lang.reflect.Method[] methods = cls.getMethods();
java.lang.reflect.AccessibleObject.setAccessible(methods, true);
int vectorPointer = 0;
for (int i=1;i<methods.length;i++) {
String method = methods[i].getName();
if (method.indexOf("set") == 0) {
if (!method.substring(3).equals("Class")) {
parms[0] = (String)v.get(vectorPointer);
methods[i].invoke(this, parms);
vectorPointer++;
}
}
}
}
my problem is that the setters are not running in the order that was
coded.
in other words, when i constructed the vector argument, the values do
not
match the setters.
any ideas??
Dan Nuttle - 12 Mar 2005 03:59 GMT
The javadocs for Class.getMethods says, in part:
"The elements in the array returned are not sorted and are not in any
particular order."
So that's why they don't match. There is no way to tell in what order the
methods will be in your Methods[] array. To fix this, you could put your
values into a Map instead of a Vector (a List), and the keys for the map
could be the method names.
> coded this method in bean. The intent was for the bean to run
> all the setters using the values in a vector argument. here's
[quoted text clipped - 24 lines]
>
> any ideas??