1. /*
  2. * @(#)DocPrintJob.java 1.10 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 javax.print.attribute.AttributeSet;
  9. import javax.print.attribute.PrintJobAttributeSet;
  10. import javax.print.attribute.PrintRequestAttributeSet;
  11. import javax.print.event.PrintJobAttributeListener;
  12. import javax.print.event.PrintJobListener;
  13. import javax.print.PrintException;
  14. /**
  15. *
  16. * This interface represents a print job that can print a specified
  17. * document with a set of job attributes. An object implementing
  18. * this interface is obtained from a print service.
  19. *
  20. */
  21. public interface DocPrintJob {
  22. /**
  23. * Determines the {@link PrintService} object to which this print job
  24. * object is bound.
  25. *
  26. * @return <code>PrintService</code> object.
  27. *
  28. */
  29. public PrintService getPrintService();
  30. /**
  31. * Obtains this Print Job's set of printing attributes.
  32. * The returned attribute set object is unmodifiable.
  33. * The returned attribute set object is a "snapshot" of this Print Job's
  34. * attribute set at the time of the {@link #getAttributes()} method
  35. * call; that is, the returned attribute set's object's contents will
  36. * not be updated if this Print Job's attribute set's contents change
  37. * in the future. To detect changes in attribute values, call
  38. * <code>getAttributes()</code> again and compare the new attribute
  39. * set to the previous attribute set; alternatively, register a
  40. * listener for print job events.
  41. * The returned value may be an empty set but should not be null.
  42. * @return the print job attributes
  43. */
  44. public PrintJobAttributeSet getAttributes();
  45. /**
  46. * Registers a listener for event occurring during this print job.
  47. * If listener is null, no exception is thrown and no action is
  48. * performed.
  49. * If listener is already registered, it will be registered again.
  50. * @see #removePrintJobListener
  51. *
  52. * @param listener The object implementing the listener interface
  53. *
  54. */
  55. public void addPrintJobListener(PrintJobListener listener);
  56. /**
  57. * Removes a listener from this print job.
  58. * This method performs no function, nor does it throw an exception,
  59. * if the listener specified by the argument was not previously added
  60. * to this component. If listener is null, no exception is thrown and
  61. * no action is performed. If a listener was registered more than once
  62. * only one of the registrations will be removed.
  63. * @see #addPrintJobListener
  64. *
  65. * @param listener The object implementing the listener interface
  66. */
  67. public void removePrintJobListener(PrintJobListener listener);
  68. /**
  69. * Registers a listener for changes in the specified attributes.
  70. * If listener is null, no exception is thrown and no action is
  71. * performed.
  72. * To determine the attribute updates that may be reported by this job,
  73. * a client can call <code>getAttributes()/<code> and identify the
  74. * subset that are interesting and likely to be reported to the
  75. * listener. Clients expecting to be updated about changes in a
  76. * specific job attribute should verify it is in that set, but
  77. * updates about an attribute will be made only if it changes and this
  78. * is detected by the job. Also updates may be subject to batching
  79. * by the job. To minimise overhead in print job processing it is
  80. * recommended to listen on only that subset of attributes which
  81. * are likely to change.
  82. * If the specified set is empty no attribute updates will be reported
  83. * to the listener.
  84. * If the attribute set is null, then this means to listen on all
  85. * dynamic attributes that the job supports. This may result in no
  86. * update notifications if a job can not report any attribute updates.
  87. *
  88. * If listener is already registered, it will be registered again.
  89. * @see #removePrintJobAttributeListener
  90. *
  91. * @param listener The object implementing the listener interface
  92. * @param attributes The attributes to listen on, or null to mean
  93. * all attributes that can change, as determined by the job.
  94. */
  95. public void addPrintJobAttributeListener(
  96. PrintJobAttributeListener listener,
  97. PrintJobAttributeSet attributes);
  98. /**
  99. * Removes an attribute listener from this print job.
  100. * This method performs no function, nor does it throw an exception,
  101. * if the listener specified by the argument was not previously added
  102. * to this component. If the listener is null, no exception is thrown
  103. * and no action is performed.
  104. * If a listener is registered more than once, even for a different
  105. * set of attributes, no guarantee is made which listener is removed.
  106. * @see #addPrintJobAttributeListener
  107. *
  108. * @param listener The object implementing the listener interface
  109. *
  110. */
  111. public void removePrintJobAttributeListener(
  112. PrintJobAttributeListener listener);
  113. /**
  114. * Prints a document with the specified job attributes.
  115. * This method should only be called once for a given print job.
  116. * Calling it again will not result in a new job being spooled to
  117. * the printer. The service implementation will define policy
  118. * for service interruption and recovery.
  119. * When the print method returns, printing may not yet have completed as
  120. * printing may happen asynchronously, perhaps in a different thread.
  121. * Application clients which want to monitor the success or failure
  122. * should register a PrintJobListener.
  123. * <p>
  124. * Print service implementors should close any print data streams (ie
  125. * Reader or InputStream implementations) that they obtain
  126. * from the client doc. Robust clients may still wish to verify this.
  127. * An exception is always generated if a <code>DocFlavor</code> cannot
  128. * be printed.
  129. *
  130. * @param doc The document to be printed. If must be a flavor
  131. * supported by this PrintJob.
  132. *
  133. * @param attributes The job attributes to be applied to this print job.
  134. * If this parameter is null then the default attributes are used.
  135. * @throws PrintException The exception additionally may implement
  136. * an interface that more precisely describes the cause of the
  137. * exception
  138. * <ul>
  139. * <li>FlavorException.
  140. * If the document has a flavor not supported by this print job.
  141. * <li>AttributeException.
  142. * If one or more of the attributes are not valid for this print job.
  143. * </ul>
  144. */
  145. public void print(Doc doc, PrintRequestAttributeSet attributes)
  146. throws PrintException;
  147. }