List of usage examples for java.util ServiceLoader load
@CallerSensitive public static <S> ServiceLoader<S> load(ModuleLayer layer, Class<S> service)
From source file:org.apache.geode.internal.cache.xmlcache.CacheXmlParser.java
/** * Get delegate {@link XmlParser} for the given <code>namespaceUri</code> * /*from www . j a va2s .co m*/ * @param namespaceUri to find {@link XmlParser} for. * @return {@link XmlParser} if found, otherwise null. * @since GemFire 8.1 */ // UnitTest CacheXmlParser.testGetDelegate() private XmlParser getDelegate(final String namespaceUri) { XmlParser delegate = delegates.get(namespaceUri); if (null == delegate) { try { final ServiceLoader<XmlParser> serviceLoader = ServiceLoader.load(XmlParser.class, ClassPathLoader.getLatestAsClassLoader()); for (final XmlParser xmlParser : serviceLoader) { if (xmlParser.getNamespaceUri().equals(namespaceUri)) { delegate = xmlParser; delegate.setStack(stack); delegate.setDocumentLocator(documentLocator); delegates.put(xmlParser.getNamespaceUri(), xmlParser); break; } } } catch (final Exception e) { logger.error(e.getMessage(), e); } } return delegate; }