< prev index next >

src/java.desktop/share/classes/javax/print/StreamPrintServiceFactory.java

Print this page




  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.print;
  27 
  28 import java.io.OutputStream;
  29 
  30 import java.util.ArrayList;
  31 import java.util.Iterator;
  32 
  33 import javax.print.DocFlavor;
  34 
  35 import sun.awt.AppContext;
  36 import java.util.ServiceLoader;
  37 import java.util.ServiceConfigurationError;
  38 
  39 /**
  40  * A <code>StreamPrintServiceFactory</code> is the factory for
  41  * {@link StreamPrintService} instances,
  42  * which can print to an output stream in a particular
  43  * document format described as a mime type.
  44  * A typical output document format may be Postscript(TM).
  45  * <p>
  46  * This class is implemented by a service and located by the
  47  * implementation using the
  48  * <a href="../../../technotes/guides/jar/jar.html#Service%20Provider">
  49  * SPI JAR File specification</a>.
  50  * <p>
  51  * Applications locate instances of this class by calling the
  52  * {@link #lookupStreamPrintServiceFactories(DocFlavor, String)} method.
  53  * <p>
  54  * Applications can use a <code>StreamPrintService</code> obtained from a
  55  * factory in place of a <code>PrintService</code> which represents a
  56  * physical printer device.
  57  */
  58 
  59 public abstract class StreamPrintServiceFactory {
  60 
  61     static class Services {
  62         private ArrayList<StreamPrintServiceFactory> listOfFactories = null;
  63     }
  64 
  65     private static Services getServices() {
  66         Services services =
  67             (Services)AppContext.getAppContext().get(Services.class);
  68         if (services == null) {
  69             services = new Services();
  70             AppContext.getAppContext().put(Services.class, services);
  71         }
  72         return services;
  73     }
  74 
  75     private static ArrayList<StreamPrintServiceFactory> getListOfFactories() {


 110 
 111          ArrayList<StreamPrintServiceFactory> list = getFactories(flavor, outputMimeType);
 112          return list.toArray(new StreamPrintServiceFactory[list.size()]);
 113      }
 114 
 115     /** Queries the factory for the document format that is emitted
 116      * by printers obtained from this factory.
 117      *
 118      * @return the output format described as a mime type.
 119      */
 120     public abstract String getOutputFormat();
 121 
 122     /**
 123      * Queries the factory for the document flavors that can be accepted
 124      * by printers obtained from this factory.
 125      * @return array of supported doc flavors.
 126      */
 127     public abstract DocFlavor[] getSupportedDocFlavors();
 128 
 129     /**
 130      * Returns a <code>StreamPrintService</code> that can print to
 131      * the specified output stream.
 132      * The output stream is created and managed by the application.
 133      * It is the application's responsibility to close the stream and
 134      * to ensure that this Printer is not reused.
 135      * The application should not close this stream until any print job
 136      * created from the printer is complete. Doing so earlier may generate
 137      * a <code>PrinterException</code> and an event indicating that the
 138      * job failed.
 139      * <p>
 140      * Whereas a <code>PrintService</code> connected to a physical printer
 141      * can be reused,
 142      * a <code>StreamPrintService</code> connected to a stream cannot.
 143      * The underlying <code>StreamPrintService</code> may be disposed by
 144      * the print system with
 145      * the {@link StreamPrintService#dispose() dispose} method
 146      * before returning from the
 147      * {@link DocPrintJob#print(Doc, javax.print.attribute.PrintRequestAttributeSet) print}
 148      * method of <code>DocPrintJob</code> so that the print system knows
 149      * this printer is no longer usable.
 150      * This is equivalent to a physical printer going offline - permanently.
 151      * Applications may supply a null print stream to create a queryable
 152      * service. It is not valid to create a PrintJob for such a stream.
 153      * Implementations which allocate resources on construction should examine
 154      * the stream and may wish to only allocate resources if the stream is
 155      * non-null.
 156      *
 157      * @param out destination stream for generated output.
 158      * @return a PrintService which will generate the format specified by the
 159      * DocFlavor supported by this Factory.
 160      */
 161     public abstract StreamPrintService getPrintService(OutputStream out);
 162 
 163 
 164     private static ArrayList<StreamPrintServiceFactory> getAllFactories() {
 165         synchronized (StreamPrintServiceFactory.class) {
 166 
 167           ArrayList<StreamPrintServiceFactory> listOfFactories = getListOfFactories();
 168             if (listOfFactories != null) {




  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.print;
  27 
  28 import java.io.OutputStream;
  29 
  30 import java.util.ArrayList;
  31 import java.util.Iterator;
  32 
  33 import javax.print.DocFlavor;
  34 
  35 import sun.awt.AppContext;
  36 import java.util.ServiceLoader;
  37 import java.util.ServiceConfigurationError;
  38 
  39 /**
  40  * A {@code StreamPrintServiceFactory} is the factory for
  41  * {@link StreamPrintService} instances,
  42  * which can print to an output stream in a particular
  43  * document format described as a mime type.
  44  * A typical output document format may be Postscript(TM).
  45  * <p>
  46  * This class is implemented by a service and located by the
  47  * implementation using the
  48  * <a href="../../../technotes/guides/jar/jar.html#Service%20Provider">
  49  * SPI JAR File specification</a>.
  50  * <p>
  51  * Applications locate instances of this class by calling the
  52  * {@link #lookupStreamPrintServiceFactories(DocFlavor, String)} method.
  53  * <p>
  54  * Applications can use a {@code StreamPrintService} obtained from a
  55  * factory in place of a {@code PrintService} which represents a
  56  * physical printer device.
  57  */
  58 
  59 public abstract class StreamPrintServiceFactory {
  60 
  61     static class Services {
  62         private ArrayList<StreamPrintServiceFactory> listOfFactories = null;
  63     }
  64 
  65     private static Services getServices() {
  66         Services services =
  67             (Services)AppContext.getAppContext().get(Services.class);
  68         if (services == null) {
  69             services = new Services();
  70             AppContext.getAppContext().put(Services.class, services);
  71         }
  72         return services;
  73     }
  74 
  75     private static ArrayList<StreamPrintServiceFactory> getListOfFactories() {


 110 
 111          ArrayList<StreamPrintServiceFactory> list = getFactories(flavor, outputMimeType);
 112          return list.toArray(new StreamPrintServiceFactory[list.size()]);
 113      }
 114 
 115     /** Queries the factory for the document format that is emitted
 116      * by printers obtained from this factory.
 117      *
 118      * @return the output format described as a mime type.
 119      */
 120     public abstract String getOutputFormat();
 121 
 122     /**
 123      * Queries the factory for the document flavors that can be accepted
 124      * by printers obtained from this factory.
 125      * @return array of supported doc flavors.
 126      */
 127     public abstract DocFlavor[] getSupportedDocFlavors();
 128 
 129     /**
 130      * Returns a {@code StreamPrintService} that can print to
 131      * the specified output stream.
 132      * The output stream is created and managed by the application.
 133      * It is the application's responsibility to close the stream and
 134      * to ensure that this Printer is not reused.
 135      * The application should not close this stream until any print job
 136      * created from the printer is complete. Doing so earlier may generate
 137      * a {@code PrinterException} and an event indicating that the
 138      * job failed.
 139      * <p>
 140      * Whereas a {@code PrintService} connected to a physical printer
 141      * can be reused,
 142      * a {@code StreamPrintService} connected to a stream cannot.
 143      * The underlying {@code StreamPrintService} may be disposed by
 144      * the print system with
 145      * the {@link StreamPrintService#dispose() dispose} method
 146      * before returning from the
 147      * {@link DocPrintJob#print(Doc, javax.print.attribute.PrintRequestAttributeSet) print}
 148      * method of {@code DocPrintJob} so that the print system knows
 149      * this printer is no longer usable.
 150      * This is equivalent to a physical printer going offline - permanently.
 151      * Applications may supply a null print stream to create a queryable
 152      * service. It is not valid to create a PrintJob for such a stream.
 153      * Implementations which allocate resources on construction should examine
 154      * the stream and may wish to only allocate resources if the stream is
 155      * non-null.
 156      *
 157      * @param out destination stream for generated output.
 158      * @return a PrintService which will generate the format specified by the
 159      * DocFlavor supported by this Factory.
 160      */
 161     public abstract StreamPrintService getPrintService(OutputStream out);
 162 
 163 
 164     private static ArrayList<StreamPrintServiceFactory> getAllFactories() {
 165         synchronized (StreamPrintServiceFactory.class) {
 166 
 167           ArrayList<StreamPrintServiceFactory> listOfFactories = getListOfFactories();
 168             if (listOfFactories != null) {


< prev index next >