summaryrefslogtreecommitdiffstats
path: root/awt/javax/imageio/spi/ImageReaderWriterSpi.java
blob: 9ca08b5ea08532edd1861a19ce014c5c8827fea4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
/**
 * @author Rustem V. Rafikov
 * @version $Revision: 1.3 $
 */

package javax.imageio.spi;

import org.apache.harmony.x.imageio.metadata.IIOMetadataUtils;

import javax.imageio.metadata.IIOMetadataFormat;

/**
 * The ImageReaderWriterSpi class is a superclass for the ImageReaderSpi and
 * ImageWriterSpi SPIs.
 * 
 * @since Android 1.0
 */
public abstract class ImageReaderWriterSpi extends IIOServiceProvider implements
        RegisterableService {

    /**
     * The names.
     */
    protected String[] names;

    /**
     * The suffixes.
     */
    protected String[] suffixes;

    /**
     * The MIME types.
     */
    protected String[] MIMETypes;

    /**
     * The plug-in class name.
     */
    protected String pluginClassName;

    /**
     * Whether the reader/writer supports standard stream metadata format.
     */
    protected boolean supportsStandardStreamMetadataFormat;

    /**
     * The native stream metadata format name.
     */
    protected String nativeStreamMetadataFormatName;

    /**
     * The native stream metadata format class name.
     */
    protected String nativeStreamMetadataFormatClassName;

    /**
     * The extra stream metadata format names.
     */
    protected String[] extraStreamMetadataFormatNames;

    /**
     * The extra stream metadata format class names.
     */
    protected String[] extraStreamMetadataFormatClassNames;

    /**
     * Whether the reader/writer supports standard image metadata format.
     */
    protected boolean supportsStandardImageMetadataFormat;

    /**
     * The native image metadata format name.
     */
    protected String nativeImageMetadataFormatName;

    /**
     * The native image metadata format class name.
     */
    protected String nativeImageMetadataFormatClassName;

    /**
     * The extra image metadata format names.
     */
    protected String[] extraImageMetadataFormatNames;

    /**
     * The extra image metadata format class names.
     */
    protected String[] extraImageMetadataFormatClassNames;

    /**
     * Instantiates a new ImageReaderWriterSpi.
     * 
     * @param vendorName
     *            the vendor name.
     * @param version
     *            the version.
     * @param names
     *            the format names.
     * @param suffixes
     *            the array of strings representing the file suffixes.
     * @param MIMETypes
     *            the an array of strings representing MIME types.
     * @param pluginClassName
     *            the plug-in class name.
     * @param supportsStandardStreamMetadataFormat
     *            the value indicating if stream metadata can be described by
     *            standard metadata format.
     * @param nativeStreamMetadataFormatName
     *            the native stream metadata format name, returned by
     *            getNativeStreamMetadataFormatName.
     * @param nativeStreamMetadataFormatClassName
     *            the native stream metadata format class name, returned by
     *            getNativeStreamMetadataFormat.
     * @param extraStreamMetadataFormatNames
     *            the extra stream metadata format names, returned by
     *            getExtraStreamMetadataFormatNames.
     * @param extraStreamMetadataFormatClassNames
     *            the extra stream metadata format class names, returned by
     *            getStreamMetadataFormat.
     * @param supportsStandardImageMetadataFormat
     *            the value indicating if image metadata can be described by
     *            standard metadata format.
     * @param nativeImageMetadataFormatName
     *            the native image metadata format name, returned by
     *            getNativeImageMetadataFormatName.
     * @param nativeImageMetadataFormatClassName
     *            the native image metadata format class name, returned by
     *            getNativeImageMetadataFormat.
     * @param extraImageMetadataFormatNames
     *            the extra image metadata format names, returned by
     *            getExtraImageMetadataFormatNames.
     * @param extraImageMetadataFormatClassNames
     *            the extra image metadata format class names, returned by
     *            getImageMetadataFormat.
     */
    public ImageReaderWriterSpi(String vendorName, String version, String[] names,
            String[] suffixes, String[] MIMETypes, String pluginClassName,
            boolean supportsStandardStreamMetadataFormat, String nativeStreamMetadataFormatName,
            String nativeStreamMetadataFormatClassName, String[] extraStreamMetadataFormatNames,
            String[] extraStreamMetadataFormatClassNames,
            boolean supportsStandardImageMetadataFormat, String nativeImageMetadataFormatName,
            String nativeImageMetadataFormatClassName, String[] extraImageMetadataFormatNames,
            String[] extraImageMetadataFormatClassNames) {
        super(vendorName, version);

        if (names == null || names.length == 0) {
            throw new NullPointerException("format names array cannot be NULL or empty");
        }

        if (pluginClassName == null) {
            throw new NullPointerException("Plugin class name cannot be NULL");
        }

        // We clone all the arrays to be consistent with the fact that
        // some methods of this class must return clones of the arrays
        // as it is stated in the spec.
        this.names = names.clone();
        this.suffixes = suffixes == null ? null : suffixes.clone();
        this.MIMETypes = MIMETypes == null ? null : MIMETypes.clone();
        this.pluginClassName = pluginClassName;
        this.supportsStandardStreamMetadataFormat = supportsStandardStreamMetadataFormat;
        this.nativeStreamMetadataFormatName = nativeStreamMetadataFormatName;
        this.nativeStreamMetadataFormatClassName = nativeStreamMetadataFormatClassName;

        this.extraStreamMetadataFormatNames = extraStreamMetadataFormatNames == null ? null
                : extraStreamMetadataFormatNames.clone();

        this.extraStreamMetadataFormatClassNames = extraStreamMetadataFormatClassNames == null ? null
                : extraStreamMetadataFormatClassNames.clone();

        this.supportsStandardImageMetadataFormat = supportsStandardImageMetadataFormat;
        this.nativeImageMetadataFormatName = nativeImageMetadataFormatName;
        this.nativeImageMetadataFormatClassName = nativeImageMetadataFormatClassName;

        this.extraImageMetadataFormatNames = extraImageMetadataFormatNames == null ? null
                : extraImageMetadataFormatNames.clone();

        this.extraImageMetadataFormatClassNames = extraImageMetadataFormatClassNames == null ? null
                : extraImageMetadataFormatClassNames.clone();
    }

    /**
     * Instantiates a new ImageReaderWriterSpi.
     */
    public ImageReaderWriterSpi() {
    }

    /**
     * Gets an array of strings representing names of the formats that can be
     * used by the ImageReader or ImageWriter implementation associated with
     * this service provider.
     * 
     * @return the array of supported format names.
     */
    public String[] getFormatNames() {
        return names.clone();
    }

    /**
     * Gets an array of strings representing file suffixes associated with the
     * formats that can be used by the ImageReader or ImageWriter implementation
     * of this service provider.
     * 
     * @return the array of file suffixes.
     */
    public String[] getFileSuffixes() {
        return suffixes == null ? null : suffixes.clone();
    }

    /**
     * Gets an array of strings with the names of additional formats of the
     * image metadata objects produced or consumed by this plug-in.
     * 
     * @return the array of extra image metadata format names.
     */
    public String[] getExtraImageMetadataFormatNames() {
        return extraImageMetadataFormatNames == null ? null : extraImageMetadataFormatNames.clone();
    }

    /**
     * Gets an array of strings with the names of additional formats of the
     * stream metadata objects produced or consumed by this plug-in.
     * 
     * @return the array of extra stream metadata format names.
     */
    public String[] getExtraStreamMetadataFormatNames() {
        return extraStreamMetadataFormatNames == null ? null : extraStreamMetadataFormatNames
                .clone();
    }

    /**
     * Gets an IIOMetadataFormat object for the specified image metadata format
     * name.
     * 
     * @param formatName
     *            the format name.
     * @return the IIOMetadataFormat, or null.
     */
    public IIOMetadataFormat getImageMetadataFormat(String formatName) {
        return IIOMetadataUtils.instantiateMetadataFormat(formatName,
                supportsStandardImageMetadataFormat, nativeImageMetadataFormatName,
                nativeImageMetadataFormatClassName, extraImageMetadataFormatNames,
                extraImageMetadataFormatClassNames);
    }

    /**
     * Gets an IIOMetadataFormat object for the specified stream metadata format
     * name.
     * 
     * @param formatName
     *            the format name.
     * @return the IIOMetadataFormat, or null.
     */
    public IIOMetadataFormat getStreamMetadataFormat(String formatName) {
        return IIOMetadataUtils.instantiateMetadataFormat(formatName,
                supportsStandardStreamMetadataFormat, nativeStreamMetadataFormatName,
                nativeStreamMetadataFormatClassName, extraStreamMetadataFormatNames,
                extraStreamMetadataFormatClassNames);
    }

    /**
     * Gets an array of strings representing the MIME types of the formats that
     * are supported by the ImageReader or ImageWriter implementation of this
     * service provider.
     * 
     * @return the array MIME types.
     */
    public String[] getMIMETypes() {
        return MIMETypes == null ? null : MIMETypes.clone();
    }

    /**
     * Gets the name of the native image metadata format for this reader/writer,
     * which allows for lossless encoding or decoding of the image metadata with
     * the format.
     * 
     * @return the string with native image metadata format name, or null.
     */
    public String getNativeImageMetadataFormatName() {
        return nativeImageMetadataFormatName;
    }

    /**
     * Gets the name of the native stream metadata format for this
     * reader/writer, which allows for lossless encoding or decoding of the
     * stream metadata with the format.
     * 
     * @return the string with native stream metadata format name, or null.
     */
    public String getNativeStreamMetadataFormatName() {
        return nativeStreamMetadataFormatName;
    }

    /**
     * Gets the class name of the ImageReader or ImageWriter associated with
     * this service provider.
     * 
     * @return the class name.
     */
    public String getPluginClassName() {
        return pluginClassName;
    }

    /**
     * Checks if the standard metadata format is supported by the getAsTree and
     * setFromTree methods for the image metadata objects produced or consumed
     * by this reader or writer.
     * 
     * @return true, if standard image metadata format is supported, false
     *         otherwise.
     */
    public boolean isStandardImageMetadataFormatSupported() {
        return supportsStandardImageMetadataFormat;
    }

    /**
     * Checks if the standard metadata format is supported by the getAsTree and
     * setFromTree methods for the stream metadata objects produced or consumed
     * by this reader or writer.
     * 
     * @return true, if standard stream metadata format is supported, false
     *         otherwise.
     */
    public boolean isStandardStreamMetadataFormatSupported() {
        return supportsStandardStreamMetadataFormat;
    }
}