Exemplo n.º 1
0
def _JClassNew(arg, loader=None, initialize=True):
    params = None
    if isinstance(arg, str):
        if arg.endswith(">"):
            i = arg.find("<")
            params = arg[i + 1:-1]
            arg = arg[:i]
            if params:
                params = params.split(',')
            else:
                params = []
            # FIXME we can check the geneic parameters better.

    if loader and isinstance(arg, str):
        arg = _java_lang_Class.forName(arg, initialize, loader)

    if isinstance(arg, _jpype.PyJPClass):
        javaClass = arg
    else:
        javaClass = _jpype.PyJPClass(arg)

    if javaClass is None:
        raise _java_lang_RuntimeException("Java class '%s' not found" % name)

    # Lookup the class name
    name = javaClass.getCanonicalName()

    # See if we have an existing class in the cache
    if name in _JCLASSES:
        cls = _JCLASSES[name]
    else:
        cls = _JClassFactory(name, javaClass)

    if params is not None:
        acceptParams = len(cls.class_.getTypeParameters())
        if acceptParams == 0:
            raise TypeError("Java class '%s' does not take parameters" %
                            (cls.__name__))
        if len(params) > 0 and len(params) != len(
                cls.class_.getTypeParameters()):
            raise TypeError("Java generic class '%s' length mismatch" %
                            (cls.__name__))
    return cls
Exemplo n.º 2
0
def _JClassNew(arg, loader=None, initialize=True):
    if loader and isinstance(arg, str):
        arg = _java_lang_Class.forName(arg, initialize, loader)

    if isinstance(arg, _jpype.PyJPClass):
        javaClass = arg
    else:
        javaClass = _jpype.PyJPClass(arg)

    if javaClass is None:
        raise _java_lang_RuntimeException("Java class '%s' not found" % name)

    # Lookup the class name
    name = javaClass.getCanonicalName()

    # See if we have an existing class in the cache
    if name in _JCLASSES:
        return _JCLASSES[name]
    return _JClassFactory(name, javaClass)
Exemplo n.º 3
0
def _JPrimitiveLoad(cls, boxedType):
    type.__setattr__(cls, '__javaclass__', _jpype.PyJPClass(cls.__name__))
    type.__setattr__(cls, '_java_boxed_class', boxedType)
Exemplo n.º 4
0
def _initialize():
    type.__setattr__(JObject, '__javaclass__',
                     _jpype.PyJPClass('java.lang.Object'))
Exemplo n.º 5
0
 def jinit():
     type.__setattr__(res, '__javaclass__', _jpype.PyJPClass(jclass))
Exemplo n.º 6
0
 def _load(self, boxed):
     type.__setattr__(self, '__javaclass__',
                      _jpype.PyJPClass(self.__name__))
     type.__setattr__(self, '_java_boxed_class', boxed)
Exemplo n.º 7
0
def runNoMethodCode(path):
    _jpype.startup(path, tuple(), False, False)
    cls = _jpype.PyJPClass("java.lang.String")
    methods = cls.getClassMethods()
    methods[0].__code__  # RuntimeError