public virtual char RemoveNext()
            {
                if (id_removeNext == IntPtr.Zero)
                {
                    id_removeNext = JNIEnv.GetMethodID(class_ref, "removeNext", "()C");
                }

                if (GetType() == ThresholdType)
                {
                    return(JNIEnv.CallCharMethod(Handle, id_removeNext));
                }
                else
                {
                    return(JNIEnv.CallNonvirtualCharMethod(Handle, ThresholdClass, JNIEnv.GetMethodID(ThresholdClass, "removeNext", "()C")));
                }
            }
コード例 #2
0
 private static object PrimJ2C(JniLocalHandle obj, JNIEnv env, Type type)
 {
     if (type == typeof(bool))
     {
         return(env.CallBooleanMethod(obj, boolValue));
     }
     if (type == typeof(char))
     {
         return(env.CallCharMethod(obj, charValue));
     }
     if (type == typeof(byte))
     {
         return(env.CallByteMethod(obj, byteValue));
     }
     if (type == typeof(short))
     {
         return(env.CallShortMethod(obj, shortValue));
     }
     if (type == typeof(int))
     {
         return(env.CallIntMethod(obj, intValue));
     }
     if (type == typeof(long))
     {
         return(env.CallLongMethod(obj, longValue));
     }
     if (type == typeof(double))
     {
         return(env.CallDoubleMethod(obj, doubleValue));
     }
     if (type == typeof(float))
     {
         return(env.CallFloatMethod(obj, floatValue));
     }
     throw new InvalidProgramException("Unnknown primitive type" + type);
 }
コード例 #3
0
        public T CallMethod <T>(string methodName, string sig, List <object> param)
        {
            IntPtr methodId = env.GetMethodId(javaClass, methodName, sig);

            try
            {
                if (typeof(T) == typeof(byte))
                {
                    // Call the byte method
                    byte res = env.CallByteMethod(javaObject, methodId, ParseParameters(sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(bool))
                {
                    // Call the boolean method
                    bool res = env.CallBooleanMethod(javaObject, methodId, ParseParameters(sig, param));
                    return((T)(object)res);
                }
                if (typeof(T) == typeof(char))
                {
                    // Call the char method
                    char res = env.CallCharMethod(javaObject, methodId, ParseParameters(sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(short))
                {
                    // Call the short method
                    short res = env.CallShortMethod(javaObject, methodId, ParseParameters(sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(int))
                {
                    // Call the int method
                    int res = env.CallIntMethod(javaObject, methodId, ParseParameters(sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(long))
                {
                    // Call the long method
                    long res = env.CallLongMethod(javaObject, methodId, ParseParameters(sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(float))
                {
                    // Call the float method
                    float res = env.CallFloatMethod(javaObject, methodId, ParseParameters(sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(double))
                {
                    // Call the double method
                    double res = env.CallDoubleMethod(javaObject, methodId, ParseParameters(sig, param));
                    return((T)(object)res);  // need to fix this
                }
                else if (typeof(T) == typeof(string))
                {
                    // Call the string method
                    IntPtr jstr = env.CallObjectMethod(javaObject, methodId, ParseParameters(sig, param));

                    string res = env.JStringToString(jstr);
                    env.DeleteLocalRef(jstr);
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(byte[]))
                {
                    // Call the string method
                    IntPtr jstr = env.CallStaticObjectMethod(javaObject, methodId, ParseParameters(sig, param));
                    if (jstr.ToInt32() == 0)
                    {
                        return(default(T));
                    }
                    byte[] res = env.JStringToByte(jstr);
                    env.DeleteLocalRef(jstr);
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(object))
                {
                    // Call the object method and deal with whatever comes back in the call code
                    IntPtr res = env.CallObjectMethod(javaObject, methodId, ParseParameters(sig, param));
                    return((T)(object)res);
                }
                return(default(T));
            }
            catch
            {
                throw new Exception(env.CatchJavaException());
            }
        }
コード例 #4
0
        /// <summary>
        /// Java object method callers
        /// </summary>
        /// <typeparam name="T">expect return type</typeparam>
        /// <param name="javaClass">Java class pointer</param>
        /// <param name="javaObject">Java Object pointer</param>
        /// <param name="methodName">Name of the method to call</param>
        /// <param name="sig">Method's JNI signature</param>
        /// <param name="param">Paramters of the method call</param>
        /// <returns></returns>
        public T CallMethod <T>(IntPtr javaClass, IntPtr javaObject, string methodName, string sig, params object[] param)
        {
            IntPtr methodId = env.GetMethodID(javaClass, methodName, sig);

            try {
                if (typeof(T) == typeof(byte))
                {
                    // Call the byte method
                    byte res = env.CallByteMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(bool))
                {
                    // Call the boolean method
                    bool res = env.CallBooleanMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    return((T)(object)res);
                }
                if (typeof(T) == typeof(char))
                {
                    // Call the char method
                    char res = env.CallCharMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(short))
                {
                    // Call the short method
                    short res = env.CallShortMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(int))
                {
                    // Call the int method
                    int res = env.CallIntMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(long))
                {
                    // Call the long method
                    long res = env.CallLongMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(float))
                {
                    // Call the float method
                    float res = env.CallFloatMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(double))
                {
                    // Call the double method
                    double res = env.CallDoubleMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    return((T)(object)res); // need to fix this
                }
                else if (typeof(T) == typeof(string))
                {
                    // Call the string method
                    IntPtr jstr = env.CallObjectMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));

                    string res = env.JStringToString(jstr);
                    env.DeleteLocalRef(jstr);
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(byte[]))
                {
                    // Call the byte method
                    IntPtr jobj = env.CallStaticObjectMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    if (jobj == IntPtr.Zero)
                    {
                        return(default(T));
                    }
                    byte[] res = env.JStringToByte(jobj);
                    env.DeleteLocalRef(jobj);
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(string[]))
                {
                    // Call the string array method
                    IntPtr jobj = env.CallObjectMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    if (jobj == IntPtr.Zero)
                    {
                        return(default(T));
                    }

                    IntPtr[] objArray = env.GetObjectArray(jobj);
                    string[] res      = new string[objArray.Length];

                    for (int i = 0; i < objArray.Length; i++)
                    {
                        res[i] = env.JStringToString(objArray[i]);
                    }

                    env.DeleteLocalRef(jobj);
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(int[]))
                {
                    // Call the int array method
                    IntPtr jobj = env.CallObjectMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    if (jobj == IntPtr.Zero)
                    {
                        return(default(T));
                    }
                    int[] res = env.GetIntArray(jobj);
                    env.DeleteLocalRef(jobj);
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(IntPtr))
                {
                    // Call the object method and deal with whatever comes back in the call code
                    IntPtr res = env.CallObjectMethod(javaObject, methodId, ParseParameters(javaClass, sig, param));
                    return((T)(object)res);
                }
                return(default(T));
            } catch {
                throw new Exception(env.CatchJavaException());
            }
        }