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