JNIEXPORT jobject JNICALL Java_java_io_FileSystem_getFileSystem(JNIEnv *env, jclass ignored) { initializeWindowsVersion(); if (onNT) { return JNU_NewObjectByName(env, "java/io/WinNTFileSystem", "()V"); } else { return JNU_NewObjectByName(env, "java/io/Win32FileSystem", "()V"); } }
/** * Call this to throw an internal UnixException when a system/library * call fails */ static void throwUnixException(JNIEnv* env, int errnum) { jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException", "(I)V", errnum); if (x != NULL) { (*env)->Throw(env, x); } }
static void throwWindowsException(JNIEnv* env, DWORD lastError) { jobject x = JNU_NewObjectByName(env, "sun/nio/fs/WindowsException", "(I)V", lastError); if (x != NULL) { (*env)->Throw(env, x); } }
jobject AwtFileDialog::_GetLocationOnScreen(void *param) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); jobject result = NULL; HWND hwnd = (HWND)env->GetLongField((jobject)param, AwtComponent::hwndID); if (::IsWindow(hwnd)) { RECT rect; VERIFY(::GetWindowRect(hwnd, &rect)); result = JNU_NewObjectByName(env, "java/awt/Point", "(II)V", ScaleDownX(rect.left, hwnd), ScaleDownY(rect.top, hwnd)); } if (result != NULL) { jobject resultRef = env->NewGlobalRef(result); env->DeleteLocalRef(result); return resultRef; } else { return NULL; } }
static void setCharValueAtObjectArray(JNIEnv *env, jobjectArray array, jsize index, jchar value) { static const char* class_name = "java/lang/Character"; static const char* signature = "(C)V"; jobject obj = JNU_NewObjectByName(env, class_name, signature, value); (*env)->SetObjectArrayElement(env, array, index, obj); }
BOOL AwtMenuItem::CheckMenuCreation(JNIEnv *env, jobject self, HMENU hMenu) { // fix for 5088782 // check if CreateMenu() returns not null value and if it does - // create an InternalError or OutOfMemoryError based on GetLastError(). // This error is set to createError field of WObjectPeer and then // checked and thrown in WMenuPeer or WMenuItemPeer constructor. We // can't throw an error here because this code is invoked on Toolkit thread // return TRUE if menu is created successfully, FALSE otherwise if (hMenu == NULL) { DWORD dw = GetLastError(); jobject createError = NULL; if (dw == ERROR_OUTOFMEMORY) { jstring errorMsg = env->NewStringUTF("too many menu handles"); createError = JNU_NewObjectByName(env, "java/lang/OutOfMemoryError", "(Ljava/lang/String;)V", errorMsg); env->DeleteLocalRef(errorMsg); } else { TCHAR *buf; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&buf, 0, NULL); jstring s = JNU_NewStringPlatform(env, buf); createError = JNU_NewObjectByName(env, "java/lang/InternalError", "(Ljava/lang/String;)V", s); LocalFree(buf); env->DeleteLocalRef(s); } env->SetObjectField(self, AwtObject::createErrorID, createError); if (createError != NULL) { env->DeleteLocalRef(createError); } return FALSE; } return TRUE; }
/* * Class: sun_awt_windows_WColor * Method: getDefaultColor * Signature: (I)Ljava/awt/Color; */ JNIEXPORT jobject JNICALL Java_sun_awt_windows_WColor_getDefaultColor(JNIEnv *env, jclass cls, jint index) { TRY; int iColor = 0; switch(index) { case sun_awt_windows_WColor_WINDOW_BKGND: iColor = COLOR_WINDOW; break; case sun_awt_windows_WColor_WINDOW_TEXT: iColor = COLOR_WINDOWTEXT; break; case sun_awt_windows_WColor_FRAME: iColor = COLOR_WINDOWFRAME; break; case sun_awt_windows_WColor_SCROLLBAR: iColor = COLOR_SCROLLBAR; break; case sun_awt_windows_WColor_MENU_BKGND: iColor = COLOR_MENU; break; case sun_awt_windows_WColor_MENU_TEXT: iColor = COLOR_MENUTEXT; break; case sun_awt_windows_WColor_BUTTON_BKGND: iColor = (IS_NT) ? COLOR_BTNFACE : COLOR_3DFACE; break; case sun_awt_windows_WColor_BUTTON_TEXT: iColor = COLOR_BTNTEXT; break; case sun_awt_windows_WColor_HIGHLIGHT: iColor = COLOR_HIGHLIGHT; break; default: return NULL; } DWORD c = ::GetSysColor(iColor); jobject wColor = JNU_NewObjectByName(env, "java/awt/Color", "(III)V", GetRValue(c), GetGValue(c), GetBValue(c)); DASSERT(!safe_ExceptionOccurred(env)); return wColor; CATCH_BAD_ALLOC_RET(NULL); }
static void ThrowZipException(JNIEnv *env, const char *msg) { jstring s = NULL; jobject x; if (msg != NULL) { s = JNU_NewStringPlatform(env, msg); } x = JNU_NewObjectByName(env, "java/util/zip/ZipException", "(Ljava/lang/String;)V", s); if (x != NULL) { (*env)->Throw(env, x); } }
/* * Create a Java locale object from its name string */ jobject CreateLocaleObject(JNIEnv *env, const char * name) { TRY; // get language, country, variant information char * language = (char *)safe_Malloc(strlen(name) + 1); char * country; char * variant; DASSERT(!safe_ExceptionOccurred(env)); strcpy(language, name); for (country = language; *country != '_' && *country != '\0'; country++); if (*country == '_') { *country++ = '\0'; for (variant = country; *variant != '_' && *variant != '\0'; variant++); if (*variant == '_') { *variant++ = '\0'; } } else { variant = country; } // create Locale object jobject langObj = env->NewStringUTF(language); jobject ctryObj = env->NewStringUTF(country); jobject vrntObj = env->NewStringUTF(variant); jobject localeObj = JNU_NewObjectByName(env, "java/util/Locale", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", langObj, ctryObj, vrntObj); free(language); env->DeleteLocalRef(langObj); env->DeleteLocalRef(ctryObj); env->DeleteLocalRef(vrntObj); return localeObj; CATCH_BAD_ALLOC_RET(NULL); }
JNIEXPORT jint JNICALL Java_sun_management_Flag_getFlags (JNIEnv *env, jclass cls, jobjectArray names, jobjectArray flags, jint count) { char errmsg[128]; jint num_flags, i, index; jmmVMGlobal* globals; const char* class_name = "sun/management/Flag"; const char* signature = "(Ljava/lang/String;Ljava/lang/Object;ZZLcom/sun/management/VMOption$Origin;)V"; jobject origin; jobject valueObj; jobject flag; if (flags == NULL) { JNU_ThrowNullPointerException(env, 0); return 0; } if (count == 0) { JNU_ThrowIllegalArgumentException(env, 0); return 0; } globals = (jmmVMGlobal*) malloc(count * sizeof(jmmVMGlobal)); if (globals == NULL) { JNU_ThrowOutOfMemoryError(env, 0); return 0; } num_flags = jmm_interface->GetVMGlobals(env, names, globals, count); if (num_flags == 0) { free(globals); return 0; } index = 0; for (i = 0; i < count; i++) { if (globals[i].name == NULL) { continue; } switch (globals[i].type) { case JMM_VMGLOBAL_TYPE_JBOOLEAN: valueObj = JNU_NewObjectByName(env, "java/lang/Boolean", "(Z)V", globals[i].value.z); break; case JMM_VMGLOBAL_TYPE_JSTRING: valueObj = globals[i].value.l; break; case JMM_VMGLOBAL_TYPE_JLONG: valueObj = JNU_NewObjectByName(env, "java/lang/Long", "(J)V", globals[i].value.j); break; default: // unsupported type sprintf(errmsg, "Unsupported VMGlobal Type %d", globals[i].type); JNU_ThrowInternalError(env, errmsg); free(globals); return 0; } switch (globals[i].origin) { case JMM_VMGLOBAL_ORIGIN_DEFAULT: origin = default_origin; break; case JMM_VMGLOBAL_ORIGIN_COMMAND_LINE: origin = vm_creation_origin; break; case JMM_VMGLOBAL_ORIGIN_MANAGEMENT: origin = mgmt_origin; break; case JMM_VMGLOBAL_ORIGIN_ENVIRON_VAR: origin = envvar_origin; break; case JMM_VMGLOBAL_ORIGIN_CONFIG_FILE: origin = config_file_origin; break; case JMM_VMGLOBAL_ORIGIN_ERGONOMIC: origin = ergo_origin; break; case JMM_VMGLOBAL_ORIGIN_OTHER: origin = other_origin; break; default: // unknown origin origin = other_origin; break; } flag = JNU_NewObjectByName(env, class_name, signature, globals[i].name, valueObj, globals[i].writeable, globals[i].external, origin); if (flag == NULL) { free(globals); JNU_ThrowOutOfMemoryError(env, 0); return 0; } (*env)->SetObjectArrayElement(env, flags, index, flag); index++; } if (index != num_flags) { JNU_ThrowInternalError(env, "Number of Flag objects created unmatched"); free(globals); return 0; } free(globals); /* return the number of Flag objects created */ return num_flags; }
JNIEXPORT jobject JNICALL Java_java_io_FileSystem_getFileSystem(JNIEnv *env, jclass ignored) { return JNU_NewObjectByName(env, "java/io/VxWorksFileSystem", "()V"); }
JNIEXPORT jobject JNICALL Java_com_sun_management_internal_GcInfoBuilder_getLastGcInfo0 (JNIEnv *env, jobject builder, jobject gc, jint ext_att_count, jobjectArray ext_att_values, jcharArray ext_att_types, jobjectArray usageBeforeGC, jobjectArray usageAfterGC) { jmmGCStat gc_stat; jchar* nativeTypes; jsize i; jvalue v; if (gc == NULL) { JNU_ThrowNullPointerException(env, "Invalid GarbageCollectorMBean"); return 0; } if (ext_att_count <= 0) { JNU_ThrowIllegalArgumentException(env, "Invalid ext_att_count"); return 0; } gc_stat.usage_before_gc = usageBeforeGC; gc_stat.usage_after_gc = usageAfterGC; gc_stat.gc_ext_attribute_values_size = ext_att_count; if (ext_att_count > 0) { gc_stat.gc_ext_attribute_values = (jvalue*) malloc((size_t)ext_att_count * sizeof(jvalue)); if (gc_stat.gc_ext_attribute_values == NULL) { JNU_ThrowOutOfMemoryError(env, 0); return 0; } } else { gc_stat.gc_ext_attribute_values = NULL; } jmm_interface->GetLastGCStat(env, gc, &gc_stat); if (gc_stat.gc_index == 0) { if (gc_stat.gc_ext_attribute_values != NULL) { free(gc_stat.gc_ext_attribute_values); } return 0; } // convert the ext_att_types to native types nativeTypes = (jchar*) malloc((size_t)ext_att_count * sizeof(jchar)); if (nativeTypes == NULL) { if (gc_stat.gc_ext_attribute_values != NULL) { free(gc_stat.gc_ext_attribute_values); } JNU_ThrowOutOfMemoryError(env, 0); return 0; } (*env)->GetCharArrayRegion(env, ext_att_types, 0, ext_att_count, nativeTypes); for (i = 0; i < ext_att_count; i++) { v = gc_stat.gc_ext_attribute_values[i]; switch (nativeTypes[i]) { case 'Z': setBooleanValueAtObjectArray(env, ext_att_values, i, v.z); break; case 'B': setByteValueAtObjectArray(env, ext_att_values, i, v.b); break; case 'C': setCharValueAtObjectArray(env, ext_att_values, i, v.c); break; case 'S': setShortValueAtObjectArray(env, ext_att_values, i, v.s); break; case 'I': setIntValueAtObjectArray(env, ext_att_values, i, v.i); break; case 'J': setLongValueAtObjectArray(env, ext_att_values, i, v.j); break; case 'F': setFloatValueAtObjectArray(env, ext_att_values, i, v.f); break; case 'D': setDoubleValueAtObjectArray(env, ext_att_values, i, v.d); break; default: if (gc_stat.gc_ext_attribute_values != NULL) { free(gc_stat.gc_ext_attribute_values); } if (nativeTypes != NULL) { free(nativeTypes); } JNU_ThrowInternalError(env, "Unsupported attribute type"); return 0; } } if (gc_stat.gc_ext_attribute_values != NULL) { free(gc_stat.gc_ext_attribute_values); } if (nativeTypes != NULL) { free(nativeTypes); } return JNU_NewObjectByName(env, "com/sun/management/GcInfo", "(Lcom/sun/management/internal/GcInfoBuilder;JJJ[Ljava/lang/management/MemoryUsage;[Ljava/lang/management/MemoryUsage;[Ljava/lang/Object;)V", builder, gc_stat.gc_index, gc_stat.start_time, gc_stat.end_time, usageBeforeGC, usageAfterGC, ext_att_values); }