1. /*
  2. * @(#)PrintService.java 1.9 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.print;
  8. import java.util.Locale;
  9. import javax.print.attribute.Attribute;
  10. import javax.print.attribute.AttributeSet;
  11. import javax.print.attribute.PrintServiceAttribute;
  12. import javax.print.attribute.PrintServiceAttributeSet;
  13. import javax.print.event.PrintServiceAttributeListener;
  14. /**
  15. * Interface PrintService is the factory for a DocPrintJob. A PrintService
  16. * describes the capabilities of a Printer and can be queried regarding
  17. * a printer's supported attributes.
  18. * <P>
  19. * Example:
  20. * <PRE>
  21. * DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
  22. * PrintRequestAttributeSet aset = new HashPrintRequestHashAttributeSet();
  23. * aset.add(MediaSizeName.ISO_A4);
  24. * PrintService[] pservices =
  25. * PrintServiceLookup.lookupPrintServices(flavor, aset);
  26. * if (pservices.length > 0) {
  27. * DocPrintJob pj = pservices[0].createPrintJob();
  28. * // InputStreamDoc is an implementation of the Doc interface //
  29. * Doc doc = new InputStreamDoc("test.ps", flavor);
  30. * try {
  31. * pj.print(doc, aset);
  32. * } catch (PrintException e) {
  33. * }
  34. * }
  35. * </PRE>
  36. */
  37. public interface PrintService {
  38. /** Returns a String name for this print service which may be used
  39. * by applications to request a particular print service.
  40. * In a suitable context, such as a name service, this name must be
  41. * unique.
  42. * In some environments this unique name may be the same as the user
  43. * friendly printer name defined as the
  44. * {@link javax.print.attribute.standard.PrinterName PrinterName}
  45. * attribute.
  46. * @return name of the service.
  47. */
  48. public String getName();
  49. /**
  50. * Creates and returns a PrintJob capable of handling data from
  51. * any of the supported document flavors.
  52. * @return a DocPrintJob object
  53. */
  54. public DocPrintJob createPrintJob();
  55. /**
  56. * Registers a listener for events on this PrintService.
  57. * @param listener a PrintServiceAttributeListener, which
  58. * monitors the status of a print service
  59. * @see #removePrintServiceAttributeListener
  60. */
  61. public void addPrintServiceAttributeListener(
  62. PrintServiceAttributeListener listener);
  63. /**
  64. * Removes the print-service listener from this print service.
  65. * This means the listener is no longer interested in
  66. * <code>PrintService</code> events.
  67. * @param listener a PrintServiceAttributeListener object
  68. * @see #addPrintServiceAttributeListener
  69. */
  70. public void removePrintServiceAttributeListener(
  71. PrintServiceAttributeListener listener);
  72. /**
  73. * Obtains this print service's set of printer description attributes
  74. * giving this Print Service's status. The returned attribute set object
  75. * is unmodifiable. The returned attribute set object is a "snapshot" of
  76. * this Print Service's attribute set at the time of the
  77. * <CODE>getAttributes()</CODE> method call: that is, the returned
  78. * attribute set's contents will <I>not</I> be updated if this print
  79. * service's attribute set's contents change in the future. To detect
  80. * changes in attribute values, call <CODE>getAttributes()</CODE> again
  81. * and compare the new attribute set to the previous attribute set;
  82. * alternatively, register a listener for print service events.
  83. *
  84. * @return Unmodifiable snapshot of this Print Service's attribute set.
  85. * May be empty, but not null.
  86. */
  87. public PrintServiceAttributeSet getAttributes();
  88. /**
  89. * Gets the value of the single specified service attribute.
  90. * This may be useful to clients which only need the value of one
  91. * attribute and want to minimise overhead.
  92. * @param category the category of a PrintServiceAttribute supported
  93. * by this service - may not be null.
  94. * @return the value of the supported attribute or null if the
  95. * attribute is not supported by this service.
  96. * @exception NullPointerException if the category is null.
  97. * @exception IllegalArgumentException
  98. * (unchecked exception) if <CODE>category</CODE> is not a
  99. * <code>Class</code> that implements interface
  100. *{@link javax.print.attribute.PrintServiceAttribute PrintServiceAttribute}.
  101. */
  102. public PrintServiceAttribute getAttribute(Class category);
  103. /**
  104. * Determines the print data formats a client can specify when setting
  105. * up a job for this <code>PrintService</code>. A print data format is
  106. * designated by a "doc
  107. * flavor" (class {@link javax.print.DocFlavor DocFlavor})
  108. * consisting of a MIME type plus a print data representation class.
  109. * <P>
  110. * Note that some doc flavors may not be supported in combination
  111. * with all attributes. Use <code>getUnsupportedAttributes(..)</code>
  112. * to validate specific combinations.
  113. *
  114. * @return Array of supported doc flavors, should have at least
  115. * one element.
  116. *
  117. */
  118. public DocFlavor[] getSupportedDocFlavors();
  119. /**
  120. * Determines if this print service supports a specific
  121. * <code>DocFlavor</code>. This is a convenience method to determine
  122. * if the <code>DocFlavor</code> would be a member of the result of
  123. * <code>getSupportedDocFlavors()</code>.
  124. * <p>
  125. * Note that some doc flavors may not be supported in combination
  126. * with all attributes. Use <code>getUnsupportedAttributes(..)</code>
  127. * to validate specific combinations.
  128. *
  129. * @param flavor the <code>DocFlavor</code>to query for support.
  130. * @return <code>true</code> if this print service supports the
  131. * specified <code>DocFlavor</code> <code>false</code> otherwise.
  132. * @exception NullPointerException
  133. * (unchecked exception) Thrown if <CODE>flavor</CODE> is null.
  134. */
  135. public boolean isDocFlavorSupported(DocFlavor flavor);
  136. /**
  137. * Determines the printing attribute categories a client can specify
  138. * when setting up a job for this print service.
  139. * A printing attribute category is
  140. * designated by a <code>Class</code> that implements interface
  141. * {@link javax.print.attribute.Attribute Attribute}. This method returns
  142. * just the attribute <I>categories</I> that are supported; it does not
  143. * return the particular attribute <I>values</I> that are supported.
  144. * <P>
  145. * This method returns all the printing attribute
  146. * categories this print service supports for any possible job.
  147. * Some categories may not be supported in a particular context (ie
  148. * for a particular <code>DocFlavor</code>).
  149. * Use one of the methods that include a <code>DocFlavor</code> to
  150. * validate the request before submitting it, such as
  151. * <code>getSupportedAttributeValues(..)</code>.
  152. *
  153. * @return Array of printing attribute categories that the client can
  154. * specify as a doc-level or job-level attribute in a Print
  155. * Request. Each element in the array is a {@link java.lang.Class
  156. * Class} that implements interface {@link
  157. * javax.print.attribute.Attribute Attribute}.
  158. * The array is empty if no categories are supported.
  159. */
  160. public Class[] getSupportedAttributeCategories();
  161. /**
  162. * Determines whether a client can specify the given printing
  163. * attribute category when setting up a job for this print service. A
  164. * printing attribute category is designated by a <code>Class</code>
  165. * that implements interface {@link javax.print.attribute.Attribute
  166. * Attribute}. This method tells whether the attribute <I>category</I> is
  167. * supported; it does not tell whether a particular attribute <I>value</I>
  168. * is supported.
  169. * <p>
  170. * Some categories may not be supported in a particular context (ie
  171. * for a particular <code>DocFlavor</code>).
  172. * Use one of the methods which include a <code>DocFlavor</code> to
  173. * validate the request before submitting it, such as
  174. * <code>getSupportedAttributeValues(..)</code>.
  175. * <P>
  176. * This is a convenience method to determine if the category
  177. * would be a member of the result of
  178. * <code>getSupportedAttributeCategories()</code>.
  179. *
  180. * @param category Printing attribute category to test. It must be a
  181. * <code>Class</code> that implements
  182. * interface
  183. * {@link javax.print.attribute.Attribute Attribute}.
  184. *
  185. * @return <code>true</code> if this print service supports
  186. * specifying a doc-level or
  187. * job-level attribute in <CODE>category</CODE> in a Print
  188. * Request; <code>false</code> if it doesn't.
  189. *
  190. * @exception NullPointerException
  191. * (unchecked exception) Thrown if <CODE>category</CODE> is null.
  192. * @exception IllegalArgumentException
  193. * (unchecked exception) Thrown if <CODE>category</CODE> is not a
  194. * <code>Class</code> that implements interface
  195. * {@link javax.print.attribute.Attribute Attribute}.
  196. */
  197. public boolean isAttributeCategorySupported(Class category);
  198. /**
  199. * Determines this print service's default printing attribute value in
  200. * the given category. A printing attribute value is an instance of
  201. * a class that implements interface
  202. * {@link javax.print.attribute.Attribute Attribute}. If a client sets
  203. * up a print job and does not specify any attribute value in the
  204. * given category, this Print Service will use the
  205. * default attribute value instead.
  206. * <p>
  207. * Some attributes may not be supported in a particular context (ie
  208. * for a particular <code>DocFlavor</code>).
  209. * Use one of the methods that include a <code>DocFlavor</code> to
  210. * validate the request before submitting it, such as
  211. * <code>getSupportedAttributeValues(..)</code>.
  212. * <P>
  213. * Not all attributes have a default value. For example the
  214. * service will not have a defaultvalue for <code>RequestingUser</code>
  215. * i.e. a null return for a supported category means there is no
  216. * service default value for that category. Use the
  217. * <code>isAttributeCategorySupported(Class)</code> method to
  218. * distinguish these cases.
  219. *
  220. * @param category Printing attribute category for which the default
  221. * attribute value is requested. It must be a {@link
  222. * java.lang.Class Class} that implements interface
  223. * {@link javax.print.attribute.Attribute
  224. * Attribute}.
  225. *
  226. * @return Default attribute value for <CODE>category</CODE>, or null
  227. * if this Print Service does not support specifying a doc-level or
  228. * job-level attribute in <CODE>category</CODE> in a Print
  229. * Request, or the service does not have a default value
  230. * for this attribute.
  231. *
  232. * @exception NullPointerException
  233. * (unchecked exception) Thrown if <CODE>category</CODE> is null.
  234. * @exception IllegalArgumentException
  235. * (unchecked exception) Thrown if <CODE>category</CODE> is not a
  236. * {@link java.lang.Class Class} that implements interface {@link
  237. * javax.print.attribute.Attribute Attribute}.
  238. */
  239. public Object getDefaultAttributeValue(Class category);
  240. /**
  241. * Determines the printing attribute values a client can specify in
  242. * the given category when setting up a job for this print service. A
  243. * printing
  244. * attribute value is an instance of a class that implements interface
  245. * {@link javax.print.attribute.Attribute Attribute}.
  246. * <P>
  247. * If <CODE>flavor</CODE> is null and <CODE>attributes</CODE> is null
  248. * or is an empty set, this method returns all the printing attribute
  249. * values this Print Service supports for any possible job. If
  250. * <CODE>flavor</CODE> is not null or <CODE>attributes</CODE> is not
  251. * an empty set, this method returns just the printing attribute values
  252. * that are compatible with the given doc flavor and/or set of attributes.
  253. * That is, a null return value may indicate that specifying this attribute
  254. * is incompatible with the specified DocFlavor.
  255. * Also if DocFlavor is not null it must be a flavor supported by this
  256. * PrintService, else IllegalArgumentException will be thrown.
  257. * <P>
  258. * If the <code>attributes</code> parameter contains an Attribute whose
  259. * category is the same as the <code>category</code> parameter, the service
  260. * must ignore this attribute in the AttributeSet.
  261. * <p>
  262. * <code>DocAttribute</code>s which are to be specified on the
  263. * <code>Doc</code> must be included in this set to accurately
  264. * represent the context.
  265. * <p>
  266. * This method returns an Object because different printing attribute
  267. * categories indicate the supported attribute values in different ways.
  268. * The documentation for each printing attribute in package {@link
  269. * javax.print.attribute.standard javax.print.attribute.standard}
  270. * describes how each attribute indicates its supported values. Possible
  271. * ways of indicating support include:
  272. * <UL>
  273. * <LI>
  274. * Return a single instance of the attribute category to indicate that any
  275. * value is legal -- used, for example, by an attribute whose value is an
  276. * arbitrary text string. (The value of the returned attribute object is
  277. * irrelevant.)
  278. * <LI>
  279. * Return an array of one or more instances of the attribute category,
  280. * containing the legal values -- used, for example, by an attribute with
  281. * a list of enumerated values. The type of the array is an array of the
  282. * specified attribute category type as returned by its
  283. * <code>getCategory(Class)</code>.
  284. * <LI>
  285. * Return a single object (of some class other than the attribute category)
  286. * that indicates bounds on the legal values -- used, for example, by an
  287. * integer-valued attribute that must lie within a certain range.
  288. * </UL>
  289. * <P>
  290. *
  291. * @param category Printing attribute category to test. It must be a
  292. * {@link java.lang.Class Class} that implements
  293. * interface {@link
  294. * javax.print.attribute.Attribute Attribute}.
  295. * @param flavor Doc flavor for a supposed job, or null.
  296. * @param attributes Set of printing attributes for a supposed job
  297. * (both job-level attributes and document-level
  298. * attributes), or null.
  299. *
  300. * @return Object indicating supported values for <CODE>category</CODE>,
  301. * or null if this Print Service does not support specifying a
  302. * doc-level or job-level attribute in <CODE>category</CODE> in
  303. * a Print Request.
  304. *
  305. * @exception NullPointerException
  306. * (unchecked exception) Thrown if <CODE>category</CODE> is null.
  307. * @exception IllegalArgumentException
  308. * (unchecked exception) Thrown if <CODE>category</CODE> is not a
  309. * {@link java.lang.Class Class} that implements interface {@link
  310. * javax.print.attribute.Attribute Attribute}, or
  311. * <code>DocFlavor</code> is not supported by this service.
  312. */
  313. public Object getSupportedAttributeValues(Class category,
  314. DocFlavor flavor,
  315. AttributeSet attributes);
  316. /**
  317. * Determines whether a client can specify the given printing
  318. * attribute
  319. * value when setting up a job for this Print Service. A printing
  320. * attribute value is an instance of a class that implements interface
  321. * {@link javax.print.attribute.Attribute Attribute}.
  322. * <P>
  323. * If <CODE>flavor</CODE> is null and <CODE>attributes</CODE> is null or
  324. * is an empty set, this method tells whether this Print Service supports
  325. * the given printing attribute value for some possible combination of doc
  326. * flavor and set of attributes. If <CODE>flavor</CODE> is not null or
  327. * <CODE>attributes</CODE> is not an empty set, this method tells whether
  328. * this Print Service supports the given printing attribute value in
  329. * combination with the given doc flavor and/or set of attributes.
  330. * <p>
  331. * Also if DocFlavor is not null it must be a flavor supported by this
  332. * PrintService, else IllegalArgumentException will be thrown.
  333. * <p>
  334. * <code>DocAttribute</code>s which are to be specified on the
  335. * <code>Doc</code> must be included in this set to accurately
  336. * represent the context.
  337. * <p>
  338. * This is a convenience method to determine if the value
  339. * would be a member of the result of
  340. * <code>getSupportedAttributeValues(...)</code>.
  341. *
  342. * @param attrval Printing attribute value to test.
  343. * @param flavor Doc flavor for a supposed job, or null.
  344. * @param attributes Set of printing attributes for a supposed job
  345. * (both job-level attributes and document-level
  346. * attributes), or null.
  347. *
  348. * @return True if this Print Service supports specifying
  349. * <CODE>attrval</CODE> as a doc-level or job-level attribute in a
  350. * Print Request, false if it doesn't.
  351. *
  352. * @exception NullPointerException
  353. * (unchecked exception) if <CODE>attrval</CODE> is null.
  354. * @exception IllegalArgumentException if flavor is not supported by
  355. * this PrintService.
  356. */
  357. public boolean isAttributeValueSupported(Attribute attrval,
  358. DocFlavor flavor,
  359. AttributeSet attributes);
  360. /**
  361. * Identifies the attributes that are unsupported for a print request
  362. * in the context of a particular DocFlavor.
  363. * This method is useful for validating a potential print job and
  364. * identifying the specific attributes which cannot be supported.
  365. * It is important to supply only a supported DocFlavor or an
  366. * IllegalArgumentException will be thrown. If the
  367. * return value from this method is null, all attributes are supported.
  368. * <p>
  369. * <code>DocAttribute</code>s which are to be specified on the
  370. * <code>Doc</code> must be included in this set to accurately
  371. * represent the context.
  372. * <p>
  373. * If the return value is non-null, all attributes in the returned
  374. * set are unsupported with this DocFlavor. The returned set does not
  375. * distinguish attribute categories that are unsupported from
  376. * unsupported attribute values.
  377. * <p>
  378. * A supported print request can then be created by removing
  379. * all unsupported attributes from the original attribute set,
  380. * except in the case that the DocFlavor is unsupported.
  381. * <p>
  382. * If any attributes are unsupported only because they are in conflict
  383. * with other attributes then it is at the discretion of the service
  384. * to select the attribute(s) to be identified as the cause of the
  385. * conflict.
  386. * <p>
  387. * Use <code>isDocFlavorSupported()</code> to verify that a DocFlavor
  388. * is supported before calling this method.
  389. *
  390. * @param flavor Doc flavor to test, or null
  391. * @param attributes Set of printing attributes for a supposed job
  392. * (both job-level attributes and document-level
  393. * attributes), or null.
  394. *
  395. * @return null if this Print Service supports the print request
  396. * specification, else the unsupported attributes.
  397. *
  398. * @exception IllegalArgumentException if<CODE>flavor</CODE> is
  399. * not supported by this PrintService.
  400. */
  401. public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
  402. AttributeSet attributes);
  403. /**
  404. * Returns a factory for UI components which allow users to interact
  405. * with the service in various roles.
  406. * Services which do not provide any UI should return null.
  407. * Print Services which do provide UI but want to be supported in
  408. * an environment with no UI support should ensure that the factory
  409. * is not initialised unless the application calls this method to
  410. * obtain the factory.
  411. * See <code>ServiceUIFactory</code> for more information.
  412. * @return null or a factory for UI components.
  413. */
  414. public ServiceUIFactory getServiceUIFactory();
  415. /**
  416. * Determines if two services are referring to the same underlying
  417. * service. Objects encapsulating a print service may not exhibit
  418. * equality of reference even though they refer to the same underlying
  419. * service.
  420. * <p>
  421. * Clients should call this method to determine if two services are
  422. * referring to the same underlying service.
  423. * <p>
  424. * Services must implement this method and return true only if the
  425. * service objects being compared may be used interchangeably by the
  426. * client.
  427. * Services are free to return the same object reference to an underlying
  428. * service if that, but clients must not depend on equality of reference.
  429. * @param obj the reference object with which to compare.
  430. * @return true if this service is the same as the obj argument,
  431. * false otherwise.
  432. */
  433. public boolean equals(Object obj);
  434. /**
  435. * This method should be implemented consistently with
  436. * <code>equals(Object)</code>.
  437. * @return hash code of this object.
  438. */
  439. public int hashCode();
  440. }