Re: Problem: Calling methods of dynamically loaded inner classes at runtime
You seem to be discarding errors silently -- not the best way to find out
I changed catch block so that it handles each error separately and
removed the condition.
Still, no error appeared
It's possible that you are specifying the wrong names for the inner classes.
Checked that too, here everything is fine...
Also:
Constructor attributeCon = attributeClass.getConstructor();
Object attributeObject = attributeCon.newInstance();
If your "inner" classes really are inner, rather than just static nested
classes, then none of them will have a no-args constructor. All non-static
nested classes require a pointer to their outer object, and that is passed in
as a (hidden) parameter to each constructor, which is added by javac. When you
call the constructor in normall code the compiler automatically adds a ref to
the outer object to the parameters you pass -- but if can't do that when you
are using reflection.
Well, classes are inner, and I rather cannot make them static, because
in all cases ececute() is using non-static variables being fields of
outer class...
If I try to make inner classes static, environment says that you cannot
reference non-static variable from static content...
Do you have any idea how to get that magic pointer to outer object and
pass it?... Or maybe how to make it accept such reference?...
I also played a little bit more with the code
and for such code
Map attrs = page.getAttributes();
for (Object o : attrs.keySet())
{
try {
1) Class attributeClass =
Class.forName(o.toString());
2) log.info("AAAA"+attributeClass.toString());
3) Constructor attributeCon =
attributeClass.getConstructor();
4) log.info("BBBB"+attributeCon.toString());
5) Object attributeObject =
attributeCon.newInstance();
6) log.info("CCCC"+attributeObject.toString());
7) ((Module)attributeObject).execute(page, request,
response);
}
catch (InstantiationException e) {e.getMessage();}
catch (IllegalAccessException e) {e.getMessage();}
catch (InvocationTargetException e) {e.getMessage();}
catch (NoSuchMethodException e) {e.getMessage();}
catch (ClassNotFoundException e) {e.getMessage();}
}
got output:
[2006-08-01 12:20:33,570] INFO [Test] AAAAclass
com.cp2portal.util.Test$CP2Test
[2006-08-01 12:20:33,576] INFO [Test] AAAAclass
com.cp2portal.util.Test$MailTest
It seems not to execute code from line 3-7. Anything that is outside
try-catch block works fine.No errors appeared...
I'm really confused.