changeset 6520:6b8ba389829c

improve JNI code
author felipe
date Wed, 19 Mar 2014 14:43:27 -0700
parents 7ecb97f4d8ff
children 54d4f4b10dec
files modules/graphics/src/main/native-glass/win/GlassAccessible.cpp modules/graphics/src/main/native-glass/win/GlassTextRangeProvider.cpp
diffstat 2 files changed, 114 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/native-glass/win/GlassAccessible.cpp	Wed Mar 19 14:41:57 2014 -0700
+++ b/modules/graphics/src/main/native-glass/win/GlassAccessible.cpp	Wed Mar 19 14:43:27 2014 -0700
@@ -162,9 +162,12 @@
             if (str != NULL) {
                 UINT length = env->GetStringLength(str);
                 const jchar* ptr = env->GetStringCritical(str, NULL);
-                pRetVal->bstrVal = SysAllocStringLen(reinterpret_cast<const OLECHAR *>(ptr), length);
-                env->ReleaseStringCritical(str, ptr);
-            } else {
+                if (ptr != NULL) {
+					pRetVal->bstrVal = SysAllocStringLen(reinterpret_cast<const OLECHAR *>(ptr), length);
+					env->ReleaseStringCritical(str, ptr);
+                }
+            }
+            if (pRetVal->parray == NULL) {
                 pRetVal->vt = VT_EMPTY;
             }
             break;
@@ -177,11 +180,13 @@
                 SAFEARRAY *psa = SafeArrayCreateVector(VT_R8, 0, size);
                 if (psa) {
                     jdouble* listPtr = (jdouble*)env->GetPrimitiveArrayCritical(list, 0);
-                    for (LONG i = 0; i < size; i++) {
-                        SafeArrayPutElement(psa, &i, (void*)&(listPtr[i]));
+                    if (listPtr != NULL) {
+						for (LONG i = 0; i < size; i++) {
+							SafeArrayPutElement(psa, &i, (void*)&(listPtr[i]));
+						}
+						env->ReleasePrimitiveArrayCritical(list, listPtr, 0);
+						pRetVal->parray = psa;
                     }
-                    env->ReleasePrimitiveArrayCritical(list, listPtr, 0);
-                    pRetVal->parray = psa;
                 }
             }
             if (pRetVal->parray == NULL) {
@@ -586,8 +591,10 @@
     size_t size = wcslen(val);
     JNIEnv* env = GetEnv();
     jstring str = env->NewString((const jchar *)val, (jsize)size);
-    env->CallVoidMethod(m_jAccessible, mid_SetValueString, str);
-    CheckAndClearException(env);
+    if (!CheckAndClearException(env)) {
+    	env->CallVoidMethod(m_jAccessible, mid_SetValueString, str);
+    	CheckAndClearException(env);
+    }
     return S_OK;
 }
 
@@ -599,8 +606,10 @@
     if (str) {
         UINT length = env->GetStringLength(str);
         const jchar* ptr = env->GetStringCritical(str, NULL);
-        *pRetVal = SysAllocStringLen(reinterpret_cast<const OLECHAR *>(ptr), length);
-        env->ReleaseStringCritical(str, ptr);
+        if (ptr != NULL) {
+        	*pRetVal = SysAllocStringLen(reinterpret_cast<const OLECHAR *>(ptr), length);
+        	env->ReleaseStringCritical(str, ptr);
+        }
     } else {
         *pRetVal = NULL;
     }
@@ -935,115 +944,191 @@
 {
     /* IRawElementProviderSimple */
     mid_GetPatternProvider = env->GetMethodID(jClass, "GetPatternProvider", "(I)J");
+    if (env->ExceptionCheck()) return;
     mid_get_HostRawElementProvider = env->GetMethodID(jClass, "get_HostRawElementProvider", "()J");
+    if (env->ExceptionCheck()) return;
     mid_GetPropertyValue = env->GetMethodID(jClass, "GetPropertyValue", "(I)Lcom/sun/glass/ui/win/WinVariant;");
+    if (env->ExceptionCheck()) return;
 
     /* IRawElementProviderFragment */
     mid_get_BoundingRectangle = env->GetMethodID(jClass, "get_BoundingRectangle", "()[F");
+    if (env->ExceptionCheck()) return;
     mid_get_FragmentRoot = env->GetMethodID(jClass, "get_FragmentRoot", "()J");
+    if (env->ExceptionCheck()) return;
     mid_GetEmbeddedFragmentRoots = env->GetMethodID(jClass, "GetEmbeddedFragmentRoots", "()[J");
+    if (env->ExceptionCheck()) return;
     mid_GetRuntimeId = env->GetMethodID(jClass, "GetRuntimeId", "()[I");
+    if (env->ExceptionCheck()) return;
     mid_Navigate = env->GetMethodID(jClass, "Navigate", "(I)J");
+    if (env->ExceptionCheck()) return;
     mid_SetFocus = env->GetMethodID(jClass, "SetFocus", "()V");
+    if (env->ExceptionCheck()) return;
 
     /* IRawElementProviderFragmentRoot */
     mid_ElementProviderFromPoint = env->GetMethodID(jClass, "ElementProviderFromPoint", "(DD)J");
+    if (env->ExceptionCheck()) return;
     mid_GetFocus = env->GetMethodID(jClass, "GetFocus", "()J");
+    if (env->ExceptionCheck()) return;
 
     /* IInvokeProvider */
     mid_Invoke = env->GetMethodID(jClass, "Invoke", "()V");
+    if (env->ExceptionCheck()) return;
 
     /* ISelectionProvider */
     mid_GetSelection = env->GetMethodID(jClass, "GetSelection", "()[J");
+    if (env->ExceptionCheck()) return;
     mid_get_CanSelectMultiple = env->GetMethodID(jClass, "get_CanSelectMultiple", "()Z");
+    if (env->ExceptionCheck()) return;
     mid_get_IsSelectionRequired = env->GetMethodID(jClass, "get_IsSelectionRequired", "()Z");
+    if (env->ExceptionCheck()) return;
 
     /* ISelectionItemProvider */
     mid_Select = env->GetMethodID(jClass, "Select", "()V");
+    if (env->ExceptionCheck()) return;
     mid_AddToSelection = env->GetMethodID(jClass, "AddToSelection", "()V");
+    if (env->ExceptionCheck()) return;
     mid_RemoveFromSelection = env->GetMethodID(jClass, "RemoveFromSelection", "()V");
+    if (env->ExceptionCheck()) return;
     mid_get_IsSelected = env->GetMethodID(jClass, "get_IsSelected", "()Z");
+    if (env->ExceptionCheck()) return;
     mid_get_SelectionContainer = env->GetMethodID(jClass, "get_SelectionContainer", "()J");
+    if (env->ExceptionCheck()) return;
 
     /* IRangeValueProvider */
     mid_SetValue = env->GetMethodID(jClass, "SetValue", "(D)V");
+    if (env->ExceptionCheck()) return;
     mid_get_Value = env->GetMethodID(jClass, "get_Value", "()D");
+    if (env->ExceptionCheck()) return;
     mid_get_IsReadOnly = env->GetMethodID(jClass, "get_IsReadOnly", "()Z");
+    if (env->ExceptionCheck()) return;
     mid_get_Maximum = env->GetMethodID(jClass, "get_Maximum", "()D");
+    if (env->ExceptionCheck()) return;
     mid_get_Minimum = env->GetMethodID(jClass, "get_Minimum", "()D");
+    if (env->ExceptionCheck()) return;
     mid_get_LargeChange = env->GetMethodID(jClass, "get_LargeChange", "()D");
+    if (env->ExceptionCheck()) return;
     mid_get_SmallChange = env->GetMethodID(jClass, "get_SmallChange", "()D");
+    if (env->ExceptionCheck()) return;
 
     /* IValueProvider */
     mid_SetValueString = env->GetMethodID(jClass, "SetValueString", "(Ljava/lang/String;)V");
+    if (env->ExceptionCheck()) return;
     mid_get_ValueString = env->GetMethodID(jClass, "get_ValueString", "()Ljava/lang/String;");
+    if (env->ExceptionCheck()) return;
 
     /* IValueProvider */
     mid_GetVisibleRanges = env->GetMethodID(jClass, "GetVisibleRanges", "()[J");
+    if (env->ExceptionCheck()) return;
     mid_RangeFromChild = env->GetMethodID(jClass, "RangeFromChild", "(J)J");
+    if (env->ExceptionCheck()) return;
     mid_RangeFromPoint = env->GetMethodID(jClass, "RangeFromPoint", "(DD)J");
+    if (env->ExceptionCheck()) return;
     mid_get_DocumentRange = env->GetMethodID(jClass, "get_DocumentRange", "()J");
+    if (env->ExceptionCheck()) return;
     mid_get_SupportedTextSelection = env->GetMethodID(jClass, "get_SupportedTextSelection", "()I");
+    if (env->ExceptionCheck()) return;
 
     /* IGridProvider */
     mid_get_ColumnCount = env->GetMethodID(jClass, "get_ColumnCount", "()I");
+    if (env->ExceptionCheck()) return;
     mid_get_RowCount = env->GetMethodID(jClass, "get_RowCount", "()I");
+    if (env->ExceptionCheck()) return;
     mid_GetItem = env->GetMethodID(jClass, "GetItem", "(II)J");
+    if (env->ExceptionCheck()) return;
 
     /* IGridItemProvider */
     mid_get_Column = env->GetMethodID(jClass, "get_Column", "()I");
+    if (env->ExceptionCheck()) return;
     mid_get_ColumnSpan = env->GetMethodID(jClass, "get_ColumnSpan", "()I");
+    if (env->ExceptionCheck()) return;
     mid_get_ContainingGrid = env->GetMethodID(jClass, "get_ContainingGrid", "()J");
+    if (env->ExceptionCheck()) return;
     mid_get_Row = env->GetMethodID(jClass, "get_Row", "()I");
+    if (env->ExceptionCheck()) return;
     mid_get_RowSpan = env->GetMethodID(jClass, "get_RowSpan", "()I");
+    if (env->ExceptionCheck()) return;
 
     /* ITableProvider */
     mid_GetColumnHeaders = env->GetMethodID(jClass, "GetColumnHeaders", "()[J");
+    if (env->ExceptionCheck()) return;
     mid_GetRowHeaders = env->GetMethodID(jClass, "GetRowHeaders", "()[J");
+    if (env->ExceptionCheck()) return;
     mid_get_RowOrColumnMajor = env->GetMethodID(jClass, "get_RowOrColumnMajor", "()I");
+    if (env->ExceptionCheck()) return;
 
     /* ITableItemProvider */
     mid_GetColumnHeaderItems = env->GetMethodID(jClass, "GetColumnHeaderItems", "()[J");
+    if (env->ExceptionCheck()) return;
     mid_GetRowHeaderItems = env->GetMethodID(jClass, "GetRowHeaderItems", "()[J");
+    if (env->ExceptionCheck()) return;
 
     /* IToggleProvider */
     mid_Toggle = env->GetMethodID(jClass, "Toggle", "()V");
+    if (env->ExceptionCheck()) return;
     mid_get_ToggleState = env->GetMethodID(jClass, "get_ToggleState", "()I");
+    if (env->ExceptionCheck()) return;
 
     /* IExpandCollapseProvider */
     mid_Collapse= env->GetMethodID(jClass, "Collapse", "()V");
+    if (env->ExceptionCheck()) return;
     mid_Expand = env->GetMethodID(jClass, "Expand", "()V");
+    if (env->ExceptionCheck()) return;
     mid_get_ExpandCollapseState = env->GetMethodID(jClass, "get_ExpandCollapseState", "()I");
+    if (env->ExceptionCheck()) return;
 
     /* ITransformProvider */
     mid_get_CanMove = env->GetMethodID(jClass, "get_CanMove", "()Z");
+    if (env->ExceptionCheck()) return;
     mid_get_CanResize = env->GetMethodID(jClass, "get_CanResize", "()Z");
+    if (env->ExceptionCheck()) return;
     mid_get_CanRotate = env->GetMethodID(jClass, "get_CanRotate", "()Z");
+    if (env->ExceptionCheck()) return;
     mid_Move = env->GetMethodID(jClass, "Move", "(DD)V");
+    if (env->ExceptionCheck()) return;
     mid_Resize = env->GetMethodID(jClass, "Resize", "(DD)V");
+    if (env->ExceptionCheck()) return;
     mid_Rotate = env->GetMethodID(jClass, "Rotate", "(D)V");
+    if (env->ExceptionCheck()) return;
 
     /* IScrollProvider */
     mid_Scroll = env->GetMethodID(jClass, "Scroll", "(II)V");
+    if (env->ExceptionCheck()) return;
     mid_SetScrollPercent = env->GetMethodID(jClass, "SetScrollPercent", "(DD)V");
+    if (env->ExceptionCheck()) return;
     mid_get_HorizontallyScrollable = env->GetMethodID(jClass, "get_HorizontallyScrollable", "()Z");
+    if (env->ExceptionCheck()) return;
     mid_get_HorizontalScrollPercent = env->GetMethodID(jClass, "get_HorizontalScrollPercent", "()D");
+    if (env->ExceptionCheck()) return;
     mid_get_HorizontalViewSize = env->GetMethodID(jClass, "get_HorizontalViewSize", "()D");
+    if (env->ExceptionCheck()) return;
     mid_get_VerticallyScrollable = env->GetMethodID(jClass, "get_VerticallyScrollable", "()Z");
+    if (env->ExceptionCheck()) return;
     mid_get_VerticalScrollPercent = env->GetMethodID(jClass, "get_VerticalScrollPercent", "()D");
+    if (env->ExceptionCheck()) return;
     mid_get_VerticalViewSize = env->GetMethodID(jClass, "get_VerticalViewSize", "()D");
+    if (env->ExceptionCheck()) return;
 
     /* Variant */
     jclass jVariantClass = env->FindClass("com/sun/glass/ui/win/WinVariant");
+    if (env->ExceptionCheck()) return;
     fid_vt = env->GetFieldID(jVariantClass, "vt", "S");
+    if (env->ExceptionCheck()) return;
     fid_iVal= env->GetFieldID(jVariantClass, "iVal", "S");
+    if (env->ExceptionCheck()) return;
     fid_lVal= env->GetFieldID(jVariantClass, "lVal", "I");
+    if (env->ExceptionCheck()) return;
     fid_punkVal= env->GetFieldID(jVariantClass, "punkVal", "J");
+    if (env->ExceptionCheck()) return;
     fid_fltVal= env->GetFieldID(jVariantClass, "fltVal", "F");
+    if (env->ExceptionCheck()) return;
     fid_dblVal= env->GetFieldID(jVariantClass, "dblVal", "D");
+    if (env->ExceptionCheck()) return;
     fid_boolVal= env->GetFieldID(jVariantClass, "boolVal", "Z");
+    if (env->ExceptionCheck()) return;
     fid_bstrVal= env->GetFieldID(jVariantClass, "bstrVal", "Ljava/lang/String;");
+    if (env->ExceptionCheck()) return;
     fid_pDblVal= env->GetFieldID(jVariantClass, "pDblVal", "[D");
+    if (env->ExceptionCheck()) return;
 }
 
 /*
--- a/modules/graphics/src/main/native-glass/win/GlassTextRangeProvider.cpp	Wed Mar 19 14:41:57 2014 -0700
+++ b/modules/graphics/src/main/native-glass/win/GlassTextRangeProvider.cpp	Wed Mar 19 14:43:27 2014 -0700
@@ -114,8 +114,6 @@
 {
     GlassTextRangeProvider* glassRange = reinterpret_cast<GlassTextRangeProvider*>(range);
     if (glassRange == NULL ||  glassRange->m_jTextRangeProvider == NULL) {
-        fprintf(stdout, "GlassTextRangeProvider::Compare() failed to map range\n");
-        fflush(stdout);
         *pRetVal = FALSE; /* Can't compare against an unknown object */
         return S_OK;
     }
@@ -130,8 +128,6 @@
 {
     GlassTextRangeProvider* glassRange = reinterpret_cast<GlassTextRangeProvider*>(targetRange);
     if (glassRange == NULL ||  glassRange->m_jTextRangeProvider == NULL) {
-        fprintf(stdout, "GlassTextRangeProvider::CompareEndpoints() failed to map range\n");
-        fflush(stdout);
         *pRetVal = FALSE; /* Can't compare against an unknown object */
         return S_OK;
     }
@@ -298,23 +294,41 @@
   (JNIEnv *env, jclass jClass)
 {
     mid_Clone = env->GetMethodID(jClass, "Clone", "()J");
+    if (env->ExceptionCheck()) return;
     mid_Compare = env->GetMethodID(jClass, "Compare", "(Lcom/sun/glass/ui/win/WinTextRangeProvider;)Z");
+    if (env->ExceptionCheck()) return;
     mid_CompareEndpoints = env->GetMethodID(jClass, "CompareEndpoints", "(ILcom/sun/glass/ui/win/WinTextRangeProvider;I)I");
+    if (env->ExceptionCheck()) return;
     mid_ExpandToEnclosingUnit = env->GetMethodID(jClass, "ExpandToEnclosingUnit", "(I)V");
+    if (env->ExceptionCheck()) return;
     mid_FindAttribute = env->GetMethodID(jClass, "FindAttribute", "(ILcom/sun/glass/ui/win/WinVariant;Z)J");
+    if (env->ExceptionCheck()) return;
     mid_FindText = env->GetMethodID(jClass, "FindText", "(Ljava/lang/String;ZZ)J");
+    if (env->ExceptionCheck()) return;
     mid_GetAttributeValue = env->GetMethodID(jClass, "GetAttributeValue", "(I)Lcom/sun/glass/ui/win/WinVariant;");
+    if (env->ExceptionCheck()) return;
     mid_GetBoundingRectangles = env->GetMethodID(jClass, "GetBoundingRectangles", "()[D");
+    if (env->ExceptionCheck()) return;
     mid_GetEnclosingElement = env->GetMethodID(jClass, "GetEnclosingElement", "()J");
+    if (env->ExceptionCheck()) return;
     mid_GetText = env->GetMethodID(jClass, "GetText", "(I)Ljava/lang/String;");
+    if (env->ExceptionCheck()) return;
     mid_Move = env->GetMethodID(jClass, "Move", "(II)I");
+    if (env->ExceptionCheck()) return;
     mid_MoveEndpointByUnit = env->GetMethodID(jClass, "MoveEndpointByUnit", "(III)I");
+    if (env->ExceptionCheck()) return;
     mid_MoveEndpointByRange = env->GetMethodID(jClass, "MoveEndpointByRange", "(ILcom/sun/glass/ui/win/WinTextRangeProvider;I)V");
+    if (env->ExceptionCheck()) return;
     mid_Select = env->GetMethodID(jClass, "Select", "()V");
+    if (env->ExceptionCheck()) return;
     mid_AddToSelection = env->GetMethodID(jClass, "AddToSelection", "()V");
+    if (env->ExceptionCheck()) return;
     mid_RemoveFromSelection = env->GetMethodID(jClass, "RemoveFromSelection", "()V");
+    if (env->ExceptionCheck()) return;
     mid_ScrollIntoView = env->GetMethodID(jClass, "ScrollIntoView", "(Z)V");
+    if (env->ExceptionCheck()) return;
     mid_GetChildren = env->GetMethodID(jClass, "GetChildren", "()[J");
+    if (env->ExceptionCheck()) return;
 }
 
 /*