summaryrefslogtreecommitdiff
path: root/subversion/bindings/javahl/native/JNIUtil.h
diff options
context:
space:
mode:
Diffstat (limited to 'subversion/bindings/javahl/native/JNIUtil.h')
-rw-r--r--subversion/bindings/javahl/native/JNIUtil.h118
1 files changed, 82 insertions, 36 deletions
diff --git a/subversion/bindings/javahl/native/JNIUtil.h b/subversion/bindings/javahl/native/JNIUtil.h
index d353984..e05d1ef 100644
--- a/subversion/bindings/javahl/native/JNIUtil.h
+++ b/subversion/bindings/javahl/native/JNIUtil.h
@@ -37,11 +37,29 @@ class SVNBase;
#include <fstream>
#include <apr_time.h>
#include <string>
+#include <vector>
+
struct svn_error_t;
+struct svn_string_t;
-#define JAVA_PACKAGE "org/apache/subversion/javahl"
+#include "svn_error.h"
+
+
+/**
+ * The name of the package in which the JavaHL classes are defined.
+ */
+#define JAVAHL_PACKAGE "org/apache/subversion/javahl"
+
+/**
+ * Construct a JavaHL class name for JNIEnv::FindClass.
+ */
+#define JAVAHL_CLASS(name) JAVAHL_PACKAGE name
+
+/**
+ * Construct a JavaHL class parameter name for JNIEnv::GetMethodID & co.
+ */
+#define JAVAHL_ARG(name) "L" JAVAHL_PACKAGE name
-struct svn_string_t;
/**
* Class to hold a number of JNI related utility methods. No Objects
@@ -67,19 +85,24 @@ class JNIUtil
static jbyteArray makeJByteArray(const void *data, int length);
static jbyteArray makeJByteArray(const svn_string_t *str);
static jobject createDate(apr_time_t time);
+ static apr_time_t getDate(jobject jdate);
static void logMessage(const char *message);
static int getLogLevel();
- static char *getFormatBuffer();
static void initLogFile(int level, jstring path);
static jstring makeJString(const char *txt);
- static bool isJavaExceptionThrown();
static JNIEnv *getEnv();
- static void setEnv(JNIEnv *);
/**
* @return Whether any Throwable has been raised.
*/
- static bool isExceptionThrown();
+ static bool isExceptionThrown() { return isJavaExceptionThrown(); }
+ static bool isJavaExceptionThrown()
+ {
+ return getEnv()->ExceptionCheck();
+ }
+
+ static svn_error_t *wrapJavaException();
+ static jthrowable unwrapJavaException(const svn_error_t *err);
static void handleAPRError(int error, const char *op);
@@ -107,12 +130,27 @@ class JNIUtil
static const char *thrownExceptionToCString(SVN::Pool &in_pool);
/**
+ * Check if a Java exception was thrown and convert it to a
+ * Subversion error, using @a errorcode as the generic error code.
+ */
+ static svn_error_t* checkJavaException(apr_status_t errorcode);
+
+ /**
+ * Create a Java exception corresponding to err, and run
+ * svn_error_clear() on err.
+ */
+ static jthrowable createClientException(svn_error_t *err,
+ jthrowable jcause = NULL);
+
+ /**
* Throw a Java exception corresponding to err, and run
* svn_error_clear() on err.
*/
- static void handleSVNError(svn_error_t *err);
+ static void handleSVNError(svn_error_t *err, jthrowable jcause = NULL);
- static jstring makeSVNErrorMessage(svn_error_t *err);
+ static std::string makeSVNErrorMessage(svn_error_t *err,
+ jstring *jerror_message,
+ jobject *jmessage_stack);
/**
* Create and throw a java.lang.Throwable instance.
@@ -130,28 +168,27 @@ class JNIUtil
*/
static void throwError(const char *message)
{
- raiseThrowable(JAVA_PACKAGE"/JNIError", message);
+ raiseThrowable(JAVAHL_CLASS("/JNIError"), message);
}
static apr_pool_t *getPool();
- static bool JNIGlobalInit(JNIEnv *env);
static bool JNIInit(JNIEnv *env);
static bool initializeJNIRuntime();
- enum { formatBufferSize = 2048 };
enum { noLog, errorLog, exceptionLog, entryLog } LogLevel;
+ /**
+ * Mutex that secures the global configuration object.
+ */
+ static JNIMutex *g_configMutex;
+
private:
- static void wrappedHandleSVNError(svn_error_t *err);
- static void assembleErrorMessage(svn_error_t *err, int depth,
- apr_status_t parent_apr_err,
- std::string &buffer);
+ friend bool initialize_jni_util(JNIEnv *env);
+ static bool JNIGlobalInit(JNIEnv *env);
+
+ static jthrowable wrappedCreateClientException(svn_error_t *err,
+ jthrowable jcause);
static void putErrorsInTrace(svn_error_t *err,
std::vector<jobject> &stackTrace);
- /**
- * Set the appropriate global or thread-local flag that an exception
- * has been thrown to @a flag.
- */
- static void setExceptionThrown(bool flag = true);
/**
* The log level of this module.
@@ -185,22 +222,6 @@ class JNIUtil
static bool g_initException;
/**
- * Flag, that one thread is in the init code. Cannot use mutex
- * here since apr is not initialized yet.
- */
- static bool g_inInit;
-
- /**
- * The JNI environment used during initialization.
- */
- static JNIEnv *g_initEnv;
-
- /**
- * Fuffer the format error messages during initialization.
- */
- static char g_initFormatBuffer[formatBufferSize];
-
- /**
* The stream to write log messages to.
*/
static std::ofstream g_logStream;
@@ -270,6 +291,16 @@ class JNIUtil
} \
while (0)
+#define POP_AND_RETURN_EXCEPTION_AS_SVNERROR() \
+ do \
+ { \
+ svn_error_t *svn__err_for_exception = JNIUtil::wrapJavaException(); \
+ \
+ env->PopLocalFrame(NULL); \
+ return svn__err_for_exception; \
+ } \
+ while (0)
+
/**
* A useful macro.
@@ -284,4 +315,19 @@ class JNIUtil
} \
} while (0)
+#define SVN_JNI_CATCH(statement, errorcode) \
+ do { \
+ do { statement; } while(0); \
+ SVN_ERR(JNIUtil::checkJavaException((errorcode))); \
+ } while(0)
+
+#define SVN_JNI_CATCH_VOID(statement) \
+ do { \
+ do { statement; } while(0); \
+ if (JNIUtil::getEnv()->ExceptionCheck()) { \
+ JNIUtil::getEnv()->ExceptionClear(); \
+ return; \
+ } \
+ } while(0)
+
#endif // JNIUTIL_H