* src/native/jni.h: Removed.
[cacao.git] / src / native / vm / gnuclasspath / gnu_classpath_VMSystemProperties.cpp
1 /* src/native/vm/gnuclasspath/gnu_classpath_VMSystemProperties.cpp
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "vm/types.h"
32
33 #include "mm/memory.h"
34
35 #include "native/jni.hpp"
36 #include "native/native.h"
37
38 #if defined(ENABLE_JNI_HEADERS)
39 # include "native/include/gnu_classpath_VMSystemProperties.h"
40 #endif
41
42 #include "vm/exceptions.hpp"
43 #include "vm/properties.h"
44 #include "vm/vm.hpp"
45
46
47 // Native functions are exported as C functions.
48 extern "C" {
49
50 /*
51  * Class:     gnu/classpath/VMSystemProperties
52  * Method:    preInit
53  * Signature: (Ljava/util/Properties;)V
54  */
55 JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_preInit(JNIEnv *env, jclass clazz, jobject properties)
56 {
57         java_handle_t *p;
58
59         p = (java_handle_t *) properties;
60
61         if (p == NULL) {
62                 exceptions_throw_nullpointerexception();
63                 return;
64         }
65
66         /* fill the java.util.Properties object */
67
68         properties_system_add_all(p);
69 }
70
71
72 /*
73  * Class:     gnu/classpath/VMSystemProperties
74  * Method:    postInit
75  * Signature: (Ljava/util/Properties;)V
76  */
77 JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_postInit(JNIEnv *env, jclass clazz, jobject properties)
78 {
79         java_handle_t *p;
80 #if defined(ENABLE_JRE_LAYOUT)
81         const char *java_home;
82         char *path;
83         s4    len;
84 #endif
85
86         p = (java_handle_t *) properties;
87
88         if (p == NULL) {
89                 exceptions_throw_nullpointerexception();
90                 return;
91         }
92
93         /* post-set some properties */
94
95 #if defined(ENABLE_JRE_LAYOUT)
96         /* XXX when we do it that way, we can't set these properties on
97            commandline */
98
99         java_home = properties_get("java.home");
100
101         properties_system_add(p, "gnu.classpath.home", java_home);
102
103         len =
104                 strlen("file://") +
105                 strlen(java_home) +
106                 strlen("/lib") +
107                 strlen("0");
108
109         path = MNEW(char, len);
110
111         strcpy(path, "file://");
112         strcat(path, java_home);
113         strcat(path, "/lib");
114
115         properties_system_add(p, "gnu.classpath.home.url", path);
116
117         MFREE(path, char, len);
118 #endif
119 }
120
121 } // extern "C"
122
123
124 /* native methods implemented by this file ************************************/
125
126 static JNINativeMethod methods[] = {
127         { (char*) "preInit",  (char*) "(Ljava/util/Properties;)V", (void*) (uintptr_t) &Java_gnu_classpath_VMSystemProperties_preInit  },
128         { (char*) "postInit", (char*) "(Ljava/util/Properties;)V", (void*) (uintptr_t) &Java_gnu_classpath_VMSystemProperties_postInit },
129 };
130
131
132 /* _Jv_gnu_classpat_VMSystemProperties_init ************************************
133
134    Register native functions.
135
136 *******************************************************************************/
137
138 // FIXME
139 extern "C" {
140 void _Jv_gnu_classpath_VMSystemProperties_init(void)
141 {
142         utf *u;
143
144         u = utf_new_char("gnu/classpath/VMSystemProperties");
145
146         native_method_register(u, methods, NATIVE_METHODS_COUNT);
147 }
148 }
149
150
151 /*
152  * These are local overrides for various environment variables in Emacs.
153  * Please do not remove this and leave it at the end of the file, where
154  * Emacs will automagically detect them.
155  * ---------------------------------------------------------------------
156  * Local variables:
157  * mode: c++
158  * indent-tabs-mode: t
159  * c-basic-offset: 4
160  * tab-width: 4
161  * End:
162  */