jdk/src/share/classes/javax/imageio/spi/IIORegistry.java
author henryjen
Fri, 21 Feb 2014 15:28:39 -0800
changeset 23313 f100f0d49e0b
parent 15263 f401cac7510b
child 23328 4c53a6ebc779
permissions -rw-r--r--
8035487: Fix raw and unchecked lint warnings in javax.imageio.spi Reviewed-by: darcy, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
15263
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 5506
diff changeset
     2
 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.imageio.spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.NoSuchElementException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.imageio.spi.FileImageInputStreamSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.imageio.spi.FileImageOutputStreamSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.imageio.spi.InputStreamImageInputStreamSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import com.sun.imageio.spi.OutputStreamImageOutputStreamSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import com.sun.imageio.spi.RAFImageInputStreamSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import com.sun.imageio.spi.RAFImageOutputStreamSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import com.sun.imageio.plugins.gif.GIFImageReaderSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import com.sun.imageio.plugins.gif.GIFImageWriterSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import com.sun.imageio.plugins.jpeg.JPEGImageReaderSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import com.sun.imageio.plugins.jpeg.JPEGImageWriterSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import com.sun.imageio.plugins.png.PNGImageReaderSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import com.sun.imageio.plugins.png.PNGImageWriterSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import com.sun.imageio.plugins.bmp.BMPImageReaderSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import com.sun.imageio.plugins.bmp.BMPImageWriterSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import com.sun.imageio.plugins.wbmp.WBMPImageReaderSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import com.sun.imageio.plugins.wbmp.WBMPImageWriterSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import sun.awt.AppContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.util.ServiceLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.util.ServiceConfigurationError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * A registry for service provider instances.  Service provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * classes may be detected at run time by means of meta-information in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * the JAR files containing them.  The intent is that it be relatively
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * inexpensive to load and inspect all available service provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * classes.  These classes may them be used to locate and instantiate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * more heavyweight classes that will perform actual work, in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * case instances of <code>ImageReader</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <code>ImageWriter</code>, <code>ImageTranscoder</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <code>ImageInputStream</code>, and <code>ImageOutputStream</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
15263
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 5506
diff changeset
    67
 * <p> Service providers found on the system classpath (typically
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 5506
diff changeset
    68
 * the <code>lib/ext</code> directory in the Java
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 5506
diff changeset
    69
 * installation directory) are automatically loaded as soon as this class is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * instantiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <p> When the <code>registerApplicationClasspathSpis</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * is called, service provider instances declared in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * meta-information section of JAR files on the application class path
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * are loaded.  To declare a service provider, a <code>services</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * subdirectory is placed within the <code>META-INF</code> directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * that is present in every JAR file.  This directory contains a file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * for each service provider interface that has one or more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * implementation classes present in the JAR file.  For example, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * the JAR file contained a class named
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <code>com.mycompany.imageio.MyFormatReaderSpi</code> which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * implements the <code>ImageReaderSpi</code> interface, the JAR file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * would contain a file named:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * META-INF/services/javax.imageio.spi.ImageReaderSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * containing the line:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * com.mycompany.imageio.MyFormatReaderSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * <p> The service provider classes are intended to be lightweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * and quick to load.  Implementations of these interfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * should avoid complex dependencies on other classes and on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * native code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <p> It is also possible to manually add service providers not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * automatically, as well as to remove those that are using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * interfaces of the <code>ServiceRegistry</code> class.  Thus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * the application may customize the contents of the registry as it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * sees fit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * <p> For more details on declaring service providers, and the JAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * format in general, see the <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * href="{@docRoot}/../technotes/guides/jar/jar.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * JAR File Specification</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
public final class IIORegistry extends ServiceRegistry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * A <code>Vector</code> containing the valid IIO registry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * categories (superinterfaces) to be used in the constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
23313
f100f0d49e0b 8035487: Fix raw and unchecked lint warnings in javax.imageio.spi
henryjen
parents: 15263
diff changeset
   118
    private static final Vector<Class<?>> initialCategories = new Vector<>(5);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        initialCategories.add(ImageReaderSpi.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        initialCategories.add(ImageWriterSpi.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        initialCategories.add(ImageTranscoderSpi.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        initialCategories.add(ImageInputStreamSpi.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        initialCategories.add(ImageOutputStreamSpi.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Set up the valid service provider categories and automatically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * register all available service providers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * <p> The constructor is private in order to prevent creation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * additional instances.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    private IIORegistry() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        super(initialCategories.iterator());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        registerStandardSpis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        registerApplicationClasspathSpis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Returns the default <code>IIORegistry</code> instance used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * the Image I/O API.  This instance should be used for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * registry functions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * <p> Each <code>ThreadGroup</code> will receive its own
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * instance; this allows different <code>Applet</code>s in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * same browser (for example) to each have their own registry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @return the default registry for the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * <code>ThreadGroup</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public static IIORegistry getDefaultInstance() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        AppContext context = AppContext.getAppContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        IIORegistry registry =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            (IIORegistry)context.get(IIORegistry.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if (registry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            // Create an instance for this AppContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            registry = new IIORegistry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            context.put(IIORegistry.class, registry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        return registry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    private void registerStandardSpis() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        // Hardwire standard SPIs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        registerServiceProvider(new GIFImageReaderSpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        registerServiceProvider(new GIFImageWriterSpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        registerServiceProvider(new BMPImageReaderSpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        registerServiceProvider(new BMPImageWriterSpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        registerServiceProvider(new WBMPImageReaderSpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        registerServiceProvider(new WBMPImageWriterSpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        registerServiceProvider(new PNGImageReaderSpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        registerServiceProvider(new PNGImageWriterSpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        registerServiceProvider(new JPEGImageReaderSpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        registerServiceProvider(new JPEGImageWriterSpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        registerServiceProvider(new FileImageInputStreamSpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        registerServiceProvider(new FileImageOutputStreamSpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        registerServiceProvider(new InputStreamImageInputStreamSpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        registerServiceProvider(new OutputStreamImageOutputStreamSpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        registerServiceProvider(new RAFImageInputStreamSpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        registerServiceProvider(new RAFImageOutputStreamSpi());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        registerInstalledProviders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Registers all available service providers found on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * application class path, using the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * <code>ClassLoader</code>.  This method is typically invoked by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * the <code>ImageIO.scanForPlugins</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @see javax.imageio.ImageIO#scanForPlugins
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @see ClassLoader#getResources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public void registerApplicationClasspathSpis() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        // FIX: load only from application classpath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
23313
f100f0d49e0b 8035487: Fix raw and unchecked lint warnings in javax.imageio.spi
henryjen
parents: 15263
diff changeset
   201
        Iterator<Class<?>> categories = getCategories();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        while (categories.hasNext()) {
23313
f100f0d49e0b 8035487: Fix raw and unchecked lint warnings in javax.imageio.spi
henryjen
parents: 15263
diff changeset
   203
            @SuppressWarnings("unchecked")
f100f0d49e0b 8035487: Fix raw and unchecked lint warnings in javax.imageio.spi
henryjen
parents: 15263
diff changeset
   204
            Class<IIOServiceProvider> c = (Class<IIOServiceProvider>)categories.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            Iterator<IIOServiceProvider> riter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    ServiceLoader.load(c, loader).iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            while (riter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    // Note that the next() call is required to be inside
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    // the try/catch block; see 6342404.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    IIOServiceProvider r = riter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                    registerServiceProvider(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                } catch (ServiceConfigurationError err) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    if (System.getSecurityManager() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                        // In the applet case, we will catch the  error so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                        // registration of other plugins can  proceed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                        err.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                        // In the application case, we will  throw the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                        // error to indicate app/system  misconfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                        throw err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    private void registerInstalledProviders() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        /*
15263
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 5506
diff changeset
   230
          We need to load installed providers from the
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 5506
diff changeset
   231
          system classpath (typically the <code>lib/ext</code>
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 5506
diff changeset
   232
          directory in in the Java installation directory)
f401cac7510b 8005250: Downgrade normative references to ${java.home}/lib folder from Java client code.
uta
parents: 5506
diff changeset
   233
          in the privileged mode in order to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
          be able read corresponding jar files even if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
          file read capability is restricted (like the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
          applet context case).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
         */
23313
f100f0d49e0b 8035487: Fix raw and unchecked lint warnings in javax.imageio.spi
henryjen
parents: 15263
diff changeset
   238
        PrivilegedAction<Object> doRegistration =
f100f0d49e0b 8035487: Fix raw and unchecked lint warnings in javax.imageio.spi
henryjen
parents: 15263
diff changeset
   239
            new PrivilegedAction<Object>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                public Object run() {
23313
f100f0d49e0b 8035487: Fix raw and unchecked lint warnings in javax.imageio.spi
henryjen
parents: 15263
diff changeset
   241
                    Iterator<Class<?>> categories = getCategories();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    while (categories.hasNext()) {
23313
f100f0d49e0b 8035487: Fix raw and unchecked lint warnings in javax.imageio.spi
henryjen
parents: 15263
diff changeset
   243
                        @SuppressWarnings("unchecked")
f100f0d49e0b 8035487: Fix raw and unchecked lint warnings in javax.imageio.spi
henryjen
parents: 15263
diff changeset
   244
                        Class<IIOServiceProvider> c = (Class<IIOServiceProvider>)categories.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                        for (IIOServiceProvider p : ServiceLoader.loadInstalled(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                            registerServiceProvider(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        AccessController.doPrivileged(doRegistration);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
}