jdk/src/share/classes/javax/print/Doc.java
author jgodinez
Thu, 04 Dec 2008 10:05:36 -0800
changeset 1738 64832045cb32
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6587245: Import declaration not used in sun.print.* Reviewed-by: tdv, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2000-2001 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.print;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.Reader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.print.attribute.DocAttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Interface Doc specifies the interface for an object that supplies one piece
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * of print data for a Print Job. "Doc" is a short, easy-to-pronounce term
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * that means "a piece of print data." The client passes to the Print Job an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * object that implements interface Doc, and the Print Job calls methods on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * that object to obtain the print data. The Doc interface lets a Print Job:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Determine the format, or "doc flavor" (class {@link DocFlavor DocFlavor}),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * in which the print data is available. A doc flavor designates the print
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * data format (a MIME type) and the representation class of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * from which the print data comes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Obtain the print data representation object, which is an instance of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * doc flavor's representation class. The Print Job can then obtain the actual
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * print data from the representation object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * Obtain the printing attributes that specify additional characteristics of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * the doc or that specify processing instructions to be applied to the doc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Printing attributes are defined in package {@link javax.print.attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * javax.print.attribute}. The doc returns its printing attributes stored in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * an {@link javax.print.attribute.DocAttributeSet javax.print.attribute.DocAttributeSet}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * Each method in an implementation of interface Doc is permitted always to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * return the same object each time the method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * This has implications
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * for a Print Job or other caller of a doc object whose print data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * representation object "consumes" the print data as the caller obtains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * print data, such as a print data representation object which is a stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * Once the Print Job has called {@link #getPrintData()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <CODE>getPrintData()</CODE>} and obtained the stream, any further calls to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * {@link #getPrintData() <CODE>getPrintData()</CODE>} will return the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * stream object upon which reading may already be in progress, <I>not</I> a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * stream object that will re-read the print data from the beginning. Specifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * a doc object to behave this way simplifies the implementation of doc objects,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * and is justified on the grounds that a particular doc is intended to convey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * print data only to one Print Job, not to several different Print Jobs. (To
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * convey the same print data to several different Print Jobs, you have to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * create several different doc objects on top of the same print data source.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * Interface Doc affords considerable implementation flexibility. The print data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * might already be in existence when the doc object is constructed. In this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * case the objects returned by the doc's methods can be supplied to the doc's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * constructor, be stored in the doc ahead of time, and simply be returned when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * called for. Alternatively, the print data might not exist yet when the doc
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * object is constructed. In this case the doc object might provide a "lazy"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * implementation that generates the print data representation object (and/or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * the print data) only when the Print Job calls for it (when the Print Job
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * calls the {@link #getPrintData() <CODE>getPrintData()</CODE>} method).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * There is no restriction on the number of client threads that may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * simultaneously accessing the same doc. Therefore, all implementations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * interface Doc must be designed to be multiple thread safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * However there can only be one consumer of the print data obtained from a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * Doc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * If print data is obtained from the client as a stream, by calling Doc's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <code>getReaderForText()</code> or <code>getStreamForBytes()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * methods, or because the print data source is already an InputStream or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * Reader, then the print service should always close these streams for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * client on all job completion conditions. With the following caveat.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * If the print data is itself a stream, the service will always close it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * If the print data is otherwise something that can be requested as a stream,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * the service will only close the stream if it has obtained the stream before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * terminating. That is, just because a print service might request data as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * a stream does not mean that it will, with the implications that Doc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * implementors which rely on the service to close them should create such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * streams only in response to a request from the service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * <HR>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
public interface Doc {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Determines the doc flavor in which this doc object will supply its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * piece of print data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @return  Doc flavor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public DocFlavor getDocFlavor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Obtains the print data representation object that contains this doc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * object's piece of print data in the format corresponding to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * supported doc flavor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * The <CODE>getPrintData()</CODE> method returns an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * the representation class whose name is given by <CODE>{@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * #getDocFlavor() getDocFlavor()}.{@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * DocFlavor#getRepresentationClassName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * getRepresentationClassName()}</CODE>, and the return value can be cast
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * from class Object to that representation class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @return  Print data representation object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @exception  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *     Thrown if the representation class is a stream and there was an I/O
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *     error while constructing the stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public Object getPrintData() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Obtains the set of printing attributes for this doc object. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * returned attribute set includes an instance of a particular attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * <I>X,</I> the printer must use that attribute value for this doc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * overriding any value of attribute <I>X</I> in the job's attribute set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * If the returned attribute set does not include an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * of a particular attribute <I>X</I> or if null is returned, the printer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * must consult the job's attribute set to obtain the value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * attribute <I>X,</I> and if not found there, the printer must use an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * implementation-dependent default value. The returned attribute set is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * unmodifiable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @return  Unmodifiable set of printing attributes for this doc, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *          to obtain all attribute values from the job's attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *          set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public DocAttributeSet getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Obtains a reader for extracting character print data from this doc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * The Doc implementation is required to support this method if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * DocFlavor has one of the following print data representation classes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * and return null otherwise:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * <LI> char[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * <LI> java.lang.String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * <LI> java.io.Reader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * The doc's print data representation object is used to construct and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * return a Reader for reading the print data as a stream of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * from the print data representation object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * However, if the print data representation object is itself a Reader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * then the print data representation object is simply returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @return  Reader for reading the print data characters from this doc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *          If a reader cannot be provided because this doc does not meet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *          the criteria stated above, null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @exception  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *     Thrown if there was an I/O error while creating the reader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public Reader getReaderForText() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Obtains an input stream for extracting byte print data from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * doc.  The Doc implementation is required to support this method if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * the DocFlavor has one of the following print data representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * classes, and return null otherwise:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * <LI> byte[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * <LI> java.io.InputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * This doc's print data representation object is obtained, then an input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * stream for reading the print data from the print data representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * object as a stream of bytes is created and returned. However, if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * print data representation object is itself an input stream, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * print data representation object is simply returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @return  Input stream for reading the print data bytes from this doc. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *          an input stream cannot be provided because this doc does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *          meet the criteria stated above, null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @exception  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *     Thrown if there was an I/O error while creating the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public InputStream getStreamForBytes() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
}