1 /*
2  * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package javax.print.attribute.standard;
27 
28 import java.util.Calendar;
29 import java.util.Date;
30 
31 import javax.print.attribute.Attribute;
32 import javax.print.attribute.DateTimeSyntax;
33 import javax.print.attribute.PrintJobAttribute;
34 import javax.print.attribute.PrintRequestAttribute;
35 
36 /**
37  * Class {@code JobHoldUntil} is a printing attribute class, a date-time
38  * attribute, that specifies the exact date and time at which the job must
39  * become a candidate for printing.
40  * <p>
41  * If the value of this attribute specifies a date-time that is in the future,
42  * the printer should add the {@link JobStateReason JobStateReason} value of
43  * {@code JOB_HOLD_UNTIL_SPECIFIED} to the job's
44  * {@link JobStateReasons JobStateReasons} attribute, must move the job to the
45  * {@code PENDING_HELD} state, and must not schedule the job for printing until
46  * the specified date-time arrives.
47  * <p>
48  * When the specified date-time arrives, the printer must remove the
49  * {@link JobStateReason JobStateReason} value of
50  * {@code JOB_HOLD_UNTIL_SPECIFIED} from the job's
51  * {@link JobStateReasons JobStateReasons} attribute, if present. If there are
52  * no other job state reasons that keep the job in the {@code PENDING_HELD}
53  * state, the printer must consider the job as a candidate for processing by
54  * moving the job to the PENDING state.
55  * <p>
56  * If the specified date-time has already passed, the job must be a candidate
57  * for processing immediately. Thus, one way to make the job immediately become
58  * a candidate for processing is to specify a {@code JobHoldUntil} attribute
59  * constructed like this
60  * (denoting a date-time of January 1, 1970, 00:00:00 GMT):
61  * <pre>
62  *     JobHoldUntil immediately = new JobHoldUntil (new Date (0L));
63  * </pre>
64  * <p>
65  * If the client does not supply this attribute in a Print Request and the
66  * printer supports this attribute, the printer must use its
67  * (implementation-dependent) default {@code JobHoldUntil} value at job
68  * submission time (unlike most job template attributes that are used if
69  * necessary at job processing time).
70  * <p>
71  * To construct a {@code JobHoldUntil} attribute from separate values of the
72  * year, month, day, hour, minute, and so on, use a {@link Calendar Calendar}
73  * object to construct a {@link Date Date} object, then use the
74  * {@link Date Date} object to construct the {@code JobHoldUntil} attribute. To
75  * convert a {@code JobHoldUntil} attribute to separate values of the year,
76  * month, day, hour, minute, and so on, create a {@link Calendar Calendar}
77  * object and set it to the {@link Date Date} from the {@code JobHoldUntil}
78  * attribute.
79  * <p>
80  * <b>IPP Compatibility:</b> Although IPP supports a "job-hold-until" attribute
81  * specified as a keyword, IPP does not at this time support a "job-hold-until"
82  * attribute specified as a date and time. However, the date and time can be
83  * converted to one of the standard IPP keywords with some loss of precision;
84  * for example, a {@code JobHoldUntil} value with today's date and 9:00pm local
85  * time might be converted to the standard IPP keyword "night". The category
86  * name returned by {@code getName()} gives the IPP attribute name.
87  *
88  * @author Alan Kaminsky
89  */
90 public final class JobHoldUntil extends DateTimeSyntax
91         implements PrintRequestAttribute, PrintJobAttribute {
92 
93     /**
94      * Use serialVersionUID from JDK 1.4 for interoperability.
95      */
96     private static final long serialVersionUID = -1664471048860415024L;
97 
98     /**
99      * Construct a new job hold until date-time attribute with the given
100      * {@link Date Date} value.
101      *
102      * @param  dateTime {@link Date Date} value
103      * @throws NullPointerException if {@code dateTime} is {@code null}
104      */
JobHoldUntil(Date dateTime)105     public JobHoldUntil(Date dateTime) {
106         super (dateTime);
107     }
108 
109     /**
110      * Returns whether this job hold until attribute is equivalent to the passed
111      * in object. To be equivalent, all of the following conditions must be
112      * true:
113      * <ol type=1>
114      *   <li>{@code object} is not {@code null}.
115      *   <li>{@code object} is an instance of class {@code JobHoldUntil}.
116      *   <li>This job hold until attribute's {@link Date Date} value and
117      *   {@code object}'s {@link Date Date} value are equal.
118      * </ol>
119      *
120      * @param  object {@code Object} to compare to
121      * @return {@code true} if {@code object} is equivalent to this job hold
122      *         until attribute, {@code false} otherwise
123      */
equals(Object object)124     public boolean equals(Object object) {
125         return (super.equals(object) && object instanceof JobHoldUntil);
126     }
127 
128     /**
129      * Get the printing attribute class which is to be used as the "category"
130      * for this printing attribute value.
131      * <p>
132      * For class {@code JobHoldUntil}, the category is class
133      * {@code JobHoldUntil} itself.
134      *
135      * @return printing attribute class (category), an instance of class
136      *         {@link Class java.lang.Class}
137      */
getCategory()138     public final Class<? extends Attribute> getCategory() {
139         return JobHoldUntil.class;
140     }
141 
142     /**
143      * Get the name of the category of which this attribute value is an
144      * instance.
145      * <p>
146      * For class {@code JobHoldUntil}, the category name is
147      * {@code "job-hold-until"}.
148      *
149      * @return attribute category name
150      */
getName()151     public final String getName() {
152         return "job-hold-until";
153     }
154 }
155