RequestingUserName.java revision 17757:ad37f4ce2062
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
26package javax.print.attribute.standard;
27
28import java.util.Locale;
29
30import javax.print.attribute.Attribute;
31import javax.print.attribute.PrintRequestAttribute;
32import javax.print.attribute.TextSyntax;
33
34/**
35 * Class {@code RequestingUserName} is a printing attribute class, a text
36 * attribute, that specifies the name of the end user that submitted the print
37 * job. A requesting user name is an arbitrary string defined by the client. The
38 * printer does not put the client-specified {@code RequestingUserName}
39 * attribute into the Print Job's attribute set; rather, the printer puts in a
40 * {@link JobOriginatingUserName JobOriginatingUserName} attribute. This means
41 * that services which support specifying a username with this attribute should
42 * also report a {@code JobOriginatingUserName} in the job's attribute set. Note
43 * that many print services may have a way to independently authenticate the
44 * user name, and so may state support for a requesting user name, but in
45 * practice will then report the user name authenticated by the service rather
46 * than that specified via this attribute.
47 * <p>
48 * <b>IPP Compatibility:</b> The string value gives the IPP name value. The
49 * locale gives the IPP natural language. The category name returned by
50 * {@code getName()} gives the IPP attribute name.
51 *
52 * @author Alan Kaminsky
53 */
54public final class RequestingUserName   extends TextSyntax
55    implements PrintRequestAttribute {
56
57    /**
58     * Use serialVersionUID from JDK 1.4 for interoperability.
59     */
60    private static final long serialVersionUID = -2683049894310331454L;
61
62    /**
63     * Constructs a new requesting user name attribute with the given user name
64     * and locale.
65     *
66     * @param  userName user name
67     * @param  locale natural language of the text string. {@code null} is
68     *         interpreted to mean the default locale as returned by
69     *         {@code Locale.getDefault()}
70     * @throws NullPointerException if {@code userName} is {@code null}
71     */
72    public RequestingUserName(String userName, Locale locale) {
73        super (userName, locale);
74    }
75
76    /**
77     * Returns whether this requesting user name attribute is equivalent to the
78     * passed in object. To be equivalent, all of the following conditions must
79     * be true:
80     * <ol type=1>
81     *   <li>{@code object} is not {@code null}.
82     *   <li>{@code object} is an instance of class {@code RequestingUserName}.
83     *   <li>This requesting user name attribute's underlying string and
84     *   {@code object}'s underlying string are equal.
85     *   <li>This requesting user name attribute's locale and {@code object}'s
86     *   locale are equal.
87     * </ol>
88     *
89     * @param  object {@code Object} to compare to
90     * @return {@code true} if {@code object} is equivalent to this requesting
91     *         user name attribute, {@code false} otherwise
92     */
93    public boolean equals(Object object) {
94        return (super.equals(object) &&
95                object instanceof RequestingUserName);
96    }
97
98    /**
99     * Get the printing attribute class which is to be used as the "category"
100     * for this printing attribute value.
101     * <p>
102     * For class {@code RequestingUserName}, the category is class
103     * {@code RequestingUserName} itself.
104     *
105     * @return printing attribute class (category), an instance of class
106     *         {@link Class java.lang.Class}
107     */
108    public final Class<? extends Attribute> getCategory() {
109        return RequestingUserName.class;
110    }
111
112    /**
113     * Get the name of the category of which this attribute value is an
114     * instance.
115     * <p>
116     * For class {@code RequestingUserName}, the category name is
117     * {@code "requesting-user-name"}.
118     *
119     * @return attribute category name
120     */
121    public final String getName() {
122        return "requesting-user-name";
123    }
124}
125