efbe31d3f00437c91d28e62aa289c7be6d80bb02
[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/llni.h"
39 #include "native/native.h"
40
41 #if defined(WITH_CLASSPATH_SUN)
42 # include "native/include/java_lang_String.h"           /* required by j.l.CL */
43 # include "native/include/java_nio_ByteBuffer.h"        /* required by j.l.CL */
44 # include "native/include/java_lang_ClassLoader.h"       /* required my j.l.C */
45 #endif
46
47 #include "native/include/java_lang_Object.h"             /* required my j.l.C */
48 #include "native/include/java_lang_Class.h"
49 #include "native/include/java_lang_String.h"
50
51 #include "native/include/java_lang_reflect_Constructor.h"
52
53 #include "native/vm/java_lang_reflect_Constructor.h"
54
55 #include "toolbox/logging.h"
56
57 #include "vm/builtin.h"
58 #include "vm/exceptions.h"
59 #include "vm/access.h"
60 #include "vm/stringlocal.h"
61
62 #include "vmcore/class.h"
63 #include "vmcore/method.h"
64
65
66 /*
67  * Class:     java/lang/reflect/Constructor
68  * Method:    getModifiers
69  * Signature: ()I
70  */
71 s4 _Jv_java_lang_reflect_Constructor_getModifiers(JNIEnv *env, java_lang_reflect_Constructor *this)
72 {
73         classinfo  *c;
74         methodinfo *m;
75         int32_t     slot;
76
77         LLNI_field_get_cls(this, clazz, c);
78         LLNI_field_get_val(this, slot , slot);
79         m = &(c->methods[slot]);
80
81         return m->flags;
82 }
83
84
85 /*
86  * Class:     java/lang/reflect/Constructor
87  * Method:    getParameterTypes
88  * Signature: ()[Ljava/lang/Class;
89  */
90 java_handle_objectarray_t *_Jv_java_lang_reflect_Constructor_getParameterTypes(JNIEnv *env, java_lang_reflect_Constructor *this)
91 {
92         classinfo  *c;
93         methodinfo *m;
94         int32_t     slot;
95
96         LLNI_field_get_cls(this, clazz, c);
97         LLNI_field_get_val(this, slot , slot);
98         m = &(c->methods[slot]);
99
100         return method_get_parametertypearray(m);
101 }
102
103
104 /*
105  * Class:     java/lang/reflect/Constructor
106  * Method:    getExceptionTypes
107  * Signature: ()[Ljava/lang/Class;
108  */
109 java_handle_objectarray_t *_Jv_java_lang_reflect_Constructor_getExceptionTypes(JNIEnv *env, java_lang_reflect_Constructor *this)
110 {
111         classinfo  *c;
112         methodinfo *m;
113         int32_t     slot;
114
115         LLNI_field_get_cls(this, clazz, c);
116         LLNI_field_get_val(this, slot , slot);
117         m = &(c->methods[slot]);
118
119         return method_get_exceptionarray(m);
120 }
121
122
123 /*
124  * Class:     java/lang/reflect/Constructor
125  * Method:    newInstance
126  * Signature: ([Ljava/lang/Object;)Ljava/lang/Object;
127  */
128 java_lang_Object *_Jv_java_lang_reflect_Constructor_newInstance(JNIEnv *env, java_lang_reflect_Constructor *this, java_handle_objectarray_t *args)
129 {
130         classinfo     *c;
131         methodinfo    *m;
132         s4             override;
133         java_handle_t *o;
134         int32_t        slot;
135
136         LLNI_field_get_cls(this, clazz, c);
137         LLNI_field_get_val(this, slot , slot);
138         m = &(c->methods[slot]);
139
140         /* check method access */
141
142         /* check if we should bypass security checks (AccessibleObject) */
143
144 #if defined(WITH_CLASSPATH_GNU)
145         LLNI_field_get_val(this, flag, override);
146 #elif defined(WITH_CLASSPATH_SUN)
147         LLNI_field_get_val(this, override, override);
148 #else
149 # error unknown classpath configuration
150 #endif
151
152         if (override == false) {
153                 if (!access_check_method(m, 1))
154                         return NULL;
155         }
156
157         /* create object */
158
159         o = builtin_new(c);
160
161         if (o == NULL)
162                 return NULL;
163         
164         /* call initializer */
165
166         (void) _Jv_jni_invokeNative(m, o, args);
167
168         return (java_lang_Object *) o;
169 }
170
171
172 /*
173  * Class:     java/lang/reflect/Constructor
174  * Method:    getSignature
175  * Signature: ()Ljava/lang/String;
176  */
177 java_lang_String *_Jv_java_lang_reflect_Constructor_getSignature(JNIEnv *env, java_lang_reflect_Constructor *this)
178 {
179         classinfo     *c;
180         methodinfo    *m;
181         java_handle_t *o;
182         int32_t        slot;
183
184         LLNI_field_get_cls(this, clazz, c);
185         LLNI_field_get_val(this, slot , slot);
186         m = &(c->methods[slot]);
187
188         if (m->signature == NULL)
189                 return NULL;
190
191         o = javastring_new(m->signature);
192
193         /* in error case o is NULL */
194
195         return (java_lang_String *) o;
196 }
197
198
199 /*
200  * These are local overrides for various environment variables in Emacs.
201  * Please do not remove this and leave it at the end of the file, where
202  * Emacs will automagically detect them.
203  * ---------------------------------------------------------------------
204  * Local variables:
205  * mode: c
206  * indent-tabs-mode: t
207  * c-basic-offset: 4
208  * tab-width: 4
209  * End:
210  */