Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/print/PrintService.java
38829 views
/*1* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.print;2627import java.util.Locale;2829import javax.print.attribute.Attribute;30import javax.print.attribute.AttributeSet;31import javax.print.attribute.PrintServiceAttribute;32import javax.print.attribute.PrintServiceAttributeSet;33import javax.print.event.PrintServiceAttributeListener;343536/**37* Interface PrintService is the factory for a DocPrintJob. A PrintService38* describes the capabilities of a Printer and can be queried regarding39* a printer's supported attributes.40* <P>41* Example:42* <PRE>{@code43* DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;44* PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();45* aset.add(MediaSizeName.ISO_A4);46* PrintService[] pservices =47* PrintServiceLookup.lookupPrintServices(flavor, aset);48* if (pservices.length > 0) {49* DocPrintJob pj = pservices[0].createPrintJob();50* try {51* FileInputStream fis = new FileInputStream("test.ps");52* Doc doc = new SimpleDoc(fis, flavor, null);53* pj.print(doc, aset);54* } catch (FileNotFoundException fe) {55* } catch (PrintException e) {56* }57* }58* }</PRE>59*/60public interface PrintService {6162/** Returns a String name for this print service which may be used63* by applications to request a particular print service.64* In a suitable context, such as a name service, this name must be65* unique.66* In some environments this unique name may be the same as the user67* friendly printer name defined as the68* {@link javax.print.attribute.standard.PrinterName PrinterName}69* attribute.70* @return name of the service.71*/72public String getName();7374/**75* Creates and returns a PrintJob capable of handling data from76* any of the supported document flavors.77* @return a DocPrintJob object78*/79public DocPrintJob createPrintJob();8081/**82* Registers a listener for events on this PrintService.83* @param listener a PrintServiceAttributeListener, which84* monitors the status of a print service85* @see #removePrintServiceAttributeListener86*/87public void addPrintServiceAttributeListener(88PrintServiceAttributeListener listener);8990/**91* Removes the print-service listener from this print service.92* This means the listener is no longer interested in93* <code>PrintService</code> events.94* @param listener a PrintServiceAttributeListener object95* @see #addPrintServiceAttributeListener96*/97public void removePrintServiceAttributeListener(98PrintServiceAttributeListener listener);99100/**101* Obtains this print service's set of printer description attributes102* giving this Print Service's status. The returned attribute set object103* is unmodifiable. The returned attribute set object is a "snapshot" of104* this Print Service's attribute set at the time of the105* <CODE>getAttributes()</CODE> method call: that is, the returned106* attribute set's contents will <I>not</I> be updated if this print107* service's attribute set's contents change in the future. To detect108* changes in attribute values, call <CODE>getAttributes()</CODE> again109* and compare the new attribute set to the previous attribute set;110* alternatively, register a listener for print service events.111*112* @return Unmodifiable snapshot of this Print Service's attribute set.113* May be empty, but not null.114*/115public PrintServiceAttributeSet getAttributes();116117/**118* Gets the value of the single specified service attribute.119* This may be useful to clients which only need the value of one120* attribute and want to minimize overhead.121* @param category the category of a PrintServiceAttribute supported122* by this service - may not be null.123* @return the value of the supported attribute or null if the124* attribute is not supported by this service.125* @exception NullPointerException if the category is null.126* @exception IllegalArgumentException127* (unchecked exception) if <CODE>category</CODE> is not a128* <code>Class</code> that implements interface129*{@link javax.print.attribute.PrintServiceAttribute PrintServiceAttribute}.130*/131public <T extends PrintServiceAttribute>132T getAttribute(Class<T> category);133134/**135* Determines the print data formats a client can specify when setting136* up a job for this <code>PrintService</code>. A print data format is137* designated by a "doc138* flavor" (class {@link javax.print.DocFlavor DocFlavor})139* consisting of a MIME type plus a print data representation class.140* <P>141* Note that some doc flavors may not be supported in combination142* with all attributes. Use <code>getUnsupportedAttributes(..)</code>143* to validate specific combinations.144*145* @return Array of supported doc flavors, should have at least146* one element.147*148*/149public DocFlavor[] getSupportedDocFlavors();150151/**152* Determines if this print service supports a specific153* <code>DocFlavor</code>. This is a convenience method to determine154* if the <code>DocFlavor</code> would be a member of the result of155* <code>getSupportedDocFlavors()</code>.156* <p>157* Note that some doc flavors may not be supported in combination158* with all attributes. Use <code>getUnsupportedAttributes(..)</code>159* to validate specific combinations.160*161* @param flavor the <code>DocFlavor</code>to query for support.162* @return <code>true</code> if this print service supports the163* specified <code>DocFlavor</code>; <code>false</code> otherwise.164* @exception NullPointerException165* (unchecked exception) Thrown if <CODE>flavor</CODE> is null.166*/167public boolean isDocFlavorSupported(DocFlavor flavor);168169170/**171* Determines the printing attribute categories a client can specify172* when setting up a job for this print service.173* A printing attribute category is174* designated by a <code>Class</code> that implements interface175* {@link javax.print.attribute.Attribute Attribute}. This method returns176* just the attribute <I>categories</I> that are supported; it does not177* return the particular attribute <I>values</I> that are supported.178* <P>179* This method returns all the printing attribute180* categories this print service supports for any possible job.181* Some categories may not be supported in a particular context (ie182* for a particular <code>DocFlavor</code>).183* Use one of the methods that include a <code>DocFlavor</code> to184* validate the request before submitting it, such as185* <code>getSupportedAttributeValues(..)</code>.186*187* @return Array of printing attribute categories that the client can188* specify as a doc-level or job-level attribute in a Print189* Request. Each element in the array is a {@link java.lang.Class190* Class} that implements interface {@link191* javax.print.attribute.Attribute Attribute}.192* The array is empty if no categories are supported.193*/194public Class<?>[] getSupportedAttributeCategories();195196/**197* Determines whether a client can specify the given printing198* attribute category when setting up a job for this print service. A199* printing attribute category is designated by a <code>Class</code>200* that implements interface {@link javax.print.attribute.Attribute201* Attribute}. This method tells whether the attribute <I>category</I> is202* supported; it does not tell whether a particular attribute <I>value</I>203* is supported.204* <p>205* Some categories may not be supported in a particular context (ie206* for a particular <code>DocFlavor</code>).207* Use one of the methods which include a <code>DocFlavor</code> to208* validate the request before submitting it, such as209* <code>getSupportedAttributeValues(..)</code>.210* <P>211* This is a convenience method to determine if the category212* would be a member of the result of213* <code>getSupportedAttributeCategories()</code>.214*215* @param category Printing attribute category to test. It must be a216* <code>Class</code> that implements217* interface218* {@link javax.print.attribute.Attribute Attribute}.219*220* @return <code>true</code> if this print service supports221* specifying a doc-level or222* job-level attribute in <CODE>category</CODE> in a Print223* Request; <code>false</code> if it doesn't.224*225* @exception NullPointerException226* (unchecked exception) Thrown if <CODE>category</CODE> is null.227* @exception IllegalArgumentException228* (unchecked exception) Thrown if <CODE>category</CODE> is not a229* <code>Class</code> that implements interface230* {@link javax.print.attribute.Attribute Attribute}.231*/232public boolean233isAttributeCategorySupported(Class<? extends Attribute> category);234235/**236* Determines this print service's default printing attribute value in237* the given category. A printing attribute value is an instance of238* a class that implements interface239* {@link javax.print.attribute.Attribute Attribute}. If a client sets240* up a print job and does not specify any attribute value in the241* given category, this Print Service will use the242* default attribute value instead.243* <p>244* Some attributes may not be supported in a particular context (ie245* for a particular <code>DocFlavor</code>).246* Use one of the methods that include a <code>DocFlavor</code> to247* validate the request before submitting it, such as248* <code>getSupportedAttributeValues(..)</code>.249* <P>250* Not all attributes have a default value. For example the251* service will not have a defaultvalue for <code>RequestingUser</code>252* i.e. a null return for a supported category means there is no253* service default value for that category. Use the254* <code>isAttributeCategorySupported(Class)</code> method to255* distinguish these cases.256*257* @param category Printing attribute category for which the default258* attribute value is requested. It must be a {@link259* java.lang.Class Class} that implements interface260* {@link javax.print.attribute.Attribute261* Attribute}.262*263* @return Default attribute value for <CODE>category</CODE>, or null264* if this Print Service does not support specifying a doc-level or265* job-level attribute in <CODE>category</CODE> in a Print266* Request, or the service does not have a default value267* for this attribute.268*269* @exception NullPointerException270* (unchecked exception) Thrown if <CODE>category</CODE> is null.271* @exception IllegalArgumentException272* (unchecked exception) Thrown if <CODE>category</CODE> is not a273* {@link java.lang.Class Class} that implements interface {@link274* javax.print.attribute.Attribute Attribute}.275*/276public Object277getDefaultAttributeValue(Class<? extends Attribute> category);278279/**280* Determines the printing attribute values a client can specify in281* the given category when setting up a job for this print service. A282* printing283* attribute value is an instance of a class that implements interface284* {@link javax.print.attribute.Attribute Attribute}.285* <P>286* If <CODE>flavor</CODE> is null and <CODE>attributes</CODE> is null287* or is an empty set, this method returns all the printing attribute288* values this Print Service supports for any possible job. If289* <CODE>flavor</CODE> is not null or <CODE>attributes</CODE> is not290* an empty set, this method returns just the printing attribute values291* that are compatible with the given doc flavor and/or set of attributes.292* That is, a null return value may indicate that specifying this attribute293* is incompatible with the specified DocFlavor.294* Also if DocFlavor is not null it must be a flavor supported by this295* PrintService, else IllegalArgumentException will be thrown.296* <P>297* If the <code>attributes</code> parameter contains an Attribute whose298* category is the same as the <code>category</code> parameter, the service299* must ignore this attribute in the AttributeSet.300* <p>301* <code>DocAttribute</code>s which are to be specified on the302* <code>Doc</code> must be included in this set to accurately303* represent the context.304* <p>305* This method returns an Object because different printing attribute306* categories indicate the supported attribute values in different ways.307* The documentation for each printing attribute in package {@link308* javax.print.attribute.standard javax.print.attribute.standard}309* describes how each attribute indicates its supported values. Possible310* ways of indicating support include:311* <UL>312* <LI>313* Return a single instance of the attribute category to indicate that any314* value is legal -- used, for example, by an attribute whose value is an315* arbitrary text string. (The value of the returned attribute object is316* irrelevant.)317* <LI>318* Return an array of one or more instances of the attribute category,319* containing the legal values -- used, for example, by an attribute with320* a list of enumerated values. The type of the array is an array of the321* specified attribute category type as returned by its322* <code>getCategory(Class)</code>.323* <LI>324* Return a single object (of some class other than the attribute category)325* that indicates bounds on the legal values -- used, for example, by an326* integer-valued attribute that must lie within a certain range.327* </UL>328* <P>329*330* @param category Printing attribute category to test. It must be a331* {@link java.lang.Class Class} that implements332* interface {@link333* javax.print.attribute.Attribute Attribute}.334* @param flavor Doc flavor for a supposed job, or null.335* @param attributes Set of printing attributes for a supposed job336* (both job-level attributes and document-level337* attributes), or null.338*339* @return Object indicating supported values for <CODE>category</CODE>,340* or null if this Print Service does not support specifying a341* doc-level or job-level attribute in <CODE>category</CODE> in342* a Print Request.343*344* @exception NullPointerException345* (unchecked exception) Thrown if <CODE>category</CODE> is null.346* @exception IllegalArgumentException347* (unchecked exception) Thrown if <CODE>category</CODE> is not a348* {@link java.lang.Class Class} that implements interface {@link349* javax.print.attribute.Attribute Attribute}, or350* <code>DocFlavor</code> is not supported by this service.351*/352public Object353getSupportedAttributeValues(Class<? extends Attribute> category,354DocFlavor flavor,355AttributeSet attributes);356357/**358* Determines whether a client can specify the given printing359* attribute360* value when setting up a job for this Print Service. A printing361* attribute value is an instance of a class that implements interface362* {@link javax.print.attribute.Attribute Attribute}.363* <P>364* If <CODE>flavor</CODE> is null and <CODE>attributes</CODE> is null or365* is an empty set, this method tells whether this Print Service supports366* the given printing attribute value for some possible combination of doc367* flavor and set of attributes. If <CODE>flavor</CODE> is not null or368* <CODE>attributes</CODE> is not an empty set, this method tells whether369* this Print Service supports the given printing attribute value in370* combination with the given doc flavor and/or set of attributes.371* <p>372* Also if DocFlavor is not null it must be a flavor supported by this373* PrintService, else IllegalArgumentException will be thrown.374* <p>375* <code>DocAttribute</code>s which are to be specified on the376* <code>Doc</code> must be included in this set to accurately377* represent the context.378* <p>379* This is a convenience method to determine if the value380* would be a member of the result of381* <code>getSupportedAttributeValues(...)</code>.382*383* @param attrval Printing attribute value to test.384* @param flavor Doc flavor for a supposed job, or null.385* @param attributes Set of printing attributes for a supposed job386* (both job-level attributes and document-level387* attributes), or null.388*389* @return True if this Print Service supports specifying390* <CODE>attrval</CODE> as a doc-level or job-level attribute in a391* Print Request, false if it doesn't.392*393* @exception NullPointerException394* (unchecked exception) if <CODE>attrval</CODE> is null.395* @exception IllegalArgumentException if flavor is not supported by396* this PrintService.397*/398public boolean isAttributeValueSupported(Attribute attrval,399DocFlavor flavor,400AttributeSet attributes);401402403/**404* Identifies the attributes that are unsupported for a print request405* in the context of a particular DocFlavor.406* This method is useful for validating a potential print job and407* identifying the specific attributes which cannot be supported.408* It is important to supply only a supported DocFlavor or an409* IllegalArgumentException will be thrown. If the410* return value from this method is null, all attributes are supported.411* <p>412* <code>DocAttribute</code>s which are to be specified on the413* <code>Doc</code> must be included in this set to accurately414* represent the context.415* <p>416* If the return value is non-null, all attributes in the returned417* set are unsupported with this DocFlavor. The returned set does not418* distinguish attribute categories that are unsupported from419* unsupported attribute values.420* <p>421* A supported print request can then be created by removing422* all unsupported attributes from the original attribute set,423* except in the case that the DocFlavor is unsupported.424* <p>425* If any attributes are unsupported only because they are in conflict426* with other attributes then it is at the discretion of the service427* to select the attribute(s) to be identified as the cause of the428* conflict.429* <p>430* Use <code>isDocFlavorSupported()</code> to verify that a DocFlavor431* is supported before calling this method.432*433* @param flavor Doc flavor to test, or null434* @param attributes Set of printing attributes for a supposed job435* (both job-level attributes and document-level436* attributes), or null.437*438* @return null if this Print Service supports the print request439* specification, else the unsupported attributes.440*441* @exception IllegalArgumentException if<CODE>flavor</CODE> is442* not supported by this PrintService.443*/444public AttributeSet getUnsupportedAttributes(DocFlavor flavor,445AttributeSet attributes);446447/**448* Returns a factory for UI components which allow users to interact449* with the service in various roles.450* Services which do not provide any UI should return null.451* Print Services which do provide UI but want to be supported in452* an environment with no UI support should ensure that the factory453* is not initialised unless the application calls this method to454* obtain the factory.455* See <code>ServiceUIFactory</code> for more information.456* @return null or a factory for UI components.457*/458public ServiceUIFactory getServiceUIFactory();459460/**461* Determines if two services are referring to the same underlying462* service. Objects encapsulating a print service may not exhibit463* equality of reference even though they refer to the same underlying464* service.465* <p>466* Clients should call this method to determine if two services are467* referring to the same underlying service.468* <p>469* Services must implement this method and return true only if the470* service objects being compared may be used interchangeably by the471* client.472* Services are free to return the same object reference to an underlying473* service if that, but clients must not depend on equality of reference.474* @param obj the reference object with which to compare.475* @return true if this service is the same as the obj argument,476* false otherwise.477*/478public boolean equals(Object obj);479480/**481* This method should be implemented consistently with482* <code>equals(Object)</code>.483* @return hash code of this object.484*/485public int hashCode();486487}488489490