javaclass

java/lang/reflect.py

158:a52e70c3f294
2005-01-23 Paul Boddie Added "safety measures" for exception offset insertion, although better measures are necessary to avoid bizarre JDK 1.4 exception tables.
     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