/*
* @(#)StreamPrintServiceFactory.java 1.10 06/08/04
*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
package javax.print;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Iterator;
import javax.print.DocFlavor;
import sun.awt.AppContext;
import sun.misc.Service;
/**
* A <code>StreamPrintServiceFactory</code> is the factory for
* {@link StreamPrintService} instances,
* which can print to an output stream in a particular
* document format described as a mime type.
* A typical output document format may be Postscript(TM).
* <p>
* This class is implemented by a service and located by the
* implementation using the
* <a href="../../../technotes/guides/jar/jar.html#Service Provider">
* SPI JAR File specification</a>.
* <p>
* Applications locate instances of this class by calling the
* {@link #lookupStreamPrintServiceFactories(DocFlavor, String)} method.
* <p>
* Applications can use a <code>StreamPrintService</code> obtained from a
* factory in place of a <code>PrintService</code> which represents a
* physical printer device.
*/
public abstract class StreamPrintServiceFactory {
static class Services {
private ArrayList listOfFactories = null;
}
private static Services getServices() {
Services services =
(Services)AppContext.getAppContext().get(Services.class);
if (services == null) {
services = new Services();
AppContext.getAppContext().put(Services.class, services);
}
return services;
}
private static ArrayList getListOfFactories() {
return getServices().listOfFactories;
}
private static ArrayList initListOfFactories() {
ArrayList listOfFactories = new ArrayList();
getServices().listOfFactories = listOfFactories;
return listOfFactories;
}
/**
* Locates factories for print services that can be used with
* a print job to output a stream of data in the
* format specified by <code>flavor</code>.
* For example, the doc flavor is the document type that you want to
* create, not the flavor of the
* document before printing.
* <p>
* Although null is an acceptable value to use in the lookup of stream
* printing services, it's typical to search for a particular
* desired format, such as Postscript(TM).
* <p>
* @param flavor of the input document type - null means match all
* types.
* @param outputMimeType representing the required output format, used to
* identify suitable stream printer factories. A value of null means
* match all formats.
* @return - matching factories for stream print service instance,
* empty if no suitable factories could be located.
*/
public static StreamPrintServiceFactory[]
lookupStreamPrintServiceFactories(DocFlavor flavor,
String outputMimeType) {
ArrayList list = getFactories(flavor, outputMimeType);
return (StreamPrintServiceFactory[])
(list.toArray(new StreamPrintServiceFactory[list.size()]));
}
/** Queries the factory for the document format that is emitted
* by printers obtained from this factory.
*
* @return the output format described as a mime type.
*/
public abstract String getOutputFormat();
=1= |