1. /*
  2. * @(#)IIOServiceProvider.java 1.18 04/05/05
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.imageio.spi;
  8. import java.util.Locale;
  9. import javax.imageio.spi.RegisterableService;
  10. import javax.imageio.spi.ServiceRegistry;
  11. /**
  12. * A superinterface for functionality common to all Image I/O service
  13. * provider interfaces (SPIs). For more information on service
  14. * provider classes, see the class comment for the
  15. * <code>IIORegistry</code> class.
  16. *
  17. * @see IIORegistry
  18. * @see javax.imageio.spi.ImageReaderSpi
  19. * @see javax.imageio.spi.ImageWriterSpi
  20. * @see javax.imageio.spi.ImageTranscoderSpi
  21. * @see javax.imageio.spi.ImageInputStreamSpi
  22. *
  23. * @version 0.5
  24. */
  25. public abstract class IIOServiceProvider implements RegisterableService {
  26. /**
  27. * A <code>String</code> to be returned from
  28. * <code>getVendorName</code>, initially <code>null</code>.
  29. * Constructors should set this to a non-<code>null</code> value.
  30. */
  31. protected String vendorName;
  32. /**
  33. * A <code>String</code> to be returned from
  34. * <code>getVersion</code>, initially null. Constructors should
  35. * set this to a non-<code>null</code> value.
  36. */
  37. protected String version;
  38. /**
  39. * Constructs an <code>IIOServiceProvider</code> with a given
  40. * vendor name and version identifier.
  41. *
  42. * @param vendorName the vendor name.
  43. * @param version a version identifier.
  44. *
  45. * @exception IllegalArgumentException if <code>vendorName</code>
  46. * is <code>null</code>.
  47. * @exception IllegalArgumentException if <code>version</code>
  48. * is <code>null</code>.
  49. */
  50. public IIOServiceProvider(String vendorName,
  51. String version) {
  52. if (vendorName == null) {
  53. throw new IllegalArgumentException("vendorName == null!");
  54. }
  55. if (version == null) {
  56. throw new IllegalArgumentException("version == null!");
  57. }
  58. this.vendorName = vendorName;
  59. this.version = version;
  60. }
  61. /**
  62. * Constructs a blank <code>IIOServiceProvider</code>. It is up
  63. * to the subclass to initialize instance variables and/or
  64. * override method implementations in order to ensure that the
  65. * <code>getVendorName</code> and <code>getVersion</code> methods
  66. * will return non-<code>null</code> values.
  67. */
  68. public IIOServiceProvider() {
  69. }
  70. /**
  71. * A callback that will be called exactly once after the Spi class
  72. * has been instantiated and registered in a
  73. * <code>ServiceRegistry</code>. This may be used to verify that
  74. * the environment is suitable for this service, for example that
  75. * native libraries can be loaded. If the service cannot function
  76. * in the environment where it finds itself, it should deregister
  77. * itself from the registry.
  78. *
  79. * <p> Only the registry should call this method.
  80. *
  81. * <p> The default implementation does nothing.
  82. *
  83. * @see ServiceRegistry#registerServiceProvider(Object provider)
  84. */
  85. public void onRegistration(ServiceRegistry registry,
  86. Class<?> category) {}
  87. /**
  88. * A callback that will be whenever the Spi class has been
  89. * deregistered from a <code>ServiceRegistry</code>.
  90. *
  91. * <p> Only the registry should call this method.
  92. *
  93. * <p> The default implementation does nothing.
  94. *
  95. * @see ServiceRegistry#deregisterServiceProvider(Object provider)
  96. */
  97. public void onDeregistration(ServiceRegistry registry,
  98. Class<?> category) {}
  99. /**
  100. * Returns the name of the vendor responsible for creating this
  101. * service provider and its associated implementation. Because
  102. * the vendor name may be used to select a service provider,
  103. * it is not localized.
  104. *
  105. * <p> The default implementation returns the value of the
  106. * <code>vendorName</code> instance variable.
  107. *
  108. * @return a non-<code>null</code> <code>String</code> containing
  109. * the name of the vendor.
  110. */
  111. public String getVendorName() {
  112. return vendorName;
  113. }
  114. /**
  115. * Returns a string describing the version
  116. * number of this service provider and its associated
  117. * implementation. Because the version may be used by transcoders
  118. * to identify the service providers they understand, this method
  119. * is not localized.
  120. *
  121. * <p> The default implementation returns the value of the
  122. * <code>version</code> instance variable.
  123. *
  124. * @return a non-<code>null</code> <code>String</code> containing
  125. * the version of this service provider.
  126. */
  127. public String getVersion() {
  128. return version;
  129. }
  130. /**
  131. * Returns a brief, human-readable description of this service
  132. * provider and its associated implementation. The resulting
  133. * string should be localized for the supplied
  134. * <code>Locale</code>, if possible.
  135. *
  136. * @param locale a <code>Locale</code> for which the return value
  137. * should be localized.
  138. *
  139. * @return a <code>String</code> containing a description of this
  140. * service provider.
  141. */
  142. public abstract String getDescription(Locale locale);
  143. }