1 7 8 package javax.imageio.spi; 9 10 import java.io.IOException ; 11 import java.lang.reflect.Constructor ; 12 import java.lang.reflect.Method ; 13 import java.util.Arrays ; 14 import java.util.Iterator ; 15 import javax.imageio.ImageReader ; 16 import javax.imageio.metadata.IIOMetadata ; 17 import javax.imageio.metadata.IIOMetadataFormat ; 18 import javax.imageio.metadata.IIOMetadataFormatImpl ; 19 import javax.imageio.stream.ImageInputStream ; 20 21 31 public abstract class ImageReaderWriterSpi extends IIOServiceProvider { 32 33 38 protected String [] names = null; 39 40 44 protected String [] suffixes = null; 45 46 50 protected String [] MIMETypes = null; 51 52 56 protected String pluginClassName = null; 57 58 63 protected boolean supportsStandardStreamMetadataFormat = false; 64 65 70 protected String nativeStreamMetadataFormatName = null; 71 72 77 protected String nativeStreamMetadataFormatClassName = null; 78 79 84 protected String [] extraStreamMetadataFormatNames = null; 85 86 91 protected String [] extraStreamMetadataFormatClassNames = null; 92 93 98 protected boolean supportsStandardImageMetadataFormat = false; 99 100 105 protected String nativeImageMetadataFormatName = null; 106 107 112 protected String nativeImageMetadataFormatClassName = null; 113 114 119 protected String [] extraImageMetadataFormatNames = null; 120 121 126 protected String [] extraImageMetadataFormatClassNames = null; 127 128 198 public ImageReaderWriterSpi(String vendorName, 199 String version, 200 String [] names, 201 String [] suffixes, 202 String [] MIMETypes, 203 String pluginClassName, 204 boolean supportsStandardStreamMetadataFormat, 205 String nativeStreamMetadataFormatName, 206 String nativeStreamMetadataFormatClassName, 207 String [] extraStreamMetadataFormatNames, 208 String [] extraStreamMetadataFormatClassNames, 209 boolean supportsStandardImageMetadataFormat, 210 String nativeImageMetadataFormatName, 211 String nativeImageMetadataFormatClassName, 212 String [] extraImageMetadataFormatNames, 213 String [] extraImageMetadataFormatClassNames) { 214 super(vendorName, version); 215 if (names == null) { 216 throw new IllegalArgumentException ("names == null!"); 217 } 218 if (names.length == 0) { 219 throw new IllegalArgumentException ("names.length == 0!"); 220 } 221 if (pluginClassName == null) { 222 throw new IllegalArgumentException ("pluginClassName == null!"); 223 } 224 225 this.names = (String [])names.clone(); 226 if (suffixes != null && suffixes.length > 0) { 228 this.suffixes = (String [])suffixes.clone(); 229 } 230 if (MIMETypes != null && MIMETypes.length > 0) { 232 this.MIMETypes = (String [])MIMETypes.clone(); 233 } 234 this.pluginClassName = pluginClassName; 235 236 this.supportsStandardStreamMetadataFormat = 237 supportsStandardStreamMetadataFormat; 238 this.nativeStreamMetadataFormatName = nativeStreamMetadataFormatName; 239 this.nativeStreamMetadataFormatClassName = 240 nativeStreamMetadataFormatClassName; 241 if (extraStreamMetadataFormatNames != null && 243 extraStreamMetadataFormatNames.length > 0) { 244 this.extraStreamMetadataFormatNames = 245 (String [])extraStreamMetadataFormatNames.clone(); 246 } 247 if (extraStreamMetadataFormatClassNames != null && 249 extraStreamMetadataFormatClassNames.length > 0) { 250 this.extraStreamMetadataFormatClassNames = 251 (String [])extraStreamMetadataFormatClassNames.clone(); 252 } 253 this.supportsStandardImageMetadataFormat = 254 supportsStandardImageMetadataFormat; 255 this.nativeImageMetadataFormatName = nativeImageMetadataFormatName; 256 this.nativeImageMetadataFormatClassName = 257 nativeImageMetadataFormatClassName; 258 if (extraImageMetadataFormatNames != null && 260 extraImageMetadataFormatNames.length > 0) { 261 this.extraImageMetadataFormatNames = 262 (String [])extraImageMetadataFormatNames.clone(); 263 } 264 if (extraImageMetadataFormatClassNames != null && 266 extraImageMetadataFormatClassNames.length > 0) { 267 this.extraImageMetadataFormatClassNames = 268 (String [])extraImageMetadataFormatClassNames.clone(); 269 } 270 } 271 272 278 public ImageReaderWriterSpi() { 279 } 280 281 293 public String [] getFormatNames() { 294 return (String [])names.clone(); 295 } 296 297 317 public String [] getFileSuffixes() { 318 return suffixes == null ? null : (String [])suffixes.clone(); 319 } 320 321 352 public String [] getMIMETypes() { 353 return MIMETypes == null ? null : (String [])MIMETypes.clone(); 354 } 355 356 364 public String getPluginClassName() { 365 return pluginClassName; 366 } 367 368 378 public boolean isStandardStreamMetadataFormatSupported() { 379 return supportsStandardStreamMetadataFormat; 380 } 381 382 397 public String getNativeStreamMetadataFormatName() { 398 return nativeStreamMetadataFormatName; 399 } 400 401 427 public String [] getExtraStreamMetadataFormatNames() { 428 return extraStreamMetadataFormatNames == null ? 429 null : (String [])extraStreamMetadataFormatNames.clone(); 430 } 431 432 442 public boolean isStandardImageMetadataFormatSupported() { 443 return supportsStandardImageMetadataFormat; 444 } 445 446 462 public String getNativeImageMetadataFormatName() { 463 return nativeImageMetadataFormatName; 464 } 465 466 491 public String [] getExtraImageMetadataFormatNames() { 492 return extraImageMetadataFormatNames == null ? 493 null : (String [])extraImageMetadataFormatNames.clone(); 494 } 495 496 511 public IIOMetadataFormat getStreamMetadataFormat(String formatName) { 512 return getMetadataFormat(formatName, 513 supportsStandardStreamMetadataFormat, 514 nativeStreamMetadataFormatName, 515 nativeStreamMetadataFormatClassName, 516 extraStreamMetadataFormatNames, 517 extraStreamMetadataFormatClassNames); 518 } 519 520 535 public IIOMetadataFormat getImageMetadataFormat(String formatName) { 536 return getMetadataFormat(formatName, 537 supportsStandardImageMetadataFormat, 538 nativeImageMetadataFormatName, 539 nativeImageMetadataFormatClassName, 540 extraImageMetadataFormatNames, 541 extraImageMetadataFormatClassNames); 542 } 543 544 private IIOMetadataFormat getMetadataFormat(String formatName, 545 boolean supportsStandard, 546 String nativeName, 547 String nativeClassName, 548 String [] extraNames, 549 String [] extraClassNames) { 550 if (formatName == null) { 551 throw new IllegalArgumentException ("formatName == null!"); 552 } 553 if (supportsStandard && formatName.equals 554 (IIOMetadataFormatImpl.standardMetadataFormatName)) { 555 556 return IIOMetadataFormatImpl.getStandardFormatInstance(); 557 } 558 String formatClassName = null; 559 if (formatName.equals(nativeName)) { 560 formatClassName = nativeClassName; 561 } else if (extraNames != null) { 562 for (int i = 0; i < extraNames.length; i++) { 563 if (formatName.equals(extraNames[i])) { 564 formatClassName = extraClassNames[i]; 565 break; } 567 } 568 } 569 if (formatClassName == null) { 570 throw new IllegalArgumentException ("Unsupported format name"); 571 } 572 try { 573 Class cls = Class.forName(formatClassName, true, 574 ClassLoader.getSystemClassLoader()); 575 Method meth = cls.getMethod("getInstance", null); 576 return (IIOMetadataFormat ) meth.invoke(null, null); 577 } catch (Exception e) { 578 RuntimeException ex = 579 new IllegalStateException ("Can't obtain format"); 580 ex.initCause(e); 581 throw ex; 582 } 583 } 584 } 585 | Popular Tags |