diff --git a/docs/ReleaseNotes.html b/docs/ReleaseNotes.html index 2ee23e2..ff65995 100644 --- a/docs/ReleaseNotes.html +++ b/docs/ReleaseNotes.html @@ -9,6 +9,18 @@
  • Build process now notifies developer if version property missing
  • +
  • + API Changes + +
  • Tracked Changes

    @@ -18,11 +30,31 @@ 1550604 - Build process died with confusing error if version not set in properties file + Build process died with confusing error if version not set in properties file(pre1) SF1511033 - Fix array index out of bounds problem due to coding error + Fix array index out of bounds problem due to coding error (pre1) + + + 1570270 + ~Event method in EventProxy may unhook java thread from VM. + Can get JNI error because unhooking listner detatched Java VM thread (pre1) + + + 1538011 + toString() non compliant with java standards. The toString() method + converted the underlying data to a string and it shouldn't. This caused + a rethinking of all toXXX() methods other than toDispatch(). Most of the + toXXX() methods have now been deprecated and should be replaced with getXXX() methods. + (pre1) + + + 1478162 + Variant does not warn user if methods called after released. + All putXXX() and getXXX() methods now check to see if they've been released + prior to calling the JNI code. toXXX() methods are deprecated but protected + in the same way.(pre1)   @@ -36,7 +68,7 @@ Support command line parameter dll location specification. Applets and other tools can now specificy the dll location that is fed to a System.load() rather than System.loadLibrary for the - situation where the app can't write the dll to a library path directory. + situation where the app can't write the dll to a library path directory.(pre1)   @@ -49,7 +81,7 @@ 1550628 Moved all LoadLibrary requests into JacobObject. Classes not subclassed off of JacobObject make calls to a static method on JacobObject to make sure - DLL is loaded + DLL is loaded(pre1) diff --git a/jni/EventProxy.cpp b/jni/EventProxy.cpp index d31a500..c49bd10 100644 --- a/jni/EventProxy.cpp +++ b/jni/EventProxy.cpp @@ -33,15 +33,14 @@ EventProxy::EventProxy(JNIEnv *env, eventIID(eid), MethNum(mNum), MethName(mName), MethID(mID) { - // don't really need the variant object but we keep a reference - // anyway - javaSinkObj = env->NewGlobalRef(aSinkObj); - if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();} + // keep a pointer to the sink + javaSinkObj = env->NewGlobalRef(aSinkObj); + if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();} // we need this to attach to the event invocation thread - env->GetJavaVM(&jvm); - if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();} - AddRef(); + env->GetJavaVM(&jvm); + if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();} + AddRef(); Connect(env); } @@ -60,24 +59,36 @@ EventProxy::~EventProxy() { JNIEnv *env; Disconnect(); - // attach to the current running thread - #ifdef JNI_VERSION_1_2 - printf("using version 1.2 API\n"); - jvm->AttachCurrentThread((void **)&env, jvm); - #else - printf("not using version 1.2 API\n"); - jvm->AttachCurrentThread((void**)&env, NULL); - #endif + jint vmConnectionStatus = JNI_EVERSION ; + + // attach to the current running thread -- JDK 1.4 jni.h has two param cover for 3 param call + vmConnectionStatus = jvm->GetEnv((void **)&env, JNI_VERSION_1_2); + if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();} + if (vmConnectionStatus == JNI_EDETACHED){ + //printf("Unhook: Attaching to current thread using JNI Version 1.2 (%d)\n",vmConnectionStatus); + jvm->AttachCurrentThread((void **)&env, jvm); + if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();} + } else { + // should really look for JNI_OK versus an error + // started method hooked so no need to attach again + //printf("Unhook: No need to attach because already attached %d\n",vmConnectionStatus); + } - env->DeleteGlobalRef(javaSinkObj); - if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();} - if (MethNum) { - delete [] MethName; - delete [] MethID; - } + env->DeleteGlobalRef(javaSinkObj); + if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();} + if (MethNum) { + delete [] MethName; + delete [] MethID; + } // detach from thread - jvm->DetachCurrentThread(); + if (vmConnectionStatus == JNI_EDETACHED){ + jvm->DetachCurrentThread(); + //printf("Unhook: Detached\n"); + } else { + //printf("Unhook: No need to detatch because attached prior to method\n"); + } + //fflush(stdout); } void EventProxy::Disconnect() { @@ -113,12 +124,9 @@ STDMETHODIMP EventProxy::Invoke(DISPID dispID, REFIID riid, LCID lcid, unsigned short wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr) { - //Visual C++ 6.0 recognized this as an unused variable - //HRESULT hr; - - const char *eventMethodName = NULL; //Sourceforge report 1394001 - JNIEnv *env = NULL; - jobject retObj; + const char *eventMethodName = NULL; //Sourceforge report 1394001 + JNIEnv *env = NULL; + jobject retObj; // map dispID to jmethodID for(int i=0;iAttachCurrentThread((void **)&env, jvm); - #else - jvm->AttachCurrentThread((void**)&env, NULL); - #endif + //printf("Invoke: Attaching to current thread using JNI Version 1.2\n"); + jvm->AttachCurrentThread((void **)&env, jvm); + if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();} if (!eventMethodName) { - ThrowComFail(env, "Event method received was not defined as part of callback interface", -1); // user did not implement this method + printf("Invoke: didn't find method name\n"); + ThrowComFail(env, "Event method received was not defined as part of callback interface", -1); + + // should we detatch before returning?? The old code didn't but I don't see why not. + // jvm->DetachCurrentThread(); return S_OK; } - // find the class of the InvocationHandler jclass javaSinkClass = env->GetObjectClass(javaSinkObj); - if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();} - jmethodID invokeMethod; - invokeMethod = env->GetMethodID(javaSinkClass, "invoke", "(Ljava/lang/String;[Lcom/jacob/com/Variant;)Lcom/jacob/com/Variant;"); + if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();} + //printf("Invoke: Got sink class\n"); + jmethodID invokeMethod; + invokeMethod = env->GetMethodID(javaSinkClass, "invoke", "(Ljava/lang/String;[Lcom/jacob/com/Variant;)Lcom/jacob/com/Variant;"); if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();} jstring eventMethodNameAsString = env->NewStringUTF(eventMethodName); + //printf("Invoke: Got method name\n"); // now do what we need for the variant - jmethodID getVariantMethod = env->GetMethodID(javaSinkClass, "getVariant", "()Lcom/jacob/com/Variant;"); + jmethodID getVariantMethod = env->GetMethodID(javaSinkClass, "getVariant", "()Lcom/jacob/com/Variant;"); if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();} + //printf("Invoke: Found way too getVariant\n"); jobject aVariantObj = env->CallObjectMethod(javaSinkObj, getVariantMethod); if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();} + //printf("Invoke: Made Variant\n"); jclass variantClass = env->GetObjectClass(aVariantObj); if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();} @@ -166,6 +180,7 @@ STDMETHODIMP EventProxy::Invoke(DISPID dispID, REFIID riid, // make an array of them jobjectArray varr = env->NewObjectArray(numVariantParams, variantClass, 0); if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();} + //printf("Invoke: Created Array\n"); int i,j; for(i=numVariantParams-1,j=0;i>=0;i--,j++) { @@ -181,14 +196,16 @@ STDMETHODIMP EventProxy::Invoke(DISPID dispID, REFIID riid, env->DeleteLocalRef(arg); if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();} } - // Set up the return value - jobject ret; + //printf("Invoke: Filled Array\n"); + // Set up the return value + jobject ret; - ret = env->CallObjectMethod(javaSinkObj, invokeMethod, - eventMethodNameAsString, varr); - if (!env->ExceptionOccurred() && ret != NULL) { - VariantCopy(pVarResult, extractVariant(env,ret)); - } + ret = env->CallObjectMethod(javaSinkObj, invokeMethod, + eventMethodNameAsString, varr); + //printf("Invoke: Invoked callback\n"); + if (!env->ExceptionOccurred() && ret != NULL) { + VariantCopy(pVarResult, extractVariant(env,ret)); + } if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();} // don't need the first variant we created to get the class env->DeleteLocalRef(aVariantObj); @@ -197,17 +214,19 @@ STDMETHODIMP EventProxy::Invoke(DISPID dispID, REFIID riid, // Begin code from Jiffie team that copies parameters back from java to COM for(i=numVariantParams-1,j=0;i>=0;i--,j++) { - jobject arg = env->GetObjectArrayElement(varr, j); - VARIANT *java = extractVariant(env, arg); - VARIANT *com = &pDispParams->rgvarg[i]; - convertJavaVariant(java, com); - zeroVariant(env, arg); - env->DeleteLocalRef(arg); - } - // End code from Jiffie team that copies parameters back from java to COM - // detach from thread - jvm->DetachCurrentThread(); - return S_OK; + jobject arg = env->GetObjectArrayElement(varr, j); + VARIANT *java = extractVariant(env, arg); + VARIANT *com = &pDispParams->rgvarg[i]; + convertJavaVariant(java, com); + zeroVariant(env, arg); + env->DeleteLocalRef(arg); + } + // End code from Jiffie team that copies parameters back from java to COM + // detach from thread + //printf("Invoke: Detatching\n"); + jvm->DetachCurrentThread(); + //fflush(stdout); + return S_OK; } return E_NOINTERFACE; } diff --git a/jni/Variant.cpp b/jni/Variant.cpp index 76c2dfe..90c48b1 100644 --- a/jni/Variant.cpp +++ b/jni/Variant.cpp @@ -155,61 +155,6 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_SerializationReadFromBytes } } -/** - * Converts the data to a Int object and then returns it as a Dispatch - */ - -JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_toInt - (JNIEnv *env, jobject _this) -{ - VARIANT *v = extractVariant(env, _this); - if (v) { - HRESULT hr; - if (FAILED(hr = VariantChangeType(v, v, 0, VT_I4))) { - ThrowComFail(env, "VariantChangeType failed", hr); - return NULL; - } - return (jint)V_I4(v); - } - return NULL; -} - -/** - * Converts the data to a Date object and then returns it as a Dispatch - */ -JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_toDate - (JNIEnv *env, jobject _this) -{ - VARIANT *v = extractVariant(env, _this); - if (v) { - HRESULT hr; - if (FAILED(hr = VariantChangeType(v, v, 0, VT_DATE))) { - ThrowComFail(env, "VariantChangeType failed", hr); - return NULL; - } - return (jdouble)V_DATE(v); - } - return NULL; -} - -/** - * Converts the data to a Boolean object and then returns it as a Dispatch - */ -JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_toBoolean - (JNIEnv *env, jobject _this) -{ - VARIANT *v = extractVariant(env, _this); - if (v) { - HRESULT hr; - if (FAILED(hr = VariantChangeType(v, v, 0, VT_BOOL))) { - ThrowComFail(env, "VariantChangeType failed", hr); - return NULL; - } - return (jboolean)V_BOOL(v); - } - return NULL; -} - /** * Converts the data to a Enum Variant object and then returns it as a Dispatch */ @@ -243,7 +188,7 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toEnumVariant return NULL; } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putNull +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantNull (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -259,44 +204,8 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_cloneIndirect return NULL; } -/** - * Converts the data to a Double object and then returns it as a Dispatch - */ -JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_toDouble - (JNIEnv *env, jobject _this) -{ - VARIANT *v = extractVariant(env, _this); - if (v) { - HRESULT hr; - if (FAILED(hr = VariantChangeType(v, v, 0, VT_R8))) { - ThrowComFail(env, "VariantChangeType failed", hr); - return NULL; - } - return (jdouble)V_R8(v); - } - return NULL; -} -/** - * Converts the data to a Long object and then returns it as a Dispatch - */ -JNIEXPORT jlong JNICALL Java_com_jacob_com_Variant_toCurrency - (JNIEnv *env, jobject _this) -{ - VARIANT *v = extractVariant(env, _this); - if (v) { - HRESULT hr; - if (FAILED(hr = VariantChangeType(v, v, 0, VT_CY))) { - ThrowComFail(env, "VariantChangeType failed", hr); - return NULL; - } - CY cy = V_CY(v); - return (jlong)cy.int64; - } - return NULL; -} - -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putShortRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantShortRef (JNIEnv *env, jobject _this, jshort s) { VARIANT *v = extractVariant(env, _this); @@ -309,7 +218,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putShortRef } } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putIntRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantIntRef (JNIEnv *env, jobject _this, jint s) { VARIANT *v = extractVariant(env, _this); @@ -322,7 +231,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putIntRef } } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putDoubleRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDoubleRef (JNIEnv *env, jobject _this, jdouble s) { VARIANT *v = extractVariant(env, _this); @@ -334,7 +243,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putDoubleRef } } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putDateRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDateRef (JNIEnv *env, jobject _this, jdouble s) { VARIANT *v = extractVariant(env, _this); @@ -348,7 +257,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putDateRef } // SF 1065533 added unicode support -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putStringRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantStringRef (JNIEnv *env, jobject _this, jstring s) { VARIANT *v = extractVariant(env, _this); @@ -371,7 +280,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putStringRef env->ReleaseStringChars(s,cStr); } } -JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getShortRef +JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getVariantShortRef (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -384,7 +293,7 @@ JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getShortRef return NULL; } -JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getIntRef +JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantIntRef (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -397,7 +306,7 @@ JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getIntRef return NULL; } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putShort +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantShort (JNIEnv *env, jobject _this, jshort s) { VARIANT *v = extractVariant(env, _this); @@ -408,7 +317,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putShort } } -JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getShort +JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getVariantShort (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -421,7 +330,7 @@ JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getShort return NULL; } -JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getDoubleRef +JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getVariantDoubleRef (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -434,7 +343,7 @@ JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getDoubleRef return NULL; } -JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getDateRef +JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getVariantDateRef (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -447,7 +356,7 @@ JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getDateRef return NULL; } -JNIEXPORT jstring JNICALL Java_com_jacob_com_Variant_getStringRef +JNIEXPORT jstring JNICALL Java_com_jacob_com_Variant_getVariantStringRef (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -462,6 +371,9 @@ JNIEXPORT jstring JNICALL Java_com_jacob_com_Variant_getStringRef return NULL; } +/** + * cover for underlying C VariantClear function + */ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_VariantClear (JNIEnv *env, jobject _this) { @@ -474,7 +386,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_VariantClear /** * Converts the data to a Dispatch object and then returns it as a Dispatch */ -JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toDispatchObject +JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toVariantDispatch (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -503,42 +415,12 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_clone return NULL; } -/** - * Converts the data to a String object and then returns it as a Dispatch - */ -JNIEXPORT jstring JNICALL Java_com_jacob_com_Variant_toString - (JNIEnv *env, jobject _this) -{ - VARIANT *v = extractVariant(env, _this); - if (v) { - switch (V_VT(v)) - { - case VT_EMPTY: - case VT_NULL: - case VT_ERROR: - // causes VariantChangeType to bomb - return env->NewStringUTF("null"); - } - HRESULT hr; - // this actually changes the type of the variant to a String! - if (FAILED(hr = VariantChangeType(v, v, 0, VT_BSTR))) { - // cannot change type to a string - return env->NewStringUTF("???"); - } - // create a returnable string from the converted variant - BSTR bs = V_BSTR(v); - jstring js = env->NewString(bs, SysStringLen(bs)); - return js; - } - return NULL; -} - /** * Returns the value of this int as a Boolea if it is of that type. * Otherwise it will return null (no conversion done) */ -JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getInt +JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantInt (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -556,7 +438,7 @@ JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getInt * Otherwise it will return null (no conversion done) */ -JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getDate +JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getVariantDate (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -569,7 +451,7 @@ JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getDate return NULL; } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putInt +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantInt (JNIEnv *env, jobject _this, jint i) { VARIANT *v = extractVariant(env, _this); @@ -580,7 +462,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putInt } } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putDate +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDate (JNIEnv *env, jobject _this, jdouble date) { VARIANT *v = extractVariant(env, _this); @@ -591,29 +473,11 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putDate } } -/** - * Converts the data to a Byte object and then returns it as a Dispatch - */ -JNIEXPORT jbyte JNICALL Java_com_jacob_com_Variant_toByte - (JNIEnv *env, jobject _this) -{ - VARIANT *v = extractVariant(env, _this); - if (v) { - HRESULT hr; - if (FAILED(hr = VariantChangeType(v, v, 0, VT_UI1))) { - ThrowComFail(env, "VariantChangeType failed", hr); - return NULL; - } - return (jbyte)V_UI1(v); - } - return NULL; -} - /** * Returns the value of this Variant as a Boolea if it is of that type. * Otherwise it will return null (no conversion done) */ -JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_getBoolean +JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_getVariantBoolean (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -630,7 +494,7 @@ JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_getBoolean * Returns the value of this Variant as a Byte if it is of that type. * Otherwise it will return null (no conversion done) */ -JNIEXPORT jbyte JNICALL Java_com_jacob_com_Variant_getByte +JNIEXPORT jbyte JNICALL Java_com_jacob_com_Variant_getVariantByte (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -643,7 +507,7 @@ JNIEXPORT jbyte JNICALL Java_com_jacob_com_Variant_getByte return NULL; } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putBoolean +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantBoolean (JNIEnv *env, jobject _this, jboolean b) { VARIANT *v = extractVariant(env, _this); @@ -652,10 +516,10 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putBoolean V_VT(v) = VT_BOOL; V_BOOL(v) = b == JNI_TRUE ? VARIANT_TRUE : VARIANT_FALSE; } - else ThrowComFail(env, "putBoolean failed", -1); + else ThrowComFail(env, "putVariantBoolean failed", -1); } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putByte +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantByte (JNIEnv *env, jobject _this, jbyte b) { VARIANT *v = extractVariant(env, _this); @@ -664,25 +528,10 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putByte V_VT(v) = VT_UI1; V_UI1(v) = b; } - else ThrowComFail(env, "putByte failed", -1); + else ThrowComFail(env, "putVariantByte failed", -1); } -JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_toError - (JNIEnv *env, jobject _this) -{ - VARIANT *v = extractVariant(env, _this); - if (v) { - HRESULT hr; - if (FAILED(hr = VariantChangeType(v, v, 0, VT_ERROR))) { - ThrowComFail(env, "VariantChangeType failed", hr); - return NULL; - } - return (jint)V_ERROR(v); - } - return NULL; -} - -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putEmpty +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantEmpty (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -695,7 +544,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putEmpty /** * Sets the variant type to dispatch with no value object **/ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putNothing +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantNothing (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -705,7 +554,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putNothing } } -JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getError +JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantError (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -718,7 +567,7 @@ JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getError return NULL; } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putError +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantError (JNIEnv *env, jobject _this, jint i) { VARIANT *v = extractVariant(env, _this); @@ -734,7 +583,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putError * Returns the value of this Variant as a double if it is of that type. * Otherwise it will return null (no conversion done) */ -JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getDouble +JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getVariantDouble (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -747,7 +596,7 @@ JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getDouble return NULL; } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putCurrency +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantCurrency (JNIEnv *env, jobject _this, jlong cur) { VARIANT *v = extractVariant(env, _this); @@ -757,7 +606,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putCurrency pf.int64 = (LONGLONG)cur; V_VT(v) = VT_CY; V_CY(v) = pf; - } else ThrowComFail(env, "putCurrency failed", -1); + } else ThrowComFail(env, "putVariantCurrency failed", -1); } /** @@ -765,7 +614,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putCurrency * There is currently no way to pass NULL into this method * to create something like "NOTHING" from VB * */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putDispatchObject +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDispatch (JNIEnv *env, jobject _this, jobject _that) { VARIANT *v = extractVariant(env, _this); @@ -779,7 +628,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putDispatchObject } else ThrowComFail(env, "putObject failed", -1); } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putDouble +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDouble (JNIEnv *env, jobject _this, jdouble d) { VARIANT *v = extractVariant(env, _this); @@ -794,7 +643,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putDouble * Returns the value of this Variant as a long if it is of that type. * Otherwise it will return null (no conversion done) */ -JNIEXPORT jlong JNICALL Java_com_jacob_com_Variant_getCurrency +JNIEXPORT jlong JNICALL Java_com_jacob_com_Variant_getVariantCurrency (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -812,7 +661,7 @@ JNIEXPORT jlong JNICALL Java_com_jacob_com_Variant_getCurrency } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putFloatRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantFloatRef (JNIEnv *env, jobject _this, jfloat val) { VARIANT *v = extractVariant(env, _this); @@ -825,7 +674,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putFloatRef } } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putCurrencyRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantCurrencyRef (JNIEnv *env, jobject _this, jlong cur) { VARIANT *v = extractVariant(env, _this); @@ -838,7 +687,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putCurrencyRef } } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putErrorRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantErrorRef (JNIEnv *env, jobject _this, jint i) { VARIANT *v = extractVariant(env, _this); @@ -849,7 +698,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putErrorRef } } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putBooleanRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantBooleanRef (JNIEnv *env, jobject _this, jboolean b) { VARIANT *v = extractVariant(env, _this); @@ -862,7 +711,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putBooleanRef } } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putByteRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantByteRef (JNIEnv *env, jobject _this, jbyte b) { VARIANT *v = extractVariant(env, _this); @@ -879,7 +728,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putByteRef * Returns the value of this Variant as a String if it is of that type. * Otherwise it will return null (no conversion done) */ -JNIEXPORT jstring JNICALL Java_com_jacob_com_Variant_getString +JNIEXPORT jstring JNICALL Java_com_jacob_com_Variant_getVariantString (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -894,8 +743,10 @@ JNIEXPORT jstring JNICALL Java_com_jacob_com_Variant_getString return NULL; } -// SF 1065533 added unicode support -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putString +/** + * SF 1065533 added unicode support + * */ +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantString (JNIEnv *env, jobject _this, jstring s) { VARIANT *v = extractVariant(env, _this); @@ -918,7 +769,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putString } } -JNIEXPORT jfloat JNICALL Java_com_jacob_com_Variant_getFloatRef +JNIEXPORT jfloat JNICALL Java_com_jacob_com_Variant_getVariantFloatRef (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -931,7 +782,7 @@ JNIEXPORT jfloat JNICALL Java_com_jacob_com_Variant_getFloatRef return NULL; } -JNIEXPORT jlong JNICALL Java_com_jacob_com_Variant_getCurrencyRef +JNIEXPORT jlong JNICALL Java_com_jacob_com_Variant_getVariantCurrencyRef (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -948,7 +799,7 @@ JNIEXPORT jlong JNICALL Java_com_jacob_com_Variant_getCurrencyRef return NULL; } -JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getErrorRef +JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantErrorRef (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -961,7 +812,7 @@ JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getErrorRef return NULL; } -JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_getBooleanRef +JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_getVariantBooleanRef (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -975,7 +826,7 @@ JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_getBooleanRef } -JNIEXPORT jbyte JNICALL Java_com_jacob_com_Variant_getByteRef +JNIEXPORT jbyte JNICALL Java_com_jacob_com_Variant_getVariantByteRef (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -988,28 +839,10 @@ JNIEXPORT jbyte JNICALL Java_com_jacob_com_Variant_getByteRef return NULL; } -/** - * Converts the data to a Float object and then returns it as a Dispatch - */ -JNIEXPORT jfloat JNICALL Java_com_jacob_com_Variant_toFloat - (JNIEnv *env, jobject _this) -{ - VARIANT *v = extractVariant(env, _this); - if (v) { - HRESULT hr; - if (FAILED(hr = VariantChangeType(v, v, 0, VT_R4))) { - ThrowComFail(env, "VariantChangeType failed", hr); - return NULL; - } - return (jfloat)V_R4(v); - } - return NULL; -} - /** * Converts the data to a Safe Array object and then returns it as a Dispatch */ -JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toSafeArray +JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toVariantSafeArray (JNIEnv *env, jobject _this, jboolean deepCopy) { VARIANT *v = extractVariant(env, _this); @@ -1031,7 +864,7 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toSafeArray return NULL; } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putSafeArrayRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantSafeArrayRef (JNIEnv *env, jobject _this, jobject sa) { SAFEARRAY *psa = extractSA(env, sa); @@ -1054,7 +887,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putSafeArrayRef return; } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putSafeArray +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantSafeArray (JNIEnv *env, jobject _this, jobject sa) { SAFEARRAY *psa = extractSA(env, sa); @@ -1078,7 +911,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putSafeArray /** * sets the type to VT_ERROR and the error message to DISP_E_PARAMNOTFOIUND * */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_noParam +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantNoParam (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -1092,7 +925,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_noParam * Returns the value of this Variant as a Float if it is of that type. * Otherwise it will return null (no conversion done) */ -JNIEXPORT jfloat JNICALL Java_com_jacob_com_Variant_getFloat +JNIEXPORT jfloat JNICALL Java_com_jacob_com_Variant_getVariantFloat (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -1105,7 +938,7 @@ JNIEXPORT jfloat JNICALL Java_com_jacob_com_Variant_getFloat return NULL; } -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putFloat +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantFloat (JNIEnv *env, jobject _this, jfloat val) { VARIANT *v = extractVariant(env, _this); @@ -1119,7 +952,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putFloat /** * changes the type of the underlying variant data * */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_changeType +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_changeVariantType (JNIEnv *env, jobject _this, jshort t) { VARIANT *v = extractVariant(env, _this); @@ -1132,7 +965,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_changeType * returns the variant type if it is set, otherwise * returns null * */ -JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getvt +JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getVariantType (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); @@ -1142,39 +975,14 @@ JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getvt return NULL; } -/** - * Converts the data to a short object and then returns it as a Dispatch - */ -JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_toShort - (JNIEnv *env, jobject _this) -{ - VARIANT *v = extractVariant(env, _this); - if (v) { - HRESULT hr; - if (FAILED(hr = VariantChangeType(v, v, 0, VT_I2))) { - ThrowComFail(env, "VariantChangeType failed", hr); - return NULL; - } - return (jshort)V_I2(v); - } - return NULL; -} - -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putSafeArrayRefHelper - (JNIEnv *env, jobject _this, jint pSA) -{ - VARIANT *v = extractVariant(env, _this); - if (v) { - VariantClear(v); // whatever was there before - } -} +// removed Java_com_jacob_com_Variant_putSafeArrayRefHelper /** * this is a big cover method that returns TRUE if * the variant type is * VT_EMPTY, VT_NULL, VT_ERROR or VT_DISPATCH with no dispatch object * */ -JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_isNull +JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_isVariantConsideredNull (JNIEnv *env, jobject _this) { VARIANT *v = extractVariant(env, _this); diff --git a/jni/Variant.h b/jni/Variant.h index 5626b90..d7d1149 100644 --- a/jni/Variant.h +++ b/jni/Variant.h @@ -25,29 +25,6 @@ #ifdef __cplusplus extern "C" { #endif -/* - * Class: com_jacob_com_Variant - * Method: toInt - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_toInt - (JNIEnv *, jobject); - -/* - * Class: com_jacob_com_Variant - * Method: toDate - * Signature: ()D - */ -JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_toDate - (JNIEnv *, jobject); - -/* - * Class: com_jacob_com_Variant - * Method: toBoolean - * Signature: ()Z - */ -JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_toBoolean - (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant @@ -59,10 +36,10 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toEnumVariant /* * Class: com_jacob_com_Variant - * Method: putNull + * Method: putVariantNull * Signature: ()V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putNull +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantNull (JNIEnv *, jobject); /* @@ -75,106 +52,90 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_cloneIndirect /* * Class: com_jacob_com_Variant - * Method: toDouble - * Signature: ()D - */ -JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_toDouble - (JNIEnv *, jobject); - -/* - * Class: com_jacob_com_Variant - * Method: toCurrency - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_com_jacob_com_Variant_toCurrency - (JNIEnv *, jobject); - -/* - * Class: com_jacob_com_Variant - * Method: putShortRef + * Method: putVariantShortRef * Signature: (S)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putShortRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantShortRef (JNIEnv *, jobject, jshort); /* * Class: com_jacob_com_Variant - * Method: putIntRef + * Method: putVariantIntRef * Signature: (I)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putIntRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantIntRef (JNIEnv *, jobject, jint); /* * Class: com_jacob_com_Variant - * Method: putDoubleRef + * Method: putVariantDoubleRef * Signature: (D)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putDoubleRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDoubleRef (JNIEnv *, jobject, jdouble); /* * Class: com_jacob_com_Variant - * Method: putDateRef + * Method: putVariantDateRef * Signature: (D)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putDateRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDateRef (JNIEnv *, jobject, jdouble); /* * Class: com_jacob_com_Variant - * Method: putStringRef + * Method: putVariantStringRef * Signature: (Ljava/lang/String;)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putStringRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantStringRef (JNIEnv *, jobject, jstring); /* * Class: com_jacob_com_Variant - * Method: getShortRef + * Method: getVariantShortRef * Signature: ()S */ -JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getShortRef +JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getVariantShortRef (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: getIntRef + * Method: getVariantIntRef * Signature: ()I */ -JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getIntRef +JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantIntRef (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: putShort + * Method: putVariantShort * Signature: (S)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putShort +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantShort (JNIEnv *, jobject, jshort); /* * Class: com_jacob_com_Variant - * Method: getShort + * Method: getVariantShort * Signature: ()S */ -JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getShort +JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getVariantShort (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: getDoubleRef + * Method: getVariantDoubleRef * Signature: ()D */ -JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getDoubleRef +JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getVariantDoubleRef (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: getDateRef + * Method: getVariantDateRef * Signature: ()D */ -JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getDateRef +JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getVariantDateRef (JNIEnv *, jobject); /* @@ -182,7 +143,7 @@ JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getDateRef * Method: getStringRef * Signature: ()Ljava/lang/String; */ -JNIEXPORT jstring JNICALL Java_com_jacob_com_Variant_getStringRef +JNIEXPORT jstring JNICALL Java_com_jacob_com_Variant_getVariantStringRef (JNIEnv *, jobject); /* @@ -198,7 +159,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_com_jacob_com_VariantClear * Method: toDispatch * Signature: ()LDispatch; */ -JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toDispatchObject +JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toVariantDispatch (JNIEnv *, jobject); /* @@ -211,194 +172,170 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_clone /* * Class: com_jacob_com_Variant - * Method: toString - * Signature: ()Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_com_jacob_com_Variant_toString - (JNIEnv *, jobject); - -/* - * Class: com_jacob_com_Variant - * Method: getInt + * Method: getVariantInt * Signature: ()I */ -JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getInt +JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantInt (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: getDate + * Method: getVariantDate * Signature: ()D */ -JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getDate +JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getVariantDate (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: putInt + * Method: putVariantInt * Signature: (I)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putInt +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantInt (JNIEnv *, jobject, jint); /* * Class: com_jacob_com_Variant - * Method: putDate + * Method: putVariantDate * Signature: (D)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putDate +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDate (JNIEnv *, jobject, jdouble); /* * Class: com_jacob_com_Variant - * Method: toByte - * Signature: ()B - */ -JNIEXPORT jbyte JNICALL Java_com_jacob_com_Variant_toByte - (JNIEnv *, jobject); - -/* - * Class: com_jacob_com_Variant - * Method: getBoolean + * Method: getVariantBoolean * Signature: ()Z */ -JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_getBoolean +JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_getVariantBoolean (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: getByte + * Method: getVariantByte * Signature: ()B */ -JNIEXPORT jbyte JNICALL Java_com_jacob_com_Variant_getByte +JNIEXPORT jbyte JNICALL Java_com_jacob_com_Variant_getVariantByte (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: putBoolean + * Method: putVariantBoolean * Signature: (Z)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putBoolean +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantBoolean (JNIEnv *, jobject, jboolean); /* * Class: com_jacob_com_Variant - * Method: putByte + * Method: putVariantByte * Signature: (B)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putByte +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantByte (JNIEnv *, jobject, jbyte); /* * Class: com_jacob_com_Variant - * Method: toError - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_toError - (JNIEnv *, jobject); - -/* - * Class: com_jacob_com_Variant - * Method: putEmpty + * Method: putVariantEmpty * Signature: ()V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putEmpty +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantEmpty (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: putEmpty + * Method: putVariantNothing * Signature: ()V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putNothing +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantNothing (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: getError + * Method: getVariantError * Signature: ()I */ -JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getError +JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantError (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: putError + * Method: putVariantError * Signature: (I)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putError +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantError (JNIEnv *, jobject, jint); /* * Class: com_jacob_com_Variant - * Method: getDouble + * Method: getVariantDouble * Signature: ()D */ -JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getDouble +JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getVariantDouble (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: putCurrency + * Method: putVariantCurrency * Signature: (J)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putCurrency +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantCurrency (JNIEnv *, jobject, jlong); /* * Class: com_jacob_com_Variant - * Method: putObject + * Method: putVariantDispatch * Signature: (Ljava/lang/Object;)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putDispatchObject +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDispatch (JNIEnv *, jobject, jobject); /* * Class: com_jacob_com_Variant - * Method: putDouble + * Method: putVariantDouble * Signature: (D)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putDouble +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDouble (JNIEnv *, jobject, jdouble); /* * Class: com_jacob_com_Variant - * Method: getCurrency + * Method: getVariantCurrency * Signature: ()J */ -JNIEXPORT jlong JNICALL Java_com_jacob_com_Variant_getCurrency +JNIEXPORT jlong JNICALL Java_com_jacob_com_Variant_getVariantCurrency (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: putFloatRef + * Method: putVariantFloatRef * Signature: (F)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putFloatRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantFloatRef (JNIEnv *, jobject, jfloat); /* * Class: com_jacob_com_Variant - * Method: putCurrencyRef + * Method: putVariantCurrencyRef * Signature: (J)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putCurrencyRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantCurrencyRef (JNIEnv *, jobject, jlong); /* * Class: com_jacob_com_Variant - * Method: putErrorRef + * Method: putVariantErrorRef * Signature: (I)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putErrorRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantErrorRef (JNIEnv *, jobject, jint); /* * Class: com_jacob_com_Variant - * Method: putBooleanRef + * Method: putVariantBooleanRef * Signature: (Z)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putBooleanRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantBooleanRef (JNIEnv *, jobject, jboolean); /* @@ -411,10 +348,10 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putObjectRef /* * Class: com_jacob_com_Variant - * Method: putByteRef + * Method: putVariantByteRef * Signature: (B)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putByteRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantByteRef (JNIEnv *, jobject, jbyte); /* @@ -422,135 +359,119 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putByteRef * Method: getString * Signature: ()Ljava/lang/String; */ -JNIEXPORT jstring JNICALL Java_com_jacob_com_Variant_getString +JNIEXPORT jstring JNICALL Java_com_jacob_com_Variant_getVariantString (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: putString + * Method: putVariantString * Signature: (Ljava/lang/String;)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putString +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantString (JNIEnv *, jobject, jstring); /* * Class: com_jacob_com_Variant - * Method: getFloatRef + * Method: getVariantFloatRef * Signature: ()F */ -JNIEXPORT jfloat JNICALL Java_com_jacob_com_Variant_getFloatRef +JNIEXPORT jfloat JNICALL Java_com_jacob_com_Variant_getVariantFloatRef (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: getCurrencyRef + * Method: getVariantCurrencyRef * Signature: ()J */ -JNIEXPORT jlong JNICALL Java_com_jacob_com_Variant_getCurrencyRef +JNIEXPORT jlong JNICALL Java_com_jacob_com_Variant_getVariantCurrencyRef (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: getErrorRef + * Method: getVariantErrorRef * Signature: ()I */ -JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getErrorRef +JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantErrorRef (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: getBooleanRef + * Method: getVariantBooleanRef * Signature: ()Z */ -JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_getBooleanRef +JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_getVariantBooleanRef (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: getByteRef + * Method: getVariantByteRef * Signature: ()B */ -JNIEXPORT jbyte JNICALL Java_com_jacob_com_Variant_getByteRef +JNIEXPORT jbyte JNICALL Java_com_jacob_com_Variant_getVariantByteRef (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: toFloat - * Signature: ()F - */ -JNIEXPORT jfloat JNICALL Java_com_jacob_com_Variant_toFloat - (JNIEnv *, jobject); - -/* - * Class: com_jacob_com_Variant - * Method: toSafeArray + * Method: toVariantSafeArray * Signature: (Z)Lcom/jacob/com/SafeArray; */ -JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toSafeArray +JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toVariantSafeArray (JNIEnv *, jobject, jboolean); /* * Class: com_jacob_com_Variant - * Method: putSafeArrayRef + * Method: putVariantSafeArrayRef * Signature: (LSafeArray;)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putSafeArrayRef +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantSafeArrayRef (JNIEnv *, jobject, jobject); /* * Class: com_jacob_com_Variant - * Method: putSafeArray + * Method: putVariantSafeArray * Signature: (LSafeArray;)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putSafeArray +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantSafeArray (JNIEnv *, jobject, jobject); /* * Class: com_jacob_com_Variant - * Method: noParam + * Method: putVariantNoParam * Signature: ()V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_noParam +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantNoParam (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: getFloat + * Method: getVariantFloat * Signature: ()F */ -JNIEXPORT jfloat JNICALL Java_com_jacob_com_Variant_getFloat +JNIEXPORT jfloat JNICALL Java_com_jacob_com_Variant_getVariantFloat (JNIEnv *, jobject); /* * Class: com_jacob_com_Variant - * Method: putFloat + * Method: putVariantFloat * Signature: (F)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putFloat +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantFloat (JNIEnv *, jobject, jfloat); /* * Class: com_jacob_com_Variant - * Method: changeType + * Method: changeVariantType * Signature: (S)V */ -JNIEXPORT void JNICALL Java_com_jacob_com_Variant_changeType +JNIEXPORT void JNICALL Java_com_jacob_com_Variant_changeVariantType (JNIEnv *, jobject, jshort); /* * Class: com_jacob_com_Variant - * Method: getvt + * Method: getVariantType * Signature: ()S */ -JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getvt - (JNIEnv *, jobject); - -/* - * Class: com_jacob_com_Variant - * Method: toShort - * Signature: ()S - */ -JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_toShort +JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getVariantType (JNIEnv *, jobject); /* @@ -577,10 +498,10 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_SerializationReadFromBytes /* * Class: com_jacob_com_Variant - * Method: isNull + * Method: isVariantConsideredNull * Signature: ()Z */ -JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_isNull +JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_isVariantConsideredNull (JNIEnv *, jobject); /* diff --git a/samples/com/jacob/samples/access/Access.java b/samples/com/jacob/samples/access/Access.java index 25069dc..827fc6f 100644 --- a/samples/com/jacob/samples/access/Access.java +++ b/samples/com/jacob/samples/access/Access.java @@ -23,7 +23,8 @@ import com.jacob.com.*; import com.jacob.activeX.*; /** - * this + * May need to run with some command line options. If so, then try these + * -Djava.library.path=d:/jacob/release -Dcom.jacob.autogc=false -Dcom.jacob.debug=true -Xcheck:jni * @author joe * */ @@ -124,7 +125,7 @@ class Access public static String[] getColumns(Dispatch recset) { Dispatch flds = Dispatch.get(recset, "Fields").toDispatch(); - int n_flds = Dispatch.get(flds, "Count").toInt(); + int n_flds = Dispatch.get(flds, "Count").getInt(); String[] s = new String[n_flds]; Variant vi = new Variant(); for (int i=0;i * This method added 12/2005 for possible use by jacobgen instead of its conversion code - * @return java.util.Date - * (after possible conversion) + *

    + * This does not convert the data + * @deprecated callers should use getDate() + * @return java.util.Date version of this variant if it is a date, otherwise null + * */ public Date toJavaDate(){ - double windowsDate = toDate(); - if (windowsDate == 0){ - return null; - } else { - return DateUtilities.convertWindowsTimeToDate(getDate()); - } + changeType(Variant.VariantDate); + return getJavaDate(); } /** + * @deprecated should be replaced by changeType() followed by getBoolean() * @return the value of this variant as boolean (after possible conversion) */ - public native boolean toBoolean(); + public boolean toBoolean(){ + changeType(Variant.VariantBoolean); + return getBoolean(); + } /** @return the value of this variant as an enumeration (java style) */ public native EnumVariant toEnumVariant(); @@ -173,22 +184,42 @@ public class Variant extends JacobObject { /** * Set this Variant's type to VT_NULL (the VB equivalent of NULL) * */ - public native void putNull(); + private native void putVariantNull(); + /** + * Set this Variant's type to VT_NULL (the VB equivalent of NULL) + * */ + public void putNull(){ + // verify we aren't released yet + getvt(); + putVariantNull(); + } + /** * @deprecated No longer used * @return null ! */ public native Variant cloneIndirect(); - /** @return the content of this variant as a double */ - public native double toDouble(); + /** + * @deprecated should call changeType() then getDouble() + * @return the content of this variant as a double + * (after possible conversion) + **/ + public double toDouble(){ + changeType(Variant.VariantDouble); + return getDouble(); + } /** + * @deprecated should be replaced by changeType() followed by getCurrency * @return the content of this variant as a long reprensenting a monetary * amount */ - public native long toCurrency(); + public long toCurrency(){ + changeType(Variant.VariantCurrency); + return getCurrency(); + } /** * @deprecated superceded by SafeArray @@ -211,6 +242,7 @@ public class Variant extends JacobObject { /** * Exists to support jacobgen. * This would be deprecated if it weren't for jacobgen + * @deprecated superceded by "this" * @return this same object */ public Variant toVariant() { return this; } @@ -228,25 +260,65 @@ public class Variant extends JacobObject { * set the content of this variant to a short (VT_I2|VT_BYREF) * @param in */ - public native void putShortRef(short in); + private native void putVariantShortRef(short in); + + /** + * set the content of this variant to a short (VT_I2|VT_BYREF) + * @param in + */ + public void putShortRef(short in){ + // verify we aren't released + getvt(); + putVariantShortRef(in); + } /** * set the content of this variant to an int (VT_I4|VT_BYREF) * @param in */ - public native void putIntRef(int in); + private native void putVariantIntRef(int in); + + /** + * set the content of this variant to an int (VT_I4|VT_BYREF) + * @param in + */ + public void putIntRef(int in){ + // verify we aren't released + getvt(); + putVariantIntRef(in); + } /** * set the content of this variant to a double (VT_R8|VT_BYREF) * @param in */ - public native void putDoubleRef(double in); + private native void putVariantDoubleRef(double in); + + /** + * set the content of this variant to a double (VT_R8|VT_BYREF) + * @param in + */ + public void putDoubleRef(double in){ + // verify we aren't released + getvt(); + putVariantDoubleRef(in); + } /** * set the content of this variant to a date (VT_DATE|VT_BYREF) * @param in */ - public native void putDateRef(double in); + private native void putVariantDateRef(double in); + + /** + * set the content of this variant to a date (VT_DATE|VT_BYREF) + * @param in + */ + public void putDateRef(double in){ + // verify we aren't released + getvt(); + putVariantDateRef(in); + } /** * converts a java date to a windows time and calls putDateRef(double) @@ -267,43 +339,132 @@ public class Variant extends JacobObject { * set the content of this variant to a string (VT_BSTR|VT_BYREF) * @param in */ - public native void putStringRef(String in); + private native void putVariantStringRef(String in); + /** + * set the content of this variant to a string (VT_BSTR|VT_BYREF) + * @param in + */ + public void putStringRef(String in){ + // verify we aren't released + getvt(); + putVariantStringRef(in); + } /** * get the content of this variant as a short * @return short */ - public native short getShortRef(); + private native short getVariantShortRef(); /** * get the content of this variant as an int * @return int */ - public native int getIntRef(); + public short getShortRef(){ + if ((this.getvt() & VariantShort) == VariantShort && + (this.getvt() & VariantByref) == VariantByref) { + return getVariantShortRef(); + } else { + throw new IllegalStateException( + "getShortRef() only legal on byRef Variants of type VariantShort, not "+this.getvt()); + } + } + + /** + * get the content of this variant as an int + * @return int + */ + private native int getVariantIntRef(); + + /** + * get the content of this variant as an int + * @return int + */ + public int getIntRef(){ + if ((this.getvt() & VariantInt) == VariantInt && + (this.getvt() & VariantByref) == VariantByref) { + return getVariantIntRef(); + } else { + throw new IllegalStateException( + "getIntRef() only legal on byRef Variants of type VariantInt, not "+this.getvt()); + } + } /** * set the content of this variant to a short (VT_I2) * @param in */ - public native void putShort(short in); + private native void putVariantShort(short in); + /** + * set the content of this variant to a short (VT_I2) + * @param in + */ + public void putShort(short in){ + // verify we aren't released + getvt(); + putVariantShort(in); + } /** * get the content of this variant as a short * @return short */ - public native short getShort(); + private native short getVariantShort(); + /** + * return the int value held in this variant (fails on other types?) + * @return int + */ + public short getShort(){ + if (this.getvt() == VariantShort){ + return getVariantShort(); + } else { + throw new IllegalStateException( + "getShort() only legal on Variants of type VariantShort, not "+this.getvt()); + } + } + + /** * get the content of this variant as a double * @return double */ - public native double getDoubleRef(); + private native double getVariantDoubleRef(); + /** + * + * @return returns the double value, throws exception if not a currency type + */ + public double getDobuleRef(){ + if ((this.getvt() & VariantDouble) == VariantDouble && + (this.getvt() & VariantByref) == VariantByref) { + return getVariantDoubleRef(); + } else { + throw new IllegalStateException( + "getDoubleRef() only legal on byRef Variants of type VariantDouble, not "+this.getvt()); + } + } + + /** * get the content of this variant as a double representing a date * @return double */ - public native double getDateRef(); + private native double getVariantDateRef(); + + /** + * + * @return returns the date value as a double, throws exception if not a currency type + */ + public double getDateRef(){ + if ((this.getvt() & VariantDate) == VariantDate && + (this.getvt() & VariantByref) == VariantByref) { + return getVariantDateRef(); + } else { + throw new IllegalStateException( + "getDateRef() only legal on byRef Variants of type VariantDate, not "+this.getvt()); + } + } /** * returns the windows time contained in this Variant to a Java Date @@ -324,7 +485,22 @@ public class Variant extends JacobObject { * get the content of this variant as a string * @return String */ - public native String getStringRef(); + private native String getVariantStringRef(); + + /** + * gets the content of the veriant as a string ref + * @return + */ + public String getStringRef(){ + if ((this.getvt() & VariantString) == VariantString && + (this.getvt() & VariantByref) == VariantByref) { + return getVariantStringRef(); + } else { + throw new IllegalStateException( + "getStringRef() only legal on byRef Variants of type VariantString, not "+this.getvt()); + } + } + /** * @deprecated superceded by SafeArray @@ -341,15 +517,15 @@ public class Variant extends JacobObject { public native void VariantClear(); /** - * @return the content of this variant as a Dispatch object + * @return the content of this variant as a Dispatch object (after possible conversion) */ - public Dispatch toDispatch(){ return toDispatchObject(); } + public Dispatch toDispatch(){ return toVariantDispatch(); } /** * native method used by toDispatch() * @return */ - private native Dispatch toDispatchObject(); + private native Dispatch toVariantDispatch(); /** * this returns null @@ -358,52 +534,133 @@ public class Variant extends JacobObject { public native Object clone(); /** + * This method now correctly implements java toString() semantics * Attempts to return the content of this variant as a string - * Will convert the underlying data type to a string(!) - * @return String + *