/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A registry for service provider instances. Service provider
* classes may be detected at run time by means of meta-information in
* the JAR files containing them. The intent is that it be relatively
* inexpensive to load and inspect all available service provider
* classes. These classes may them be used to locate and instantiate
* more heavyweight classes that will perform actual work, in this
* case instances of <code>ImageReader</code>,
* <code>ImageWriter</code>, <code>ImageTranscoder</code>,
* <code>ImageInputStream</code>, and <code>ImageOutputStream</code>.
*
* <p> Service providers found on the system classpath (<i>e.g.</i>,
* JDK) are automatically loaded as soon as this class is
* instantiated.
*
* <p> When the <code>registerApplicationClasspathSpis</code> method
* is called, service provider instances declared in the
* meta-information section of JAR files on the application class path
* are loaded. To declare a service provider, a <code>services</code>
* subdirectory is placed within the <code>META-INF</code> directory
* that is present in every JAR file. This directory contains a file
* for each service provider interface that has one or more
* implementation classes present in the JAR file. For example, if
* the JAR file contained a class named
* <code>com.mycompany.imageio.MyFormatReaderSpi</code> which
* implements the <code>ImageReaderSpi</code> interface, the JAR file
* would contain a file named:
*
* <pre>
* </pre>
*
* containing the line:
*
* <pre>
* com.mycompany.imageio.MyFormatReaderSpi
* </pre>
*
* <p> The service provider classes are intended to be lightweight
* and quick to load. Implementations of these interfaces
* should avoid complex dependencies on other classes and on
* native code.
*
* <p> It is also possible to manually add service providers not found
* automatically, as well as to remove those that are using the
* interfaces of the <code>ServiceRegistry</code> class. Thus
* the application may customize the contents of the registry as it
* sees fit.
*
* <p> For more details on declaring service providers, and the JAR
* format in general, see the <a
* JAR File Specification</a>.
*
*/
/**
* A <code>Vector</code> containing the valid IIO registry
* categories (superinterfaces) to be used in the constructor.
*/
static {
}
/**
* Set up the valid service provider categories and automatically
* register all available service providers.
*
* <p> The constructor is private in order to prevent creation of
* additional instances.
*/
private IIORegistry() {
super(initialCategories.iterator());
}
/**
* Returns the default <code>IIORegistry</code> instance used by
* the Image I/O API. This instance should be used for all
* registry functions.
*
* <p> Each <code>ThreadGroup</code> will receive its own
* instance; this allows different <code>Applet</code>s in the
* same browser (for example) to each have their own registry.
*
* @return the default registry for the current
* <code>ThreadGroup</code>.
*/
// Create an instance for this AppContext
registry = new IIORegistry();
}
return registry;
}
private void registerStandardSpis() {
// Hardwire standard SPIs
}
/**
* Registers all available service providers found on the
* application class path, using the default
* <code>ClassLoader</code>. This method is typically invoked by
* the <code>ImageIO.scanForPlugins</code> method.
*
* @see javax.imageio.ImageIO#scanForPlugins
* @see ClassLoader#getResources
*/
public void registerApplicationClasspathSpis() {
// FIX: load only from application classpath
while (categories.hasNext()) {
try {
// Note that the next() call is required to be inside
} catch (ServiceConfigurationError err) {
// In the applet case, we will catch the error so
// registration of other plugins can proceed
} else {
// In the application case, we will throw the
throw err;
}
}
}
}
}
private void registerInstalledProviders() {
/*
directory in the privileged mode in order to
be able read corresponding jar files even if
file read capability is restricted (like the
applet context case).
*/
new PrivilegedAction() {
while (categories.hasNext()) {
}
}
return this;
}
};
}
}