You can use the PrintObjectList class and its subclasses to work with lists of print objects. Each subclass has methods that allow filtering of the list based on what makes sense for that particular type of print object. For example, SpooledFileList allows you to filter a list of spooled files based on the user who created the spooled files, the output queue that the spooled files are on, the form type, or user data of the spooled files. Only those spooled files that match the filter criteria are listed. If no filters are set, a default for each of the filters are used.
To actually retrieve the list of print objects from the server, the openSynchronously() or openAsynchronously() methods are used. The openSynchronously() method does not return until all objects in the list have been retrieved from the server. The openAsynchronously() method returns immediately, and the caller can do other things in the foreground while waiting for the list to build. The asynchronously opened list also allows the caller to start displaying the objects to the user as the objects come back. Because the user can see the objects as they come back, the response time may seem faster to the user. In fact, the response time may actually take longer overall due to the extra processing being done on each object in the list.
If the list is opened asynchronously, the caller may get feedback on the building of the list. Methods, such as isCompleted() and size(), indicate whether the list has finished being built or return the current size of the list. Other methods, waitForListToComplete() and waitForItem(), allow the caller to wait for the list to complete or for a particular item. In addition to calling these PrintObjectList methods, the caller may register with the list as a listener. In this situation, the caller is notified of events that happen to the list. To register or unregister for the events, the caller uses PrintObjectListListener(), and then calls addPrintObjectListListener() to register or removePrintObjectListListener() to unregister. The following table shows the events that are delivered from a PrintObjectList.
PrintObjectList event | When event is delivered |
---|---|
listClosed | When the list is closed. |
listCompleted | When the list completes. |
listErrorOccurred | If any exception is thrown while the list is being retrieved. |
listOpened | When the list is opened. |
listObjectAdded | When an object is added to the list. |
After the list has been opened and the objects in the list processed, close the list using the close() method. This frees up any resources allocated to the garbage collector during the open. After a list has been closed, its filters can be modified, and the list can be opened again.
When print objects are listed, attributes about each print object listed are sent from the server and stored with the print object. These attributes can be updated using the update() method in the PrintObject class. Which attributes are sent back from the server depends on the type of print object being listed. A default list of attributes for each type of print object that can be overridden by using the setAttributesToRetrieve() method in PrintObjectList exists. See the Retrieving PrintObject attributes section for a list of the attributes each type of print object supports.
Listing AFP™ Resources is allowed only on Version 3 Release 7 and later releases of i5/OS™. Opening an AFPResourceList to an system older than V3R7 generates a RequestNotSupportedException exception.
The following examples show different ways to list spooled files.
Example: Listing spooled files asynchronously (using listeners) shows how to asynchronously list all spooled files on a system and how to use the PrintObjectListListener interface to get feedback as the list is being built
Example: Listing spooled files asynchronously (without using listeners) shows how to asynchronously list all spooled files on a system without using the PrintObjectListListener interface
Example: Listing spooled files synchronously shows how to synchronously list all spooled files on a system