1 /**
2 Copyright (c) 2003, Technology Concepts & Design, Inc.
3 Copyright (c) 2006,2008,2011, Olly Betts
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without modification, are permitted
7 provided that the following conditions are met:
8
9 - Redistributions of source code must retain the above copyright notice, this list of conditions
10 and the following disclaimer.
11
12 - Redistributions in binary form must reproduce the above copyright notice, this list of conditions
13 and the following disclaimer in the documentation and/or other materials provided with the distribution.
14
15 - Neither the name of Technology Concepts & Design, Inc. nor the names of its contributors may be used to
16 endorse or promote products derived from this software without specific prior written permission.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
19 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25 THE POSSIBILITY OF SUCH DAMAGE.
26 **/
27
28 #include "xapian_jni.h"
29
check_for_java_exception(JNIEnv * env)30 bool check_for_java_exception(JNIEnv *env) {
31 jthrowable exception = env->ExceptionOccurred();
32 if (exception) {
33 env->ExceptionClear();
34 env->Throw(exception);
35 return true;
36 }
37
38 return false;
39 }
40
toArray(JNIEnv * env,jobjectArray j_array,int len)41 string *toArray(JNIEnv *env, jobjectArray j_array, int len) {
42 string *array = new string[len];
43 for (int x=0; x<len; x++) {
44 jstring term = (jstring) env->GetObjectArrayElement(j_array, x);
45 const char *c_term = env->GetStringUTFChars(term, 0);
46 array[x].assign(c_term, env->GetStringUTFLength(term));
47 env->ReleaseStringUTFChars(term, c_term);
48 }
49 return array;
50 }
51