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