blob: b3c0f92fa064da3706b370a6f407153d67d2207d [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 */
21package javax.imageio.spi;
22
23import org.apache.harmony.x.imageio.metadata.IIOMetadataUtils;
24
25import javax.imageio.metadata.IIOMetadataFormat;
26
27/**
28 * The ImageReaderWriterSpi class is a superclass for the
29 * ImageReaderSpi and ImageWriterSpi SPIs.
30 */
31public abstract class ImageReaderWriterSpi extends IIOServiceProvider
32 implements RegisterableService {
33
34 /** The names. */
35 protected String[] names;
36
37 /** The suffixes. */
38 protected String[] suffixes;
39
40 /** The MIME types. */
41 protected String[] MIMETypes;
42
43 /** The plugin class name. */
44 protected String pluginClassName;
45
46 /** Whether the reader/writer supports standard stream metadata format. */
47 protected boolean supportsStandardStreamMetadataFormat;
48
49 /** The native stream metadata format name. */
50 protected String nativeStreamMetadataFormatName;
51
52 /** The native stream metadata format class name. */
53 protected String nativeStreamMetadataFormatClassName;
54
55 /** The extra stream metadata format names. */
56 protected String[] extraStreamMetadataFormatNames;
57
58 /** The extra stream metadata format class names. */
59 protected String[] extraStreamMetadataFormatClassNames;
60
61 /** Whether the reader/writer supports standard image metadata format. */
62 protected boolean supportsStandardImageMetadataFormat;
63
64 /** The native image metadata format name. */
65 protected String nativeImageMetadataFormatName;
66
67 /** The native image metadata format class name. */
68 protected String nativeImageMetadataFormatClassName;
69
70 /** The extra image metadata format names. */
71 protected String[] extraImageMetadataFormatNames;
72
73 /** The extra image metadata format class names. */
74 protected String[] extraImageMetadataFormatClassNames;
75
76 /**
77 * Instantiates a new ImageReaderWriterSpi.
78 *
79 * @param vendorName the vendor name.
80 * @param version the version.
81 * @param names the format names.
82 * @param suffixes the array of strings representing the file suffixes.
83 * @param MIMETypes the an array of strings representing MIME types.
84 * @param pluginClassName the plugin class name.
85 * @param supportsStandardStreamMetadataFormat the value indicating
86 * if stream metadata can be described by standart metadata format.
87 * @param nativeStreamMetadataFormatName the native stream metadata
88 * format name, returned by getNativeStreamMetadataFormatName.
89 * @param nativeStreamMetadataFormatClassName the native stream
90 * metadata format class name, returned by getNativeStreamMetadataFormat.
91 * @param extraStreamMetadataFormatNames the extra stream metadata
92 * format names, returned by getExtraStreamMetadataFormatNames.
93 * @param extraStreamMetadataFormatClassNames the extra stream metadata
94 * format class names, returned by getStreamMetadataFormat.
95 * @param supportsStandardImageMetadataFormat the value indicating
96 * if image metadata can be described by standard metadata format.
97 * @param nativeImageMetadataFormatName the native image metadata
98 * format name, returned by getNativeImageMetadataFormatName.
99 * @param nativeImageMetadataFormatClassName the native image
100 * metadata format class name, returned by getNativeImageMetadataFormat.
101 * @param extraImageMetadataFormatNames the extra image metadata
102 * format names, returned by getExtraImageMetadataFormatNames.
103 * @param extraImageMetadataFormatClassNames the extra image metadata
104 * format class names, returned by getImageMetadataFormat.
105 */
106 public ImageReaderWriterSpi(String vendorName, String version, String[] names,
107 String[] suffixes, String[] MIMETypes,
108 String pluginClassName,
109 boolean supportsStandardStreamMetadataFormat,
110 String nativeStreamMetadataFormatName,
111 String nativeStreamMetadataFormatClassName,
112 String[] extraStreamMetadataFormatNames,
113 String[] extraStreamMetadataFormatClassNames,
114 boolean supportsStandardImageMetadataFormat,
115 String nativeImageMetadataFormatName,
116 String nativeImageMetadataFormatClassName,
117 String[] extraImageMetadataFormatNames,
118 String[] extraImageMetadataFormatClassNames) {
119 super(vendorName, version);
120
121 if (names == null || names.length == 0) {
122 throw new NullPointerException("format names array cannot be NULL or empty");
123 }
124
125 if (pluginClassName == null) {
126 throw new NullPointerException("Plugin class name cannot be NULL");
127 }
128
129 // We clone all the arrays to be consistent with the fact that
130 // some methods of this class must return clones of the arrays
131 // as it is stated in the spec.
132 this.names = names.clone();
133 this.suffixes = suffixes == null ? null : suffixes.clone();
134 this.MIMETypes = MIMETypes == null ? null : MIMETypes.clone();
135 this.pluginClassName = pluginClassName;
136 this.supportsStandardStreamMetadataFormat = supportsStandardStreamMetadataFormat;
137 this.nativeStreamMetadataFormatName = nativeStreamMetadataFormatName;
138 this.nativeStreamMetadataFormatClassName = nativeStreamMetadataFormatClassName;
139
140 this.extraStreamMetadataFormatNames =
141 extraStreamMetadataFormatNames == null ?
142 null : extraStreamMetadataFormatNames.clone();
143
144 this.extraStreamMetadataFormatClassNames =
145 extraStreamMetadataFormatClassNames == null ?
146 null : extraStreamMetadataFormatClassNames.clone();
147
148 this.supportsStandardImageMetadataFormat = supportsStandardImageMetadataFormat;
149 this.nativeImageMetadataFormatName = nativeImageMetadataFormatName;
150 this.nativeImageMetadataFormatClassName = nativeImageMetadataFormatClassName;
151
152 this.extraImageMetadataFormatNames =
153 extraImageMetadataFormatNames == null ?
154 null : extraImageMetadataFormatNames.clone();
155
156 this.extraImageMetadataFormatClassNames =
157 extraImageMetadataFormatClassNames == null ?
158 null : extraImageMetadataFormatClassNames.clone();
159 }
160
161 /**
162 * Instantiates a new ImageReaderWriterSpi.
163 */
164 public ImageReaderWriterSpi() {}
165
166 /**
167 * Gets an array of strings representing names of the formats
168 * that can be used by the ImageReader
169 * or ImageWriter implementation associated with this service
170 * provider.
171 *
172 * @return an array of supported format names.
173 */
174 public String[] getFormatNames() {
175 return names.clone();
176 }
177
178 /**
179 * Gets an array of strings representing file suffixes
180 * associated with the formats that can be used by the
181 * ImageReader or ImageWriter implementation of this
182 * service provider.
183 *
184 * @return an array of file suffixes.
185 */
186 public String[] getFileSuffixes() {
187 return suffixes == null ? null : suffixes.clone();
188 }
189
190 /**
191 * Gets an array of strings with the names of
192 * additional formats of the image metadata objects
193 * produced or consumed by this plug-in.
194 *
195 * @return the array of extra image metadata format names.
196 */
197 public String[] getExtraImageMetadataFormatNames() {
198 return extraImageMetadataFormatNames == null ? null : extraImageMetadataFormatNames.clone();
199 }
200
201 /**
202 * Gets an array of strings with the names of
203 * additional formats of the stream metadata objects
204 * produced or consumed by this plug-in.
205 *
206 * @return the array of extra stream metadata format names.
207 */
208 public String[] getExtraStreamMetadataFormatNames() {
209 return extraStreamMetadataFormatNames == null ? null : extraStreamMetadataFormatNames.clone();
210 }
211
212 /**
213 * Gets an IIOMetadataFormat object for the specified image
214 * metadata format name.
215 *
216 * @param formatName the format name.
217 *
218 * @return the IIOMetadataFormat, or null.
219 */
220 public IIOMetadataFormat getImageMetadataFormat(String formatName) {
221 return IIOMetadataUtils.instantiateMetadataFormat(
222 formatName, supportsStandardImageMetadataFormat,
223 nativeImageMetadataFormatName, nativeImageMetadataFormatClassName,
224 extraImageMetadataFormatNames, extraImageMetadataFormatClassNames
225 );
226 }
227
228 /**
229 * Gets an IIOMetadataFormat object for the specified stream
230 * metadata format name.
231 *
232 * @param formatName the format name.
233 *
234 * @return the IIOMetadataFormat, or null.
235 */
236 public IIOMetadataFormat getStreamMetadataFormat(String formatName) {
237 return IIOMetadataUtils.instantiateMetadataFormat(
238 formatName, supportsStandardStreamMetadataFormat,
239 nativeStreamMetadataFormatName, nativeStreamMetadataFormatClassName,
240 extraStreamMetadataFormatNames, extraStreamMetadataFormatClassNames
241 );
242 }
243
244 /**
245 * Gets an array of strings representing the MIME types
246 * of the formats that are supported by the
247 * ImageReader or ImageWriter implementation of this
248 * service provider.
249 *
250 * @return the array MIME types.
251 */
252 public String[] getMIMETypes() {
253 return MIMETypes == null ? null : MIMETypes.clone();
254 }
255
256 /**
257 * Gets the name of the native image metadata format for
258 * this reader/writer, which allows for lossless encoding
259 * or decoding of the image metadata with the format.
260 *
261 * @return the string with native image metadata format name,
262 * or null.
263 */
264 public String getNativeImageMetadataFormatName() {
265 return nativeImageMetadataFormatName;
266 }
267
268 /**
269 * Gets the name of the native stream metadata format for
270 * this reader/writer, which allows for lossless encoding
271 * or decoding of the stream metadata with the format.
272 *
273 * @return the string with native stream metadata format name,
274 * or null.
275 */
276 public String getNativeStreamMetadataFormatName() {
277 return nativeStreamMetadataFormatName;
278 }
279
280 /**
281 * Gets the class name of the ImageReader
282 * or ImageWriter associated with this service provider.
283 *
284 * @return the class name.
285 */
286 public String getPluginClassName() {
287 return pluginClassName;
288 }
289
290 /**
291 * Checks if the standard metadata format is supported
292 * by the getAsTree and setFromTree methods for the
293 * image metadata objects produced or consumed by this
294 * reader or writer.
295 *
296 * @return true, if standard image metadata format is
297 * supported, false otherwise.
298 */
299 public boolean isStandardImageMetadataFormatSupported() {
300 return supportsStandardImageMetadataFormat;
301 }
302
303 /**
304 * Checks if the standard metadata format is supported
305 * by the getAsTree and setFromTree methods for the
306 * stream metadata objects produced or consumed by this
307 * reader or writer.
308 *
309 * @return true, if standard stream metadata format is
310 * supported, false otherwise.
311 */
312 public boolean isStandardStreamMetadataFormatSupported() {
313 return supportsStandardStreamMetadataFormat;
314 }
315}