jdk/src/solaris/classes/sun/print/UnixPrintService.java
author darcy
Mon, 09 Jun 2014 11:47:18 -0700
changeset 25140 80e863984492
parent 22603 816588059f9d
permissions -rw-r--r--
8042870: Fix raw and unchecked warnings in sun.print Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1727
diff changeset
     2
 * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1727
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1727
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1727
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1727
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1727
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.print;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.net.URI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.net.URISyntaxException;
22603
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
    31
import java.util.ArrayList;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.print.DocFlavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.print.DocPrintJob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.print.PrintService;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.print.ServiceUIFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.print.attribute.Attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.print.attribute.AttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.print.attribute.AttributeSetUtilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.print.attribute.HashAttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.print.attribute.PrintServiceAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.print.attribute.PrintServiceAttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.print.attribute.HashPrintServiceAttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.print.attribute.Size2DSyntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.print.attribute.standard.PrinterName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.print.attribute.standard.PrinterIsAcceptingJobs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.print.attribute.standard.QueuedJobCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.print.attribute.standard.JobName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.print.attribute.standard.JobSheets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import javax.print.attribute.standard.RequestingUserName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import javax.print.attribute.standard.Chromaticity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import javax.print.attribute.standard.ColorSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import javax.print.attribute.standard.Copies;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import javax.print.attribute.standard.CopiesSupported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import javax.print.attribute.standard.Destination;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import javax.print.attribute.standard.Fidelity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import javax.print.attribute.standard.Media;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import javax.print.attribute.standard.MediaPrintableArea;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import javax.print.attribute.standard.MediaSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import javax.print.attribute.standard.MediaSizeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import javax.print.attribute.standard.OrientationRequested;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import javax.print.attribute.standard.PageRanges;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import javax.print.attribute.standard.PrinterState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import javax.print.attribute.standard.PrinterStateReason;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import javax.print.attribute.standard.PrinterStateReasons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import javax.print.attribute.standard.Severity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
import javax.print.attribute.standard.SheetCollate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
import javax.print.attribute.standard.Sides;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
import javax.print.event.PrintServiceAttributeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
public class UnixPrintService implements PrintService, AttributeUpdater,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                                         SunPrinterJobService {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /* define doc flavors for text types in the default encoding of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * this platform since we can always read those.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static String encoding = "ISO8859_1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private static DocFlavor textByteFlavor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static DocFlavor[] supportedDocFlavors = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private static final DocFlavor[] supportedDocFlavorsInit = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
         DocFlavor.BYTE_ARRAY.POSTSCRIPT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
         DocFlavor.INPUT_STREAM.POSTSCRIPT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
         DocFlavor.URL.POSTSCRIPT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
         DocFlavor.BYTE_ARRAY.GIF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         DocFlavor.INPUT_STREAM.GIF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         DocFlavor.URL.GIF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         DocFlavor.BYTE_ARRAY.JPEG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
         DocFlavor.INPUT_STREAM.JPEG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
         DocFlavor.URL.JPEG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
         DocFlavor.BYTE_ARRAY.PNG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
         DocFlavor.INPUT_STREAM.PNG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
         DocFlavor.URL.PNG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
         DocFlavor.CHAR_ARRAY.TEXT_PLAIN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
         DocFlavor.READER.TEXT_PLAIN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
         DocFlavor.STRING.TEXT_PLAIN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
         DocFlavor.BYTE_ARRAY.TEXT_PLAIN_UTF_8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
         DocFlavor.BYTE_ARRAY.TEXT_PLAIN_UTF_16,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
         DocFlavor.BYTE_ARRAY.TEXT_PLAIN_UTF_16BE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
         DocFlavor.BYTE_ARRAY.TEXT_PLAIN_UTF_16LE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
         DocFlavor.BYTE_ARRAY.TEXT_PLAIN_US_ASCII,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
         DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
         DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_16,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
         DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_16BE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
         DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_16LE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
         DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
         DocFlavor.URL.TEXT_PLAIN_UTF_8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
         DocFlavor.URL.TEXT_PLAIN_UTF_16,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
         DocFlavor.URL.TEXT_PLAIN_UTF_16BE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
         DocFlavor.URL.TEXT_PLAIN_UTF_16LE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
         DocFlavor.URL.TEXT_PLAIN_US_ASCII,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
         DocFlavor.SERVICE_FORMATTED.PAGEABLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
         DocFlavor.SERVICE_FORMATTED.PRINTABLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
         DocFlavor.BYTE_ARRAY.AUTOSENSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
         DocFlavor.URL.AUTOSENSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         DocFlavor.INPUT_STREAM.AUTOSENSE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private static final DocFlavor[] supportedHostDocFlavors = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        DocFlavor.BYTE_ARRAY.TEXT_PLAIN_HOST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        DocFlavor.INPUT_STREAM.TEXT_PLAIN_HOST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        DocFlavor.URL.TEXT_PLAIN_HOST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    String[] lpcStatusCom = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
      "",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
      "| grep -E '^[ 0-9a-zA-Z_-]*@' | awk '{print $2, $3}'"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    String[] lpcQueueCom = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
      "",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
      "| grep -E '^[ 0-9a-zA-Z_-]*@' | awk '{print $4}'"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        encoding = java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            new sun.security.action.GetPropertyAction("file.encoding"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /* let's try to support a few of these */
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 22603
diff changeset
   151
    private static final Class<?>[] serviceAttrCats = {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        PrinterName.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        PrinterIsAcceptingJobs.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        QueuedJobCount.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /*  it turns out to be inconvenient to store the other categories
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *  separately because many attributes are in multiple categories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 22603
diff changeset
   160
    private static final Class<?>[] otherAttrCats = {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        Chromaticity.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        Copies.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        Destination.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        Fidelity.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        JobName.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        JobSheets.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        Media.class, /* have to support this somehow ... */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        MediaPrintableArea.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        OrientationRequested.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        PageRanges.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        RequestingUserName.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        SheetCollate.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        Sides.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    private static int MAXCOPIES = 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    private static final MediaSizeName mediaSizes[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        MediaSizeName.NA_LETTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        MediaSizeName.TABLOID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        MediaSizeName.LEDGER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        MediaSizeName.NA_LEGAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        MediaSizeName.EXECUTIVE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        MediaSizeName.ISO_A3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        MediaSizeName.ISO_A4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        MediaSizeName.ISO_A5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        MediaSizeName.ISO_B4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        MediaSizeName.ISO_B5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    private String printer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    private PrinterName name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    private boolean isInvalid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    transient private PrintServiceAttributeSet lastSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    transient private ServiceNotifier notifier = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    UnixPrintService(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            throw new IllegalArgumentException("null printer name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        printer = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        isInvalid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public void invalidateService() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        isInvalid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        return printer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    private PrinterName getPrinterName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            name = new PrinterName(printer, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsSysV() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        String command = "/usr/bin/lpstat -a " + printer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        String results[]= UnixPrintServiceLookup.execCmd(command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        if (results != null && results.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            if (results[0].startsWith(printer + " accepting requests")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            else if (results[0].startsWith(printer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                /* As well as "myprinter accepting requests", look for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                 * "myprinter@somehost accepting requests".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                int index = printer.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                String str = results[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                if (str.length() > index &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    str.charAt(index) == '@' &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    str.indexOf(" accepting requests", index) > 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    str.indexOf(" not accepting requests", index) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                   return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsBSD() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (UnixPrintServiceLookup.cmdIndex ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            UnixPrintServiceLookup.UNINITIALIZED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            UnixPrintServiceLookup.cmdIndex =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                UnixPrintServiceLookup.getBSDCommandIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        String command = "/usr/sbin/lpc status " + printer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            + lpcStatusCom[UnixPrintServiceLookup.cmdIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        String results[]= UnixPrintServiceLookup.execCmd(command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if (results != null && results.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            if (UnixPrintServiceLookup.cmdIndex ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                UnixPrintServiceLookup.BSD_LPD_NG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                if (results[0].startsWith("enabled enabled")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    return PrinterIsAcceptingJobs.ACCEPTING_JOBS ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                if ((results[1].trim().startsWith("queuing is enabled") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    results[2].trim().startsWith("printing is enabled")) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    (results.length >= 4 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                     results[2].trim().startsWith("queuing is enabled") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                     results[3].trim().startsWith("printing is enabled"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                    return PrinterIsAcceptingJobs.ACCEPTING_JOBS ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
22603
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   277
    // Filter the list of possible AIX Printers and remove header lines
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   278
    // and extra lines which have been added for remote printers.
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   279
    // 'protected' because this method is also used from UnixPrintServiceLookup.
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   280
    protected static String[] filterPrinterNamesAIX(String[] posPrinters) {
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 22603
diff changeset
   281
        ArrayList<String> printers = new ArrayList<>();
22603
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   282
        String [] splitPart;
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   283
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   284
        for(int i = 0; i < posPrinters.length; i++) {
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   285
            // Remove the header lines
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   286
            if (posPrinters[i].startsWith("---") ||
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   287
                posPrinters[i].startsWith("Queue") ||
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   288
                posPrinters[i].equals("")) continue;
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   289
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   290
            // Check if there is a ":" in the end of the first colomn.
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   291
            // This means that it is not a valid printer definition.
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   292
            splitPart = posPrinters[i].split(" ");
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   293
            if(splitPart.length >= 1 && !splitPart[0].trim().endsWith(":")) {
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   294
                printers.add(posPrinters[i]);
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   295
            }
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   296
        }
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   297
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 22603
diff changeset
   298
        return printers.toArray(new String[printers.size()]);
22603
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   299
    }
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   300
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   301
    private PrinterIsAcceptingJobs getPrinterIsAcceptingJobsAIX() {
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   302
        // On AIX there should not be a blank after '-a'.
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   303
        String command = "/usr/bin/lpstat -a" + printer;
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   304
        String results[]= UnixPrintServiceLookup.execCmd(command);
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   305
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   306
        // Remove headers and bogus entries added by remote printers.
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   307
        results = filterPrinterNamesAIX(results);
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   308
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   309
        if (results != null && results.length > 0) {
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   310
            for (int i = 0; i < results.length; i++) {
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   311
                if (results[i].contains("READY") ||
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   312
                    results[i].contains("RUNNING")) {
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   313
                    return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   314
                }
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   315
            }
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   316
        }
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   317
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   318
        return PrinterIsAcceptingJobs.NOT_ACCEPTING_JOBS;
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   319
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   320
    }
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   321
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    private PrinterIsAcceptingJobs getPrinterIsAcceptingJobs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if (UnixPrintServiceLookup.isSysV()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            return getPrinterIsAcceptingJobsSysV();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        } else if (UnixPrintServiceLookup.isBSD()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            return getPrinterIsAcceptingJobsBSD();
22603
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   327
        } else if (UnixPrintServiceLookup.isAIX()) {
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   328
            return getPrinterIsAcceptingJobsAIX();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            return PrinterIsAcceptingJobs.ACCEPTING_JOBS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    private PrinterState getPrinterState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        if (isInvalid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            return PrinterState.STOPPED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    private PrinterStateReasons getPrinterStateReasons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        if (isInvalid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            PrinterStateReasons psr = new PrinterStateReasons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            psr.put(PrinterStateReason.SHUTDOWN, Severity.ERROR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            return psr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    private QueuedJobCount getQueuedJobCountSysV() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        String command = "/usr/bin/lpstat -R " + printer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        String results[]= UnixPrintServiceLookup.execCmd(command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        int qlen = (results == null) ? 0 : results.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        return new QueuedJobCount(qlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    private QueuedJobCount getQueuedJobCountBSD() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        if (UnixPrintServiceLookup.cmdIndex ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            UnixPrintServiceLookup.UNINITIALIZED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            UnixPrintServiceLookup.cmdIndex =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                UnixPrintServiceLookup.getBSDCommandIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        int qlen = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        String command = "/usr/sbin/lpc status " + printer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            + lpcQueueCom[UnixPrintServiceLookup.cmdIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        String results[] = UnixPrintServiceLookup.execCmd(command);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        if (results != null && results.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            String queued;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            if (UnixPrintServiceLookup.cmdIndex ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                UnixPrintServiceLookup.BSD_LPD_NG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                queued = results[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                queued = results[3].trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                if (queued.startsWith("no")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    return new QueuedJobCount(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                    queued = queued.substring(0, queued.indexOf(' '));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                qlen = Integer.parseInt(queued);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            } catch (NumberFormatException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        return new QueuedJobCount(qlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
22603
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   396
    private QueuedJobCount getQueuedJobCountAIX() {
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   397
        // On AIX there should not be a blank after '-a'.
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   398
        String command = "/usr/bin/lpstat -a" + printer;
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   399
        String results[]=  UnixPrintServiceLookup.execCmd(command);
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   400
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   401
        // Remove headers and bogus entries added by remote printers.
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   402
        results = filterPrinterNamesAIX(results);
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   403
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   404
        int qlen = 0;
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   405
        if (results != null && results.length > 0){
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   406
            for (int i = 0; i < results.length; i++) {
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   407
                if (results[i].contains("QUEUED")){
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   408
                    qlen ++;
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   409
                }
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   410
            }
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   411
        }
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   412
        return new QueuedJobCount(qlen);
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   413
    }
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   414
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    private QueuedJobCount getQueuedJobCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        if (UnixPrintServiceLookup.isSysV()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            return getQueuedJobCountSysV();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        } else if (UnixPrintServiceLookup.isBSD()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            return getQueuedJobCountBSD();
22603
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   420
        } else if (UnixPrintServiceLookup.isAIX()) {
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   421
            return getQueuedJobCountAIX();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            return new QueuedJobCount(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    private PrintServiceAttributeSet getSysVServiceAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        PrintServiceAttributeSet attrs = new HashPrintServiceAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        attrs.add(getQueuedJobCountSysV());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        attrs.add(getPrinterIsAcceptingJobsSysV());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        return attrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    private PrintServiceAttributeSet getBSDServiceAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        PrintServiceAttributeSet attrs = new HashPrintServiceAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        attrs.add(getQueuedJobCountBSD());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        attrs.add(getPrinterIsAcceptingJobsBSD());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        return attrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
22603
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   441
    private PrintServiceAttributeSet getAIXServiceAttributes() {
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   442
        PrintServiceAttributeSet attrs = new HashPrintServiceAttributeSet();
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   443
        attrs.add(getQueuedJobCountAIX());
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   444
        attrs.add(getPrinterIsAcceptingJobsAIX());
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   445
        return attrs;
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   446
    }
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   447
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    private boolean isSupportedCopies(Copies copies) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        int numCopies = copies.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        return (numCopies > 0 && numCopies < MAXCOPIES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    private boolean isSupportedMedia(MediaSizeName msn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        for (int i=0; i<mediaSizes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            if (msn.equals(mediaSizes[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    public DocPrintJob createPrintJob() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
      SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
      if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        security.checkPrintJobAccess();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        return new UnixPrintJob(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    private PrintServiceAttributeSet getDynamicAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        if (UnixPrintServiceLookup.isSysV()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            return getSysVServiceAttributes();
22603
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   473
        } else if (UnixPrintServiceLookup.isAIX()) {
816588059f9d 8031134: PPC64: implement printing on AIX
simonis
parents: 5506
diff changeset
   474
            return getAIXServiceAttributes();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            return getBSDServiceAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    public PrintServiceAttributeSet getUpdatedAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        PrintServiceAttributeSet currSet = getDynamicAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        if (lastSet == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            lastSet = currSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            return AttributeSetUtilities.unmodifiableView(currSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            PrintServiceAttributeSet updates =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                new HashPrintServiceAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            Attribute []attrs = currSet.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            Attribute attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            for (int i=0; i<attrs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                attr = attrs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                if (!lastSet.containsValue(attr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                    updates.add(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            lastSet = currSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            return AttributeSetUtilities.unmodifiableView(updates);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    public void wakeNotifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            if (notifier != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                notifier.wake();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    public void addPrintServiceAttributeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                                 PrintServiceAttributeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            if (listener == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            if (notifier == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                notifier = new ServiceNotifier(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            notifier.addListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    public void removePrintServiceAttributeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                                  PrintServiceAttributeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            if (listener == null || notifier == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            notifier.removeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            if (notifier.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                notifier.stopNotifier();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                notifier = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 22603
diff changeset
   536
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    public <T extends PrintServiceAttribute>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        T getAttribute(Class<T> category)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        if (category == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            throw new NullPointerException("category");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        if (!(PrintServiceAttribute.class.isAssignableFrom(category))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            throw new IllegalArgumentException("Not a PrintServiceAttribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        if (category == PrinterName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            return (T)getPrinterName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        } else if (category == PrinterState.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            return (T)getPrinterState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        } else if (category == PrinterStateReasons.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            return (T)getPrinterStateReasons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        } else if (category == QueuedJobCount.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            return (T)getQueuedJobCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        } else if (category == PrinterIsAcceptingJobs.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            return (T)getPrinterIsAcceptingJobs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    public PrintServiceAttributeSet getAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        PrintServiceAttributeSet attrs = new HashPrintServiceAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        attrs.add(getPrinterName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        attrs.add(getPrinterIsAcceptingJobs());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        PrinterState prnState = getPrinterState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        if (prnState != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            attrs.add(prnState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        PrinterStateReasons prnStateReasons = getPrinterStateReasons();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        if (prnStateReasons != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            attrs.add(prnStateReasons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        attrs.add(getQueuedJobCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        return AttributeSetUtilities.unmodifiableView(attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    private void initSupportedDocFlavors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        String hostEnc = DocFlavor.hostEncoding.toLowerCase(Locale.ENGLISH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        if (!hostEnc.equals("utf-8") && !hostEnc.equals("utf-16") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            !hostEnc.equals("utf-16be") && !hostEnc.equals("utf-16le") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            !hostEnc.equals("us-ascii")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            int len = supportedDocFlavorsInit.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            DocFlavor[] flavors =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                new DocFlavor[len + supportedHostDocFlavors.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            // copy host encoding flavors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            System.arraycopy(supportedHostDocFlavors, 0, flavors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                             len, supportedHostDocFlavors.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            System.arraycopy(supportedDocFlavorsInit, 0, flavors, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            supportedDocFlavors = flavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            supportedDocFlavors = supportedDocFlavorsInit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    public DocFlavor[] getSupportedDocFlavors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        if (supportedDocFlavors == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            initSupportedDocFlavors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        int len = supportedDocFlavors.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        DocFlavor[] flavors = new DocFlavor[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        System.arraycopy(supportedDocFlavors, 0, flavors, 0, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        return flavors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    public boolean isDocFlavorSupported(DocFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        if (supportedDocFlavors == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            initSupportedDocFlavors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        for (int f=0; f<supportedDocFlavors.length; f++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            if (flavor.equals(supportedDocFlavors[f])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 22603
diff changeset
   621
    public Class<?>[] getSupportedAttributeCategories() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        int totalCats = otherAttrCats.length;
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 22603
diff changeset
   623
        Class<?>[] cats = new Class<?>[totalCats];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        System.arraycopy(otherAttrCats, 0, cats, 0, otherAttrCats.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        return cats;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    public boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        isAttributeCategorySupported(Class<? extends Attribute> category)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        if (category == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            throw new NullPointerException("null category");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        if (!(Attribute.class.isAssignableFrom(category))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            throw new IllegalArgumentException(category +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                                             " is not an Attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        for (int i=0;i<otherAttrCats.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            if (category == otherAttrCats[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    /* return defaults for all attributes for which there is a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    public Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        getDefaultAttributeValue(Class<? extends Attribute> category)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        if (category == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            throw new NullPointerException("null category");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        if (!Attribute.class.isAssignableFrom(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            throw new IllegalArgumentException(category +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                                             " is not an Attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        if (!isAttributeCategorySupported(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        if (category == Copies.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            return new Copies(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        } else if (category == Chromaticity.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            return Chromaticity.COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        } else if (category == Destination.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                return new Destination((new File("out.ps")).toURI());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                    return new Destination(new URI("file:out.ps"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                } catch (URISyntaxException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        } else if (category == Fidelity.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            return Fidelity.FIDELITY_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        } else if (category == JobName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            return new JobName("Java Printing", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        } else if (category == JobSheets.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            return JobSheets.STANDARD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        } else if (category == Media.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            String defaultCountry = Locale.getDefault().getCountry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            if (defaultCountry != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                (defaultCountry.equals("") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                 defaultCountry.equals(Locale.US.getCountry()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                 defaultCountry.equals(Locale.CANADA.getCountry()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                return MediaSizeName.NA_LETTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                 return MediaSizeName.ISO_A4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        } else if (category == MediaPrintableArea.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            String defaultCountry = Locale.getDefault().getCountry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            float iw, ih;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            if (defaultCountry != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                (defaultCountry.equals("") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                 defaultCountry.equals(Locale.US.getCountry()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                 defaultCountry.equals(Locale.CANADA.getCountry()))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                iw = MediaSize.NA.LETTER.getX(Size2DSyntax.INCH) - 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                ih = MediaSize.NA.LETTER.getY(Size2DSyntax.INCH) - 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                iw = MediaSize.ISO.A4.getX(Size2DSyntax.INCH) - 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                ih = MediaSize.ISO.A4.getY(Size2DSyntax.INCH) - 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            return new MediaPrintableArea(0.25f, 0.25f, iw, ih,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                                          MediaPrintableArea.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        } else if (category == OrientationRequested.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            return OrientationRequested.PORTRAIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        } else if (category == PageRanges.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            return new PageRanges(1, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        } else if (category == RequestingUserName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            String userName = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
              userName = System.getProperty("user.name", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            return new RequestingUserName(userName, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        } else if (category == SheetCollate.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            return SheetCollate.UNCOLLATED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        } else if (category == Sides.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            return Sides.ONE_SIDED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    private boolean isAutoSense(DocFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        if (flavor.equals(DocFlavor.BYTE_ARRAY.AUTOSENSE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            flavor.equals(DocFlavor.INPUT_STREAM.AUTOSENSE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            flavor.equals(DocFlavor.URL.AUTOSENSE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    public Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        getSupportedAttributeValues(Class<? extends Attribute> category,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                                    DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                                    AttributeSet attributes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        if (category == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            throw new NullPointerException("null category");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        if (!Attribute.class.isAssignableFrom(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            throw new IllegalArgumentException(category +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                                             " does not implement Attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        if (flavor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            if (!isDocFlavorSupported(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                throw new IllegalArgumentException(flavor +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                                               " is an unsupported flavor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            } else if (isAutoSense(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        if (!isAttributeCategorySupported(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        if (category == Chromaticity.class) {
1727
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   768
            if (flavor == null || isServiceFormattedFlavor(flavor)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                Chromaticity[]arr = new Chromaticity[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                arr[0] = Chromaticity.COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                return (arr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        } else if (category == Destination.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                return new Destination((new File("out.ps")).toURI());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                    return new Destination(new URI("file:out.ps"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                } catch (URISyntaxException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        } else if (category == JobName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            return new JobName("Java Printing", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        } else if (category == JobSheets.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            JobSheets arr[] = new JobSheets[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            arr[0] = JobSheets.NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            arr[1] = JobSheets.STANDARD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        } else if (category == RequestingUserName.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            String userName = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
              userName = System.getProperty("user.name", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            } catch (SecurityException se) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            return new RequestingUserName(userName, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        } else if (category == OrientationRequested.class) {
1727
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   800
            if (flavor == null || isServiceFormattedFlavor(flavor)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                OrientationRequested []arr = new OrientationRequested[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                arr[0] = OrientationRequested.PORTRAIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                arr[1] = OrientationRequested.LANDSCAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                arr[2] = OrientationRequested.REVERSE_LANDSCAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        } else if ((category == Copies.class) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                   (category == CopiesSupported.class)) {
1727
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   811
            if (flavor == null ||
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   812
                !(flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   813
                  flavor.equals(DocFlavor.URL.POSTSCRIPT) ||
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   814
                  flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT))) {
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   815
                return new CopiesSupported(1, MAXCOPIES);
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   816
            } else {
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   817
                return null;
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   818
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        } else if (category == Media.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            Media []arr = new Media[mediaSizes.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            System.arraycopy(mediaSizes, 0, arr, 0, mediaSizes.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        } else if (category == Fidelity.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            Fidelity []arr = new Fidelity[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            arr[0] = Fidelity.FIDELITY_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            arr[1] = Fidelity.FIDELITY_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        } else if (category == MediaPrintableArea.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            /* The code below implements the behaviour that if no Media or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
             * MediaSize attribute is specified, return an array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
             * MediaPrintableArea, one for each supported Media.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
             * If a MediaSize is specified, return a MPA consistent for that,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
             * and if a Media is specified locate its MediaSize and return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
             * its MPA, and if none is found, return an MPA for the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
             * Media for this service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            if (attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                return getAllPrintableAreas();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            MediaSize mediaSize = (MediaSize)attributes.get(MediaSize.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            Media media = (Media)attributes.get(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            MediaPrintableArea []arr = new MediaPrintableArea[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            if (mediaSize == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                if (media instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                    MediaSizeName msn = (MediaSizeName)media;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                    mediaSize = MediaSize.getMediaSizeForName(msn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                    if (mediaSize == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                        /* try to get a size from the default media */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                        media = (Media)getDefaultAttributeValue(Media.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                        if (media instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                            msn = (MediaSizeName)media;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                            mediaSize = MediaSize.getMediaSizeForName(msn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                        if (mediaSize == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                            /* shouldn't happen, return a default */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                            arr[0] = new MediaPrintableArea(0.25f, 0.25f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                                                            8f, 10.5f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                                                            MediaSize.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                            return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                    return getAllPrintableAreas();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            /* If reach here MediaSize is non-null */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            assert mediaSize != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            arr[0] = new MediaPrintableArea(0.25f, 0.25f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                                mediaSize.getX(MediaSize.INCH)-0.5f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                                mediaSize.getY(MediaSize.INCH)-0.5f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                                MediaSize.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        } else if (category == PageRanges.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            if (flavor == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                PageRanges []arr = new PageRanges[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                arr[0] = new PageRanges(1, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        } else if (category == SheetCollate.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            if (flavor == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                SheetCollate []arr = new SheetCollate[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                arr[0] = SheetCollate.UNCOLLATED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                arr[1] = SheetCollate.COLLATED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        } else if (category == Sides.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            if (flavor == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                Sides []arr = new Sides[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                arr[0] = Sides.ONE_SIDED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                arr[1] = Sides.TWO_SIDED_LONG_EDGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                arr[2] = Sides.TWO_SIDED_SHORT_EDGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                return arr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    private static MediaPrintableArea[] mpas = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    private MediaPrintableArea[] getAllPrintableAreas() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        if (mpas == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            Media[] media = (Media[])getSupportedAttributeValues(Media.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                                                                 null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            mpas = new MediaPrintableArea[media.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            for (int i=0; i< mpas.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                if (media[i] instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                    MediaSizeName msn = (MediaSizeName)media[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                    MediaSize mediaSize = MediaSize.getMediaSizeForName(msn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                    if (mediaSize == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                        mpas[i] = (MediaPrintableArea)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                            getDefaultAttributeValue(MediaPrintableArea.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                        mpas[i] = new MediaPrintableArea(0.25f, 0.25f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                                        mediaSize.getX(MediaSize.INCH)-0.5f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                                        mediaSize.getY(MediaSize.INCH)-0.5f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                                        MediaSize.INCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        return mpasCopy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    /* Is this one of the flavors that this service explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * generates postscript for, and so can control how it is rendered?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    private boolean isServiceFormattedFlavor(DocFlavor flavor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            flavor.equals(DocFlavor.BYTE_ARRAY.GIF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            flavor.equals(DocFlavor.INPUT_STREAM.GIF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            flavor.equals(DocFlavor.URL.GIF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            flavor.equals(DocFlavor.BYTE_ARRAY.JPEG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            flavor.equals(DocFlavor.INPUT_STREAM.JPEG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            flavor.equals(DocFlavor.URL.JPEG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            flavor.equals(DocFlavor.BYTE_ARRAY.PNG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            flavor.equals(DocFlavor.INPUT_STREAM.PNG) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            flavor.equals(DocFlavor.URL.PNG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    public boolean isAttributeValueSupported(Attribute attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                                             DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                                             AttributeSet attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        if (attr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            throw new NullPointerException("null attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        if (flavor != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            if (!isDocFlavorSupported(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                throw new IllegalArgumentException(flavor +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                                               " is an unsupported flavor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            } else if (isAutoSense(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        }
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 22603
diff changeset
   971
        Class<? extends Attribute> category = attr.getCategory();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        if (!isAttributeCategorySupported(category)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        else if (attr.getCategory() == Chromaticity.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            if (flavor == null || isServiceFormattedFlavor(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                return attr == Chromaticity.COLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        else if (attr.getCategory() == Copies.class) {
1727
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   983
            return (flavor == null ||
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   984
                   !(flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   985
                     flavor.equals(DocFlavor.URL.POSTSCRIPT) ||
5e5e0235b14f 6732647: isAttributeValueSupported() is not consistant with getSupportedValues() for Copies, TEXT flavor
jgodinez
parents: 2
diff changeset
   986
                     flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT))) &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                isSupportedCopies((Copies)attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        } else if (attr.getCategory() == Destination.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            URI uri = ((Destination)attr).getURI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                if ("file".equals(uri.getScheme()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                    !(uri.getSchemeSpecificPart().equals(""))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        } else if (attr.getCategory() == Media.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            if (attr instanceof MediaSizeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                return isSupportedMedia((MediaSizeName)attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        } else if (attr.getCategory() == OrientationRequested.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            if (attr == OrientationRequested.REVERSE_PORTRAIT ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                (flavor != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                !isServiceFormattedFlavor(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        } else if (attr.getCategory() == PageRanges.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            if (flavor != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        } else if (attr.getCategory() == SheetCollate.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            if (flavor != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        } else if (attr.getCategory() == Sides.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            if (flavor != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                !(flavor.equals(DocFlavor.SERVICE_FORMATTED.PAGEABLE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                flavor.equals(DocFlavor.SERVICE_FORMATTED.PRINTABLE))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                                                 AttributeSet attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        if (flavor != null && !isDocFlavorSupported(flavor)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            throw new IllegalArgumentException("flavor " + flavor +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                                               "is not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        if (attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        Attribute attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        AttributeSet unsupp = new HashAttributeSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        Attribute []attrs = attributes.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        for (int i=0; i<attrs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                attr = attrs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                if (!isAttributeCategorySupported(attr.getCategory())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                    unsupp.add(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                } else if (!isAttributeValueSupported(attr, flavor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                                                      attributes)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                    unsupp.add(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        if (unsupp.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            return unsupp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
    public ServiceUIFactory getServiceUIFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        return "Unix Printer : " + getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        return  (obj == this ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                 (obj instanceof UnixPrintService &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                  ((UnixPrintService)obj).getName().equals(getName())));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        return this.getClass().hashCode()+getName().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
25140
80e863984492 8042870: Fix raw and unchecked warnings in sun.print
darcy
parents: 22603
diff changeset
  1082
    public boolean usesClass(Class<?> c) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        return (c == sun.print.PSPrinterJob.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
}