Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/print/MultiDoc.java
38829 views
/*1* Copyright (c) 2000, 2013, 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 MultiDoc specifies the interface for an object that supplies more31* 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 object34* that implements interface MultiDoc, and the Print Job calls methods on35* that object to obtain the print data.36* <P>37* Interface MultiDoc provides an abstraction similar to a "linked list" of38* 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()41* getDoc()} method to get the current doc. When it's ready to go42* on to the next doc, the Print Job can call the multidoc's {@link #next()43* next()} method to get the next multidoc, which contains the44* next doc. So Print Job code for accessing a multidoc might look like this:45* <PRE>46* void processMultiDoc(MultiDoc theMultiDoc) {47*48* MultiDoc current = theMultiDoc;4950* while (current != null) {51* processDoc (current.getDoc());52* current = current.next();53* }54* }55* </PRE>56* <P>57* Of course, interface MultiDoc can be implemented in any way that fulfills58* the contract; it doesn't have to use a linked list in the implementation.59* <P>60* To get all the print data for a multidoc print job, a Print Service61* proxy could use either of two patterns:62* <OL TYPE=1>63* <LI>64* The <B>interleaved</B> pattern: Get the doc from the current multidoc. Get65* the print data representation object from the current doc. Get all the print66* data from the print data representation object. Get the next multidoc from67* the current multidoc, and repeat until there are no more. (The code example68* above uses the interleaved pattern.)69* <P>70* <LI>71* The <B>all-at-once</B> pattern: Get the doc from the current multidoc, and72* save the doc in a list. Get the next multidoc from the current multidoc, and73* repeat until there are no more. Then iterate over the list of saved docs. Get74* the print data representation object from the current doc. Get all the print75* data from the print data representation object. Go to the next doc in the76* list, and repeat until there are no more.77* </OL>78* Now, consider a printing client that is generating print data on the fly and79* does not have the resources to store more than one piece of print data at a80* time. If the print service proxy used the all-at-once pattern to get the81* print data, it would pose a problem for such a client; the client would have82* to keep all the docs' print data around until the print service proxy comes83* back and asks for them, which the client is not able to do. To work with such84* a client, the print service proxy must use the interleaved pattern.85* <P>86* To address this problem, and to simplify the design of clients providing87* multiple docs to a Print Job, every Print Service proxy that supports88* multidoc print jobs is required to access a MultiDoc object using the89* interleaved pattern. That is, given a MultiDoc object, the print service90* proxy will call {@link #getDoc() getDoc()} one or more times91* until it successfully obtains the current Doc object. The print service proxy92* will then obtain the current doc's print data, not proceeding until all the93* print data is obtained or an unrecoverable error occurs. If it is able to94* continue, the print service proxy will then call {@link #next()95* next()} one or more times until it successfully obtains either96* the next MultiDoc object or an indication that there are no more. An97* implementation of interface MultiDoc can assume the print service proxy will98* follow this interleaved pattern; for any other pattern of usage, the MultiDoc99* implementation's behavior is unspecified.100* <P>101* There is no restriction on the number of client threads that may be102* simultaneously accessing the same multidoc. Therefore, all implementations of103* interface MultiDoc must be designed to be multiple thread safe. In fact, a104* client thread could be adding docs to the end of the (conceptual) list while105* a Print Job thread is simultaneously obtaining docs from the beginning of the106* list; provided the multidoc object synchronizes the threads properly, the two107* threads will not interfere with each other108*/109110public interface MultiDoc {111112113/**114* Obtain the current doc object.115*116* @return Current doc object.117*118* @exception IOException119* Thrown if a error occurred reading the document.120*/121public Doc getDoc() throws IOException;122123/**124* Go to the multidoc object that contains the next doc object in the125* sequence of doc objects.126*127* @return Multidoc object containing the next doc object, or null if128* there are no further doc objects.129*130* @exception IOException131* Thrown if an error occurred locating the next document132*/133public MultiDoc next() throws IOException;134135}136137138