In the Java Print
Service API, an attribute category is represented by a Java class
implementing the Attribute
interface, and attribute values are
instances of such a class or one of its subclasses. For example, to
print 5 copies of a job, an application constructs an instance of
the Copies
class with the value of 5 and uses the Copies
instance to specify the print job. The Copies
class represents the
attribute category, and the Copies
instance represents the attribute
value. Because the attribute value is encapsulated as a Java object, the
attribute value implies its attribute category, and so an attribute
value is usually referred to simply as an attribute. The category
and value constitute a key-value pair, which you can add to a set
along with other attributes. See Attribute Sets for more
information
The Attribute
interface defines just two methods: getName
and getCategory
.
The getName
method returns a String
name for the
attribute category. The getCategory
method returns the class that
first implements that
category. To ensure that all implementations of a particular
category report the same name and class, subclasses should not
override the getName
or getCategory
methods.
To determine what
attribute categories and values are supported by a printer, use the
query methods defined in the PrintService
interface. A print
request does not need to specify attribute values for all of the
target printer's supported attribute categories: each supported
attribute category has a default value. For example, a printer
might support printing up to 999 copies of a job, but if a print
request does not specify the number of copies, the printer almost
always prints a default of just 1 copy.