harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r730496 - in /harmony/enhanced/classlib/trunk/modules: luni/src/main/native/luni/shared/luniglob.c prefs/src/main/java/java/util/prefs/Preferences.java
Date Thu, 01 Jan 2009 01:15:52 GMT
Author: ndbeyer
Date: Wed Dec 31 17:15:51 2008
New Revision: 730496

URL: http://svn.apache.org/viewvc?rev=730496&view=rev
Log:
Apply patch for HARMONY-6064 - [classlib][prefs] move setting default provider of prefs to
java code

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/luniglob.c
    harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/Preferences.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/luniglob.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/luniglob.c?rev=730496&r1=730495&r2=730496&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/luniglob.c (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/luniglob.c Wed
Dec 31 17:15:51 2008
@@ -162,21 +162,6 @@
            }
        }
 
-       /* 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) {

Modified: harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/Preferences.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/Preferences.java?rev=730496&r1=730495&r2=730496&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/Preferences.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/Preferences.java
Wed Dec 31 17:15:51 2008
@@ -22,6 +22,7 @@
 import java.net.MalformedURLException;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.util.Locale;
 
 import org.apache.harmony.prefs.internal.nls.Messages;
 
@@ -115,31 +116,55 @@
 	
     //factory used to get user/system prefs root
 	private static final PreferencesFactory factory;
-	
+
+    // default provider factory name for Windows
+    private static final String DEFAULT_FACTORY_NAME_WIN = "java.util.prefs.RegistryPreferencesFactoryImpl";
//$NON-NLS-1$
+
+    // default provider factory name for Unix
+    private static final String DEFAULT_FACTORY_NAME_UNIX = "java.util.prefs.FilePreferencesFactoryImpl";
//$NON-NLS-1$
+
     /**
      * ---------------------------------------------------------
      * Class initializer
      * ---------------------------------------------------------
      */		
-	static{
-	    String factoryClassName = AccessController.doPrivileged(new PrivilegedAction<String>()
{
+    static {
+        String factoryClassName = AccessController.doPrivileged(new PrivilegedAction<String>()
{
             public String run() {
                 return System.getProperty("java.util.prefs.PreferencesFactory"); //$NON-NLS-1$
             }
         });
-	    try {
-	        ClassLoader loader = Thread.currentThread().getContextClassLoader();
-	        if(loader == null){
-	            loader = ClassLoader.getSystemClassLoader();
-	        }
-	        Class<?> factoryClass = loader.loadClass(factoryClassName);
-	        factory = (PreferencesFactory) factoryClass.newInstance();
+
+        // set default provider
+        if (factoryClassName == null) {
+            String osName = AccessController.doPrivileged(new PrivilegedAction<String>()
{
+                public String run() {
+                    return System.getProperty("os.name"); //$NON-NLS-1$
+                }
+            });
+
+            // only comparing ASCII, so assume english locale
+            osName = (osName == null ? null : osName.toLowerCase(Locale.ENGLISH));
+
+            if (osName != null && osName.startsWith("windows")) {
+                factoryClassName = DEFAULT_FACTORY_NAME_WIN;
+            } else {
+                factoryClassName = DEFAULT_FACTORY_NAME_UNIX;
+            }
+        }
+        try {
+            ClassLoader loader = Thread.currentThread().getContextClassLoader();
+            if(loader == null){
+                loader = ClassLoader.getSystemClassLoader();
+            }
+            Class<?> factoryClass = loader.loadClass(factoryClassName);
+            factory = (PreferencesFactory) factoryClass.newInstance();
         } catch (Exception e) {
             // prefs.10=Cannot initiate PreferencesFactory: {0}. Caused by {1}
             throw new InternalError(Messages.getString("prefs.10", factoryClassName, e));
  //$NON-NLS-1$
         }
-	}
-	
+    }
+
     /*
      * ---------------------------------------------------------
      * Constructors



Mime
View raw message