def __init__(self, class_name):
     '''Initialize to wrap a class name
     
     :param class_name: name of class in dotted form, e.g. java.lang.Integer
     '''
     STATIC = J.get_static_field("java/lang/reflect/Modifier", "STATIC",
                                 "I")
     self.cname = class_name.replace(".", "/")
     self.klass = J.get_class_wrapper(J.class_for_name(class_name), True)
     self.static_methods = {}
     methods = env.get_object_array_elements(self.klass.getMethods())
     self.methods = {}
     for jmethod in methods:
         if (J.call(jmethod, "getModifiers", "()I") & STATIC) != STATIC:
             continue
         method = J.get_method_wrapper(jmethod)
         name = method.getName()
         if name not in self.methods:
             self.methods[name] = []
             fn = lambda naame=name: lambda *args: self.__call_static(
                 naame, *args)
             fn = fn()
             fn.__doc__ = J.to_string(jmethod)
             setattr(self, name, fn)
         else:
             fn = getattr(self, name)
             fn.__doc__ = fn.__doc__ + "\n" + J.to_string(jmethod)
         self.methods[name].append(method)
 def __init__(self, o):
     '''Initialize the JWrapper with a Java object
     
     :param o: a Java object (class = JB_Object)
     '''
     STATIC = J.get_static_field("java/lang/reflect/Modifier", "STATIC",
                                 "I")
     self.o = o
     self.class_wrapper = J.get_class_wrapper(o)
     env = J.get_env()
     methods = env.get_object_array_elements(
         self.class_wrapper.getMethods())
     self.methods = {}
     for jmethod in methods:
         if (J.call(jmethod, "getModifiers", "()I") & STATIC) == STATIC:
             continue
         method = J.get_method_wrapper(jmethod)
         name = method.getName()
         if name not in self.methods:
             self.methods[name] = []
             fn = lambda naame=name: lambda *args: self.__call(naame, *args)
             fn = fn()
             fn.__doc__ = J.to_string(jmethod)
             setattr(self, name, fn)
         else:
             fn = getattr(self, name)
             fn.__doc__ = fn.__doc__ + "\n" + J.to_string(jmethod)
         self.methods[name].append(method)
     jfields = self.class_wrapper.getFields()
     fields = env.get_object_array_elements(jfields)
Пример #3
0
 def __init__(self, o):
     '''Initialize the JWrapper with a Java object
     
     :param o: a Java object (class = JB_Object)
     '''
     STATIC = J.get_static_field("java/lang/reflect/Modifier", "STATIC", "I")
     self.o = o
     self.class_wrapper = J.get_class_wrapper(o)
     env = J.get_env()
     jmethods = env.get_object_array_elements(self.class_wrapper.getMethods())
     methods = {}
     for jmethod in jmethods:
         if (J.call(jmethod, "getModifiers", "()I") & STATIC) == STATIC:
             continue
         method = J.get_method_wrapper(jmethod)
         name = method.getName()
         if name not in methods:
             methods[name] = []
             fn = lambda naame=name: lambda *args: self.__call(naame, *args)
             fn = fn()
             fn.__doc__ = J.to_string(jmethod)
             setattr(self, name, fn)
         else:
             fn = getattr(self, name)
             fn.__doc__ = fn.__doc__ +"\n"+J.to_string(jmethod)
         methods[name].append(method)
     self.methods = methods
Пример #4
0
 def __init__(self, class_name):
     '''Initialize to wrap a class name
     
     :param class_name: name of class in dotted form, e.g. java.lang.Integer
     '''
     STATIC = J.get_static_field("java/lang/reflect/Modifier", "STATIC", "I")
     self.cname = class_name.replace(".", "/")
     self.klass = J.get_class_wrapper(J.class_for_name(class_name), True)
     self.static_methods = {}
     env = J.get_env()
     jmethods = env.get_object_array_elements(self.klass.getMethods())
     methods = {}
     for jmethod in jmethods:
         if (J.call(jmethod, "getModifiers", "()I") & STATIC) != STATIC:
             continue
         method = J.get_method_wrapper(jmethod)
         name = method.getName()
         if name not in methods:
             methods[name] = []
             fn = lambda naame=name: lambda *args: self.__call_static(naame, *args)
             fn = fn()
             fn.__doc__ = J.to_string(jmethod)
             setattr(self, name, fn)
         else:
             fn = getattr(self, name)
             fn.__doc__ = fn.__doc__ +"\n"+J.to_string(jmethod)
         methods[name].append(method)
     self.methods = methods
Пример #5
0
        def allowOpenToCheckType(self, allow):
            '''Allow the "isThisType" function to open files

            For the cluster, you want to tell potential file formats
            not to open the image file to test if it's their format.
            '''
            if not hasattr(self, "allowOpenToCheckType_method"):
                self.allowOpenToCheckType_method = None
                class_wrapper = jutil.get_class_wrapper(self.o)
                methods = class_wrapper.getMethods()
                for method in jutil.get_env().get_object_array_elements(
                        methods):
                    m = jutil.get_method_wrapper(method)
                    if m.getName() in ('allowOpenToCheckType',
                                       'setAllowOpenFiles'):
                        self.allowOpenToCheckType_method = m
            if self.allowOpenToCheckType_method is not None:
                object_class = env.find_class('java/lang/Object')
                jexception = jutil.get_env().exception_occurred()
                if jexception is not None:
                    raise jutil.JavaException(jexception)

                boolean_value = jutil.make_instance('java/lang/Boolean',
                                                    '(Z)V', allow)
                args = jutil.get_env().make_object_array(1, object_class)
                jexception = jutil.get_env().exception_occurred()
                if jexception is not None:
                    raise jutil.JavaException(jexception)
                jutil.get_env().set_object_array_element(
                    args, 0, boolean_value)
                jexception = jutil.get_env().exception_occurred()
                if jexception is not None:
                    raise jutil.JavaException(jexception)
                self.allowOpenToCheckType_method.invoke(self.o, args)
Пример #6
0
        def allowOpenToCheckType(self, allow):
            '''Allow the "isThisType" function to open files

            For the cluster, you want to tell potential file formats
            not to open the image file to test if it's their format.
            '''
            if not hasattr(self, "allowOpenToCheckType_method"):
                self.allowOpenToCheckType_method = None
                class_wrapper = jutil.get_class_wrapper(self.o)
                methods = class_wrapper.getMethods()
                for method in jutil.get_env().get_object_array_elements(methods):
                    m = jutil.get_method_wrapper(method)
                    if m.getName() in ('allowOpenToCheckType', 'setAllowOpenFiles'):
                        self.allowOpenToCheckType_method = m
            if self.allowOpenToCheckType_method is not None:
                object_class = env.find_class('java/lang/Object')
                jexception = jutil.get_env().exception_occurred()
                if jexception is not None:
                    raise jutil.JavaException(jexception)

                boolean_value = jutil.make_instance('java/lang/Boolean',
                                                    '(Z)V', allow)
                args = jutil.get_env().make_object_array(1, object_class)
                jexception = jutil.get_env().exception_occurred()
                if jexception is not None:
                    raise jutil.JavaException(jexception)
                jutil.get_env().set_object_array_element(args, 0, boolean_value)
                jexception = jutil.get_env().exception_occurred()
                if jexception is not None:
                    raise jutil.JavaException(jexception)
                self.allowOpenToCheckType_method.invoke(self.o, args)