f13cde7e5d6da5eb8384dace83899e99988ce233
[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 7720 2007-04-16 15:49: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 #include "native/include/java_lang_Class.h"
40 #include "native/include/java_lang_Object.h"
41 #include "native/include/java_lang_String.h"
42 #include "native/include/java_lang_reflect_Constructor.h"
43
44 #include "toolbox/logging.h"
45
46 #include "vm/builtin.h"
47 #include "vm/exceptions.h"
48 #include "vm/access.h"
49 #include "vm/stringlocal.h"
50
51 #include "vmcore/class.h"
52 #include "vmcore/method.h"
53
54
55 /*
56  * Class:     java/lang/reflect/Constructor
57  * Method:    getModifiersInternal
58  * Signature: ()I
59  */
60 JNIEXPORT s4 JNICALL Java_java_lang_reflect_Constructor_getModifiersInternal(JNIEnv *env, java_lang_reflect_Constructor *this)
61 {
62         classinfo  *c;
63         methodinfo *m;
64
65         c = (classinfo *) (this->clazz);
66         m = &(c->methods[this->slot]);
67
68         return m->flags;
69 }
70
71
72 /*
73  * Class:     java/lang/reflect/Constructor
74  * Method:    getParameterTypes
75  * Signature: ()[Ljava/lang/Class;
76  */
77 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Constructor_getParameterTypes(JNIEnv *env, java_lang_reflect_Constructor *this)
78 {
79         classinfo  *c;
80         methodinfo *m;
81
82         c = (classinfo *) this->clazz;
83         m = &(c->methods[this->slot]);
84
85         return method_get_parametertypearray(m);
86 }
87
88
89 /*
90  * Class:     java/lang/reflect/Constructor
91  * Method:    getExceptionTypes
92  * Signature: ()[Ljava/lang/Class;
93  */
94 JNIEXPORT java_objectarray* JNICALL Java_java_lang_reflect_Constructor_getExceptionTypes(JNIEnv *env, java_lang_reflect_Constructor *this)
95 {
96         classinfo  *c;
97         methodinfo *m;
98
99         c = (classinfo *) this->clazz;
100         m = &(c->methods[this->slot]);
101
102         return method_get_exceptionarray(m);
103 }
104
105
106 /*
107  * Class:     java/lang/reflect/Constructor
108  * Method:    constructNative
109  * Signature: ([Ljava/lang/Object;)Ljava/lang/Object;
110  */
111 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)
112 {
113         classinfo         *c;
114         methodinfo        *m;
115         java_objectheader *o;
116
117         c = (classinfo *) declaringClass;
118         m = &(c->methods[this->slot]);
119
120         /* check method access */
121
122         /* check if we should bypass security checks (AccessibleObject) */
123
124         if (this->flag == false) {
125                 if (!access_check_member(c, m->flags, 1))
126                         return NULL;
127         }
128
129         /* create object */
130
131         o = builtin_new(c);
132
133         if (o == NULL)
134                 return NULL;
135         
136         /* call initializer */
137
138         (void) _Jv_jni_invokeNative(m, o, args);
139
140         return (java_lang_Object *) o;
141 }
142
143
144 /*
145  * Class:     java/lang/reflect/Constructor
146  * Method:    getSignature
147  * Signature: ()Ljava/lang/String;
148  */
149 JNIEXPORT java_lang_String* JNICALL Java_java_lang_reflect_Constructor_getSignature(JNIEnv *env, java_lang_reflect_Constructor *this)
150 {
151         classinfo         *c;
152         methodinfo        *m;
153         java_objectheader *o;
154
155         c = (classinfo *) this->clazz;
156         m = &(c->methods[this->slot]);
157
158         if (m->signature == NULL)
159                 return NULL;
160
161         o = javastring_new(m->signature);
162
163         /* in error case o is NULL */
164
165         return (java_lang_String *) o;
166 }
167
168
169 /*
170  * These are local overrides for various environment variables in Emacs.
171  * Please do not remove this and leave it at the end of the file, where
172  * Emacs will automagically detect them.
173  * ---------------------------------------------------------------------
174  * Local variables:
175  * mode: c
176  * indent-tabs-mode: t
177  * c-basic-offset: 4
178  * tab-width: 4
179  * End:
180  */