* src/toolbox/sequence.hpp: Added new file to hold sequence builder class.
[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 "toolbox/sequence.hpp"
43
44 #include "vm/exceptions.hpp"
45 #include "vm/properties.hpp"
46 #include "vm/vm.hpp"
47
48
49 // Native functions are exported as C functions.
50 extern "C" {
51
52 /*
53  * Class:     gnu/classpath/VMSystemProperties
54  * Method:    preInit
55  * Signature: (Ljava/util/Properties;)V
56  */
57 JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_preInit(JNIEnv *env, jclass clazz, jobject properties)
58 {
59         java_handle_t *p;
60
61         p = (java_handle_t *) properties;
62
63         if (p == NULL) {
64                 exceptions_throw_nullpointerexception();
65                 return;
66         }
67
68         // Fill the java.util.Properties object.
69         VM::get_current()->get_properties().fill(p);
70 }
71
72
73 /*
74  * Class:     gnu/classpath/VMSystemProperties
75  * Method:    postInit
76  * Signature: (Ljava/util/Properties;)V
77  */
78 JNIEXPORT void JNICALL Java_gnu_classpath_VMSystemProperties_postInit(JNIEnv *env, jclass clazz, jobject properties)
79 {
80         java_handle_t *p;
81 #if defined(ENABLE_JRE_LAYOUT)
82         const char *java_home;
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         // Use sequence builder to assemble value.
103         SequenceBuilder sb;
104
105         sb.cat("file://");
106         sb.cat(java_home);
107         sb.cat("/lib");
108
109         Properties::put(p, "gnu.classpath.home.url", sb.c_str());
110 #endif
111 }
112
113 } // extern "C"
114
115
116 /* native methods implemented by this file ************************************/
117
118 static JNINativeMethod methods[] = {
119         { (char*) "preInit",  (char*) "(Ljava/util/Properties;)V", (void*) (uintptr_t) &Java_gnu_classpath_VMSystemProperties_preInit  },
120         { (char*) "postInit", (char*) "(Ljava/util/Properties;)V", (void*) (uintptr_t) &Java_gnu_classpath_VMSystemProperties_postInit },
121 };
122
123
124 /* _Jv_gnu_classpat_VMSystemProperties_init ************************************
125
126    Register native functions.
127
128 *******************************************************************************/
129
130 void _Jv_gnu_classpath_VMSystemProperties_init(void)
131 {
132         utf* u = utf_new_char("gnu/classpath/VMSystemProperties");
133
134         NativeMethods& nm = VM::get_current()->get_nativemethods();
135         nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
136 }
137
138
139 /*
140  * These are local overrides for various environment variables in Emacs.
141  * Please do not remove this and leave it at the end of the file, where
142  * Emacs will automagically detect them.
143  * ---------------------------------------------------------------------
144  * Local variables:
145  * mode: c++
146  * indent-tabs-mode: t
147  * c-basic-offset: 4
148  * tab-width: 4
149  * End:
150  */