NeXusJavaBindings  1
 All Classes Namespaces Files Functions Variables Typedefs Macros Pages
hdfexceptionImp.c
Go to the documentation of this file.
1 
2 /****************************************************************************
3  * NCSA HDF *
4  * National Comptational Science Alliance *
5  * University of Illinois at Urbana-Champaign *
6  * 605 E. Springfield, Champaign IL 61820 *
7  * *
8  * For conditions of distribution and use, see the accompanying *
9  * hdf/COPYING file. *
10  * *
11  ****************************************************************************/
12 
13 /*
14  * This is a utility program used by the HDF Java-C wrapper layer to
15  * generate exceptions. This may be called from any part of the
16  * Java-C interface.
17  *
18  */
19 
20 #include <stdio.h>
21 #include "jni.h"
22 #include "hdfexceptionImp.h"
23 
24 jboolean buildException( JNIEnv *env, jint HDFerr)
25 {
26 jmethodID jm;
27 jclass jc;
28 int args[2];
29 jobject ex;
30 int rval;
31 
32 
33  jc = (*env)->FindClass(env, "ncsa/hdf/hdflib/HDFLibraryException");
34  if (jc == NULL) {
35  return JNI_FALSE;
36  }
37  jm = (*env)->GetMethodID(env, jc, "<init>", "(I)V");
38  if (jm == NULL) {
39  return JNI_FALSE;
40  }
41  args[0] = HDFerr;
42  args[1] = 0;
43 
44  ex = (*env)->NewObjectA ( env, jc, jm, (jvalue *)args );
45 
46  rval = (*env)->Throw(env, ex );
47 
48  return JNI_TRUE;
49 }
50 
51 jboolean NotImplemented( JNIEnv *env, char *functName)
52 {
53 jmethodID jm;
54 jclass jc;
55 char * args[2];
56 jobject ex;
57 jstring str;
58 int rval;
59 
60 
61  jc = (*env)->FindClass(env, "ncsa/hdf/hdflib/HDFNotImplementedException");
62  if (jc == NULL) {
63  return JNI_FALSE;
64  }
65  jm = (*env)->GetMethodID(env, jc, "<init>", "(Ljava/lang/String;)V");
66  if (jm == NULL) {
67  return JNI_FALSE;
68  }
69 
70  str = (*env)->NewStringUTF(env,functName);
71  args[0] = (char *)str;
72  args[1] = 0;
73  ex = (*env)->NewObjectA ( env, jc, jm, (jvalue *)args );
74 
75  rval = (*env)->Throw(env, ex );
76 
77  return JNI_TRUE;
78 }
79 
80 jboolean outOfMemory( JNIEnv *env, char *functName)
81 {
82 jmethodID jm;
83 jclass jc;
84 char * args[2];
85 jobject ex;
86 jstring str;
87 int rval;
88 
89  jc = (*env)->FindClass(env, "java/lang/OutOfMemoryError");
90  if (jc == NULL) {
91  return JNI_FALSE;
92  }
93  jm = (*env)->GetMethodID(env, jc, "<init>", "(Ljava/lang/String;)V");
94  if (jm == NULL) {
95  return JNI_FALSE;
96  }
97 
98  str = (*env)->NewStringUTF(env,functName);
99  args[0] = (char *)str;
100  args[1] = 0;
101  ex = (*env)->NewObjectA ( env, jc, jm, (jvalue *)args );
102 
103  rval = (*env)->Throw(env, ex );
104 
105  return JNI_TRUE;
106 }
107 
108 
109 /*
110  * A fatal error in a JNI call
111  */
112 jboolean JNIFatalError( JNIEnv *env, char *functName)
113 {
114 jmethodID jm;
115 jclass jc;
116 char * args[2];
117 jobject ex;
118 jstring str;
119 int rval;
120 
121  jc = (*env)->FindClass(env, "java/lang/InternalError");
122  if (jc == NULL) {
123  return JNI_FALSE;
124  }
125  jm = (*env)->GetMethodID(env, jc, "<init>", "(Ljava/lang/String;)V");
126  if (jm == NULL) {
127  return JNI_FALSE;
128  }
129 
130  str = (*env)->NewStringUTF(env,functName);
131  args[0] = (char *)str;
132  args[1] = 0;
133  ex = (*env)->NewObjectA ( env, jc, jm, (jvalue *)args );
134 
135  rval = (*env)->Throw(env, ex );
136 
137  return JNI_TRUE;
138 }
139 
140 jboolean raiseException( JNIEnv *env, char *message)
141 {
142 jmethodID jm;
143 jclass jc;
144 char * args[2];
145 jobject ex;
146 jstring str;
147 int rval;
148 
149  jc = (*env)->FindClass(env, "ncsa/hdf/hdflib/HDFLibraryException");
150  if (jc == NULL) {
151  return JNI_FALSE;
152  }
153  jm = (*env)->GetMethodID(env, jc, "<init>", "(Ljava/lang/String;)V");
154  if (jm == NULL) {
155  return JNI_FALSE;
156  }
157 
158  str = (*env)->NewStringUTF(env,message);
159  args[0] = (char *)str;
160  args[1] = 0;
161  ex = (*env)->NewObjectA ( env, jc, jm, (jvalue *)args );
162 
163  rval = (*env)->Throw(env, ex );
164 
165  return JNI_TRUE;
166 }