The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | /* |
| 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 Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 21 | |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 22 | package javax.imageio.spi; |
| 23 | |
| 24 | import java.util.Arrays; |
| 25 | |
| 26 | import org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageReaderSpi; |
| 27 | import org.apache.harmony.x.imageio.plugins.jpeg.JPEGImageWriterSpi; |
| 28 | import org.apache.harmony.x.imageio.plugins.png.PNGImageReaderSpi; |
| 29 | import org.apache.harmony.x.imageio.plugins.png.PNGImageWriterSpi; |
| 30 | import org.apache.harmony.x.imageio.spi.FileIISSpi; |
| 31 | import org.apache.harmony.x.imageio.spi.FileIOSSpi; |
| 32 | import org.apache.harmony.x.imageio.spi.InputStreamIISSpi; |
| 33 | import org.apache.harmony.x.imageio.spi.OutputStreamIOSSpi; |
| 34 | import org.apache.harmony.x.imageio.spi.RAFIISSpi; |
| 35 | import 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 Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 43 | * 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 Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 49 | */ |
| 50 | public final class IIORegistry extends ServiceRegistry { |
| 51 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 52 | /** |
| 53 | * The instance. |
| 54 | */ |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 55 | private static IIORegistry instance; |
| 56 | |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 57 | /** |
| 58 | * The Constant CATEGORIES. |
| 59 | */ |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 60 | private static final Class[] CATEGORIES = new Class[] { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 61 | 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 Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | /** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 68 | * Instantiates a new IIO registry. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 69 | */ |
| 70 | private IIORegistry() { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 71 | super(Arrays.<Class<?>> asList(CATEGORIES).iterator()); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 72 | registerBuiltinSpis(); |
| 73 | registerApplicationClasspathSpis(); |
| 74 | } |
| 75 | |
| 76 | /** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 77 | * Register built-in SPIs. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 78 | */ |
| 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 Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 88 | registerServiceProvider(new OutputStreamIOSSpi()); |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 89 | registerServiceProvider(new InputStreamIISSpi()); |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 90 | // -- TODO implement |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 91 | } |
| 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 Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 99 | // TODO implement own instance for each ThreadGroup (see also |
| 100 | // ThreadLocal) |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 101 | synchronized (IIORegistry.class) { |
| 102 | if (instance == null) { |
| 103 | instance = new IIORegistry(); |
| 104 | } |
| 105 | return instance; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | /** |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 110 | * Registers all service providers from the application class path. |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 111 | */ |
| 112 | public void registerApplicationClasspathSpis() { |
The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 113 | // -- TODO implement for non-builtin plugins |
The Android Open Source Project | 7c1b96a | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 114 | } |
| 115 | } |