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