/* * Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javax.print; import java.util.ArrayList; import java.util.Iterator; import javax.print.attribute.AttributeSet; import sun.awt.AppContext; import java.util.ServiceLoader; import java.util.ServiceConfigurationError; /** Implementations of this class provide lookup services for * print services (typically equivalent to printers) of a particular type. *
* Multiple implementations may be installed concurrently. * All implementations must be able to describe the located printers * as instances of a PrintService. * Typically implementations of this service class are located * automatically in JAR files (see the SPI JAR file specification). * These classes must be instantiable using a default constructor. * Alternatively applications may explicitly register instances * at runtime. *
* Applications use only the static methods of this abstract class. * The instance methods are implemented by a service provider in a subclass * and the unification of the results from all installed lookup classes * are reported by the static methods of this class when called by * the application. *
* A PrintServiceLookup implementor is recommended to check for the * SecurityManager.checkPrintJobAccess() to deny access to untrusted code. * Following this recommended policy means that untrusted code may not * be able to locate any print services. Downloaded applets are the most * common example of untrusted code. *
* This check is made on a per lookup service basis to allow flexibility in * the policy to reflect the needs of different lookup services. *
* Services which are registered by registerService(PrintService)
* will not be included in lookup results if a security manager is
* installed and its checkPrintJobAccess() method denies access.
*/
public abstract class PrintServiceLookup {
static class Services {
private ArrayList This method is useful to help locate a service that can print
* a
* This may include making use of any preferences API that is available
* as part of the Java or native platform.
* This algorithm may be overridden by a user setting the property
* javax.print.defaultPrinter.
* A service specified must be discovered to be valid and currently
* available to be returned as the default.
*
* @return the default PrintService.
*/
public static final PrintService lookupDefaultPrintService() {
Iterator
*
* @param sp an implementation of a lookup service.
* @return
* Implemented by a service provider, used by the static methods
* of this class.
*
* The results should be the same as obtaining all the PrintServices
* and querying each one individually on its support for the
* specified attributes and flavors, but the process can be more
* efficient by taking advantage of the capabilities of lookup services
* for the print services.
*
* @param flavor of document required. If null it is ignored.
* @param attributes required to be supported. If null this
* constraint is not used.
* @return array of matching PrintServices. If no services match, the
* array is zero-length.
*/
public abstract PrintService[] getPrintServices(DocFlavor flavor,
AttributeSet attributes);
/**
* Not called directly by applications.
* Implemented by a service provider, used by the static methods
* of this class.
* @return array of all PrintServices known to this lookup service
* class. If none are found, the array is zero-length.
*/
public abstract PrintService[] getPrintServices() ;
/**
* Not called directly by applications.
*
* Implemented by a service provider, used by the static methods
* of this class.
*
* Locates MultiDoc print services which can be positively confirmed
* to support the combination of attributes and DocFlavors specified.
*
*
* @param flavors of documents required. If null or empty it is ignored.
* @param attributes required to be supported. If null this
* constraint is not used.
* @return array of matching PrintServices. If no services match, the
* array is zero-length.
*/
public abstract MultiDocPrintService[]
getMultiDocPrintServices(DocFlavor[] flavors,
AttributeSet attributes);
/**
* Not called directly by applications.
* Implemented by a service provider, and called by the print lookup
* service
* @return the default PrintService for this lookup service.
* If there is no default, returns null.
*/
public abstract PrintService getDefaultPrintService();
private static ArrayListPrintService
objects
* representing print services that support the specified flavor
* attributes. If no services match, the array is zero-length.
*/
public static final PrintService[]
lookupPrintServices(DocFlavor flavor,
AttributeSet attributes) {
ArrayListMultiDoc
in which the elements may be different
* flavors. An application could perform this itself by multiple lookups
* on each DocFlavor
in turn and collating the results,
* but the lookup service may be able to do this more efficiently.
*
* @param flavors the flavors to print. If null or empty this
* constraint is not used.
* Otherwise return only multidoc print services that can print all
* specified doc flavors.
* @param attributes attributes that the print service must
* support. If null this constraint is not used.
*
* @return array of matching {@link MultiDocPrintService} objects.
* If no services match, the array is zero-length.
*
*/
public static final MultiDocPrintService[]
lookupMultiDocPrintServices(DocFlavor[] flavors,
AttributeSet attributes) {
ArrayListtrue
if the new lookup service is newly
* registered; false
otherwise.
*/
public static boolean registerServiceProvider(PrintServiceLookup sp) {
synchronized (PrintServiceLookup.class) {
IteratorPrintServiceLookup
instance
* instead is recommended.
* The method returns true if this service is not previously
* registered and is now successfully registered.
* This method should not be called with StreamPrintService instances.
* They will always fail to register and the method will return false.
* @param service an implementation of a print service.
* @return true
if the service is newly
* registered; false
otherwise.
*/
public static boolean registerService(PrintService service) {
synchronized (PrintServiceLookup.class) {
if (service instanceof StreamPrintService) {
return false;
}
ArrayList