StreamPrintServiceFactory.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* StreamPrintServiceFactory.java --
  2. Copyright (C) 2006 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.print;
  32. import gnu.classpath.ServiceFactory;
  33. import java.io.OutputStream;
  34. import java.util.Arrays;
  35. import java.util.HashSet;
  36. import java.util.Iterator;
  37. /**
  38. * <code>StreamPrintServiceFactory</code> provides a static method to lookup
  39. * registered factories to construct <code>StreamPrintService</code> instances.
  40. * <p>
  41. * <code>StreamPrintService</code> are used to print into a provided output
  42. * stream in the document format provided by the stream print service
  43. * implementation.
  44. * </p><p>
  45. * Implementations are located and loaded automatically through the SPI JAR
  46. * file specification. Therefore implementation classes must provide a default
  47. * constructor for instantiation.
  48. * </p>
  49. *
  50. * @author Wolfgang Baer (WBaer@gmx.de)
  51. */
  52. public abstract class StreamPrintServiceFactory
  53. {
  54. /**
  55. * Default public constructor.
  56. * Used for automatic loading and instantiation through
  57. * the SPI jar file specification.
  58. */
  59. public StreamPrintServiceFactory()
  60. {
  61. // nothing to do
  62. }
  63. /**
  64. * Searches for matching factories providing stream print services that
  65. * support the printing of documents with the given document flavor into
  66. * the given output mime type.
  67. *
  68. * @param flavor the document flavor needed, <code>null</code> doesn't
  69. * constrain the lookup result.
  70. * @param outputMimeType the mime type needed, <code>null</code> doesn't
  71. * constrain the lookup result.
  72. *
  73. * @return The matching <code>StreamPrintServiceFactory</code> instances.
  74. */
  75. public static StreamPrintServiceFactory[] lookupStreamPrintServiceFactories(
  76. DocFlavor flavor, String outputMimeType)
  77. {
  78. HashSet set = new HashSet();
  79. Iterator it =
  80. ServiceFactory.lookupProviders(StreamPrintServiceFactory.class);
  81. while (it.hasNext())
  82. {
  83. StreamPrintServiceFactory tmp = (StreamPrintServiceFactory) it.next();
  84. if (tmp.getOutputFormat().equals(outputMimeType)
  85. && Arrays.asList(tmp.getSupportedDocFlavors()).contains(flavor))
  86. set.add(tmp);
  87. }
  88. StreamPrintServiceFactory[] tmp = new StreamPrintServiceFactory[set.size()];
  89. return (StreamPrintServiceFactory[]) set.toArray(tmp);
  90. }
  91. /**
  92. * Returns the output format supported by this factory.
  93. *
  94. * @return The mime type of the output format as string representation.
  95. */
  96. public abstract String getOutputFormat();
  97. /**
  98. * Returns the document flavors this factory supports as flavors
  99. * for the input documents.
  100. *
  101. * @return The array of supported document flavors.
  102. */
  103. public abstract DocFlavor[] getSupportedDocFlavors();
  104. /**
  105. * Constructs a <code>StreamPrintService</code> which directs its output
  106. * the given output stream.
  107. *
  108. * @param out the output stream for the produced document.
  109. * @return The constructed stream print service.
  110. */
  111. public abstract StreamPrintService getPrintService(OutputStream out);
  112. }