1 /* src/native/vm/cldc1.1/java_lang_Class.c
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
29 #include "native/jni.h"
30 #include "native/llni.h"
31 #include "native/native.h"
33 #include "native/include/java_lang_String.h" /* required by j.l.C */
34 #include "native/include/java_lang_Object.h"
36 #include "native/include/java_lang_Class.h"
38 #include "vm/exceptions.h"
39 #include "vm/initialize.h"
42 /* native methods implemented by this file ************************************/
44 static JNINativeMethod methods[] = {
45 { "forName", "(Ljava/lang/String;)Ljava/lang/Class;",(void *) (ptrint) &Java_java_lang_Class_forName },
46 { "newInstance", "()Ljava/lang/Object;", (void *) (ptrint) &Java_java_lang_Class_newInstance },
47 { "isInstance", "(Ljava/lang/Object;)Z", (void *) (ptrint) &Java_java_lang_Class_isInstance },
48 { "isAssignableFrom", "(Ljava/lang/Class;)Z", (void *) (ptrint) &Java_java_lang_Class_isAssignableFrom },
49 { "isInterface", "()Z", (void *) (ptrint) &Java_java_lang_Class_isInterface },
50 { "isArray", "()Z", (void *) (ptrint) &Java_java_lang_Class_isArray },
51 { "getName", "()Ljava/lang/String;", (void *) (ptrint) &Java_java_lang_Class_getName },
54 /* _Jv_java_lang_Class_init ****************************************************
56 Register native functions.
58 *******************************************************************************/
60 void _Jv_java_lang_Class_init(void)
64 u = utf_new_char("java/lang/Class");
66 native_method_register(u, methods, NATIVE_METHODS_COUNT);
71 * Class: java/lang/Class
73 * Signature: (Ljava/lang/String;)Ljava/lang/Class;
75 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_Class_forName(JNIEnv *env, jclass clazz, java_lang_String *name)
83 /* illegal argument */
86 exceptions_throw_nullpointerexception();
90 /* create utf string in which '.' is replaced by '/' */
92 ufile = javastring_toutf((java_handle_t *) name, true);
93 uname = javastring_toutf((java_handle_t *) name, false);
95 /* name must not contain '/' (mauve test) */
97 for (i = 0, pos = LLNI_field_direct(name, value)->data + LLNI_field_direct(name, offset); i < LLNI_field_direct(name, count); i++, pos++) {
99 exceptions_throw_classnotfoundexception(uname);
104 /* try to load, ... */
106 c = load_class_bootstrap(ufile);
116 /* ...and initialize it. */
118 if (!initialize_class(c))
121 return LLNI_classinfo_wrap(c);
126 * Class: java/lang/Class
127 * Method: newInstance
128 * Signature: ()Ljava/lang/Object;
130 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_Class_newInstance(JNIEnv *env, java_lang_Class* this)
135 c = LLNI_classinfo_unwrap(this);
137 o = native_new_and_init(c);
139 return (java_lang_Object *) o;
144 * Class: java/lang/Class
146 * Signature: (Ljava/lang/Object;)Z
148 JNIEXPORT int32_t JNICALL Java_java_lang_Class_isInstance(JNIEnv *env, java_lang_Class *this, java_lang_Object *obj)
153 c = LLNI_classinfo_unwrap(this);
154 h = (java_handle_t *) obj;
156 return class_is_instance(c, h);
161 * Class: java/lang/Class
162 * Method: isAssignableFrom
163 * Signature: (Ljava/lang/Class;)Z
165 JNIEXPORT int32_t JNICALL Java_java_lang_Class_isAssignableFrom(JNIEnv *env, java_lang_Class *this, java_lang_Class *cls)
170 to = LLNI_classinfo_unwrap(this);
171 from = LLNI_classinfo_unwrap(cls);
174 exceptions_throw_nullpointerexception();
178 return class_is_assignable_from(to, from);
183 * Class: java/lang/Class
184 * Method: isInterface
187 JNIEXPORT int32_t JNICALL Java_java_lang_Class_isInterface(JNIEnv *env, java_lang_Class *this)
191 c = LLNI_classinfo_unwrap(this);
193 return class_is_interface(c);
198 * Class: java/lang/Class
202 JNIEXPORT int32_t JNICALL Java_java_lang_Class_isArray(JNIEnv *env, java_lang_Class *this)
206 c = LLNI_classinfo_unwrap(this);
208 return class_is_array(c);
213 * Class: java/lang/Class
215 * Signature: ()Ljava/lang/String;
217 JNIEXPORT java_lang_String* JNICALL Java_java_lang_Class_getName(JNIEnv *env, java_lang_Class *this)
221 c = LLNI_classinfo_unwrap(this);
223 return (java_lang_String*) class_get_classname(c);
228 * These are local overrides for various environment variables in Emacs.
229 * Please do not remove this and leave it at the end of the file, where
230 * Emacs will automagically detect them.
231 * ---------------------------------------------------------------------
234 * indent-tabs-mode: t
238 * vim:noexpandtab:sw=4:ts=4: