changeset 166:06ce348f358a

8080841: Can't register custom configuration Summary: DeviceManager probes no more DeviceProvider at DeviceManager.open(String name... Reviewed-by: alkonsta
author snazarki
date Thu, 21 May 2015 13:12:21 +0300
parents 404c859bac91
children 30bb431d877e
files src/share/classes/jdk/dio/DeviceManager.java
diffstat 1 files changed, 19 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/jdk/dio/DeviceManager.java	Tue May 19 12:02:09 2015 +0300
+++ b/src/share/classes/jdk/dio/DeviceManager.java	Thu May 21 13:12:21 2015 +0300
@@ -722,9 +722,16 @@
             );
         }
         checkMode(mode);
+
+        // try to guess if this device type is valid
+        try {
+            getFactory(intf);
+        } catch (UnsupportedDeviceTypeException e) {
+            // nothing found yet
+            checkWithProviders(intf);
+        }
+
         Iterator<DeviceDescriptor<P>> iter = Registry.getInstance().get(name, intf, properties);
-        // indicates if given device type is supprted
-        boolean supported = false;
         while (iter.hasNext()) {
             DeviceDescriptor<P> descr = iter.next();
             try {
@@ -736,9 +743,6 @@
 
                 final PeripheralFactory<P> f =  getFactory(descr.getInterface());
 
-                // we found at least one driver
-                supported = true;
-
                 final DeviceDescriptor<P> fdescr = descr;
                 final int fmode = mode;
                 return PrivilegeController.doPrivileged(new PrivilegedAction<P>() {
@@ -763,28 +767,8 @@
             }
         }
 
-        if (!supported) {
-            // if there is no configuration for given type/name
-            // try to guess if this device type is valid
-            try {
-                getFactory(intf);
-                supported = true;
-            } catch (UnsupportedDeviceTypeException e) {
-                // nothing found yet
-            }
-        }
-
-        // special case if config is null
-        if (0 != properties.length) {
-            return loadFromDriver(supported, intf, mode, properties);
-        }
-
-        if (supported) {
-            // type is valid, but no valid config is found
-            throw new DeviceNotFoundException(name);
-        } else {
-            throw new UnsupportedDeviceTypeException(intf.toString());
-        }
+        // type is valid, but no valid config is found
+        throw new DeviceNotFoundException(name);
     }
 
     /**
@@ -1211,42 +1195,22 @@
         }
     }
 
-    private static <P extends Device<? super P>> P loadFromDriver(boolean supported, Class<P> intf, int mode, String... props) throws
-        DeviceNotFoundException, UnavailableDeviceException, InvalidDeviceConfigException,
-        UnsupportedAccessModeException, IOException {
+
+    private static void checkWithProviders(Class intf) throws UnsupportedDeviceTypeException {
         Iterator<DeviceProvider>  iter = ServiceLoader.load(DeviceProvider.class).iterator();
         try {
             while (iter.hasNext()) {
                 DeviceProvider provider = iter.next();
-
-                if (!provider.getType().isAssignableFrom(intf)) {
-                    continue;
-                }
-
-                // found driver that recognizes intf type
-                supported = true;
-
-                if (provider.matches(props)) {
-                    try {
-                        return (P)provider.open(null, props, mode);
-                    } catch (UnavailableDeviceException e) {
-                        if (!iter.hasNext()) {
-                            throw e;
-                        }
-                    }
+                if (provider.getType().isAssignableFrom(intf)) {
+                    return;
                 }
             }
         } catch (ServiceConfigurationError ex) {
             // intentionally ignored
         }
-        if (supported) {
-            throw new DeviceNotFoundException(
-                ExceptionMessage.format(ExceptionMessage.DEVICE_NOT_FOUND, intf.toString())
-            );
-        } else {
-            throw new UnsupportedDeviceTypeException (
-                ExceptionMessage.format(ExceptionMessage.DEVICE_DRIVER_MISSING)
-            );
-        }
+        throw new UnsupportedDeviceTypeException (
+            ExceptionMessage.format(ExceptionMessage.DEVICE_DRIVER_MISSING)
+        );
     }
 }
+