6514993: (prefs)prefs should use java.util.ServiceLoader to lookup service providers
authorsherman
Fri, 14 Mar 2008 14:21:03 -0700
changeset 70 01cbfebae878
parent 69 c7cd7bde95f3
child 71 6d5c8d474a4e
child 103 2ccefd4e038f
6514993: (prefs)prefs should use java.util.ServiceLoader to lookup service providers Reviewed-by: iris Contributed-by: xueming.shen@sun.com
jdk/src/share/classes/java/util/prefs/Preferences.java
--- a/jdk/src/share/classes/java/util/prefs/Preferences.java	Thu Mar 13 19:34:49 2008 +0000
+++ b/jdk/src/share/classes/java/util/prefs/Preferences.java	Fri Mar 14 14:21:03 2008 -0700
@@ -32,9 +32,8 @@
 import java.security.Permission;
 import java.security.PrivilegedAction;
 import java.util.Iterator;
-import sun.misc.Service;
-import sun.misc.ServiceConfigurationError;
-
+import java.util.ServiceLoader;
+import java.util.ServiceConfigurationError;
 
 // These imports needed only as a workaround for a JavaDoc bug
 import java.lang.RuntimePermission;
@@ -274,12 +273,14 @@
 
     private static PreferencesFactory factory1() {
         // 2. Try service provider interface
-        Iterator i = Service.providers(PreferencesFactory.class,
-                                       ClassLoader.getSystemClassLoader());
+        Iterator<PreferencesFactory> itr = ServiceLoader
+            .load(PreferencesFactory.class, ClassLoader.getSystemClassLoader())
+            .iterator();
+
         // choose first provider instance
-        while (i.hasNext()) {
+        while (itr.hasNext()) {
             try {
-                return (PreferencesFactory) i.next();
+                return itr.next();
             } catch (ServiceConfigurationError sce) {
                 if (sce.getCause() instanceof SecurityException) {
                     // Ignore the security exception, try the next provider