Merged revisions 7797-7917 via svnmerge from
[cacao.git] / src / native / vm / gnu / java_lang_reflect_Constructor.c
1 /* src/native/vm/gnu/java_lang_reflect_Constructor.c
2
3    Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    $Id: java_lang_reflect_Constructor.c 7912 2007-05-18 13:12:09Z twisti $
26
27 */
28
29
30 #include "config.h"
31
32 #include <assert.h>
33 #include <stdlib.h>
34
35 #include "vm/types.h"
36
37 #include "native/jni.h"
38 #include "native/native.h"
39
40 #include "native/include/java_lang_Class.h"
41 #include "native/include/java_lang_Object.h"
42 #include "native/include/java_lang_String.h"
43
44 #include "native/include/java_lang_reflect_Constructor.h"
45
46 #include "toolbox/logging.h"
47
48 #include "vm/builtin.h"
49 #include "vm/exceptions.h"
50 #include "vm/access.h"
51 #include "vm/stringlocal.h"
52
53 #include "vmcore/class.h"
54 #include "vmcore/method.h"
55
56
57 /* native methods implemented by this file ************************************/
58
59 static JNINativeMethod methods[] = {
60         { "getModifiersInternal", "()I",                                                       (void *) (ptrint) &Java_java_lang_reflect_Constructor_getModifiersInternal },
61         { "getParameterTypes",    "()[Ljava/lang/Class;",                                      (void *) (ptrint) &Java_java_lang_reflect_Constructor_getParameterTypes    },
62         { "getExceptionTypes",    "()[Ljava/lang/Class;",                                      (void *) (ptrint) &Java_java_lang_reflect_Constructor_getExceptionTypes    },
63         { "constructNative",      "([Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;", (void *) (ptrint) &Java_java_lang_reflect_Constructor_constructNative      },
64         { "getSignature",         "()Ljava/lang/String;",                                      (void *) (ptrint) &Java_java_lang_reflect_Constructor_getSignature         },
65 };
66
67
68 /* _Jv_java_lang_reflect_Constructor_init **************************************
69
70    Register native functions.
71
72 *******************************************************************************/
73
74 void _Jv_java_lang_reflect_Constructor_init(void)
75 {
76         utf *u;
77
78         u = utf_new_char("java/lang/reflect/Constructor");
79
80         native_method_register(u, methods, NATIVE_METHODS_COUNT);
81 }
82
83
84 /*
85  * Class:     java/lang/reflect/Constructor
86  * Method:    getModifiersInternal
87  * Signature: ()I
88  */
89 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Constructor_getModifiersInternal(JNIEnv *env, java_lang_reflect_Constructor *this)
90 {
91         classinfo  *c;
92         methodinfo *m;
93
94         c = (classinfo *) (this->clazz);
95         m = &(c->methods[this->slot]);
96
97         return m->flags;
98 }
99
100
101 /*
102  * Class:     java/lang/reflect/Constructor
103  * Method:    getParameterTypes
104  * Signature: ()[Ljava/lang/Class;
105  */
106 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Constructor_getParameterTypes(JNIEnv *env, java_lang_reflect_Constructor *this)
107 {
108         classinfo  *c;
109         methodinfo *m;
110
111         c = (classinfo *) this->clazz;
112         m = &(c->methods[this->slot]);
113
114         return method_get_parametertypearray(m);
115 }
116
117
118 /*
119  * Class:     java/lang/reflect/Constructor
120  * Method:    getExceptionTypes
121  * Signature: ()[Ljava/lang/Class;
122  */
123 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Constructor_getExceptionTypes(JNIEnv *env, java_lang_reflect_Constructor *this)
124 {
125         classinfo  *c;
126         methodinfo *m;
127
128         c = (classinfo *) this->clazz;
129         m = &(c->methods[this->slot]);
130
131         return method_get_exceptionarray(m);
132 }
133
134
135 /*
136  * Class:     java/lang/reflect/Constructor
137  * Method:    constructNative
138  * Signature: ([Ljava/lang/Object;Ljava/lang/Class;I)Ljava/lang/Object;
139  */
140 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_reflect_Constructor_constructNative(JNIEnv *env, java_lang_reflect_Constructor *this, java_objectarray *args, java_lang_Class *declaringClass, s4 slot)
141 {
142         classinfo         *c;
143         methodinfo        *m;
144         java_objectheader *o;
145
146         c = (classinfo *) declaringClass;
147         m = &(c->methods[this->slot]);
148
149         /* check method access */
150
151         /* check if we should bypass security checks (AccessibleObject) */
152
153         if (this->flag == false) {
154                 if (!access_check_member(c, m->flags, 1))
155                         return NULL;
156         }
157
158         /* create object */
159
160         o = builtin_new(c);
161
162         if (o == NULL)
163                 return NULL;
164         
165         /* call initializer */
166
167         (void) _Jv_jni_invokeNative(m, o, args);
168
169         return (java_lang_Object *) o;
170 }
171
172
173 /*
174  * Class:     java/lang/reflect/Constructor
175  * Method:    getSignature
176  * Signature: ()Ljava/lang/String;
177  */
178 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Constructor_getSignature(JNIEnv *env, java_lang_reflect_Constructor *this)
179 {
180         classinfo         *c;
181         methodinfo        *m;
182         java_objectheader *o;
183
184         c = (classinfo *) this->clazz;
185         m = &(c->methods[this->slot]);
186
187         if (m->signature == NULL)
188                 return NULL;
189
190         o = javastring_new(m->signature);
191
192         /* in error case o is NULL */
193
194         return (java_lang_String *) o;
195 }
196
197
198 /*
199  * These are local overrides for various environment variables in Emacs.
200  * Please do not remove this and leave it at the end of the file, where
201  * Emacs will automagically detect them.
202  * ---------------------------------------------------------------------
203  * Local variables:
204  * mode: c
205  * indent-tabs-mode: t
206  * c-basic-offset: 4
207  * tab-width: 4
208  * End:
209  */