From bd5fc685d5e3be74e4569a4bffd5d12ee70d798c Mon Sep 17 00:00:00 2001 From: "idk%eng.sun.com" Date: Sat, 9 Jun 2001 00:12:32 +0000 Subject: [PATCH] *not part of the build* fix for 15507 15510 git-svn-id: svn://10.0.0.236/trunk@96760 18797224-902f-48f8-a5cc-f745e15eee43 --- .../org/mozilla/xpcom/XPCOMException.java | 29 +++++++++++++++++++ mozilla/java/xpcom/java/src/bcJavaStub.cpp | 14 ++++++--- .../java/src/org_mozilla_xpcom_Utilities.cpp | 26 ++++++++++++++++- .../java/xpcom/java/test/bcJavaSample.java | 8 ++--- 4 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 mozilla/java/xpcom/java/classes/org/mozilla/xpcom/XPCOMException.java diff --git a/mozilla/java/xpcom/java/classes/org/mozilla/xpcom/XPCOMException.java b/mozilla/java/xpcom/java/classes/org/mozilla/xpcom/XPCOMException.java new file mode 100644 index 00000000000..c1dc56af8f4 --- /dev/null +++ b/mozilla/java/xpcom/java/classes/org/mozilla/xpcom/XPCOMException.java @@ -0,0 +1,29 @@ +/* -*- Mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are + * Copyright (C) 1999 Sun Microsystems, Inc. All + * Rights Reserved. + * + * Contributor(s): + * Igor Kushnirskiy + */ + +package org.mozilla.xpcom; + +public class XPCOMException extends RuntimeException { + public XPCOMException(int xpcomCode) { + super(" [nsresult=" + xpcomCode + "]"); + } +} diff --git a/mozilla/java/xpcom/java/src/bcJavaStub.cpp b/mozilla/java/xpcom/java/src/bcJavaStub.cpp index 50113c8c327..10f2547ae04 100644 --- a/mozilla/java/xpcom/java/src/bcJavaStub.cpp +++ b/mozilla/java/xpcom/java/src/bcJavaStub.cpp @@ -85,11 +85,17 @@ void bcJavaStub::Dispatch(bcICall *call) { bcIUnMarshaler * um = call->GetUnMarshaler(); mt->UnMarshal(um); jobject jiid = bcIIDJava::GetObject(&iid); - jobject retval = bcJavaGlobal::GetJNIEnv()->CallStaticObjectMethod(utilitiesClass, callMethodByIndexMID, object, jiid, (jint)mid, args); - //nb return value; excepion handling + jobject retval = env->CallStaticObjectMethod(utilitiesClass, callMethodByIndexMID, object, jiid, (jint)mid, args); + nsresult result = NS_OK; + if (env->ExceptionOccurred()) { + env->ExceptionDescribe(); + result = NS_ERROR_FAILURE; + } bcIMarshaler * m = call->GetMarshaler(); - mt->Marshal(m, retval); - //nb memory deallocation + m->WriteSimple(&result, bc_T_U32); + if (NS_SUCCEEDED(result)) { + mt->Marshal(m, retval); + } delete m; delete um; delete mt; return; } diff --git a/mozilla/java/xpcom/java/src/org_mozilla_xpcom_Utilities.cpp b/mozilla/java/xpcom/java/src/org_mozilla_xpcom_Utilities.cpp index c1c8bad2f87..d010306a8e2 100644 --- a/mozilla/java/xpcom/java/src/org_mozilla_xpcom_Utilities.cpp +++ b/mozilla/java/xpcom/java/src/org_mozilla_xpcom_Utilities.cpp @@ -32,6 +32,9 @@ #include "ctype.h" #include "bcJavaGlobal.h" + +static jclass XPCOMExceptionClass = NULL; +static jmethodID XPCOMExceptionInitMID = NULL; /* * Class: org_mozilla_xpcom_Utilities * Method: callMethodByIndex @@ -68,8 +71,29 @@ JNIEXPORT jobject JNICALL Java_org_mozilla_xpcom_Utilities_callMethodByIndex mt->Marshal(m); orb->SendReceive(call); bcIUnMarshaler * um = call->GetUnMarshaler(); + nsresult result; jobject retval; - mt->UnMarshal(um, &retval); + um->ReadSimple(&result, bc_T_U32); + if (NS_SUCCEEDED(result)) { + mt->UnMarshal(um, &retval); + } else { + if (XPCOMExceptionClass == NULL) { + XPCOMExceptionClass = (jclass) env->FindClass("org/mozilla/xpcom/XPCOMException"); + if (!env->ExceptionOccurred()) { // if there is an exception it will be catched in java + XPCOMExceptionClass = (jclass)env->NewGlobalRef(XPCOMExceptionClass); + if (!env->ExceptionOccurred()) { + XPCOMExceptionInitMID = env->GetMethodID(XPCOMExceptionClass,"","(I)V"); + if (env->ExceptionOccurred()) { + XPCOMExceptionClass = NULL; + } + } + } + } + if (!env->ExceptionOccurred()) { + jthrowable exception = (jthrowable) env->NewObject(XPCOMExceptionClass, XPCOMExceptionInitMID,(jint)result); + env->Throw(exception); + } + } delete call; delete m; delete um; delete mt; return retval; diff --git a/mozilla/java/xpcom/java/test/bcJavaSample.java b/mozilla/java/xpcom/java/test/bcJavaSample.java index bb12fef93ee..92d9aae074b 100644 --- a/mozilla/java/xpcom/java/test/bcJavaSample.java +++ b/mozilla/java/xpcom/java/test/bcJavaSample.java @@ -116,10 +116,10 @@ public class bcJavaSample implements bcIJavaSample { nsISupportsString strObj; while (true) { obj = enumerator.currentItem(); - if (obj == null - || counter > 300) { - break; - } + // if (obj == null + // || counter > 300) { + // break; + //} strObj = (nsISupportsString) obj.queryInterface(nsISupportsString.IID); str = strObj.getData(); System.out.println("--[java] bcJavaSample.Test5 string "+str);