@SuppressWarnings("unchecked") @Override public void onRegistration(final ServiceRegistry registry, final Class<?> category) { ImageReaderSpi defaultProvider = lookupProviderByName(registry, "com.sun.imageio.plugins.bmp.BMPImageReaderSpi", ImageReaderSpi.class); if (defaultProvider != null) { // Order before com.sun provider, to aid ImageIO in selecting our reader registry.setOrdering((Class<ImageReaderSpi>) category, this, defaultProvider); } }
/** * THIS METHOD WILL ME MOVED/RENAMED, DO NOT USE. * * @param registry the registry to unregister from. * @param provider the provider to unregister. * @param category the category to unregister from. */ public static <T> void deregisterProvider(final ServiceRegistry registry, final IIOServiceProvider provider, final Class<T> category) { // http://www.ibm.com/developerworks/java/library/j-jtp04298.html registry.deregisterServiceProvider(category.cast(provider), category); }
/** * THIS METHOD WILL ME MOVED/RENAMED, DO NOT USE. * * @param registry the registry to lookup from. * @param providerClassName name of the provider class. * @param category provider category * * @return the provider instance, or {@code null}. */ public static <T> T lookupProviderByName(final ServiceRegistry registry, final String providerClassName, Class<T> category) { try { return category.cast(registry.getServiceProviderByClass(Class.forName(providerClassName))); } catch (ClassNotFoundException ignore) { return null; } }
public void onRegistration(ServiceRegistry registry, Class category) { if (registered) { return; } registered = true; // Set pairwise ordering to give codecLib writer precedence. Class codecLibWriterSPIClass = null; try { codecLibWriterSPIClass = Class.forName("com.github.jaiimageio.jpeg2000.impl.J2KImageWriterCodecLibSpi"); } catch(Throwable t) { // Ignore it. } if(codecLibWriterSPIClass != null) { Object codecLibWriterSPI = registry.getServiceProviderByClass(codecLibWriterSPIClass); if(codecLibWriterSPI != null) { registry.setOrdering(category, codecLibWriterSPI, this); } } }
@Override public boolean hasNext() { while ((spiIT == null || !spiIT.hasNext()) && (loaderIt.hasNext())) { final ClassLoader l = loaderIt.next(); if (checkset.contains(l)) continue; checkset.add(l); spiIT = (Iterator<T>) ServiceRegistry.lookupProviders(service, l); } return spiIT != null && spiIT.hasNext(); }
@Override public void onRegistration(ServiceRegistry registry, Class category) { super.onRegistration(registry, category); if (registered) { return; } registered = true; Iterator<ImageReaderWriterSpi> readers = ImageIOUtilities .getImageReaderWriterSPI(registry, new TIFFFilter(true), "TIFF", true).iterator(); while (readers.hasNext()) { final ImageReaderSpi spi = (ImageReaderSpi) readers.next(); if (spi == this) { continue; } registry.deregisterServiceProvider(spi); registry.setOrdering(category, this, spi); } }
/** * Upon registration, this method ensures that this SPI is listed at the top * of the ImageInputStreamSpi items, so that it will be invoked before the * default FileImageInputStreamSpi * * @param registry * ServiceRegistry where this object has been registered. * @param category * a Class object indicating the registry category under which * this object has been registered. */ public void onRegistration(ServiceRegistry registry, Class<?> category) { super.onRegistration(registry, category); Class<ImageInputStreamSpi> targetClass = ImageInputStreamSpi.class; for (Iterator<? extends ImageInputStreamSpi> i = registry.getServiceProviders(targetClass, true); i.hasNext();) { ImageInputStreamSpi other = i.next(); if (other instanceof FileImageInputStreamSpi) registry.deregisterServiceProvider(other); if (this != other) registry.setOrdering(targetClass, this, other); } }
public void onRegistration(ServiceRegistry registry, Class<?> category) { super.onRegistration(registry, category); Class<ImageInputStreamSpi> targetClass = ImageInputStreamSpi.class; for (Iterator<? extends ImageInputStreamSpi> i = registry.getServiceProviders(targetClass, true); i.hasNext(); ) { ImageInputStreamSpi other = i.next(); if (this != other) registry.setOrdering(targetClass, this, other); } } /**
final Iterator<?> it; if (subclasses) { it = registry.getServiceProviders(category, false); } else { it = Collections.singleton(registry.getServiceProviderByClass(type)).iterator(); if (type.isInstance(other) && (exclude == null || !exclude.isInstance(other))) { if (before) { registry.setOrdering(category, factory, other); } else { registry.setOrdering(category, other, factory);
@SuppressWarnings( "unchecked" ) private static void addApplicationClasspathExportFileTypes(ExportFileTypeRegistry registry) { ClassLoader classLoader = (loader != null) ? loader : Thread.currentThread().getContextClassLoader(); Iterator<Class<?>> iterator = categories.iterator(); while (iterator.hasNext()) { Class<?> category = iterator.next(); Iterator<Object> providers = Service.providers(category, classLoader).iterator(); Object previous = null; while (providers.hasNext()) { Object current = providers.next(); registry.service.registerServiceProvider(current); if (previous != null) { registry.service.setOrdering((Class<Object>)category, previous, current); } previous = current; } } } }
/** * Returns a list of all registered ExportFileTypes in the order in which * they are found in jar files on the classpath, followed by all the extra * registered ExportFileTypes as long as they do not duplicate any * ExportFileType in the list. The list is for a particular * format, or all if format is null. */ public List/*<ExportFileType>*/<ExportFileType> get(String format) { List<ExportFileType> export = new ArrayList<ExportFileType>(); // add all ExportFileTypes found in service addExportFileTypeToList(export, format, service.getServiceProviders(ExportFileType.class, true)); // add all ExportFileTypes on extraTypes addExportFileTypeToList(export, format, extraTypes.iterator()); return export; }
public void onRegistration(ServiceRegistry registry, Class category) { if (registered) { return; } registered = true; // Set pairwise ordering to give codecLib reader precedence. Class codecLibReaderSPIClass = null; try { codecLibReaderSPIClass = Class.forName("com.github.jaiimageio.jpeg2000.impl.J2KImageReaderCodecLibSpi"); } catch(Throwable t) { // Ignore it. } if(codecLibReaderSPIClass != null) { Object codecLibReaderSPI = registry.getServiceProviderByClass(codecLibReaderSPIClass); if(codecLibReaderSPI != null) { registry.setOrdering(category, codecLibReaderSPI, this); } } }
private BrailleTranslatorFactoryMaker() { logger = Logger.getLogger(BrailleTranslatorFactoryMaker.class.getCanonicalName()); factories = new ArrayList<BrailleTranslatorFactory>(); Iterator<BrailleTranslatorFactory> i = ServiceRegistry.lookupProviders(BrailleTranslatorFactory.class); while (i.hasNext()) { factories.add(i.next()); } this.map = new HashMap<String, BrailleTranslatorFactory>(); }
public void onRegistration(ServiceRegistry registry, Class category) { super.onRegistration(registry, category); if (registered) { return; } registered = true; final Iterator<ImageReaderWriterSpi> writers = ImageIOUtilities.getImageReaderWriterSPI( registry, new TIFFImageReaderSpi.TIFFFilter(false), "TIFF", true).iterator(); while (writers.hasNext()) { final ImageWriterSpi spi = (ImageWriterSpi) writers.next(); if (spi == this) { continue; } registry.deregisterServiceProvider(spi); registry.setOrdering(category, this, spi); } } }
/** * Upon registration, this method ensures that this SPI will be invoked * before the default FileImageOutputStreamSpi * * @param registry * ServiceRegistry where this object has been registered. * @param category * a Class object indicating the registry category under * which this object has been registered. */ @SuppressWarnings("unchecked") public void onRegistration(ServiceRegistry registry, Class category) { super.onRegistration(registry, category); Object other; final Class targetClass = ImageOutputStreamSpi.class; for (Iterator i = registry.getServiceProviders(targetClass, true); i.hasNext();) { other = i.next(); if (other instanceof FileImageOutputStreamSpi) registry.deregisterServiceProvider(other); if (this != other) { registry.setOrdering(targetClass, this, other); } } }
private void deregisterOtherSPIs(ServiceRegistry registry, Class category) { if (registry == null) { return; } try { Iterator<ImageReaderSpi> iter = registry.getServiceProviders(ImageReaderSpi.class, new ContainsFilter(readerFormatNamesMethod, "JPEG"), true); for (; iter.hasNext();) { ImageReaderSpi spi = iter.next(); if (!spi.getClass().equals(this.getClass())) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Deprioritizing " + spi); } // ETj: we used to deregister the other ones, but they may be // explicitely requested // registry.deregisterServiceProvider(spi); registry.setOrdering(category, this, spi); } } } catch (IllegalArgumentException e) { } }
@SuppressWarnings( "unchecked" ) private static void addApplicationClasspathExportFileTypes(ExportFileTypeRegistry registry) { ClassLoader classLoader = (loader != null) ? loader : Thread.currentThread().getContextClassLoader(); Iterator<Class<?>> iterator = categories.iterator(); while (iterator.hasNext()) { Class<?> category = iterator.next(); Iterator<Object> providers = Service.providers(category, classLoader).iterator(); Object previous = null; while (providers.hasNext()) { Object current = providers.next(); registry.service.registerServiceProvider(current); if (previous != null) { registry.service.setOrdering((Class<Object>)category, previous, current); } previous = current; } } } }
/** * Returns a list of all registered ExportFileTypes in the order in which * they are found in jar files on the classpath, followed by all the extra * registered ExportFileTypes as long as they do not duplicate any * ExportFileType in the list. The list is for a particular * format, or all if format is null. */ public List/*<ExportFileType>*/<ExportFileType> get(String format) { List<ExportFileType> export = new ArrayList<ExportFileType>(); // add all ExportFileTypes found in service addExportFileTypeToList(export, format, service.getServiceProviders(ExportFileType.class, true)); // add all ExportFileTypes on extraTypes addExportFileTypeToList(export, format, extraTypes.iterator()); return export; }
public void onRegistration(ServiceRegistry registry, Class category) { if (registered) { return; } registered = true; // Set pairwise ordering to give codecLib writer precedence. Class codecLibWriterSPIClass = null; try { codecLibWriterSPIClass = Class.forName("com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWriterCodecLibSpi"); } catch(Throwable t) { // Ignore it. } if(codecLibWriterSPIClass != null) { Object codecLibWriterSPI = registry.getServiceProviderByClass(codecLibWriterSPIClass); if(codecLibWriterSPI != null) { registry.setOrdering(category, codecLibWriterSPI, this); } } }
public static <T> T loadService(Class<T> providerClass) { Iterator i = ServiceRegistry.lookupProviders(providerClass); if(!i.hasNext()) throw new IllegalStateException("No service found for " + providerClass); T service = providerClass.cast(i.next()); if(i.hasNext()) throw new IllegalStateException("More than 1 service found for " + providerClass); return service; } }