aboutsummaryrefslogtreecommitdiff
path: root/libjava/javax/imageio/spi
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/javax/imageio/spi')
-rw-r--r--libjava/javax/imageio/spi/IIORegistry.java103
-rw-r--r--libjava/javax/imageio/spi/ImageInputStreamSpi.java2
-rw-r--r--libjava/javax/imageio/spi/ImageOutputStreamSpi.java2
-rw-r--r--libjava/javax/imageio/spi/ImageReaderSpi.java121
-rw-r--r--libjava/javax/imageio/spi/ImageWriterSpi.java135
-rw-r--r--libjava/javax/imageio/spi/ServiceRegistry.java20
6 files changed, 377 insertions, 6 deletions
diff --git a/libjava/javax/imageio/spi/IIORegistry.java b/libjava/javax/imageio/spi/IIORegistry.java
new file mode 100644
index 0000000..7728cf4
--- /dev/null
+++ b/libjava/javax/imageio/spi/IIORegistry.java
@@ -0,0 +1,103 @@
+/* IIORegistry.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath 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 for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.imageio.spi;
+
+import gnu.classpath.ServiceFactory;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+
+public final class IIORegistry extends ServiceRegistry
+{
+ private static final HashSet defaultCategories = new HashSet();
+
+ private static HashMap instances = new HashMap();
+
+ static
+ {
+ //defaultCategories.add(ImageReaderSpi.class);
+ //defaultCategories.add(ImageWriterSpi.class);
+ defaultCategories.add(ImageTranscoderSpi.class);
+ defaultCategories.add(ImageInputStreamSpi.class);
+ defaultCategories.add(ImageOutputStreamSpi.class);
+ }
+
+ public static synchronized IIORegistry getDefaultInstance()
+ {
+ ThreadGroup group = Thread.currentThread().getThreadGroup();
+ IIORegistry registry = (IIORegistry) instances.get(group);
+
+ if (registry == null)
+ {
+ registry = new IIORegistry();
+ instances.put(group, registry);
+ }
+
+ return registry;
+ }
+
+ private IIORegistry()
+ {
+ super(defaultCategories.iterator());
+
+ // XXX: Register built-in Spis here.
+
+ registerApplicationClasspathSpis();
+ }
+
+ /**
+ * Registers all available service providers found on the application
+ * classpath.
+ */
+ public void registerApplicationClasspathSpis()
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ Iterator categories = getCategories();
+
+ while (categories.hasNext())
+ {
+ Class category = (Class) categories.next();
+ Iterator providers = ServiceFactory.lookupProviders(category, loader);
+
+ while (providers.hasNext())
+ registerServiceProvider((IIOServiceProvider) providers.next());
+ }
+ }
+}
diff --git a/libjava/javax/imageio/spi/ImageInputStreamSpi.java b/libjava/javax/imageio/spi/ImageInputStreamSpi.java
index b8d5854..6e33d1d 100644
--- a/libjava/javax/imageio/spi/ImageInputStreamSpi.java
+++ b/libjava/javax/imageio/spi/ImageInputStreamSpi.java
@@ -40,8 +40,8 @@ package javax.imageio.spi;
import java.io.File;
import java.io.IOException;
-import javax.imageio.stream.ImageInputStream;
+import javax.imageio.stream.ImageInputStream;
/**
* An abstract superclass for service providers that create
diff --git a/libjava/javax/imageio/spi/ImageOutputStreamSpi.java b/libjava/javax/imageio/spi/ImageOutputStreamSpi.java
index aa287c3..935aa7c 100644
--- a/libjava/javax/imageio/spi/ImageOutputStreamSpi.java
+++ b/libjava/javax/imageio/spi/ImageOutputStreamSpi.java
@@ -40,8 +40,8 @@ package javax.imageio.spi;
import java.io.File;
import java.io.IOException;
-import javax.imageio.stream.ImageOutputStream;
+import javax.imageio.stream.ImageOutputStream;
/**
* An abstract superclass for service providers that create
diff --git a/libjava/javax/imageio/spi/ImageReaderSpi.java b/libjava/javax/imageio/spi/ImageReaderSpi.java
new file mode 100644
index 0000000..e041c37
--- /dev/null
+++ b/libjava/javax/imageio/spi/ImageReaderSpi.java
@@ -0,0 +1,121 @@
+/* ImageReaderSpi.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath 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 for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.imageio.spi;
+
+import java.io.IOException;
+
+import javax.imageio.ImageReader;
+import javax.imageio.stream.ImageInputStream;
+
+/**
+ * @author Michael Koch (konqueror@gmx.de)
+ */
+public abstract class ImageReaderSpi extends ImageReaderWriterSpi
+{
+ public static final Class[] STANDARD_INPUT_TYPE =
+ { ImageInputStream.class };
+
+ protected Class[] inputTypes;
+ protected String[] writerSpiNames;
+
+ protected ImageReaderSpi()
+ {
+ // Do nothing here.
+ }
+
+ public ImageReaderSpi(String vendorName, String version, String[] names,
+ String[] suffixes, String[] MIMETypes,
+ String readerClassName, Class[] inputTypes,
+ String[] writerSpiNames,
+ boolean supportsStandardStreamMetadataFormat,
+ String nativeStreamMetadataFormatName,
+ String nativeStreamMetadataFormatClassName,
+ String[] extraStreamMetadataFormatNames,
+ String[] extraStreamMetadataFormatClassNames,
+ boolean supportsStandardImageMetadataFormat,
+ String nativeImageMetadataFormatName,
+ String nativeImageMetadataFormatClassName,
+ String[] extraImageMetadataFormatNames,
+ String[] extraImageMetadataFormatClassNames)
+ {
+ super(vendorName, version, names, suffixes, MIMETypes, readerClassName,
+ supportsStandardStreamMetadataFormat, nativeStreamMetadataFormatName,
+ nativeStreamMetadataFormatClassName, extraStreamMetadataFormatNames,
+ extraStreamMetadataFormatClassNames, supportsStandardImageMetadataFormat,
+ nativeImageMetadataFormatName, nativeImageMetadataFormatClassName,
+ extraImageMetadataFormatNames, extraImageMetadataFormatClassNames);
+
+ if (inputTypes == null
+ || inputTypes.length == 0)
+ throw new IllegalArgumentException("inputTypes may not be null or empty");
+
+ this.inputTypes = inputTypes;
+ this.writerSpiNames = writerSpiNames;
+ }
+
+ public abstract boolean canDecodeInput(Object source)
+ throws IOException;
+
+ public ImageReader createReaderInstance()
+ throws IOException
+ {
+ return createReaderInstance(null);
+ }
+
+ public abstract ImageReader createReaderInstance(Object extension)
+ throws IOException;
+
+ public String[] getImageWriterSpiNames()
+ {
+ return writerSpiNames;
+ }
+
+ public Class[] getInputTypes()
+ {
+ return inputTypes;
+ }
+
+ public boolean isOwnReader(ImageReader reader)
+ {
+ if (reader == null)
+ throw new IllegalArgumentException("reader may not be null");
+
+ return pluginClassName.equals(reader.getClass().getName());
+ }
+}
diff --git a/libjava/javax/imageio/spi/ImageWriterSpi.java b/libjava/javax/imageio/spi/ImageWriterSpi.java
new file mode 100644
index 0000000..306408d
--- /dev/null
+++ b/libjava/javax/imageio/spi/ImageWriterSpi.java
@@ -0,0 +1,135 @@
+/* ImageWriterSpi.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath 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 for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.imageio.spi;
+
+import java.awt.image.RenderedImage;
+import java.io.IOException;
+
+import javax.imageio.ImageTypeSpecifier;
+import javax.imageio.ImageWriter;
+import javax.imageio.stream.ImageOutputStream;
+
+/**
+ * @author Michael Koch (konqueror@gmx.de)
+ */
+public abstract class ImageWriterSpi extends ImageReaderWriterSpi
+{
+ public static final Class[] STANDARD_OUTPUT_TYPE =
+ { ImageOutputStream.class };
+
+ protected Class[] outputTypes;
+ protected String[] readerSpiNames;
+
+ protected ImageWriterSpi()
+ {
+ // Do nothing here.
+ }
+
+ public ImageWriterSpi(String vendorName, String version, String[] names,
+ String[] suffixes, String[] MIMETypes,
+ String writerClassName, Class[] outputTypes,
+ String[] readerSpiNames,
+ boolean supportsStandardStreamMetadataFormat,
+ String nativeStreamMetadataFormatName,
+ String nativeStreamMetadataFormatClassName,
+ String[] extraStreamMetadataFormatNames,
+ String[] extraStreamMetadataFormatClassNames,
+ boolean supportsStandardImageMetadataFormat,
+ String nativeImageMetadataFormatName,
+ String nativeImageMetadataFormatClassName,
+ String[] extraImageMetadataFormatNames,
+ String[] extraImageMetadataFormatClassNames)
+ {
+ super(vendorName, version, names, suffixes, MIMETypes, writerClassName,
+ supportsStandardStreamMetadataFormat, nativeStreamMetadataFormatName,
+ nativeStreamMetadataFormatClassName, extraStreamMetadataFormatNames,
+ extraStreamMetadataFormatClassNames, supportsStandardImageMetadataFormat,
+ nativeImageMetadataFormatName, nativeImageMetadataFormatClassName,
+ extraImageMetadataFormatNames, extraImageMetadataFormatClassNames);
+
+ if (writerClassName == null)
+ throw new IllegalArgumentException("writerClassName is null");
+
+ if (outputTypes == null
+ || outputTypes.length == 0)
+ throw new IllegalArgumentException("outputTypes may not be null or empty");
+
+ this.outputTypes = outputTypes;
+ this.readerSpiNames = readerSpiNames;
+ }
+
+ public abstract boolean canEncodeImage(ImageTypeSpecifier type);
+
+ public boolean canEncodeImage(RenderedImage image)
+ {
+ return canEncodeImage (new ImageTypeSpecifier(image));
+ }
+
+ public ImageWriter createWriterInstance()
+ throws IOException
+ {
+ return createWriterInstance(null);
+ }
+
+ public abstract ImageWriter createWriterInstance(Object extension)
+ throws IOException;
+
+ public String[] getImageReaderSpiNames()
+ {
+ return readerSpiNames;
+ }
+
+ public Class[] getOutputTypes()
+ {
+ return outputTypes;
+ }
+
+ public boolean isFormatLossless()
+ {
+ return true;
+ }
+
+ public boolean isOwnWriter(ImageWriter writer)
+ {
+ if (writer == null)
+ throw new IllegalArgumentException("writer may not be null");
+
+ return pluginClassName.equals(writer.getClass().getName());
+ }
+}
diff --git a/libjava/javax/imageio/spi/ServiceRegistry.java b/libjava/javax/imageio/spi/ServiceRegistry.java
index c41e1b5..566d50f 100644
--- a/libjava/javax/imageio/spi/ServiceRegistry.java
+++ b/libjava/javax/imageio/spi/ServiceRegistry.java
@@ -38,9 +38,19 @@ exception statement from your version. */
package javax.imageio.spi;
-import java.util.*;
import gnu.classpath.ServiceFactory;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.IdentityHashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
/**
* A registry for service providers.
@@ -100,6 +110,8 @@ public class ServiceRegistry
/**
* Constructs a <code>ServiceRegistry</code> for the specified
* service categories.
+ *
+ * @param categories the categories to support
*
* @throws IllegalArgumentException if <code>categories</code> is
* <code>null</code>, or if its {@link Iterator#next()} method
@@ -141,7 +153,7 @@ public class ServiceRegistry
* might make sense to install only the frequently needed service
* providers on the local machine. More exotic providers can be put
* onto a server; the server will only be contacted when no suitable
- * service could be found locally.
+ * service could be found locally.</p>
*
* <p><b>Security considerations:</b> Any loaded service providers
* are loaded through the specified ClassLoader, or the system
@@ -150,7 +162,7 @@ public class ServiceRegistry
* the current {@link java.security.AccessControlContext} gets
* recorded. This captured security context will determine the
* permissions when services get loaded via the <code>next()</code>
- * method of the returned <code>Iterator</code>.
+ * method of the returned <code>Iterator</code>.</p>
*
* @param spi the service provider interface which must be
* implemented by any loaded service providers.
@@ -474,7 +486,7 @@ public class ServiceRegistry
* invoked in order to inform the provider about the removal from
* this registry. If <code>provider</code> implements several
* service categories, <code>onDeregistration</code> gets called
- * multiple times.
+ * multiple times.</p>
*
* @param provider the service provider to be de-registered.
*