1 /* src/native/vm/cldc1.1/java_lang_Class.cpp
3 Copyright (C) 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 #include "native/jni.hpp"
31 #include "native/llni.h"
32 #include "native/native.h"
34 #if defined(ENABLE_JNI_HEADERS)
35 # include "native/include/java_lang_Class.h"
38 #include "vm/exceptions.hpp"
39 #include "vm/initialize.h"
42 // Native functions are exported as C functions.
46 * Class: java/lang/Class
48 * Signature: (Ljava/lang/String;)Ljava/lang/Class;
50 JNIEXPORT jclass JNICALL Java_java_lang_Class_forName(JNIEnv *env, jclass clazz, jstring name)
58 /* illegal argument */
61 exceptions_throw_nullpointerexception();
65 /* create utf string in which '.' is replaced by '/' */
67 ufile = javastring_toutf((java_handle_t *) name, true);
68 uname = javastring_toutf((java_handle_t *) name, false);
70 /* name must not contain '/' (mauve test) */
72 // FIXME Move this check into a function.
73 for (i = 0, pos = uname->text; i < uname->blength; i++, pos++) {
75 exceptions_throw_classnotfoundexception(uname);
80 /* try to load, ... */
82 c = load_class_bootstrap(ufile);
92 /* ...and initialize it. */
94 if (!initialize_class(c))
97 return (jclass) LLNI_classinfo_wrap(c);
102 * Class: java/lang/Class
103 * Method: newInstance
104 * Signature: ()Ljava/lang/Object;
106 JNIEXPORT jobject JNICALL Java_java_lang_Class_newInstance(JNIEnv *env, jclass _this)
111 c = LLNI_classinfo_unwrap(_this);
113 o = native_new_and_init(c);
120 * Class: java/lang/Class
122 * Signature: (Ljava/lang/Object;)Z
124 JNIEXPORT jboolean JNICALL Java_java_lang_Class_isInstance(JNIEnv *env, jclass _this, jobject obj)
129 c = LLNI_classinfo_unwrap(_this);
130 h = (java_handle_t *) obj;
132 return class_is_instance(c, h);
137 * Class: java/lang/Class
138 * Method: isAssignableFrom
139 * Signature: (Ljava/lang/Class;)Z
141 JNIEXPORT jboolean JNICALL Java_java_lang_Class_isAssignableFrom(JNIEnv *env, jclass _this, jclass cls)
146 to = LLNI_classinfo_unwrap(_this);
147 from = LLNI_classinfo_unwrap(cls);
150 exceptions_throw_nullpointerexception();
154 return class_is_assignable_from(to, from);
159 * Class: java/lang/Class
160 * Method: isInterface
163 JNIEXPORT jboolean JNICALL Java_java_lang_Class_isInterface(JNIEnv *env, jclass _this)
167 c = LLNI_classinfo_unwrap(_this);
169 return class_is_interface(c);
174 * Class: java/lang/Class
178 JNIEXPORT jboolean JNICALL Java_java_lang_Class_isArray(JNIEnv *env, jclass _this)
182 c = LLNI_classinfo_unwrap(_this);
184 return class_is_array(c);
189 * Class: java/lang/Class
191 * Signature: ()Ljava/lang/String;
193 JNIEXPORT jstring JNICALL Java_java_lang_Class_getName(JNIEnv *env, jclass _this)
197 c = LLNI_classinfo_unwrap(_this);
199 return (jstring) class_get_classname(c);
205 /* native methods implemented by this file ************************************/
207 static JNINativeMethod methods[] = {
208 { (char*) "forName", (char*) "(Ljava/lang/String;)Ljava/lang/Class;",(void*) (uintptr_t) &Java_java_lang_Class_forName },
209 { (char*) "newInstance", (char*) "()Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_Class_newInstance },
210 { (char*) "isInstance", (char*) "(Ljava/lang/Object;)Z", (void*) (uintptr_t) &Java_java_lang_Class_isInstance },
211 { (char*) "isAssignableFrom", (char*) "(Ljava/lang/Class;)Z", (void*) (uintptr_t) &Java_java_lang_Class_isAssignableFrom },
212 { (char*) "isInterface", (char*) "()Z", (void*) (uintptr_t) &Java_java_lang_Class_isInterface },
213 { (char*) "isArray", (char*) "()Z", (void*) (uintptr_t) &Java_java_lang_Class_isArray },
214 { (char*) "getName", (char*) "()Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_Class_getName },
217 /* _Jv_java_lang_Class_init ****************************************************
219 Register native functions.
221 *******************************************************************************/
225 void _Jv_java_lang_Class_init(void)
229 u = utf_new_char("java/lang/Class");
231 native_method_register(u, methods, NATIVE_METHODS_COUNT);
237 * These are local overrides for various environment variables in Emacs.
238 * Please do not remove this and leave it at the end of the file, where
239 * Emacs will automagically detect them.
240 * ---------------------------------------------------------------------
243 * indent-tabs-mode: t
247 * vim:noexpandtab:sw=4:ts=4: