1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/java/lang/reflect.py Mon Jan 10 23:52:44 2005 +0100
1.3 @@ -0,0 +1,41 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +import java.lang
1.7 +
1.8 +class Class(java.lang.Object):
1.9 + def __init__(self, obj):
1.10 + self.obj = obj
1.11 +
1.12 + def getMethod(self, name, parameterTypes):
1.13 +
1.14 + """
1.15 + Find the method on this class with the given 'name' and
1.16 + 'parameterTypes'. Return a Method object.
1.17 +
1.18 + Note that this implementation remembers which object was used to obtain
1.19 + this class. This allows the Method objects to be called in Python.
1.20 + """
1.21 +
1.22 + # Build the Python name.
1.23 +
1.24 + types = []
1.25 + for parameterType in parameterTypes:
1.26 + types.append("__".join(parameterType.split(".")))
1.27 + method_name = unicode(name) + "___" + "___".join(types)
1.28 +
1.29 + # Either return a Method object or raise the appropriate exception.
1.30 + try:
1.31 + return Method(getattr(self.obj, method_name))
1.32 + except AttributeError:
1.33 + raise Exception, java.lang.NoSuchMethodException(name)
1.34 +
1.35 + getMethod___java__lang__String___java__lang__Class_array_ = getMethod
1.36 +
1.37 +class Method(java.lang.Object):
1.38 + def __init__(self, method):
1.39 + self.method = method
1.40 +
1.41 + def __call__(self, *args):
1.42 + return self.method(*args)
1.43 +
1.44 +# vim: tabstop=4 expandtab shiftwidth=4