38
38
#include <apr_time.h>
40
42
struct svn_error_t;
42
#define JAVA_PACKAGE "org/apache/subversion/javahl"
44
43
struct svn_string_t;
45
#include "svn_error.h"
49
* The name of the package in which the JavaHL classes are defined.
51
#define JAVAHL_PACKAGE "org/apache/subversion/javahl"
54
* Construct a JavaHL class name for JNIEnv::FindClass.
56
#define JAVAHL_CLASS(name) JAVAHL_PACKAGE name
59
* Construct a JavaHL class parameter name for JNIEnv::GetMethodID & co.
61
#define JAVAHL_ARG(name) "L" JAVAHL_PACKAGE name
47
65
* Class to hold a number of JNI related utility methods. No Objects
48
66
* of this class are ever created.
67
85
static jbyteArray makeJByteArray(const void *data, int length);
68
86
static jbyteArray makeJByteArray(const svn_string_t *str);
69
87
static jobject createDate(apr_time_t time);
88
static apr_time_t getDate(jobject jdate);
70
89
static void logMessage(const char *message);
71
90
static int getLogLevel();
72
static char *getFormatBuffer();
73
91
static void initLogFile(int level, jstring path);
74
92
static jstring makeJString(const char *txt);
75
static bool isJavaExceptionThrown();
76
93
static JNIEnv *getEnv();
77
static void setEnv(JNIEnv *);
80
96
* @return Whether any Throwable has been raised.
82
static bool isExceptionThrown();
98
static bool isExceptionThrown() { return isJavaExceptionThrown(); }
99
static bool isJavaExceptionThrown()
101
return getEnv()->ExceptionCheck();
104
static svn_error_t *wrapJavaException();
105
static jthrowable unwrapJavaException(const svn_error_t *err);
84
107
static void handleAPRError(int error, const char *op);
107
130
static const char *thrownExceptionToCString(SVN::Pool &in_pool);
133
* Check if a Java exception was thrown and convert it to a
134
* Subversion error, using @a errorcode as the generic error code.
136
static svn_error_t* checkJavaException(apr_status_t errorcode);
139
* Create a Java exception corresponding to err, and run
140
* svn_error_clear() on err.
142
static jthrowable createClientException(svn_error_t *err,
143
jthrowable jcause = NULL);
110
146
* Throw a Java exception corresponding to err, and run
111
147
* svn_error_clear() on err.
113
static void handleSVNError(svn_error_t *err);
149
static void handleSVNError(svn_error_t *err, jthrowable jcause = NULL);
115
static jstring makeSVNErrorMessage(svn_error_t *err);
151
static std::string makeSVNErrorMessage(svn_error_t *err,
152
jstring *jerror_message,
153
jobject *jmessage_stack);
118
156
* Create and throw a java.lang.Throwable instance.
131
169
static void throwError(const char *message)
133
raiseThrowable(JAVA_PACKAGE"/JNIError", message);
171
raiseThrowable(JAVAHL_CLASS("/JNIError"), message);
136
174
static apr_pool_t *getPool();
137
static bool JNIGlobalInit(JNIEnv *env);
138
175
static bool JNIInit(JNIEnv *env);
139
176
static bool initializeJNIRuntime();
140
enum { formatBufferSize = 2048 };
141
177
enum { noLog, errorLog, exceptionLog, entryLog } LogLevel;
180
* Mutex that secures the global configuration object.
182
static JNIMutex *g_configMutex;
144
static void wrappedHandleSVNError(svn_error_t *err);
145
static void assembleErrorMessage(svn_error_t *err, int depth,
146
apr_status_t parent_apr_err,
147
std::string &buffer);
185
friend bool initialize_jni_util(JNIEnv *env);
186
static bool JNIGlobalInit(JNIEnv *env);
188
static jthrowable wrappedCreateClientException(svn_error_t *err,
148
190
static void putErrorsInTrace(svn_error_t *err,
149
191
std::vector<jobject> &stackTrace);
151
* Set the appropriate global or thread-local flag that an exception
152
* has been thrown to @a flag.
154
static void setExceptionThrown(bool flag = true);
157
194
* The log level of this module.
185
222
static bool g_initException;
188
* Flag, that one thread is in the init code. Cannot use mutex
189
* here since apr is not initialized yet.
191
static bool g_inInit;
194
* The JNI environment used during initialization.
196
static JNIEnv *g_initEnv;
199
* Fuffer the format error messages during initialization.
201
static char g_initFormatBuffer[formatBufferSize];
204
225
* The stream to write log messages to.
206
227
static std::ofstream g_logStream;
318
#define SVN_JNI_CATCH(statement, errorcode) \
320
do { statement; } while(0); \
321
SVN_ERR(JNIUtil::checkJavaException((errorcode))); \
324
#define SVN_JNI_CATCH_VOID(statement) \
326
do { statement; } while(0); \
327
if (JNIUtil::getEnv()->ExceptionCheck()) { \
328
JNIUtil::getEnv()->ExceptionClear(); \
287
333
#endif // JNIUTIL_H