![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e709. Getting the Possible Values for a Print Job CapabilityThe capabilities of a print job are called print job attributes. Examples of print job attributes include:Copies ,
OrientationRequested , and Destination . This example
demonstrates how to retrieve the possible values of a print job
attribute.
PrintService.getSupportedAttributeValues() is the method to
use. This method returns 3 possible types of objects: 1) an instance
of the attribute which indicates arbitrary values
(e.g., Destination ); 2) an array of instances of the attribute
that indicates a set of specific values
(e.g., OrientationRequested ); and 3) an instance of something
other than the attribute type that indicates that the values are
limited to a particular range of values (the documentation is not
clear about this particular return value).
Class category = OrientationRequested.class; Object o = service.getSupportedAttributeValues(category, null, null); if (o == null) { // Attribute is not supported } else if (o.getClass() == category) { // Attribute value is arbitrary; the actual value in o is irrelevant } else if (o.getClass().isArray()) { // Attribute values are a set of values for (int i=0; i<Array.getLength(o); i++) { Object v = Array.get(o, i); // v is one of the possible values } } else { // Attribute value is limited to a range of values represented by o }
e707. Determining Print Job Capabilities Supported by a Print Service e708. Getting the Default Value of a Print Job Capability © 2002 Addison-Wesley. |