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.Locale;
  29 
  30 import javax.print.attribute.Attribute;
  31 import javax.print.attribute.PrintServiceAttribute;
  32 import javax.print.attribute.TextSyntax;
  33 
  34 /**
  35  * Class {@code PrinterName} is a printing attribute class, a text attribute,
  36  * that specifies the name of a printer. It is a name that is more end-user
  37  * friendly than a {@code URI}. An administrator determines a printer's name and
  38  * sets this attribute to that name. This name may be the last part of the
  39  * printer's {@code URI} or it may be unrelated. In non-US-English locales, a
  40  * name may contain characters that are not allowed in a {@code URI}.
  41  * <p>
  42  * <b>IPP Compatibility:</b> The string value gives the IPP name value. The
  43  * locale gives the IPP natural language. The category name returned by
  44  * {@code getName()} gives the IPP attribute name.
  45  *
  46  * @author Alan Kaminsky
  47  */
  48 public final class PrinterName extends TextSyntax
  49         implements PrintServiceAttribute {
  50 
  51     /**
  52      * Use serialVersionUID from JDK 1.4 for interoperability.
  53      */
  54     private static final long serialVersionUID = 299740639137803127L;
  55 
  56     /**
  57      * Constructs a new printer name attribute with the given name and locale.
  58      *
  59      * @param  printerName printer name
  60      * @param  locale natural language of the text string. {@code null} is
  61      *         interpreted to mean the default locale as returned by
  62      *         {@code Locale.getDefault()}
  63      * @throws NullPointerException if {@code printerName} is {@code null}
  64      */
  65     public PrinterName(String printerName, Locale locale) {
  66         super (printerName, locale);
  67     }
  68 
  69     /**
  70      * Returns whether this printer name attribute is equivalent to the passed
  71      * in object. To be equivalent, all of the following conditions must be
  72      * true:
  73      * <ol type=1>
  74      *   <li>{@code object} is not {@code null}.
  75      *   <li>{@code object} is an instance of class {@code PrinterName}.
  76      *   <li>This printer name attribute's underlying string and
  77      *   {@code object}'s underlying string are equal.
  78      *   <li>This printer name attribute's locale and {@code object}'s locale
  79      *   are equal.
  80      * </ol>
  81      *
  82      * @param  object {@code Object} to compare to
  83      * @return {@code true} if {@code object} is equivalent to this printer name
  84      *         attribute, {@code false} otherwise
  85      */
  86     public boolean equals(Object object) {
  87         return (super.equals(object) && object instanceof PrinterName);
  88     }
  89 
  90     /**
  91      * Get the printing attribute class which is to be used as the "category"
  92      * for this printing attribute value.
  93      * <p>
  94      * For class {@code PrinterName}, the category is class
  95      * {@code PrinterName} itself.
  96      *
  97      * @return printing attribute class (category), an instance of class
  98      *         {@link Class java.lang.Class}
  99      */
 100     public final Class<? extends Attribute> getCategory() {
 101         return PrinterName.class;
 102     }
 103 
 104     /**
 105      * Get the name of the category of which this attribute value is an
 106      * instance.
 107      * <p>
 108      * For class {@code PrinterName}, the category name is
 109      * {@code "printer-name"}.
 110      *
 111      * @return attribute category name
 112      */
 113     public final String getName() {
 114         return "printer-name";
 115     }
 116 }