001 /*
002 * Copyright 2000 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package javax.print;
027
028 import java.io.IOException;
029
030 /**
031 * Interface MultiDoc specifies the interface for an object that supplies more
032 * than one piece of print data for a Print Job. "Doc" is a short,
033 * easy-to-pronounce term that means "a piece of print data," and a "multidoc"
034 * is a group of several docs. The client passes to the Print Job an object
035 * that implements interface MultiDoc, and the Print Job calls methods on
036 * that object to obtain the print data.
037 * <P>
038 * Interface MultiDoc provides an abstraction similar to a "linked list" of
039 * docs. A multidoc object is like a node in the linked list, containing the
040 * current doc in the list and a pointer to the next node (multidoc) in the
041 * list. The Print Job can call the multidoc's {@link #getDoc()
042 * <CODE>getDoc()</CODE>} method to get the current doc. When it's ready to go
043 * on to the next doc, the Print Job can call the multidoc's {@link #next()
044 * <CODE>next()</CODE>} method to get the next multidoc, which contains the
045 * next doc. So Print Job code for accessing a multidoc might look like this:
046 * <PRE>
047 * void processMultiDoc(MultiDoc theMultiDoc) {
048 *
049 * MultiDoc current = theMultiDoc;
050
051 * while (current != null) {
052 * processDoc (current.getDoc());
053 * current = current.next();
054 * }
055 * }
056 * </PRE>
057 * <P>
058 * Of course, interface MultiDoc can be implemented in any way that fulfills
059 * the contract; it doesn't have to use a linked list in the implementation.
060 * <P>
061 * To get all the print data for a multidoc print job, a Print Service
062 * proxy could use either of two patterns:
063 * <OL TYPE=1>
064 * <LI>
065 * The <B>interleaved</B> pattern: Get the doc from the current multidoc. Get
066 * the print data representation object from the current doc. Get all the print
067 * data from the print data representation object. Get the next multidoc from
068 * the current multidoc, and repeat until there are no more. (The code example
069 * above uses the interleaved pattern.)
070 * <P>
071 * <LI>
072 * The <B>all-at-once</B> pattern: Get the doc from the current multidoc, and
073 * save the doc in a list. Get the next multidoc from the current multidoc, and
074 * repeat until there are no more. Then iterate over the list of saved docs. Get
075 * the print data representation object from the current doc. Get all the print
076 * data from the print data representation object. Go to the next doc in the
077 * list, and repeat until there are no more.
078 * </OL>
079 * Now, consider a printing client that is generating print data on the fly and
080 * does not have the resources to store more than one piece of print data at a
081 * time. If the print service proxy used the all-at-once pattern to get the
082 * print data, it would pose a problem for such a client; the client would have
083 * to keep all the docs' print data around until the print service proxy comes
084 * back and asks for them, which the client is not able to do. To work with such
085 * a client, the print service proxy must use the interleaved pattern.
086 * <P>
087 * To address this problem, and to simplify the design of clients providing
088 * multiple docs to a Print Job, every Print Service proxy that supports
089 * multidoc print jobs is required to access a MultiDoc object using the
090 * interleaved pattern. That is, given a MultiDoc object, the print service
091 * proxy will call {@link #getDoc() <CODE>getDoc()</CODE>} one or more times
092 * until it successfully obtains the current Doc object. The print service proxy
093 * will then obtain the current doc's print data, not proceeding until all the
094 * print data is obtained or an unrecoverable error occurs. If it is able to
095 * continue, the print service proxy will then call {@link #next()
096 * <CODE>next()</CODE>} one or more times until it successfully obtains either
097 * the next MultiDoc object or an indication that there are no more. An
098 * implementation of interface MultiDoc can assume the print service proxy will
099 * follow this interleaved pattern; for any other pattern of usage, the MultiDoc
100 * implementation's behavior is unspecified.
101 * <P>
102 * There is no restriction on the number of client threads that may be
103 * simultaneously accessing the same multidoc. Therefore, all implementations of
104 * interface MultiDoc must be designed to be multiple thread safe. In fact, a
105 * client thread could be adding docs to the end of the (conceptual) list while
106 * a Print Job thread is simultaneously obtaining docs from the beginning of the
107 * list; provided the multidoc object synchronizes the threads properly, the two
108 * threads will not interfere with each other
109 */
110
111 public interface MultiDoc {
112
113 /**
114 * Obtain the current doc object.
115 *
116 * @return Current doc object.
117 *
118 * @exception IOException
119 * Thrown if a error ocurred reading the document.
120 */
121 public Doc getDoc() throws IOException;
122
123 /**
124 * Go to the multidoc object that contains the next doc object in the
125 * sequence of doc objects.
126 *
127 * @return Multidoc object containing the next doc object, or null if
128 * there are no further doc objects.
129 *
130 * @exception IOException
131 * Thrown if an error occurred locating the next document
132 */
133 public MultiDoc next() throws IOException;
134
135 }
|