jdk/src/share/classes/javax/print/attribute/package.html
author ohair
Wed, 26 May 2010 20:28:04 -0700
changeset 5551 327690766109
parent 5506 202f599c92aa
child 21254 f6d36ee3f269
permissions -rw-r--r--
6956202: Fix a few missed rebranding issues, please contact lines etc. Reviewed-by: jjg, darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
<html>
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
<head>
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
<title>javax.print.attribute package</title>
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
<!--
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     5
Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    10
published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    12
by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
5551
327690766109 6956202: Fix a few missed rebranding issues, please contact lines etc.
ohair
parents: 5506
diff changeset
    24
Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
327690766109 6956202: Fix a few missed rebranding issues, please contact lines etc.
ohair
parents: 5506
diff changeset
    25
or visit www.oracle.com if you need additional information or have any
327690766109 6956202: Fix a few missed rebranding issues, please contact lines etc.
ohair
parents: 5506
diff changeset
    26
questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
-->
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
</head>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
<body bgcolor="white">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
Provides classes and interfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
that describe the types of Java<sup><font size="-2">TM</font></sup> Print
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
Service attributes and how they can be collected into attribute sets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
<H3>What is an Attribute?</H3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
When setting up a print job,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
a client specifies two things:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
<B>print data</B> and <B>processing instructions.</B>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
The print data is the actual content to be printed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
The processing instructions tell the printer how to print the print data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
such as: what media to use, how many copies to print, and 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
whether to print on one or both sides of a sheet.  The client specifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
these processing instructions with the attribute definitions of the Java 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
Print Service API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
The print data and the processing instructions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
are separate entities.  This means that:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
<li>You can print the same print data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
at different times using different processing instructions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
For example, you can print a slide presentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
on US letter-sized white paper,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
double-sided, stapled, 20 copies
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
to make handouts for a talk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
and you could print the same slide presentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
on US letter-sized transparencies,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
single-sided, one copy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
to make the actual slides for the talk.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
<li>You can use the same processing instructions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
at different times to print different data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
For example, you could set your default processing 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
instructions to: US letter-sized paper, double sided, stapled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
Whenever you print a job, it prints with these settings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
unless you explicitly override them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
The processing instruction does not specify how the print job 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
processes the request; each processing instruction is only a description 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
of the results of a print job.  The print job determines the manner in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
which it achieves the results specified by the processing instructions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
Representing processing instructions as descriptive items
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
provides more flexibility for implementing print jobs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
<h4>Attribute Categories and Values</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
Each printer has a set of capabilities, such as the ability to print on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
different paper sizes or the ability to print more than one copy.  Each of 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
the capabilities has a range of values.  For example, a printer's orientation 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
capability might have this range of values: [landscape, portrait]. 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
For each print request, the capability is set to one of these values.  The 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
Java Print Service API uses the term <b>attribute category</b> to refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
a printer capability and the term <b>attribute value</b> to refer to the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
of the capability.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
In the Java Print Service API, an attribute category is represented by a Java 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
class implementing the <a href="Attribute.html">Attribute</a> interface.  
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
Attribute values are instances of such a class or 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
one of its subclasses.  For example, to specify the number of copies, an 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
application constructs an instance of the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
<a href="standard/Copies.html">Copies</a> class with the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
number of desired copies and uses the <code>Copies</code> instance as part of 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
the print request.  In this case, the <code>Copies</code> class represents the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
attribute category, and the <code>Copies</code> instance represents the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
<h4><a name="role"></a>Attribute Roles</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
When submitting a print job to a printer, the client provides the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
attributes describing the characteristics of the print data, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
the document name, and how the print data should be printed, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
double-sided, five copies.  If a print job consists of multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
pieces of print data, different pieces might have different processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
instructions, such as 8 x 11 inch media for the first document, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
11 x 17 inch media for another document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
Once the printer starts processing the print job,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
additional information about the job becomes available, which might include:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
the job state (such as <i>completed</i> or <i>queued</i>) and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
the number of pages printed so far.  These pieces of information are also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
attributes.  Attributes can also describe the printer itself, such as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
the printer name, the printer location, and the number of jobs queued. 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
The Java Print Service API defines these different kinds of attributes 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
with five subinterfaces of <code>Attribute</code>: 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
<li><A HREF="DocAttribute.html">DocAttribute</A> specifies a characteristic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
of an individual document and the print job settings to be applied to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
individual document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
<li><A HREF="PrintRequestAttribute.html">PrintRequestAttribute</A> specifies 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
a setting applied to a whole print job and to all the documents in 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
the print job. 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
<li><A HREF="PrintJobAttribute.html">PrintJobAttribute</A> reports the status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
of a print job.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
<li><A HREF="PrintServiceAttribute.html">PrintServiceAttribute</A> reports the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
status of a print service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
<li><A HREF="SupportedValuesAttribute.html">SupportedValuesAttribute</A> gives
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
the supported values for another attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
Each attribute class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
implements one or more of these tagging subinterfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
to indicate where the attribute can be used in the API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
If an attribute class implements multiple tagging subinterfaces,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
the attribute can be used in multiple contexts.  For example, the media
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
attribute can apply to one document in a print job as a <code>DocAttribute</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
or to an entire print job as a <code>PrintRequestAttribute</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
Certain low-level attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
are never used on their own
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
but are always aggregated into higher-level attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
These low-level attribute classes only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
implement interface <A HREF="Attribute.html">Attribute</A>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
not any of the tagging subinterfaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
The Java Print Service API defines a group of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
standard attribute classes modeled upon the attributes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
the Internet Printing Protocol (IPP) version 1.1. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
standard attribute classes are in the subpackage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
javax.print.attribute.standard to keep the actual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
attribute classes conceptually separate from the generic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
apparatus defined in package javax.print.attribute. 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
<H3>Attribute Sets</H3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
A client usually needs to provide more than one processing 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
instruction when submitting a print job.  For example, the client might need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
specify a media size of A4 and a landscape orientation.  To send more than one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
processing instruction, the client collects the attributes into an 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
attribute set, which the Java Print Service API represents with the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
<a href="AttributeSet.html">AttributeSet</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
The <code>AttributeSet</code> interface is similar to the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
<a href="../../../java/util/Map.html">Map</a> interface: it provides a map of 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
key to values, in which each key is unique and can contain no more than one 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
value.  However, the <code>AttributeSet</code> interface is designed to 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
specifically support the needs of the Java Print Service API.  An 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
<code>AttributeSet</code> requires that:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
<OL TYPE=1>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
<LI>Each key in an <code>AttributeSet</code> corresponds to a category, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
the value of the key can only be one of the attribute values that belong
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
to the category represented by the key.  Thus, unlike a <code>Map</code>, an 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
<code>AttributeSet</code> restricts the possible values of a key: an 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
attribute category cannot be set to an attribute value that does not belong to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
that category.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
<LI>No two attributes from the same category can exist in the same set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
For example, an attribute collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
must not contain both a "one-sided" attribute and a "two-sided" attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
because these two attributes give the printer conflicting instructions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
<LI>Only attributes implementing the <code>Attribute</code> interface can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
be added to the set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
</OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
The javax.print.attribute package includes 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
<A HREF="HashAttributeSet.html">HashAttributeSet</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
as a concrete implementation of the attribute set interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
<code>HashAttributeSet</code> provides an attribute set based on a hash map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
You can use this implementation or provide your own implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
of interface <code>AttributeSet</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
The Java Print Service API provides four specializations of an attribute set 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
that are restricted to contain just one of the four kinds of attributes, 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
as discussed in the <a href="#role">Attribute Roles</a> section:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
<li><A HREF="DocAttributeSet.html">DocAttributeSet</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
<li><A HREF="PrintRequestAttributeSet.html">PrintRequestAttributeSet</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
<li><A HREF="PrintJobAttributeSet.html">PrintJobAttributeSet</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
<li><A HREF="PrintServiceAttributeSet.html">PrintServiceAttributeSet</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
Notice that only four kinds of attribute sets are listed here, but there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
five kinds of attributes.  Interface 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
<A HREF="SupportedValuesAttribute.html">SupportedValuesAttribute</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
denotes an attribute that gives the supported values for another attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
Supported-values attributes are never aggregated into attribute sets,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
so there is no attribute set subinterface defined for them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
In some contexts, an attribute set is read-only, which means that the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
client is only allowed to examine an attribute set's 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
contents but not change them. In other contexts, the attribute set is read-write,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
which means that the client is allowed both to examine and to change an 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
attribute set's contents. For a read-only attribute set, calling a mutating 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
operation throws an <code>UnmodifiableSetException</code>. 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
Package javax.print.attribute includes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
one concrete implementation of each of the attribute set subinterfaces:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
<li><A HREF="HashDocAttributeSet.html">HashDocAttributeSet</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
<li><A HREF="HashPrintRequestAttributeSet.html">HashPrintRequestAttributeSet</A>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
<li><A HREF="HashPrintJobAttributeSet.html">HashPrintJobAttributeSet</A>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
<li><A HREF="HashPrintServiceAttributeSet.html">HashPrintServiceAttributeSet</A>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
All of these classes extend <A HREF="HashAttributeSet.html">HashAttributeSet</A>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
and enforce the restriction that the attribute set is only allowed to contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
the corresponding kind of attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
<H3>Attribute Class Design</H3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
An attribute value is a small, atomic data item,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
such as an integer or an enumerated value.  The Java Print Service API 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
does not use primitive data types, such as int, to represent attribute 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
values for these reasons:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
<li>Primitive data types are not type-safe.  For example, a compiler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
should not allow a "copies" attribute value to 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
be used for a "sides" attribute. 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
<li>Some attributes must be represented as a record of several
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
values.  One example is printer resolution, which requires two 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
numbers, such as 600 and 300 representing 600 x 300 dpi.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
For type-safety and to represent all attributes uniformly, the Java 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
Print Service API defines each attribute category as a class, such as 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
class <code>Copies</code>, class <a href="standard/Sides.html">Sides</a>, and class 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
<a href="standard/PrinterResolution.html">PrinterResolution</a>.  Each 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
attribute class wraps one or more primitive data items containing the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
attribute's value.  Attribute set operations perform frequent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
comparisons between attribute category objects when adding attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
finding existing attributes in the same category, and looking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
up an attribute given its category.  Because an attribute category is 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
represented by a class, fast attribute-value comparisons can be performed 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
with the <code>Class.equals</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
Even though the Java Print Service API includes a large number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
different attribute categories, there are only a few different types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
of attribute values.  Most attributes can be represented by a small
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
number of data types, such as: integer values, integer ranges, text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
or an enumeration of integer values.  The type of the attribute value that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
a category accepts is called the attribute's abstract syntax.  To
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
provide consistency and reduce code duplication, the Java Print Service
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
API defines abstract syntax classes to represent each 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
abstract syntax, and these classes are used as the parent of standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
attributes whenever possible.  The abstract syntax classes are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
<li><a href="EnumSyntax.html">EnumSyntax</a> 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
provides a type-safe enumeration in which enumerated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
values are represented as singleton objects.  Each enumeration 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
singleton is an instance of the enumeration class that wraps a hidden
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
int value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
<li><a href="IntegerSyntax.html">IntegerSyntax</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
 is the abstract syntax for integer-valued attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
<li><a href="TextSyntax.html">TextSyntax</a> is 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
the abstract syntax for text-valued attributes, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
includes a locale giving the text string's natural language.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
<li><a href="SetOfIntegerSyntax.html">SetOfIntegerSyntax</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 is the abstract syntax for attributes 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
representing a range or set of integers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
<li><a href="ResolutionSyntax.html">ResolutionSyntax</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 is the abstract syntax for attributes representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 resolution values, such as 600x300 dpi.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
<li><a href="Size2DSyntax.html">Size2DSyntax</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 is the abstract syntax for attributes representing a 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
two-dimensional size, such as a paper size of 8.5 x 11 inches.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
<li><a href="DateTimeSyntax.html">DateTimeSyntax</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 is the abstract syntax for attributes whose value is a date and time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
<li><a href="URISyntax.html">URISyntax</a> is the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
abstract syntax for attributes whose value is a Uniform Resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
Indicator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
The abstract syntax classes are independent of the attributes that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
use them.  In fact, applications that have nothing to do with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
printing can use the abstract syntax classes.  Although most of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
standard attribute classes extend one of the abstract syntax classes, 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
no attribute class is required to extend one of these classes.  The 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
abstract syntax classes merely provide a convenient implementation that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
can be shared by many attribute classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
Each attribute class implements the <code>Attribute</code> interface, either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
directly or indirectly, to mark it as a printing attribute.  An
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
attribute class that can appear in restricted attribute sets in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
certain contexts also implements one or more subinterfaces of 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
<code>Attribute</code>.  Most attribute classes also extend the appropriate 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
abstract syntax class to get the implementation.  Consider the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
<code>Sides</code> attribute class:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
<blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
public class Sides
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
  extends EnumSyntax
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
  implements DocAttribute, PrintRequestAttribute, PrintJobAttribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
  public final Object getCategory()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    return Sides.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
  ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
</blockquote>  
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
Since every attribute class implements <code>Attribute</code>, every attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
class must provide an implementation for the 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
{@link javax.print.attribute.Attribute#getCategory() getCategory} method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
which returns the attribute category.  In the case of <code>Sides</code>, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
<code>getCategory</code> method returns <code>Sides.class</code>.  The 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
<code>getCategory</code> method is final to ensure that any vendor-defined 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
subclasses of a standard attribute class appear in the same category.  
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
Every attribute object is immutable once constructed so that attribute object 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
references can be passed around freely.  To get a different attribute 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
value, construct a different attribute object.  
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
<h3>Attribute Vendors</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
The Java Print Service API is designed so that vendors can:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
<ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
<li>define new vendor-specific values for any standard attribute 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
defined in <a href="standard/package-summary.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
javax.print.attribute.standard</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
<li>define new attribute categories representing the vendor printer's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
proprietary capabilities not already supported by the standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
To define a new value for an attribute, a client can construct 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
instances of such attributes with arbitrary values at runtime.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
However, an enumerated attribute using an abstract syntax class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
of <code>EnumSyntax</code> specifies all the possible attribute values 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
at compile time as singleton instances of the attribute class.  This 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
means that new enumerated values cannot be constructed at run time.  
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
To define new vendor-specific values for a standard enumerated 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
attribute, the vendor must define a new attribute class specifying 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
the new singleton instances.  To ensure that the new attribute values 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
fall in the same category as the standard attribute values, the new 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
attribute class must be a subclass of the standard attribute class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
To define a new attribute category, a vendor defines a new attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
class.  This attribute class, like the standard attribute classes, 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
implements <code>Attribute</code> or one of its subinterfaces and extends an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
abstract syntax class.  The vendor can either use an existing 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
abstract syntax class or define a new one.  The new vendor-defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
attribute can be used wherever an <code>Attribute</code> is used, such as in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
<code>AttributeSet</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
<h3>Using Attributes</h3>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
A typical printing application uses the <code>PrintRequestAttributeSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
because print-request attributes are the types of attributes that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
client usually specifies.  This example demonstrates creating an attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
set of print-request attributes and locating a printer that can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
print the document according to the specified attributes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
<blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
FileInputStream psStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
   psstream = new FileInputStream("file.ps");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
} catch (FileNotFoundException ffne) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
if (psstream == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
//Set the document type.  See the DocFlavor documentation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
//more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
DocFlavor psInFormat = DocFlavor.INPUT_STREAM.POSTSCRIPT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
Doc myDoc = new SimpleDoc(pstream, psInFormat, null);  
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
aset.add(new Copies(5));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
aset.add(MediaSize.A4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
aset.add(Sides.DUPLEX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
PrintService[] services = 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
		PrintServiceLookup.lookupPrintServices(psInFormat, aset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
if (services.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
   DocPrintJob job = services[0].createPrintJob();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
   try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
	job.print(myDoc, aset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
   } catch (PrintException pe) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
</blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
Please note: In the javax.print APIs, a null reference parameter to methods 
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
is incorrect unless explicitly documented on the method as having a meaningful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
interpretation. Usage to the contrary is incorrect coding and may result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
in a run time exception either immediately or at some later time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
IllegalArgumentException and NullPointerException are examples of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
typical and acceptable run time exceptions for such cases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
@since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
</body>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
</html>