/** * Get a resource uploader. * * @return A {@link CclResourceUploader} object to be used to upload CCL resources. */ public static CclResourceUploader getUploader() { @SuppressWarnings("unchecked") final Enumeration<CclResourceUploader> providers = Service.providers(CclResourceUploader.class); if (!providers.hasMoreElements()) throw new IllegalStateException("No implementations found of: " + CclResourceUploader.class.getName()); return providers.nextElement(); }
/** * Get an executor. * * @return An implementation of {@link CclExecutor}. * @throws IllegalStateException * If no implementations are found. */ public static CclExecutor getExecutor() { @SuppressWarnings("unchecked") final Enumeration<CclExecutor> providers = Service.providers(CclExecutor.class); if (!providers.hasMoreElements()) throw new IllegalStateException("No implementations found of: " + CclExecutor.class.getName()); return providers.nextElement(); }
/** * Get the rules to be used. * * @return A {@link Set} of {@link AnalysisRule} implementations. */ @SuppressWarnings("unchecked") public Set<AnalysisRule> getRules() { if (rules == null) { rules = new HashSet<AnalysisRule>(); final Enumeration<AnalysisRule> providersEnum = Service.providers(AnalysisRule.class); while (providersEnum.hasMoreElements()) rules.add(providersEnum.nextElement()); } return rules; } }
/** * as described in * sun/jdk1.3.1/docs/guide/jar/jar.html#Service Provider, * Except this uses <code>Enumeration</code> * instead of <code>Interator</code>. * * @param <T> Service Provider Interface type * @param <S> Any type extends the SPI type * @param spiClass Service Provider Interface Class * @return Enumeration of class instances ({@code S}) */ public static <T, S extends T> Enumeration<S> providers(Class<T> spiClass) { return providers(new SPInterface<T>(spiClass), null); }
/** * Get a service provider. * * @param <T> * The type of the object to be returned. * @param clazz * The {@link Class} whose implementation is to be returned. * @return The implementation of the given class. * @throws IllegalStateException * If no providers are found for the given class. */ @SuppressWarnings("unchecked") public static <T> T getProvider(final Class<T> clazz) { if (overrides.containsKey(clazz)) return (T) overrides.get(clazz); final Enumeration<T> providers = Service.providers(clazz); if (!providers.hasMoreElements()) throw new IllegalStateException("No providers found for: " + clazz.getName()); return providers.nextElement(); } }
/** * {@inheritDoc} */ @SuppressWarnings("unchecked") public Set<Violation> getCheckedViolations() { final Set<Violation> violations = new HashSet<Violation>(); final ClassLoaders classLoaders = new ClassLoaders(); final Class<Document>[] classes = new Class[] { Document.class }; final Document[] objects = new Document[] { new Document() }; classLoaders.put(Document.class.getClassLoader()); final Enumeration<Delegate> delegates = Service.providers(new SPInterface(Delegate.class, classes, objects), classLoaders); while (delegates.hasMoreElements()) { violations.addAll(delegates.nextElement().getCheckedViolations()); } return violations; }
/** * {@inheritDoc} */ @SuppressWarnings("unchecked") public Set<Violation> analyze(final String prgXml) { final Set<Violation> violations = new HashSet<Violation>(); try { final ClassLoaders classLoaders = new ClassLoaders(); final Class<Document>[] classes = new Class[] { Document.class }; final Document[] objects = new Document[] { new SAXBuilder().build(new StringReader(prgXml)) }; classLoaders.put(Document.class.getClassLoader()); final Enumeration<Delegate> delegates = Service.providers(new SPInterface(Delegate.class, classes, objects), classLoaders); if (delegates != null) { while (delegates.hasMoreElements()) { violations.addAll(delegates.nextElement().analyze()); } } } catch (final JDOMException | IOException e) { throw new JdomException("Failed to analyze XML.", e); } return violations; }
Enumeration providers = Service.providers( new SPInterface(AbstractFactoryRegistry.class), loaders); while (providers.hasMoreElements())
Enumeration providers = Service.providers( new SPInterface(AbstractFactoryRegistry.class), loaders); while (providers.hasMoreElements())