blob: 01ddeaafeea4a41355266a6d4409b4ec29e55808 [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17/**
18 * @author Rustem V. Rafikov
19 * @version $Revision: 1.3 $
20 */
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080021
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070022package javax.imageio.spi;
23
24import java.util.Arrays;
25
26import org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageReaderSpi;
27import org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageWriterSpi;
28import org.apache.harmony.x.imageio.plugins.png.PNGImageReaderSpi;
29import org.apache.harmony.x.imageio.plugins.png.PNGImageWriterSpi;
30import org.apache.harmony.x.imageio.spi.FileIISSpi;
31import org.apache.harmony.x.imageio.spi.FileIOSSpi;
32import org.apache.harmony.x.imageio.spi.InputStreamIISSpi;
33import org.apache.harmony.x.imageio.spi.OutputStreamIOSSpi;
34import org.apache.harmony.x.imageio.spi.RAFIISSpi;
35import org.apache.harmony.x.imageio.spi.RAFIOSSpi;
36
37/*
38 * @author Rustem V. Rafikov, Viskov Nikolay
39 * @version $Revision: 1.3 $
40 */
41
42/**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080043 * The IIORegistry class registers service provider instances (SPI). Service
44 * provider instances are recognized by specific meta-information in the JAR
45 * files containing them. The JAR files with SPI classes are loaded from the
46 * application class path.
47 *
48 * @since Android 1.0
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070049 */
50public final class IIORegistry extends ServiceRegistry {
51
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080052 /**
53 * The instance.
54 */
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070055 private static IIORegistry instance;
56
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080057 /**
58 * The Constant CATEGORIES.
59 */
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070060 private static final Class[] CATEGORIES = new Class[] {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080061 javax.imageio.spi.ImageWriterSpi.class, javax.imageio.spi.ImageReaderSpi.class,
62 javax.imageio.spi.ImageInputStreamSpi.class,
63 // javax.imageio.spi.ImageTranscoderSpi.class,
64 javax.imageio.spi.ImageOutputStreamSpi.class
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070065 };
66
67 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080068 * Instantiates a new IIO registry.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070069 */
70 private IIORegistry() {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080071 super(Arrays.<Class<?>> asList(CATEGORIES).iterator());
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070072 registerBuiltinSpis();
73 registerApplicationClasspathSpis();
74 }
75
76 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080077 * Register built-in SPIs.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070078 */
79 private void registerBuiltinSpis() {
80 registerServiceProvider(new JPEGImageWriterSpi());
81 registerServiceProvider(new JPEGImageReaderSpi());
82 registerServiceProvider(new PNGImageReaderSpi());
83 registerServiceProvider(new PNGImageWriterSpi());
84 registerServiceProvider(new FileIOSSpi());
85 registerServiceProvider(new FileIISSpi());
86 registerServiceProvider(new RAFIOSSpi());
87 registerServiceProvider(new RAFIISSpi());
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080088 registerServiceProvider(new OutputStreamIOSSpi());
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070089 registerServiceProvider(new InputStreamIISSpi());
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080090 // -- TODO implement
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070091 }
92
93 /**
94 * Gets the default IIORegistry instance.
95 *
96 * @return the default IIORegistry instance.
97 */
98 public static IIORegistry getDefaultInstance() {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080099 // TODO implement own instance for each ThreadGroup (see also
100 // ThreadLocal)
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700101 synchronized (IIORegistry.class) {
102 if (instance == null) {
103 instance = new IIORegistry();
104 }
105 return instance;
106 }
107 }
108
109 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800110 * Registers all service providers from the application class path.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700111 */
112 public void registerApplicationClasspathSpis() {
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800113 // -- TODO implement for non-builtin plugins
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700114 }
115}