Some sun.misc internal APIs are deprectaed in JDK 9 and will be encapsulated or removed in a future release.
Iterator<MyServiceProvider> = sun.misc.Service.providers(MyServiceProvider.class);
private static void fail(Class service, URL u, int line, String msg) throws ServiceConfigurationError { fail(service, u + ":" + line + ": " + msg); }
if (n != 0) { if ((ln.indexOf(' ') >= 0) || (ln.indexOf('\t') >= 0)) fail(service, u, lc, "Illegal configuration-file syntax"); int cp = ln.codePointAt(0); if (!Character.isJavaIdentifierStart(cp)) fail(service, u, lc, "Illegal provider-class name: " + ln); for (int i = Character.charCount(cp); i < n; i += Character.charCount(cp)) { cp = ln.codePointAt(i); if (!Character.isJavaIdentifierPart(cp) && (cp != '.')) fail(service, u, lc, "Illegal provider-class name: " + ln);
private static EditorFactory createInstanceWithSPI() { EditorFactory fact = null; Class<?> thisClass = EditorFactory.class; Iterator<?> it = Service.providers(thisClass, thisClass.getClassLoader()); if (it.hasNext()) { fact = (EditorFactory) it.next(); log.info("Use EditorFactory provided with SPI: " + fact.getClass().getName()); if (it.hasNext()) { log.warn("Several implementation of EditorFactory are provided with SPI, ignored: " + it.next().getClass().getName() + " ..."); } } return fact; }
public static <P> Collection<P> loadAllProviders(@NotNull final Class<P> serviceClass, @Nullable final ClassLoader classLoader) { final ClassLoader theClassLoader = classLoader != null ? classLoader : Thread.currentThread().getContextClassLoader(); final Iterator providersIterator = sun.misc.Service.providers(serviceClass, theClassLoader); Collection<P> providers = new LinkedList<P>(); while (providersIterator.hasNext()) { Object p = providersIterator.next(); if (serviceClass.isAssignableFrom(p.getClass())) { //noinspection unchecked providers.add((P)p); } } return providers; }
return Service.providers(service, cl);
private Set<StepListener> getCustomListeners() { if (customListeners == null) { customListeners = Collections.synchronizedSet(new HashSet<StepListener>()); Iterator<?> listenerImplementations = Service.providers(StepListener.class); while (listenerImplementations.hasNext()) { try { StepListener listener = (StepListener) listenerImplementations.next(); if (!isACore(listener)) { LOGGER.info("Registering custom listener " + listener); customListeners.add(listener); } } catch (ServiceConfigurationError e) { LOGGER.error("Could not instantiate listener ", e); } } } return customListeners; }
private static boolean loadProviderAsService() { Iterator i = Service.providers(HttpServerProvider.class, ClassLoader.getSystemClassLoader()); for (;;) { try { if (!i.hasNext()) return false; provider = (HttpServerProvider)i.next(); return true; } catch (ServiceConfigurationError sce) { if (sce.getCause() instanceof SecurityException) { // Ignore the security exception, try the next provider continue; } throw sce; } } }
/** * Create a new enunciate configuration. The module list will be constructed * using Sun's discovery mechanism. */ public EnunciateConfiguration() { this.modules = new TreeSet<DeploymentModule>(new DeploymentModuleComparator()); Iterator discoveredModules = Service.providers(DeploymentModule.class); while (discoveredModules.hasNext()) { DeploymentModule discoveredModule = (DeploymentModule) discoveredModules.next(); this.modules.add(discoveredModule); } }
cl = cl.getParent(); return Service.providers(service, prev);
private Callable<Void> getMessageProcessorCleanupTask() { MessageProcessorCleanupService cleanupTask = null; if (logger.isDebugEnabled()) { logger.debug("Trying to fetch InboundRequestProcessor from classpath.. "); } Iterator<MessageProcessorCleanupService> it = Service.providers(MessageProcessorCleanupService.class); while (it.hasNext()) { cleanupTask = it.next(); cleanupTask.setName(name); if (cleanupTask != null) { if (logger.isDebugEnabled()) { logger.debug("Message Processor Cleanup Service found : " + cleanupTask.getClass().getName()); } } return cleanupTask; } return null; }
/** * Register pluggable mediator factories from the classpath * * This looks for JAR files containing a META-INF/services that adheres to the following * http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider */ private static void registerExtensions() { // register MediatorFactory extensions Iterator it = Service.providers(MediatorFactory.class); while (it.hasNext()) { MediatorFactory mf = (MediatorFactory) it.next(); QName tag = mf.getTagQName(); factoryMap.put(tag, mf.getClass()); if (log.isDebugEnabled()) { log.debug("Added MediatorFactory " + mf.getClass() + " to handle " + tag); } } }
/** * Register plugable mediator factories from the classpath * <p/> * This looks for JAR files containing a META-INF/services that adheres to the following * http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider */ private static void registerExtensions() { // register MediatorFactory extensions Iterator it = Service.providers(ConfigurationFactory.class); while (it.hasNext()) { ConfigurationFactory cf = (ConfigurationFactory) it.next(); QName tag = cf.getTagQName(); factoryMap.put(tag, cf.getClass()); serializerMap.put(tag, cf.getSerializerClass()); if (log.isDebugEnabled()) { log.debug("Added MediatorFactory " + cf.getClass() + " to handle " + tag); } } }
/** * Register pluggable mediator factories from the classpath * <p/> * This looks for JAR files containing a META-INF/services that adheres to * the following * http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider */ private static void registerExtensions() { // log.debug("Registering mediator extensions found in the classpath : " // + System.getResource("java.class.path")); // register MediatorFactory extensions Iterator<?> it = Service.providers(StartupFactory.class); while (it.hasNext()) { StartupFactory sf = (StartupFactory) it.next(); QName tag = sf.getTagQName(); factoryMap.put(tag, sf.getClass()); serializerMap.put(tag, sf.getSerializerClass()); if (log.isDebugEnabled()) { log.debug("Added StartupFactory " + sf.getClass() + " to handle " + tag); } } }
/** * Get plug-able InboundRequest processors from the classpath * <p/> * This looks for JAR files containing a META-INF/services that adheres to the following * http://docs.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html * * @return InboundRequest processor */ private InboundRequestProcessor getInboundRequestProcessor() { if (log.isDebugEnabled()) { log.debug("Trying to fetch InboundRequestProcessor from classpath.. "); } Iterator<InboundRequestProcessorFactory> it = Service.providers(InboundRequestProcessorFactory.class); InboundProcessorParams params = populateParams(); while (it.hasNext()) { InboundRequestProcessorFactory factory = it.next(); InboundRequestProcessor inboundRequestProcessor = factory.createInboundProcessor(params); if (inboundRequestProcessor != null) { if (log.isDebugEnabled()) { log.debug("Inbound Request Processor found in factory : " + factory.getClass().getName()); } return inboundRequestProcessor; } } return null; }
/** * Loads and returns the first service that implements the given interface. * @param providerClass the desired service class. * @param <P> service class. * @return a service. * @throws NoSuchProviderException services of that class were not found. */ @NotNull public static <P> P loadProvider(@NotNull final Class<P> providerClass) throws NoSuchProviderException { final Iterator providersIterator = sun.misc.Service.providers(providerClass); if (!providersIterator.hasNext()) { throw new NoSuchProviderException("A provider named "+providerClass.getName()+" not found."); } final Object provider = providersIterator.next(); if (providerClass.isAssignableFrom(provider.getClass())) { //noinspection unchecked return (P) provider; } else { String msg = String.format("The provider named %s is an instance of %s (not the requested class)", providerClass.getName(), provider.getClass().getName()); throw new NoSuchProviderException(msg); } }
/** * Register pluggable mediator serializers from the classpath * * This looks for JAR files containing a META-INF/services that adheres to the following * http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider */ private void registerExtensions() { if (log.isDebugEnabled()) { log.debug("Registering mediator extensions found in the classpath.. "); } // register MediatorSerializer extensions Iterator it = Service.providers(MediatorSerializer.class); while (it.hasNext()) { MediatorSerializer ms = (MediatorSerializer) it.next(); String name = ms.getMediatorClassName(); try { serializerMap.put(name, ms.getClass().newInstance()); } catch (InstantiationException e) { handleException("Error instantiating mediator serializer : " + ms); } catch (IllegalAccessException e) { handleException("Error instantiating mediator serializer : " + ms); } if (log.isDebugEnabled()) { log.debug("Added MediatorSerializer " + ms.getClass().getName() + " to handle " + name); } } }
/** * The default reporters applicable for standard test runs. * * @return a list of default reporters. */ public static List<AcceptanceTestReporter> getDefaultReporters() { List<AcceptanceTestReporter> reporters = new ArrayList<AcceptanceTestReporter>(); FormatConfiguration formatConfiguration = new FormatConfiguration(Injectors.getInjector().getProvider(EnvironmentVariables.class).get() ); Iterator<?> reporterImplementations = Service.providers(AcceptanceTestReporter.class); LOGGER.info("Reporting formats: " + formatConfiguration.getFormats()); while (reporterImplementations.hasNext()) { AcceptanceTestReporter reporter = (AcceptanceTestReporter) reporterImplementations.next(); LOGGER.info("Found reporter: " + reporter + "(format = " + reporter.getFormat() + ")"); if (!reporter.getFormat().isPresent() || formatConfiguration.getFormats().contains(reporter.getFormat().get())) { LOGGER.info("Registering reporter: " + reporter); reporters.add(reporter); } } return reporters; }
Iterator providers = Service.providers(XKMSServiceExecutor.class); for (; providers.hasNext();) { XKMSServiceExecutor executor = (XKMSServiceExecutor) providers