From: Kip L. <kip...@ea...> - 2005-12-19 14:06:38
|
Cobbling together some code based on approaches suggested by Helio Zwi, Jeff Emanuel, Rick Hightower and some fragments I had previously used, I've put together a module, jylluminate.py, that addresses Bill's original question and a bit more. As it is over 500 lines, I'll only include the module docstring here. The code is available at http://home.earthlink.net/~kip.lehman/jython/jylluminate.py. Here's the module docstring for jylluminate.py ... """ Inspired by a Dec 2005 Jython users mailing list question asked by Bill Woodward and responses from Helio R. Zwi and Jeff Emanuel, this mini-module contains functions to illuminate instances of a Java object. Having dug up other useful perspectives provided by Rick Hightower, I've put together a set of functions that can help in illuminating the swamp of what lies beneath a Java object's surface. Using the functions defined here, one can: 1) Find out the instance's lineage, ie., what superclasses the object inherits from or what interfaces the object defines/implements. lineage(javaObject) 2) Find out what methods that the class defines and what interfaces are implemented (excluding superclasses). methods(javaObject) 3) Find rudimentary information about simple data attributes held by the instance. dataAttributes(javaObject) The code uses syntax legal for Jython 2.1. No attempt has been made to prove that this works for every Java object in the Milky Way galaxy. The functions here are not optimized for elegance, non-repetitiveness or performance. This is meant to be _an_ example of how to peer into a Java object instance from Jython, I make no claims that it is the _only_ or the _best_ way! Notably, I didn't make use of the declaredMethods (hadn't known about that prior to Jeff Emanuel's mention, thanks!), which could be used to come up with calling signatures for the methods. I just didn't want to deal with the additional code and output swelling that would entail, since this exercise quickly ballooned well beyond a simple little 10 line script. Kip Lehman <kipster<dash>t<at>earthlink<dot>net> """ Comments, questions, suggestions are welcome. |