1 // natConstructor.cc - Native code for Constructor class.
2 
3 /* Copyright (C) 1999, 2000, 2001, 2002, 2003  Free Software Foundation
4 
5    This file is part of libgcj.
6 
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9 details.  */
10 
11 #include <config.h>
12 
13 #include <gcj/cni.h>
14 #include <jvm.h>
15 
16 #include <java/lang/ArrayIndexOutOfBoundsException.h>
17 #include <java/lang/IllegalAccessException.h>
18 #include <java/lang/reflect/Constructor.h>
19 #include <java/lang/reflect/Method.h>
20 #include <java/lang/reflect/InvocationTargetException.h>
21 #include <java/lang/reflect/Modifier.h>
22 #include <java/lang/InstantiationException.h>
23 #include <gcj/method.h>
24 
25 jint
getModifiers()26 java::lang::reflect::Constructor::getModifiers ()
27 {
28   // Ignore all unknown flags.
29   return _Jv_FromReflectedConstructor (this)->accflags & Modifier::ALL_FLAGS;
30 }
31 
32 void
getType()33 java::lang::reflect::Constructor::getType ()
34 {
35   _Jv_GetTypesFromSignature (_Jv_FromReflectedConstructor (this),
36 			     declaringClass,
37 			     &parameter_types,
38 			     NULL);
39 
40   // FIXME: for now we have no way to get exception information.
41   exception_types =
42     (JArray<jclass> *) JvNewObjectArray (0, &java::lang::Class::class$, NULL);
43 }
44 
45 jobject
newInstance(jobjectArray args)46 java::lang::reflect::Constructor::newInstance (jobjectArray args)
47 {
48   using namespace java::lang::reflect;
49 
50   if (parameter_types == NULL)
51     getType ();
52 
53   jmethodID meth = _Jv_FromReflectedConstructor (this);
54 
55   // Check accessibility, if required.
56   if (! (Modifier::isPublic (meth->accflags) || this->isAccessible()))
57     {
58       gnu::gcj::runtime::StackTrace *t
59 	= new gnu::gcj::runtime::StackTrace(4);
60       Class *caller = NULL;
61       try
62 	{
63 	  for (int i = 1; !caller; i++)
64 	    {
65 	      caller = t->classAt (i);
66 	    }
67 	}
68       catch (::java::lang::ArrayIndexOutOfBoundsException *e)
69 	{
70 	}
71 
72       if (! _Jv_CheckAccess(caller, declaringClass, meth->accflags))
73 	throw new IllegalAccessException;
74     }
75 
76   if (Modifier::isAbstract (declaringClass->getModifiers()))
77     throw new InstantiationException;
78 
79   _Jv_InitClass (declaringClass);
80 
81   // In the constructor case the return type is the type of the
82   // constructor.
83   return _Jv_CallAnyMethodA (NULL, declaringClass, meth, true,
84 			     parameter_types, args);
85 }
86