本文整理汇总了Java中java.util.ServiceConfigurationError类的典型用法代码示例。如果您正苦于以下问题:Java ServiceConfigurationError类的具体用法?Java ServiceConfigurationError怎么用?Java ServiceConfigurationError使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServiceConfigurationError类属于java.util包,在下文中一共展示了ServiceConfigurationError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadFileSystems
import java.util.ServiceConfigurationError; //导入依赖的package包/类
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;
}
}
}
示例2: findLoader
import java.util.ServiceConfigurationError; //导入依赖的package包/类
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;
}
示例3: testIssue154
import java.util.ServiceConfigurationError; //导入依赖的package包/类
/**
* 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);
}
}
}
示例4: reload
import java.util.ServiceConfigurationError; //导入依赖的package包/类
/**
* 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);
}
示例5: loadViaServiceLoader
import java.util.ServiceConfigurationError; //导入依赖的package包/类
/**
* 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;
}
示例6: loadProviderAsService
import java.util.ServiceConfigurationError; //导入依赖的package包/类
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;
}
}
}
示例7: loadProviderAsService
import java.util.ServiceConfigurationError; //导入依赖的package包/类
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;
}
}
}
示例8: loadProviderFromProperty
import java.util.ServiceConfigurationError; //导入依赖的package包/类
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());
}
}
示例9: loadProviderFromProperty
import java.util.ServiceConfigurationError; //导入依赖的package包/类
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);
}
}
示例10: loadProviderAsService
import java.util.ServiceConfigurationError; //导入依赖的package包/类
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;
}
}
}
示例11: findServiceProvider
import java.util.ServiceConfigurationError; //导入依赖的package包/类
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;
}
}
示例12: loadProviderFromProperty
import java.util.ServiceConfigurationError; //导入依赖的package包/类
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());
}
}
示例13: loadProviderFromProperty
import java.util.ServiceConfigurationError; //导入依赖的package包/类
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);
}
}
示例14: testAddUses
import java.util.ServiceConfigurationError; //导入依赖的package包/类
/**
* 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
}
示例15: testBadFactory
import java.util.ServiceConfigurationError; //导入依赖的package包/类
@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);
}