< prev index next >

src/java.desktop/share/classes/javax/imageio/spi/ServiceRegistry.java

Print this page

663 
664     /**
665      * Deregisters all currently registered service providers from all
666      * categories.
667      */
668     public void deregisterAll() {
669         for (SubRegistry reg : categoryMap.values()) {
670             reg.clear();
671         }
672     }
673 
674     /**
675      * Finalizes this object prior to garbage collection.  The
676      * {@code deregisterAll} method is called to deregister all
677      * currently registered service providers.  This method should not
678      * be called from application code.
679      *
680      * @exception Throwable if an error occurs during superclass
681      * finalization.
682      *
683      * @deprecated The {@code finalize} method has been deprecated.
684      *     Subclasses that override {@code finalize} in order to perform cleanup
685      *     should be modified to use alternative cleanup mechanisms and
686      *     to remove the overriding {@code finalize} method.
687      *     When overriding the {@code finalize} method, its implementation must explicitly
688      *     ensure that {@code super.finalize()} is invoked as described in {@link Object#finalize}.
689      *     See the specification for {@link Object#finalize()} for further
690      *     information about migration options.
691      */
692     @Deprecated(since="9")

693     public void finalize() throws Throwable {
694         deregisterAll();
695         super.finalize();
696     }
697 
698     /**
699      * Checks whether the provided class is one of the allowed
700      * ImageIO service provider classes. If it is, returns normally.
701      * If it is not, throws IllegalArgumentException.
702      *
703      * @param clazz
704      * @throws IllegalArgumentException if clazz is null or is not one of the allowed set
705      */
706     private static void checkClassAllowed(Class<?> clazz) {
707         if (clazz == null) {
708             throw new IllegalArgumentException("class must not be null");
709         }
710 
711         if (   clazz != ImageInputStreamSpi.class
712             && clazz != ImageOutputStreamSpi.class

825         Iterator<Object> iter = map.values().iterator();
826         while (iter.hasNext()) {
827             Object provider = iter.next();
828             iter.remove();
829 
830             if (provider instanceof RegisterableService) {
831                 RegisterableService rs = (RegisterableService)provider;
832                 AccessControlContext acc = accMap.get(provider.getClass());
833                 if (acc != null || System.getSecurityManager() == null) {
834                     AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
835                     rs.onDeregistration(registry, category);
836                         return null;
837                     }, acc);
838                 }
839             }
840         }
841         poset.clear();
842         accMap.clear();
843     }
844 
845     @SuppressWarnings("deprecation")
846     public synchronized void finalize() {
847         clear();
848     }
849 }
850 
851 
852 /**
853  * A class for wrapping {@code Iterators} with a filter function.
854  * This provides an iterator for a subset without duplication.
855  */
856 class FilterIterator<T> implements Iterator<T> {
857 
858     private Iterator<? extends T> iter;
859     private ServiceRegistry.Filter filter;
860 
861     private T next = null;
862 
863     public FilterIterator(Iterator<? extends T> iter,
864                           ServiceRegistry.Filter filter) {
865         this.iter = iter;

663 
664     /**
665      * Deregisters all currently registered service providers from all
666      * categories.
667      */
668     public void deregisterAll() {
669         for (SubRegistry reg : categoryMap.values()) {
670             reg.clear();
671         }
672     }
673 
674     /**
675      * Finalizes this object prior to garbage collection.  The
676      * {@code deregisterAll} method is called to deregister all
677      * currently registered service providers.  This method should not
678      * be called from application code.
679      *
680      * @exception Throwable if an error occurs during superclass
681      * finalization.
682      *
683      * @deprecated Finalization has been deprecated for removal.  See
684      * {@link java.lang.Object#finalize} for background information and details
685      * about migration options.





686      */
687     @Deprecated(since="9", forRemoval=true)
688     @SuppressWarnings("removal")
689     public void finalize() throws Throwable {
690         deregisterAll();
691         super.finalize();
692     }
693 
694     /**
695      * Checks whether the provided class is one of the allowed
696      * ImageIO service provider classes. If it is, returns normally.
697      * If it is not, throws IllegalArgumentException.
698      *
699      * @param clazz
700      * @throws IllegalArgumentException if clazz is null or is not one of the allowed set
701      */
702     private static void checkClassAllowed(Class<?> clazz) {
703         if (clazz == null) {
704             throw new IllegalArgumentException("class must not be null");
705         }
706 
707         if (   clazz != ImageInputStreamSpi.class
708             && clazz != ImageOutputStreamSpi.class

821         Iterator<Object> iter = map.values().iterator();
822         while (iter.hasNext()) {
823             Object provider = iter.next();
824             iter.remove();
825 
826             if (provider instanceof RegisterableService) {
827                 RegisterableService rs = (RegisterableService)provider;
828                 AccessControlContext acc = accMap.get(provider.getClass());
829                 if (acc != null || System.getSecurityManager() == null) {
830                     AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
831                     rs.onDeregistration(registry, category);
832                         return null;
833                     }, acc);
834                 }
835             }
836         }
837         poset.clear();
838         accMap.clear();
839     }
840 
841     @SuppressWarnings("removal")
842     public synchronized void finalize() {
843         clear();
844     }
845 }
846 
847 
848 /**
849  * A class for wrapping {@code Iterators} with a filter function.
850  * This provides an iterator for a subset without duplication.
851  */
852 class FilterIterator<T> implements Iterator<T> {
853 
854     private Iterator<? extends T> iter;
855     private ServiceRegistry.Filter filter;
856 
857     private T next = null;
858 
859     public FilterIterator(Iterator<? extends T> iter,
860                           ServiceRegistry.Filter filter) {
861         this.iter = iter;
< prev index next >