Java 类java.util.ServiceConfigurationError 实例源码

项目:hadoop-oss    文件:FileSystem.java   
private static void loadFileSystems() {
  synchronized (FileSystem.class) {
    if (!FILE_SYSTEMS_LOADED) {
      ServiceLoader<FileSystem> serviceLoader = ServiceLoader.load(FileSystem.class);
      Iterator<FileSystem> it = serviceLoader.iterator();
      while (it.hasNext()) {
        FileSystem fs = null;
        try {
          fs = it.next();
          try {
            SERVICE_FILE_SYSTEMS.put(fs.getScheme(), fs.getClass());
          } catch (Exception e) {
            LOG.warn("Cannot load: " + fs + " from " +
                ClassUtil.findContainingJar(fs.getClass()), e);
          }
        } catch (ServiceConfigurationError ee) {
          LOG.warn("Cannot load filesystem", ee);
        }
      }
      FILE_SYSTEMS_LOADED = true;
    }
  }
}
项目:luna    文件:ModuleLib.java   
private LuaFunction findLoader(String modName) {
  try {
    for (T service : serviceLoader) {
      if (matches(modName, service)) {
        LuaFunction loader = getLoader(service);
        if (loader != null) {
          return loader;
        }
      }
    }
  } catch (ServiceConfigurationError error) {
    // TODO: maybe we should just let the VM crash?
    throw new LuaRuntimeException(error);
  }

  // not found
  return null;
}
项目:truevfs    文件:TFileTest.java   
/**
 * Tests issue #TRUEZIP-154.
 * 
 * @see    <a href="http://java.net/jira/browse/TRUEZIP-154">ServiceConfigurationError: Unknown file system scheme for path without a extension</a>
 */
@Test
public void testIssue154() {
    for (String param : new String[] {
        "mok:file:/foo!/",
        "mok:mok:file:/foo!/bar!/",
    }) {
        FsNodePath path = FsNodePath.create(URI.create(param));
        try {
            assertIssue154(new TFile(path));
            assertIssue154(new TFile(path.getUri()));
        } catch (ServiceConfigurationError error) {
            throw new AssertionError(param, error);
        }
    }
}
项目:lams    文件:NamedSPILoader.java   
/** 
 * Reloads the internal SPI list from the given {@link ClassLoader}.
 * Changes to the service list are visible after the method ends, all
 * iterators ({@link #iterator()},...) stay consistent. 
 * 
 * <p><b>NOTE:</b> Only new service providers are added, existing ones are
 * never removed or replaced.
 * 
 * <p><em>This method is expensive and should only be called for discovery
 * of new service providers on the given classpath/classloader!</em>
 */
public synchronized void reload(ClassLoader classloader) {
  final LinkedHashMap<String,S> services = new LinkedHashMap<>(this.services);
  final SPIClassIterator<S> loader = SPIClassIterator.get(clazz, classloader);
  while (loader.hasNext()) {
    final Class<? extends S> c = loader.next();
    try {
      final S service = c.newInstance();
      final String name = service.getName();
      // only add the first one for each name, later services will be ignored
      // this allows to place services before others in classpath to make 
      // them used instead of others
      if (!services.containsKey(name)) {
        checkServiceName(name);
        services.put(name, service);
      }
    } catch (Exception e) {
      throw new ServiceConfigurationError("Cannot instantiate SPI class: " + c.getName(), e);
    }
  }
  this.services = Collections.unmodifiableMap(services);
}
项目:ClassroomFlipkart    文件:RowSetProvider.java   
/**
 * Use the ServiceLoader mechanism to load  the default RowSetFactory
 * @return default RowSetFactory Implementation
 */
static private RowSetFactory loadViaServiceLoader() throws SQLException {
    RowSetFactory theFactory = null;
    try {
        trace("***in loadViaServiceLoader():");
        for (RowSetFactory factory : ServiceLoader.load(javax.sql.rowset.RowSetFactory.class)) {
            trace(" Loading done by the java.util.ServiceLoader :" + factory.getClass().getName());
            theFactory = factory;
            break;
        }
    } catch (ServiceConfigurationError e) {
        throw new SQLException(
                "RowSetFactory: Error locating RowSetFactory using Service "
                + "Loader API: " + e, e);
    }
    return theFactory;

}
项目:OpenJSharp    文件:SelectorProvider.java   
private static boolean loadProviderAsService() {

        ServiceLoader<SelectorProvider> sl =
            ServiceLoader.load(SelectorProvider.class,
                               ClassLoader.getSystemClassLoader());
        Iterator<SelectorProvider> i = sl.iterator();
        for (;;) {
            try {
                if (!i.hasNext())
                    return false;
                provider = i.next();
                return true;
            } catch (ServiceConfigurationError sce) {
                if (sce.getCause() instanceof SecurityException) {
                    // Ignore the security exception, try the next provider
                    continue;
                }
                throw sce;
            }
        }
    }
项目:OpenJSharp    文件:AsynchronousChannelProvider.java   
private static AsynchronousChannelProvider loadProviderAsService() {
    ServiceLoader<AsynchronousChannelProvider> sl =
        ServiceLoader.load(AsynchronousChannelProvider.class,
                           ClassLoader.getSystemClassLoader());
    Iterator<AsynchronousChannelProvider> i = sl.iterator();
    for (;;) {
        try {
            return (i.hasNext()) ? i.next() : null;
        } catch (ServiceConfigurationError sce) {
            if (sce.getCause() instanceof SecurityException) {
                // Ignore the security exception, try the next provider
                continue;
            }
            throw sce;
        }
    }
}
项目:OpenJSharp    文件:FtpClientProvider.java   
private static boolean loadProviderFromProperty() {
    String cm = System.getProperty("sun.net.ftpClientProvider");
    if (cm == null) {
        return false;
    }
    try {
        Class<?> c = Class.forName(cm, true, null);
        provider = (FtpClientProvider) c.newInstance();
        return true;
    } catch (ClassNotFoundException |
             IllegalAccessException |
             InstantiationException |
             SecurityException x) {
        throw new ServiceConfigurationError(x.toString());
    }
}
项目:OpenJSharp    文件:HttpServerProvider.java   
private static boolean loadProviderFromProperty() {
    String cn = System.getProperty("com.sun.net.httpserver.HttpServerProvider");
    if (cn == null)
        return false;
    try {
        Class<?> c = Class.forName(cn, true,
                                   ClassLoader.getSystemClassLoader());
        provider = (HttpServerProvider)c.newInstance();
        return true;
    } catch (ClassNotFoundException |
             IllegalAccessException |
             InstantiationException |
             SecurityException x) {
        throw new ServiceConfigurationError(null, x);
    }
}
项目:OpenJSharp    文件:HttpServerProvider.java   
private static boolean loadProviderAsService() {
    Iterator<HttpServerProvider> i =
        ServiceLoader.load(HttpServerProvider.class,
                           ClassLoader.getSystemClassLoader())
            .iterator();
    for (;;) {
        try {
            if (!i.hasNext())
                return false;
            provider = i.next();
            return true;
        } catch (ServiceConfigurationError sce) {
            if (sce.getCause() instanceof SecurityException) {
                // Ignore the security exception, try the next provider
                continue;
            }
            throw sce;
        }
    }
}
项目:OpenJSharp    文件:RowSetProvider.java   
/**
 * Use the ServiceLoader mechanism to load  the default RowSetFactory
 * @return default RowSetFactory Implementation
 */
static private RowSetFactory loadViaServiceLoader() throws SQLException {
    RowSetFactory theFactory = null;
    try {
        trace("***in loadViaServiceLoader():");
        for (RowSetFactory factory : ServiceLoader.load(javax.sql.rowset.RowSetFactory.class)) {
            trace(" Loading done by the java.util.ServiceLoader :" + factory.getClass().getName());
            theFactory = factory;
            break;
        }
    } catch (ServiceConfigurationError e) {
        throw new SQLException(
                "RowSetFactory: Error locating RowSetFactory using Service "
                + "Loader API: " + e, e);
    }
    return theFactory;

}
项目:OpenJSharp    文件:FactoryFinder.java   
private static <T> T findServiceProvider(final Class<T> type)
        throws DatatypeConfigurationException
{
    try {
        return AccessController.doPrivileged(new PrivilegedAction<T>() {
            public T run() {
                final ServiceLoader<T> serviceLoader = ServiceLoader.load(type);
                final Iterator<T> iterator = serviceLoader.iterator();
                if (iterator.hasNext()) {
                    return iterator.next();
                } else {
                    return null;
                }
            }
        });
    } catch(ServiceConfigurationError e) {
        final DatatypeConfigurationException error =
                new DatatypeConfigurationException(
                    "Provider for " + type + " cannot be found", e);
        throw error;
    }
}
项目:jdk8u-jdk    文件:SelectorProvider.java   
private static boolean loadProviderAsService() {

        ServiceLoader<SelectorProvider> sl =
            ServiceLoader.load(SelectorProvider.class,
                               ClassLoader.getSystemClassLoader());
        Iterator<SelectorProvider> i = sl.iterator();
        for (;;) {
            try {
                if (!i.hasNext())
                    return false;
                provider = i.next();
                return true;
            } catch (ServiceConfigurationError sce) {
                if (sce.getCause() instanceof SecurityException) {
                    // Ignore the security exception, try the next provider
                    continue;
                }
                throw sce;
            }
        }
    }
项目:jdk8u-jdk    文件:AsynchronousChannelProvider.java   
private static AsynchronousChannelProvider loadProviderAsService() {
    ServiceLoader<AsynchronousChannelProvider> sl =
        ServiceLoader.load(AsynchronousChannelProvider.class,
                           ClassLoader.getSystemClassLoader());
    Iterator<AsynchronousChannelProvider> i = sl.iterator();
    for (;;) {
        try {
            return (i.hasNext()) ? i.next() : null;
        } catch (ServiceConfigurationError sce) {
            if (sce.getCause() instanceof SecurityException) {
                // Ignore the security exception, try the next provider
                continue;
            }
            throw sce;
        }
    }
}
项目:jdk8u-jdk    文件:FtpClientProvider.java   
private static boolean loadProviderFromProperty() {
    String cm = System.getProperty("sun.net.ftpClientProvider");
    if (cm == null) {
        return false;
    }
    try {
        Class<?> c = Class.forName(cm, true, null);
        provider = (FtpClientProvider) c.newInstance();
        return true;
    } catch (ClassNotFoundException |
             IllegalAccessException |
             InstantiationException |
             SecurityException x) {
        throw new ServiceConfigurationError(x.toString());
    }
}
项目:jdk8u-jdk    文件:HttpServerProvider.java   
private static boolean loadProviderFromProperty() {
    String cn = System.getProperty("com.sun.net.httpserver.HttpServerProvider");
    if (cn == null)
        return false;
    try {
        Class<?> c = Class.forName(cn, true,
                                   ClassLoader.getSystemClassLoader());
        provider = (HttpServerProvider)c.newInstance();
        return true;
    } catch (ClassNotFoundException |
             IllegalAccessException |
             InstantiationException |
             SecurityException x) {
        throw new ServiceConfigurationError(null, x);
    }
}
项目:jdk8u-jdk    文件:HttpServerProvider.java   
private static boolean loadProviderAsService() {
    Iterator<HttpServerProvider> i =
        ServiceLoader.load(HttpServerProvider.class,
                           ClassLoader.getSystemClassLoader())
            .iterator();
    for (;;) {
        try {
            if (!i.hasNext())
                return false;
            provider = i.next();
            return true;
        } catch (ServiceConfigurationError sce) {
            if (sce.getCause() instanceof SecurityException) {
                // Ignore the security exception, try the next provider
                continue;
            }
            throw sce;
        }
    }
}
项目:jdk8u-jdk    文件:RowSetProvider.java   
/**
 * Use the ServiceLoader mechanism to load  the default RowSetFactory
 * @return default RowSetFactory Implementation
 */
static private RowSetFactory loadViaServiceLoader() throws SQLException {
    RowSetFactory theFactory = null;
    try {
        trace("***in loadViaServiceLoader():");
        for (RowSetFactory factory : ServiceLoader.load(javax.sql.rowset.RowSetFactory.class)) {
            trace(" Loading done by the java.util.ServiceLoader :" + factory.getClass().getName());
            theFactory = factory;
            break;
        }
    } catch (ServiceConfigurationError e) {
        throw new SQLException(
                "RowSetFactory: Error locating RowSetFactory using Service "
                + "Loader API: " + e, e);
    }
    return theFactory;

}
项目:openjdk-jdk10    文件:SelectorProvider.java   
private static boolean loadProviderAsService() {

        ServiceLoader<SelectorProvider> sl =
            ServiceLoader.load(SelectorProvider.class,
                               ClassLoader.getSystemClassLoader());
        Iterator<SelectorProvider> i = sl.iterator();
        for (;;) {
            try {
                if (!i.hasNext())
                    return false;
                provider = i.next();
                return true;
            } catch (ServiceConfigurationError sce) {
                if (sce.getCause() instanceof SecurityException) {
                    // Ignore the security exception, try the next provider
                    continue;
                }
                throw sce;
            }
        }
    }
项目:openjdk-jdk10    文件:AsynchronousChannelProvider.java   
private static AsynchronousChannelProvider loadProviderAsService() {
    ServiceLoader<AsynchronousChannelProvider> sl =
        ServiceLoader.load(AsynchronousChannelProvider.class,
                           ClassLoader.getSystemClassLoader());
    Iterator<AsynchronousChannelProvider> i = sl.iterator();
    for (;;) {
        try {
            return (i.hasNext()) ? i.next() : null;
        } catch (ServiceConfigurationError sce) {
            if (sce.getCause() instanceof SecurityException) {
                // Ignore the security exception, try the next provider
                continue;
            }
            throw sce;
        }
    }
}
项目:openjdk-jdk10    文件:FtpClientProvider.java   
private static boolean loadProviderFromProperty() {
    String cm = System.getProperty("sun.net.ftpClientProvider");
    if (cm == null) {
        return false;
    }
    try {
        @SuppressWarnings("deprecation")
        Object o = Class.forName(cm, true, null).newInstance();
        provider = (FtpClientProvider)o;
        return true;
    } catch (ClassNotFoundException |
             IllegalAccessException |
             InstantiationException |
             SecurityException x) {
        throw new ServiceConfigurationError(x.toString());
    }
}
项目:openjdk-jdk10    文件:HttpServerProvider.java   
private static boolean loadProviderFromProperty() {
    String cn = System.getProperty("com.sun.net.httpserver.HttpServerProvider");
    if (cn == null)
        return false;
    try {
        @SuppressWarnings("deprecation")
        Object o = Class.forName(cn, true,
                                 ClassLoader.getSystemClassLoader()).newInstance();
        provider = (HttpServerProvider)o;
        return true;
    } catch (ClassNotFoundException |
             IllegalAccessException |
             InstantiationException |
             SecurityException x) {
        throw new ServiceConfigurationError(null, x);
    }
}
项目:openjdk-jdk10    文件:HttpServerProvider.java   
private static boolean loadProviderAsService() {
    Iterator<HttpServerProvider> i =
        ServiceLoader.load(HttpServerProvider.class,
                           ClassLoader.getSystemClassLoader())
            .iterator();
    for (;;) {
        try {
            if (!i.hasNext())
                return false;
            provider = i.next();
            return true;
        } catch (ServiceConfigurationError sce) {
            if (sce.getCause() instanceof SecurityException) {
                // Ignore the security exception, try the next provider
                continue;
            }
            throw sce;
        }
    }
}
项目:openjdk-jdk10    文件:RowSetProvider.java   
/**
 * Use the ServiceLoader mechanism to load  the default RowSetFactory
 * @return default RowSetFactory Implementation
 */
static private RowSetFactory loadViaServiceLoader() throws SQLException {
    RowSetFactory theFactory = null;
    try {
        trace("***in loadViaServiceLoader():");
        for (RowSetFactory factory : ServiceLoader.load(javax.sql.rowset.RowSetFactory.class)) {
            trace(" Loading done by the java.util.ServiceLoader :" + factory.getClass().getName());
            theFactory = factory;
            break;
        }
    } catch (ServiceConfigurationError e) {
        throw new SQLException(
                "RowSetFactory: Error locating RowSetFactory using Service "
                + "Loader API: " + e, e);
    }
    return theFactory;

}
项目:openjdk-jdk10    文件:Main.java   
/**
 * Test Module::addUses
 */
public void testAddUses() {
    Module thisModule = Main.class.getModule();

    assertFalse(thisModule.canUse(Service.class));
    try {
        ServiceLoader.load(Service.class);
        assertTrue(false);
    } catch (ServiceConfigurationError expected) { }

    Module result = thisModule.addUses(Service.class);
    assertTrue(result== thisModule);

    assertTrue(thisModule.canUse(Service.class));
    ServiceLoader.load(Service.class); // no exception
}
项目:openjdk-jdk10    文件:BadProvidersTest.java   
@Test(dataProvider = "badfactories",
      expectedExceptions = ServiceConfigurationError.class)
public void testBadFactory(String testName, String ignore) throws Exception {
    Path mods = compileTest(TEST1_MODULE);

    // compile the bad factory
    Path source = BADFACTORIES_DIR.resolve(testName);
    Path output = Files.createTempDirectory(USER_DIR, "tmp");
    boolean compiled = CompilerUtils.compile(source, output);
    assertTrue(compiled);

    // copy the compiled class into the module
    Path classFile = Paths.get("p", "ProviderFactory.class");
    Files.copy(output.resolve(classFile),
               mods.resolve(TEST1_MODULE).resolve(classFile),
               StandardCopyOption.REPLACE_EXISTING);

    // load providers and instantiate each one
    loadProviders(mods, TEST1_MODULE).forEach(Provider::get);
}
项目:openjdk-jdk10    文件:BadProvidersTest.java   
@Test(dataProvider = "badproviders",
      expectedExceptions = ServiceConfigurationError.class)
public void testBadProvider(String testName, String ignore) throws Exception {
    Path mods = compileTest(TEST2_MODULE);

    // compile the bad provider
    Path source = BADPROVIDERS_DIR.resolve(testName);
    Path output = Files.createTempDirectory(USER_DIR, "tmp");
    boolean compiled = CompilerUtils.compile(source, output);
    assertTrue(compiled);

    // copy the compiled class into the module
    Path classFile = Paths.get("p", "Provider.class");
    Files.copy(output.resolve(classFile),
               mods.resolve(TEST2_MODULE).resolve(classFile),
               StandardCopyOption.REPLACE_EXISTING);

    // load providers and instantiate each one
    loadProviders(mods, TEST2_MODULE).forEach(Provider::get);
}
项目:openjdk-jdk10    文件:XMLReaderFactory.java   
private static <T> T findServiceProvider(final Class<T> type, final ClassLoader loader)
      throws SAXException {
  ClassLoader cl = Objects.requireNonNull(loader);
  try {
      return AccessController.doPrivileged((PrivilegedAction<T>) () -> {
          final ServiceLoader<T> serviceLoader;
          serviceLoader = ServiceLoader.load(type, cl);
          final Iterator<T> iterator = serviceLoader.iterator();
          if (iterator.hasNext()) {
              return iterator.next();
          } else {
              return null;
          }
      });
  } catch(ServiceConfigurationError e) {
      final RuntimeException x = new RuntimeException(
              "Provider for " + type + " cannot be created", e);
      throw new SAXException("Provider for " + type + " cannot be created", x);

    }
}
项目:openjdk-jdk10    文件:FactoryFinder.java   
private static <T> T findServiceProvider(final Class<T> type)
        throws DatatypeConfigurationException
{
    try {
        return AccessController.doPrivileged(new PrivilegedAction<T>() {
            public T run() {
                final ServiceLoader<T> serviceLoader = ServiceLoader.load(type);
                final Iterator<T> iterator = serviceLoader.iterator();
                if (iterator.hasNext()) {
                    return iterator.next();
                } else {
                    return null;
                }
            }
        });
    } catch(ServiceConfigurationError e) {
        final DatatypeConfigurationException error =
                new DatatypeConfigurationException(
                    "Provider for " + type + " cannot be found", e);
        throw error;
    }
}
项目:openjdk9    文件:Services.java   
/**
 * Gets the JVMCI provider for a given service for which at most one provider must be available.
 *
 * @param service the service whose provider is being requested
 * @param required specifies if an {@link InternalError} should be thrown if no provider of
 *            {@code service} is available
 */
public static <S> S loadSingle(Class<S> service, boolean required) {
    Iterable<S> providers = ServiceLoader.load(service);
    S singleProvider = null;
    try {
        for (Iterator<S> it = providers.iterator(); it.hasNext();) {
            singleProvider = it.next();
            if (it.hasNext()) {
                throw new InternalError(String.format("Multiple %s providers found", service.getName()));
            }
        }
    } catch (ServiceConfigurationError e) {
        // If the service is required we will bail out below.
    }
    if (singleProvider == null && required) {
        String javaHome = System.getProperty("java.home");
        String vmName = System.getProperty("java.vm.name");
        Formatter errorMessage = new Formatter();
        errorMessage.format("The VM does not expose required service %s.%n", service.getName());
        errorMessage.format("Currently used Java home directory is %s.%n", javaHome);
        errorMessage.format("Currently used VM configuration is: %s", vmName);
        throw new UnsupportedOperationException(errorMessage.toString());
    }
    return singleProvider;
}
项目:openjdk9    文件:SelectorProvider.java   
private static boolean loadProviderAsService() {

        ServiceLoader<SelectorProvider> sl =
            ServiceLoader.load(SelectorProvider.class,
                               ClassLoader.getSystemClassLoader());
        Iterator<SelectorProvider> i = sl.iterator();
        for (;;) {
            try {
                if (!i.hasNext())
                    return false;
                provider = i.next();
                return true;
            } catch (ServiceConfigurationError sce) {
                if (sce.getCause() instanceof SecurityException) {
                    // Ignore the security exception, try the next provider
                    continue;
                }
                throw sce;
            }
        }
    }
项目:openjdk9    文件:AsynchronousChannelProvider.java   
private static AsynchronousChannelProvider loadProviderAsService() {
    ServiceLoader<AsynchronousChannelProvider> sl =
        ServiceLoader.load(AsynchronousChannelProvider.class,
                           ClassLoader.getSystemClassLoader());
    Iterator<AsynchronousChannelProvider> i = sl.iterator();
    for (;;) {
        try {
            return (i.hasNext()) ? i.next() : null;
        } catch (ServiceConfigurationError sce) {
            if (sce.getCause() instanceof SecurityException) {
                // Ignore the security exception, try the next provider
                continue;
            }
            throw sce;
        }
    }
}
项目:openjdk9    文件:FtpClientProvider.java   
private static boolean loadProviderFromProperty() {
    String cm = System.getProperty("sun.net.ftpClientProvider");
    if (cm == null) {
        return false;
    }
    try {
        @SuppressWarnings("deprecation")
        Object o = Class.forName(cm, true, null).newInstance();
        provider = (FtpClientProvider)o;
        return true;
    } catch (ClassNotFoundException |
             IllegalAccessException |
             InstantiationException |
             SecurityException x) {
        throw new ServiceConfigurationError(x.toString());
    }
}
项目:openjdk9    文件:HttpServerProvider.java   
private static boolean loadProviderFromProperty() {
    String cn = System.getProperty("com.sun.net.httpserver.HttpServerProvider");
    if (cn == null)
        return false;
    try {
        @SuppressWarnings("deprecation")
        Object o = Class.forName(cn, true,
                                 ClassLoader.getSystemClassLoader()).newInstance();
        provider = (HttpServerProvider)o;
        return true;
    } catch (ClassNotFoundException |
             IllegalAccessException |
             InstantiationException |
             SecurityException x) {
        throw new ServiceConfigurationError(null, x);
    }
}
项目:openjdk9    文件:HttpServerProvider.java   
private static boolean loadProviderAsService() {
    Iterator<HttpServerProvider> i =
        ServiceLoader.load(HttpServerProvider.class,
                           ClassLoader.getSystemClassLoader())
            .iterator();
    for (;;) {
        try {
            if (!i.hasNext())
                return false;
            provider = i.next();
            return true;
        } catch (ServiceConfigurationError sce) {
            if (sce.getCause() instanceof SecurityException) {
                // Ignore the security exception, try the next provider
                continue;
            }
            throw sce;
        }
    }
}
项目:openjdk9    文件:RowSetProvider.java   
/**
 * Use the ServiceLoader mechanism to load  the default RowSetFactory
 * @return default RowSetFactory Implementation
 */
static private RowSetFactory loadViaServiceLoader() throws SQLException {
    RowSetFactory theFactory = null;
    try {
        trace("***in loadViaServiceLoader():");
        for (RowSetFactory factory : ServiceLoader.load(javax.sql.rowset.RowSetFactory.class)) {
            trace(" Loading done by the java.util.ServiceLoader :" + factory.getClass().getName());
            theFactory = factory;
            break;
        }
    } catch (ServiceConfigurationError e) {
        throw new SQLException(
                "RowSetFactory: Error locating RowSetFactory using Service "
                + "Loader API: " + e, e);
    }
    return theFactory;

}
项目:openjdk9    文件:XMLReaderFactory.java   
private static <T> T findServiceProvider(final Class<T> type, final ClassLoader loader)
      throws SAXException {
  ClassLoader cl = Objects.requireNonNull(loader);
  try {
      return AccessController.doPrivileged((PrivilegedAction<T>) () -> {
          final ServiceLoader<T> serviceLoader;
          serviceLoader = ServiceLoader.load(type, cl);
          final Iterator<T> iterator = serviceLoader.iterator();
          if (iterator.hasNext()) {
              return iterator.next();
          } else {
              return null;
          }
      });
  } catch(ServiceConfigurationError e) {
      final RuntimeException x = new RuntimeException(
              "Provider for " + type + " cannot be created", e);
      throw new SAXException("Provider for " + type + " cannot be created", x);

    }
}
项目:openjdk9    文件:FactoryFinder.java   
private static <T> T findServiceProvider(final Class<T> type)
        throws DatatypeConfigurationException
{
    try {
        return AccessController.doPrivileged(new PrivilegedAction<T>() {
            public T run() {
                final ServiceLoader<T> serviceLoader = ServiceLoader.load(type);
                final Iterator<T> iterator = serviceLoader.iterator();
                if (iterator.hasNext()) {
                    return iterator.next();
                } else {
                    return null;
                }
            }
        });
    } catch(ServiceConfigurationError e) {
        final DatatypeConfigurationException error =
                new DatatypeConfigurationException(
                    "Provider for " + type + " cannot be found", e);
        throw error;
    }
}
项目:aliyun-oss-hadoop-fs    文件:FileSystem.java   
private static void loadFileSystems() {
  synchronized (FileSystem.class) {
    if (!FILE_SYSTEMS_LOADED) {
      ServiceLoader<FileSystem> serviceLoader = ServiceLoader.load(FileSystem.class);
      Iterator<FileSystem> it = serviceLoader.iterator();
      while (it.hasNext()) {
        FileSystem fs = null;
        try {
          fs = it.next();
          try {
            SERVICE_FILE_SYSTEMS.put(fs.getScheme(), fs.getClass());
          } catch (Exception e) {
            LOG.warn("Cannot load: " + fs + " from " +
                ClassUtil.findContainingJar(fs.getClass()), e);
          }
        } catch (ServiceConfigurationError ee) {
          LOG.warn("Cannot load filesystem", ee);
        }
      }
      FILE_SYSTEMS_LOADED = true;
    }
  }
}
项目:Java8CN    文件:SelectorProvider.java   
private static boolean loadProviderAsService() {

        ServiceLoader<SelectorProvider> sl =
            ServiceLoader.load(SelectorProvider.class,
                               ClassLoader.getSystemClassLoader());
        Iterator<SelectorProvider> i = sl.iterator();
        for (;;) {
            try {
                if (!i.hasNext())
                    return false;
                provider = i.next();
                return true;
            } catch (ServiceConfigurationError sce) {
                if (sce.getCause() instanceof SecurityException) {
                    // Ignore the security exception, try the next provider
                    continue;
                }
                throw sce;
            }
        }
    }