use of java.util.ServiceLoader in project jdk8u_jdk by JetBrains.
the class Charset method providers.
// Creates an iterator that walks over the available providers, ignoring
// those whose lookup or instantiation causes a security exception to be
// thrown. Should be invoked with full privileges.
//
private static Iterator<CharsetProvider> providers() {
return new Iterator<CharsetProvider>() {
ClassLoader cl = ClassLoader.getSystemClassLoader();
ServiceLoader<CharsetProvider> sl = ServiceLoader.load(CharsetProvider.class, cl);
Iterator<CharsetProvider> i = sl.iterator();
CharsetProvider next = null;
private boolean getNext() {
while (next == null) {
try {
if (!i.hasNext())
return false;
next = i.next();
} catch (ServiceConfigurationError sce) {
if (sce.getCause() instanceof SecurityException) {
// Ignore security exceptions
continue;
}
throw sce;
}
}
return true;
}
public boolean hasNext() {
return getNext();
}
public CharsetProvider next() {
if (!getNext())
throw new NoSuchElementException();
CharsetProvider n = next;
next = null;
return n;
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
use of java.util.ServiceLoader in project felix by apache.
the class AbstractPojoSRTestCase method setUp.
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
// Initialize service registry
ServiceLoader loader = ServiceLoader.load(PojoServiceRegistryFactory.class);
registry = ((PojoServiceRegistryFactory) loader.iterator().next()).newPojoServiceRegistry(new HashMap());
assertNotNull(registry);
// Initialize bundle
activator = new Activator();
activator.start(registry.getBundleContext());
}
use of java.util.ServiceLoader in project Java-9-Spring-Webflux by kkTranslation.
the class Gui method main.
public static void main(String[] args) {
ServiceLoader<Analysis> analyses = ServiceLoader.load(Analysis.class);
// analyses.stream().map(ServiceLoader.Provider::get).forEach(analyzer -> System.out.println(analyzer.getName()));
Set<Analysis> collect = analyses.stream().filter(p -> isAnno(p.type())).map(ServiceLoader.Provider::get).collect(Collectors.toSet());
Person nao = new Person(0, 0);
Person miniperson = new Person(10, 0);
Person minperson = new Person(1001, 0);
Person minxperson = new Person(1001, 11);
Person maxperson = new Person(100000, 11);
Person maxxperson = new Person(100000, 26);
Person poorperson = new Person(100000, 0);
collect.forEach(p -> System.out.println(p.analyze(maxxperson)));
}
use of java.util.ServiceLoader in project Bytecoder by mirkosertic.
the class UrlDeserializedState method providers.
private static Iterator<URLStreamHandlerProvider> providers() {
return new Iterator<>() {
ClassLoader cl = ClassLoader.getSystemClassLoader();
ServiceLoader<URLStreamHandlerProvider> sl = ServiceLoader.load(URLStreamHandlerProvider.class, cl);
Iterator<URLStreamHandlerProvider> i = sl.iterator();
URLStreamHandlerProvider next = null;
private boolean getNext() {
while (next == null) {
try {
if (!i.hasNext())
return false;
next = i.next();
} catch (ServiceConfigurationError sce) {
if (sce.getCause() instanceof SecurityException) {
// Ignore security exceptions
continue;
}
throw sce;
}
}
return true;
}
public boolean hasNext() {
return getNext();
}
public URLStreamHandlerProvider next() {
if (!getNext())
throw new NoSuchElementException();
URLStreamHandlerProvider n = next;
next = null;
return n;
}
};
}
use of java.util.ServiceLoader in project Bytecoder by mirkosertic.
the class Charset method providers.
// Creates an iterator that walks over the available providers, ignoring
// those whose lookup or instantiation causes a security exception to be
// thrown. Should be invoked with full privileges.
//
private static Iterator<CharsetProvider> providers() {
return new Iterator<>() {
ClassLoader cl = ClassLoader.getSystemClassLoader();
ServiceLoader<CharsetProvider> sl = ServiceLoader.load(CharsetProvider.class, cl);
Iterator<CharsetProvider> i = sl.iterator();
CharsetProvider next = null;
private boolean getNext() {
while (next == null) {
try {
if (!i.hasNext())
return false;
next = i.next();
} catch (ServiceConfigurationError sce) {
if (sce.getCause() instanceof SecurityException) {
// Ignore security exceptions
continue;
}
throw sce;
}
}
return true;
}
public boolean hasNext() {
return getNext();
}
public CharsetProvider next() {
if (!getNext())
throw new NoSuchElementException();
CharsetProvider n = next;
next = null;
return n;
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
Aggregations