harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Regis <xu.re...@gmail.com>
Subject Re: [classlib][prefs] default provider of prefs
Date Wed, 31 Dec 2008 05:32:15 GMT


Nathan Beyer wrote:
> I doubt there is any significant reason for it other than the default
> is based on the OS and the native might have been an easy decision
> point.
Maybe.
> 
> Moving it to Java code is probably fine - the code just needs to use a
> default based on the OS.
I try the following patch, all tests are passed, so I think we could 
move it to java code safely. I used File.pathSeparatorChar to test the 
platform, is there any better way to do this?


Index: modules/luni/src/main/native/luni/shared/luniglob.c
=====================================================================
--- modules/luni/src/main/native/luni/shared/luniglob.c
+++ modules/luni/src/main/native/luni/shared/luniglob.c
@@ -162,21 +162,6 @@ JNI_OnLoad (JavaVM * vm, void *reserved)
             }
         }

-       /* Set default PreferencesFactory implementation */
-       (*vmInterface)->GetSystemProperty (vmInterface, 
"java.util.prefs.PreferencesFactory", &propVal);
-       if (propVal == NULL) {
-           propRes = (*vmInterface)->SetSystemProperty (vmInterface,
-               "java.util.prefs.PreferencesFactory",
-#ifdef _WIN32
-               "java.util.prefs.RegistryPreferencesFactoryImpl");
-#else
-               "java.util.prefs.FilePreferencesFactoryImpl");
-#endif
-           if (VMI_ERROR_NONE != propRes) {
-               /* goto fail2; */
-           }
-       }
-
         /* Prefer Xalan compiler for better performance, see 
HARMONY-3209. */
         (*vmInterface)->GetSystemProperty (vmInterface, 
"javax.xml.transform.TransformerFactory", &propVal);
         if (propVal == NULL) {
Index: modules/prefs/src/main/java/java/util/prefs/Preferences.java
=====================================================================
--- modules/prefs/src/main/java/java/util/prefs/Preferences.java
+++ modules/prefs/src/main/java/java/util/prefs/Preferences.java
@@ -16,6 +16,7 @@

  package java.util.prefs;

+import java.io.File;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
@@ -127,6 +128,13 @@ public abstract class Preferences {
                  return 
System.getProperty("java.util.prefs.PreferencesFactory"); //$NON-NLS-1$
              }
          });
+        if (factoryClassName == null) {
+            if (File.pathSeparatorChar == '\\') {
+                factoryClassName = 
"java.util.prefs.RegistryPreferencesFactoryImpl";
+            } else {
+                factoryClassName = 
"java.util.prefs.FilePreferencesFactoryImpl";
+            }
+        }
  	    try {
  	        ClassLoader loader = 
Thread.currentThread().getContextClassLoader();
  	        if(loader == null){


> -Nathan
> 
> On Tue, Dec 30, 2008 at 4:25 AM, Regis <xu.regis@gmail.com> wrote:
>> Hi,
>>
>> The provider of prefs is controlled by the property
>> "java.util.prefs.PreferencesFactory" in Harmony, and we also have different
>> default values for it on Linux and Windows, but the default values are set
>> in luni module at modules/luni/src/main/native/luni/shared/luniglob.c,
>> are there any special concerns that we must do it in luni native code? Or is
>> it possible set it in prefs module with java code, like this:
>>
>>         if (factoryClassName == null) {
>>             if (isWindows) {
>>                 factoryClassName =
>> "java.util.prefs.RegistryPreferencesFactoryImpl";
>>             } else {
>>                 factoryClassName =
>> "java.util.prefs.FilePreferencesFactoryImpl";
>>             }
>>         }
>>
>> I think there must be a way to get current platform at runtime in java.
>>
>> --
>> Best Regards,
>> Regis.
>>
> 

-- 
Best Regards,
Regis.

Mime
View raw message