J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2000-2001 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package javax.print; |
| 27 | |
| 28 | import java.io.OutputStream; |
| 29 | |
| 30 | /** |
| 31 | * This class extends {@link PrintService} and represents a |
| 32 | * print service that prints data in different formats to a |
| 33 | * client-provided output stream. |
| 34 | * This is principally intended for services where |
| 35 | * the output format is a document type suitable for viewing |
| 36 | * or archiving. |
| 37 | * The output format must be declared as a mime type. |
| 38 | * This is equivalent to an output document flavor where the |
| 39 | * representation class is always "java.io.OutputStream" |
| 40 | * An instance of the <code>StreamPrintService</code> class is |
| 41 | * obtained from a {@link StreamPrintServiceFactory} instance. |
| 42 | * <p> |
| 43 | * Note that a <code>StreamPrintService</code> is different from a |
| 44 | * <code>PrintService</code>, which supports a |
| 45 | * {@link javax.print.attribute.standard.Destination Destination} |
| 46 | * attribute. A <code>StreamPrintService</code> always requires an output |
| 47 | * stream, whereas a <code>PrintService</code> optionally accepts a |
| 48 | * <code>Destination</code>. A <code>StreamPrintService</code> |
| 49 | * has no default destination for its formatted output. |
| 50 | * Additionally a <code>StreamPrintService</code> is expected to generate |
| 51 | output in |
| 52 | * a format useful in other contexts. |
| 53 | * StreamPrintService's are not expected to support the Destination attribute. |
| 54 | */ |
| 55 | |
| 56 | public abstract class StreamPrintService implements PrintService { |
| 57 | |
| 58 | private OutputStream outStream; |
| 59 | private boolean disposed = false; |
| 60 | |
| 61 | private StreamPrintService() { |
| 62 | }; |
| 63 | |
| 64 | /** |
| 65 | * Constructs a StreamPrintService object. |
| 66 | * |
| 67 | * @param out stream to which to send formatted print data. |
| 68 | */ |
| 69 | protected StreamPrintService(OutputStream out) { |
| 70 | this.outStream = out; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Gets the output stream. |
| 75 | * |
| 76 | * @return the stream to which this service will send formatted print data. |
| 77 | */ |
| 78 | public OutputStream getOutputStream() { |
| 79 | return outStream; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Returns the document format emitted by this print service. |
| 84 | * Must be in mimetype format, compatible with the mime type |
| 85 | * components of DocFlavors @see DocFlavor. |
| 86 | * @return mime type identifying the output format. |
| 87 | */ |
| 88 | public abstract String getOutputFormat(); |
| 89 | |
| 90 | /** |
| 91 | * Disposes this <code>StreamPrintService</code>. |
| 92 | * If a stream service cannot be re-used, it must be disposed |
| 93 | * to indicate this. Typically the client will call this method. |
| 94 | * Services which write data which cannot meaningfully be appended to |
| 95 | * may also dispose the stream. This does not close the stream. It |
| 96 | * just marks it as not for further use by this service. |
| 97 | */ |
| 98 | public void dispose() { |
| 99 | disposed = true; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Returns a <code>boolean</code> indicating whether or not |
| 104 | * this <code>StreamPrintService</code> has been disposed. |
| 105 | * If this object has been disposed, will return true. |
| 106 | * Used by services and client applications to recognize streams |
| 107 | * to which no further data should be written. |
| 108 | * @return if this <code>StreamPrintService</code> has been disposed |
| 109 | */ |
| 110 | public boolean isDisposed() { |
| 111 | return disposed; |
| 112 | } |
| 113 | |
| 114 | } |