Example #1
0
 def __guessMethod(self, methods, args):
     for method in methods:
         paramTypes = java.analyseParamTypes(self.__getParamType(method))
         if len(paramTypes) != len(args):
             continue
         ok = True
         for i in range(len(paramTypes)):
             pType = type(args[i])
             jType = paramTypes[i]
             if (
                 (pType == types.BooleanType and jType == "bool")
                 or (pType == types.DictType and jType == "dict")
                 or (pType == types.FloatType and jType == "float")
                 or (pType == types.IntType and jType == "int")
                 or (pType == types.IntType and jType == "long")
                 or (pType == types.ListType and jType == "list")
                 or (pType == types.LongType and jType == "long")
                 or (pType == types.StringType and jType == "string")
                 or (pType == types.TupleType and jType == "list")
                 or (pType == types.UnicodeType and jType == "string")
                 or (pType == _model.Object and jType == args[i]._metaType)
                 or (pType == _model.Binary and jType == "byte")
             ):
                 continue
             elif pType == types.NoneType:
                 continue
             else:
                 ok = False
                 break
         if ok:
             return method
     return None
Example #2
0
 def __guessMethod(self, methods, args):
     for method in methods:
         paramTypes = java.analyseParamTypes(self.__getParamType(method))
         if len(paramTypes) != len(args):
             continue
         ok = True
         for i in range(len(paramTypes)):
             pType = type(args[i])
             jType = paramTypes[i]
             if \
                 (pType == types.BooleanType and jType == 'bool') \
                 or (pType == types.DictType and jType == 'dict') \
                 or (pType == types.FloatType and jType == 'float') \
                 or (pType == types.IntType and jType == 'int') \
                 or (pType == types.IntType and jType == 'long') \
                 or (pType == types.ListType and jType == 'list') \
                 or (pType == types.LongType and jType == 'long') \
                 or (pType == types.StringType and jType == 'string') \
                 or (pType == types.TupleType and jType == 'list') \
                 or (pType == types.UnicodeType and jType == 'string') \
                 or (pType == _model.Object and jType == args[i]._metaType) \
                 or (pType == _model.Binary and jType == 'byte') :
                 continue
             elif pType == types.NoneType:
                 continue
             else:
                 ok = False
                 break
         if ok:
             return method
     return None
Example #3
0
    def invoke(self, name, args):
        if not name in self.classInfo.methodMap:
            raise KeyError('interface ' + self.classInfo.thisClass +
                           ' has no method name ' + str(name))
        methods = self.classInfo.methodMap[name]
        if len(methods) > 1:
            method = self.__guessMethod(methods, args)
            if method == None:
                errorStr = 'can not find match method : ' + \
                        self.classInfo.thisClass + '.' + name + '(' + \
                        ', '.join([type(arg) for arg in args]) + \
                        ') maybe : '
                for method in methods:
                    errorStr += self.classInfo.thisClass + '.' + name + '(' + \
                            ', '.join(java.analyseParamTypes(self.__getParamType(method))) + \
                            ')'
                raise KeyError(errorStr)
        else:
            method = methods[0]

        paramType = self.__getParamType(method)

        attachments = self.attachments.copy()
        if name in self.methodConfig:
            attachments.update(self.methodConfig[name])
        #print attachments
        #print name, paramType, '(' + ', '.join([str(arg) for arg in args]) + ')', self.attachments
        invocation = protocol.RpcInvocation(name, paramType, args, attachments)
        return self.client.invoke(invocation)
Example #4
0
    def invoke(self, name, args):
        if not name in self.classInfo.methodMap:
            raise KeyError("interface " + self.classInfo.thisClass + " has no method name " + str(name))
        methods = self.classInfo.methodMap[name]
        if len(methods) > 1:
            method = self.__guessMethod(methods, args)
            if method == None:
                errorStr = (
                    "can not find match method : "
                    + self.classInfo.thisClass
                    + "."
                    + name
                    + "("
                    + ", ".join([type(arg) for arg in args])
                    + ") maybe : "
                )
                for method in methods:
                    errorStr += (
                        self.classInfo.thisClass
                        + "."
                        + name
                        + "("
                        + ", ".join(java.analyseParamTypes(self.__getParamType(method)))
                        + ")"
                    )
                raise KeyError(errorStr)
        else:
            method = methods[0]

        paramType = self.__getParamType(method)

        attachments = self.attachments.copy()
        if name in self.methodConfig:
            attachments.update(self.methodConfig[name])
        # print attachments
        # print name, paramType, '(' + ', '.join([str(arg) for arg in args]) + ')', self.attachments
        invocation = protocol.RpcInvocation(name, paramType, args, attachments)
        return self.client.invoke(invocation)