1. /*
  2. * @(#)MultiDoc.java 1.4 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.print;
  8. import java.io.IOException;
  9. /**
  10. * Interface MultiDoc specifies the interface for an object that supplies more
  11. * than one piece of print data for a Print Job. "Doc" is a short,
  12. * easy-to-pronounce term that means "a piece of print data," and a "multidoc"
  13. * is a group of several docs. The client passes to the Print Job an object
  14. * that implements interface MultiDoc, and the Print Job calls methods on
  15. * that object to obtain the print data.
  16. * <P>
  17. * Interface MultiDoc provides an abstraction similar to a "linked list" of
  18. * docs. A multidoc object is like a node in the linked list, containing the
  19. * current doc in the list and a pointer to the next node (multidoc) in the
  20. * list. The Print Job can call the multidoc's {@link #getDoc()
  21. * <CODE>getDoc()</CODE>} method to get the current doc. When it's ready to go
  22. * on to the next doc, the Print Job can call the multidoc's {@link #next()
  23. * <CODE>next()</CODE>} method to get the next multidoc, which contains the
  24. * next doc. So Print Job code for accessing a multidoc might look like this:
  25. * <PRE>
  26. * void processMultiDoc(MultiDoc theMultiDoc) {
  27. *
  28. * MultiDoc current = theMultiDoc;
  29. * while (current != null) {
  30. * processDoc (current.getDoc());
  31. * current = current.next();
  32. * }
  33. * }
  34. * </PRE>
  35. * <P>
  36. * Of course, interface MultiDoc can be implemented in any way that fulfills
  37. * the contract; it doesn't have to use a linked list in the implementation.
  38. * <P>
  39. * To get all the print data for a multidoc print job, a Print Service
  40. * proxy could use either of two patterns:
  41. * <OL TYPE=1>
  42. * <LI>
  43. * The <B>interleaved</B> pattern: Get the doc from the current multidoc. Get
  44. * the print data representation object from the current doc. Get all the print
  45. * data from the print data representation object. Get the next multidoc from
  46. * the current multidoc, and repeat until there are no more. (The code example
  47. * above uses the interleaved pattern.)
  48. * <P>
  49. * <LI>
  50. * The <B>all-at-once</B> pattern: Get the doc from the current multidoc, and
  51. * save the doc in a list. Get the next multidoc from the current multidoc, and
  52. * repeat until there are no more. Then iterate over the list of saved docs. Get
  53. * the print data representation object from the current doc. Get all the print
  54. * data from the print data representation object. Go to the next doc in the
  55. * list, and repeat until there are no more.
  56. * </OL>
  57. * Now, consider a printing client that is generating print data on the fly and
  58. * does not have the resources to store more than one piece of print data at a
  59. * time. If the print service proxy used the all-at-once pattern to get the
  60. * print data, it would pose a problem for such a client; the client would have
  61. * to keep all the docs' print data around until the print service proxy comes
  62. * back and asks for them, which the client is not able to do. To work with such
  63. * a client, the print service proxy must use the interleaved pattern.
  64. * <P>
  65. * To address this problem, and to simplify the design of clients providing
  66. * multiple docs to a Print Job, every Print Service proxy that supports
  67. * multidoc print jobs is required to access a MultiDoc object using the
  68. * interleaved pattern. That is, given a MultiDoc object, the print service
  69. * proxy will call {@link #getDoc() <CODE>getDoc()</CODE>} one or more times
  70. * until it successfully obtains the current Doc object. The print service proxy
  71. * will then obtain the current doc's print data, not proceeding until all the
  72. * print data is obtained or an unrecoverable error occurs. If it is able to
  73. * continue, the print service proxy will then call {@link #next()
  74. * <CODE>next()</CODE>} one or more times until it successfully obtains either
  75. * the next MultiDoc object or an indication that there are no more. An
  76. * implementation of interface MultiDoc can assume the print service proxy will
  77. * follow this interleaved pattern; for any other pattern of usage, the MultiDoc
  78. * implementation's behavior is unspecified.
  79. * <P>
  80. * There is no restriction on the number of client threads that may be
  81. * simultaneously accessing the same multidoc. Therefore, all implementations of
  82. * interface MultiDoc must be designed to be multiple thread safe. In fact, a
  83. * client thread could be adding docs to the end of the (conceptual) list while
  84. * a Print Job thread is simultaneously obtaining docs from the beginning of the
  85. * list; provided the multidoc object synchronizes the threads properly, the two
  86. * threads will not interfere with each other
  87. */
  88. public interface MultiDoc {
  89. /**
  90. * Obtain the current doc object.
  91. *
  92. * @return Current doc object.
  93. *
  94. * @exception IOException
  95. * Thrown if a error ocurred reading the document.
  96. */
  97. public Doc getDoc() throws IOException;
  98. /**
  99. * Go to the multidoc object that contains the next doc object in the
  100. * sequence of doc objects.
  101. *
  102. * @return Multidoc object containing the next doc object, or null if
  103. * there are no further doc objects.
  104. *
  105. * @exception IOException
  106. * Thrown if an error occurred locating the next document
  107. */
  108. public MultiDoc next() throws IOException;
  109. }