Path: blob/master/src/java.desktop/share/classes/javax/print/MultiDoc.java
41153 views
/*1* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.print;2627import java.io.IOException;2829/**30* Interface {@code MultiDoc} specifies the interface for an object that31* supplies more than one piece of print data for a Print Job. "Doc" is a short,32* easy-to-pronounce term that means "a piece of print data," and a "multidoc"33* is a group of several docs. The client passes to the Print Job an object that34* implements interface {@code MultiDoc}, and the Print Job calls methods on35* that object to obtain the print data.36* <p>37* Interface {@code MultiDoc} provides an abstraction similar to a "linked list"38* of docs. A multidoc object is like a node in the linked list, containing the39* current doc in the list and a pointer to the next node (multidoc) in the40* list. The Print Job can call the multidoc's {@link #getDoc() getDoc()} method41* to get the current doc. When it's ready to go on to the next doc, the Print42* Job can call the multidoc's {@link #next() next()} method to get the next43* multidoc, which contains the next doc. So Print Job code for accessing a44* multidoc might look like this:45*46* <pre>47* void processMultiDoc(MultiDoc theMultiDoc) {48*49* MultiDoc current = theMultiDoc;50*51* while (current != null) {52* processDoc (current.getDoc());53* current = current.next();54* }55* }56* </pre>57* Of course, interface {@code MultiDoc} can be implemented in any way that58* fulfills the contract; it doesn't have to use a linked list in the59* implementation.60* <p>61* To get all the print data for a multidoc print job, a Print Service proxy62* could use either of two patterns:63* <ol type=1>64* <li>The <b>interleaved</b> pattern: Get the doc from the current multidoc.65* Get the print data representation object from the current doc. Get all the66* print data from the print data representation object. Get the next multidoc67* from the current multidoc, and repeat until there are no more. (The code68* example above uses the interleaved pattern.)69* <li>The <b>all-at-once</b> pattern: Get the doc from the current multidoc,70* and save the doc in a list. Get the next multidoc from the current71* multidoc, and repeat until there are no more. Then iterate over the list of72* saved docs. Get the print data representation object from the current doc.73* Get all the print data from the print data representation object. Go to the74* next doc in the list, and repeat until there are no more.75* </ol>76* Now, consider a printing client that is generating print data on the fly and77* does not have the resources to store more than one piece of print data at a78* time. If the print service proxy used the all-at-once pattern to get the79* print data, it would pose a problem for such a client; the client would have80* to keep all the docs' print data around until the print service proxy comes81* back and asks for them, which the client is not able to do. To work with such82* a client, the print service proxy must use the interleaved pattern.83* <p>84* To address this problem, and to simplify the design of clients providing85* multiple docs to a Print Job, every Print Service proxy that supports86* multidoc print jobs is required to access a {@code MultiDoc} object using the87* interleaved pattern. That is, given a {@code MultiDoc} object, the print88* service proxy will call {@link #getDoc() getDoc()} one or more times until it89* successfully obtains the current {@code Doc} object. The print service proxy90* will then obtain the current doc's print data, not proceeding until all the91* print data is obtained or an unrecoverable error occurs. If it is able to92* continue, the print service proxy will then call {@link #next() next()} one93* or more times until it successfully obtains either the next {@code MultiDoc}94* object or an indication that there are no more. An implementation of95* interface {@code MultiDoc} can assume the print service proxy will follow96* this interleaved pattern; for any other pattern of usage, the97* {@code MultiDoc} implementation's behavior is unspecified.98* <p>99* There is no restriction on the number of client threads that may be100* simultaneously accessing the same multidoc. Therefore, all implementations of101* interface MultiDoc must be designed to be multiple thread safe. In fact, a102* client thread could be adding docs to the end of the (conceptual) list while103* a Print Job thread is simultaneously obtaining docs from the beginning of the104* list; provided the multidoc object synchronizes the threads properly, the two105* threads will not interfere with each other.106*/107public interface MultiDoc {108109/**110* Obtain the current doc object.111*112* @return current doc object113* @throws IOException if an error occurred when reading the document114*/115public Doc getDoc() throws IOException;116117/**118* Go to the multidoc object that contains the next doc object in the119* sequence of doc objects.120*121* @return multidoc object containing the next doc object, or {@code null}122* if there are no further doc objects123* @throws IOException if an error occurred locating the next document124*/125public MultiDoc next() throws IOException;126}127128129