javaclass

java/lang/reflect.py

114:2420bedaf184
2005-01-10 Paul Boddie Moved the lang module contents into the lang package. Fixed various java.lang and java.io circular imports by introducing a java.lang._object module. Corrected various base classes (object -> java.lang.Object, Exception -> java.lang.Exception) and fixed raising of exceptions in certain cases. Added reflection capabilities.
     1 #!/usr/bin/env python     2      3 import java.lang     4      5 class Class(java.lang.Object):     6     def __init__(self, obj):     7         self.obj = obj     8      9     def getMethod(self, name, parameterTypes):    10     11         """    12         Find the method on this class with the given 'name' and    13         'parameterTypes'. Return a Method object.    14     15         Note that this implementation remembers which object was used to obtain    16         this class. This allows the Method objects to be called in Python.    17         """    18     19         # Build the Python name.    20     21         types = []    22         for parameterType in parameterTypes:    23             types.append("__".join(parameterType.split(".")))    24         method_name = unicode(name) + "___" + "___".join(types)    25     26         # Either return a Method object or raise the appropriate exception.    27         try:    28             return Method(getattr(self.obj, method_name))    29         except AttributeError:    30             raise Exception, java.lang.NoSuchMethodException(name)    31     32     getMethod___java__lang__String___java__lang__Class_array_ = getMethod    33     34 class Method(java.lang.Object):    35     def __init__(self, method):    36         self.method = method    37     38     def __call__(self, *args):    39         return self.method(*args)    40     41 # vim: tabstop=4 expandtab shiftwidth=4