dc4e5ebb04726356aa8a571c0f3b228669a116b9
[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.hpp"
34
35 #include "native/jni.hpp"
36 #include "native/native.hpp"
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.hpp"
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         VM::get_current()->get_properties().fill(p);
68 }
69
70
71 /*
72  * Class:     gnu/classpath/VMSystemProperties
73  * Method:    postInit
74  * Signature: (Ljava/util/Properties;)V
75  */
76 JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_postInit(JNIEnv *env, jclass clazz, jobject properties)
77 {
78         java_handle_t *p;
79 #if defined(ENABLE_JRE_LAYOUT)
80         const char *java_home;
81         char *path;
82         s4    len;
83 #endif
84
85         p = (java_handle_t *) properties;
86
87         if (p == NULL) {
88                 exceptions_throw_nullpointerexception();
89                 return;
90         }
91
92         /* post-set some properties */
93
94 #if defined(ENABLE_JRE_LAYOUT)
95         /* XXX when we do it that way, we can't set these properties on
96            commandline */
97
98         java_home = VM::get_current()->get_properties().get("java.home");
99
100         Properties::put(p, "gnu.classpath.home", java_home);
101
102         len =
103                 strlen("file://") +
104                 strlen(java_home) +
105                 strlen("/lib") +
106                 strlen("0");
107
108         path = MNEW(char, len);
109
110         strcpy(path, "file://");
111         strcat(path, java_home);
112         strcat(path, "/lib");
113
114         Properties::put(p, "gnu.classpath.home.url", path);
115
116         MFREE(path, char, len);
117 #endif
118 }
119
120 } // extern "C"
121
122
123 /* native methods implemented by this file ************************************/
124
125 static JNINativeMethod methods[] = {
126         { (char*) "preInit",  (char*) "(Ljava/util/Properties;)V", (void*) (uintptr_t) &Java_gnu_classpath_VMSystemProperties_preInit  },
127         { (char*) "postInit", (char*) "(Ljava/util/Properties;)V", (void*) (uintptr_t) &Java_gnu_classpath_VMSystemProperties_postInit },
128 };
129
130
131 /* _Jv_gnu_classpat_VMSystemProperties_init ************************************
132
133    Register native functions.
134
135 *******************************************************************************/
136
137 void _Jv_gnu_classpath_VMSystemProperties_init(void)
138 {
139         utf* u = utf_new_char("gnu/classpath/VMSystemProperties");
140
141         NativeMethods& nm = VM::get_current()->get_nativemethods();
142         nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
143 }
144
145
146 /*
147  * These are local overrides for various environment variables in Emacs.
148  * Please do not remove this and leave it at the end of the file, where
149  * Emacs will automagically detect them.
150  * ---------------------------------------------------------------------
151  * Local variables:
152  * mode: c++
153  * indent-tabs-mode: t
154  * c-basic-offset: 4
155  * tab-width: 4
156  * End:
157  */