* src/vm/jit/parse.c (parse_realloc_instructions): Renamed ipc to
[cacao.git] / src / vm / properties.c
index 69582ec24cc3903f92d50ed9f94b972159da4c5e..25301d77c3ec1e43b9582c095f534cdb31a38f87 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vm/properties.c - handling commandline properties
 
-   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
    J. Wenninger, Institut f. Computersprachen - TU Wien
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Contact: cacao@cacaojvm.org
-
-   Authors: Christian Thalinger
-
-   $Id: properties.c 5991 2006-11-15 18:26:40Z twisti $
+   $Id: properties.c 7257 2007-01-29 23:07:40Z twisti $
 
 */
 
 
 #include "mm/memory.h"
 
-#include "vm/global.h"
+#include "native/jni.h"
+
+#include "vm/global.h"                      /* required by java_lang_String.h */
 #include "native/include/java_lang_String.h"
-#include "native/include/java_util_Properties.h"
+
 #include "toolbox/list.h"
 #include "toolbox/util.h"
-#include "vm/method.h"
-#include "vm/options.h"
+
 #include "vm/properties.h"
 #include "vm/stringlocal.h"
 #include "vm/vm.h"
+
 #include "vm/jit/asmpart.h"
 
+#include "vmcore/method.h"
+#include "vmcore/options.h"
+
 
 /* internal property structure ************************************************/
 
@@ -139,7 +140,7 @@ bool properties_init(void)
        properties_add("java.vm.version", VERSION);
        properties_add("java.vm.vendor", "CACAO Team");
        properties_add("java.vm.name", "CACAO");
-       properties_add("java.specification.version", "1.4");
+       properties_add("java.specification.version", "1.5");
        properties_add("java.specification.vendor", "Sun Microsystems Inc.");
        properties_add("java.specification.name", "Java Platform API Specification");
        properties_add("java.class.version", CLASS_VERSION);
@@ -279,8 +280,8 @@ bool properties_init(void)
        }
 #elif defined(ENABLE_JAVAME_CLDC1_1)
     properties_add("microedition.configuration", "CLDC-1.1");
-    properties_add("microedition.platform", "PowerPC");
-    properties_add("microedition.encoding", "ISO-8859-1");
+    properties_add("microedition.platform", "generic");
+    properties_add("microedition.encoding", "ISO8859_1");
     properties_add("microedition.profiles", "");
 #else
 #error unknown Java configuration
@@ -315,20 +316,36 @@ bool properties_postinit(void)
 
 /* properties_add **************************************************************
 
-   Adds a property entry to the internal property list.
+   Adds a property entry to the internal property list.  If there's
+   already an entry with the same key, replace it.
 
 *******************************************************************************/
 
 void properties_add(char *key, char *value)
 {
-       list_properties_entry *p;
+       list_properties_entry *pe;
 
-       p = NEW(list_properties_entry);
+       /* search for the entry */
 
-       p->key   = key;
-       p->value = value;
+       for (pe = list_first_unsynced(list_properties); pe != NULL;
+                pe = list_next_unsynced(list_properties, pe)) {
+               if (strcmp(pe->key, key) == 0) {
+                       /* entry was found, replace the value */
 
-       list_add_last_unsynced(list_properties, p);
+                       pe->value = value;
+
+                       return;
+               }
+       }
+
+       /* entry was not found, insert a new one */
+
+       pe = NEW(list_properties_entry);
+
+       pe->key   = key;
+       pe->value = value;
+
+       list_add_last_unsynced(list_properties, pe);
 }
 
 
@@ -342,11 +359,8 @@ char *properties_get(char *key)
 {
        list_properties_entry *pe;
 
-       /* We search backwards, so we get the newest entry for a key, as
-          the list may contain more than one entry for a specific key. */
-
-       for (pe = list_last(list_properties); pe != NULL;
-                pe = list_prev(list_properties, pe)) {
+       for (pe = list_first_unsynced(list_properties); pe != NULL;
+                pe = list_next_unsynced(list_properties, pe)) {
                if (strcmp(pe->key, key) == 0)
                        return pe->value;
        }
@@ -355,25 +369,60 @@ char *properties_get(char *key)
 }
 
 
+/* properties_system_add *******************************************************
+
+   Adds a given property to the Java system properties.
+
+*******************************************************************************/
+
+void properties_system_add(java_objectheader *p, char *key, char *value)
+{
+       methodinfo        *m;
+       java_objectheader *k;
+       java_objectheader *v;
+
+       /* search for method to add properties */
+
+       m = class_resolveclassmethod(p->vftbl->class,
+                                                                utf_put,
+                                                                utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"),
+                                                                NULL,
+                                                                true);
+
+       if (m == NULL)
+               return;
+
+       /* add to the Java system properties */
+
+       k = javastring_new_from_utf_string(key);
+       v = javastring_new_from_utf_string(value);
+
+       (void) vm_call_method(m, p, k, v);
+}
+
+
 /* properties_system_add_all ***************************************************
 
    Adds all properties from the properties list to the Java system
    properties.
 
+   ARGUMENTS:
+       p.... is actually a java_util_Properties structure
+
 *******************************************************************************/
 
 #if defined(ENABLE_JAVASE)
-void properties_system_add_all(java_util_Properties *p)
+void properties_system_add_all(java_objectheader *p)
 {
        list_properties_entry *pe;
        methodinfo            *m;
-       java_lang_String      *key;
-       java_lang_String      *value;
+       java_objectheader     *key;
+       java_objectheader     *value;
 
        /* search for method to add properties */
 
-       m = class_resolveclassmethod(p->header.vftbl->class,
-                                                                utf_new_char("put"),
+       m = class_resolveclassmethod(p->vftbl->class,
+                                                                utf_put,
                                                                 utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"),
                                                                 NULL,
                                                                 true);