jdk/src/solaris/classes/sun/print/AttributeClass.java
author dxu
Thu, 15 Aug 2013 14:11:16 -0700
changeset 19419 67b5c7d91daa
parent 5506 202f599c92aa
child 22584 eed64ee05369
permissions -rw-r--r--
8017109: Cleanup overrides warning in src/solaris/classes/sun/print/AttributeClass.java Reviewed-by: jgodinez
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: 715
diff changeset
     2
 * Copyright (c) 2003, 2008, 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: 715
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: 715
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: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.print;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
19419
67b5c7d91daa 8017109: Cleanup overrides warning in src/solaris/classes/sun/print/AttributeClass.java
dxu
parents: 5506
diff changeset
    27
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.ByteArrayInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
public class AttributeClass {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
    private String myName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
    private int myType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    private int nameLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    private Object myValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
535
e6b909c9e627 6633656: Cross platform print dialog doesn't check for orientation being unsupported.
jgodinez
parents: 2
diff changeset
    36
    public static final int TAG_UNSUPPORTED_VALUE = 0x10;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    public static final int TAG_INT = 0x21;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    public static final int TAG_BOOL = 0x22;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    public static final int TAG_ENUM = 0x23;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    public static final int TAG_OCTET = 0x30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    public static final int TAG_DATE = 0x31;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    public static final int TAG_RESOLUTION = 0x32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    public static final int TAG_RANGE_INTEGER = 0x33;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public static final int TAG_TEXT_LANGUAGE = 0x35;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    public static final int TAG_NAME_LANGUAGE = 0x36;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public static final int TAG_TEXT_WO_LANGUAGE = 0x41;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public static final int TAG_NAME_WO_LANGUAGE = 0x42;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public static final int TAG_KEYWORD = 0x44;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static final int TAG_URI = 0x45;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public static final int TAG_CHARSET = 0x47;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static final int TAG_NATURALLANGUAGE = 0x48;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static final int TAG_MIME_MEDIATYPE = 0x49;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public static final int TAG_MEMBER_ATTRNAME = 0x4A;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public static final AttributeClass ATTRIBUTES_CHARSET =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        new AttributeClass("attributes-charset",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                           TAG_CHARSET, "utf-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public static final AttributeClass ATTRIBUTES_NATURAL_LANGUAGE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        new AttributeClass("attributes-natural-language",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                           TAG_NATURALLANGUAGE, "en");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * value passed in by IPPPrintService.readIPPResponse is a sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * of bytes with this format
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * | length1 | byte1 | byte 2 | ... byten | length2 | byte1 ... byten |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *      :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * | lengthN | byte1 ... byten | total number of values|
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    protected AttributeClass(String name, int type, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        myName = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        myType = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        nameLen = name.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        myValue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public byte getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        return (byte)myType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public char[] getLenChars() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        char[] chars = new char[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        chars[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        chars[1] = (char)nameLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return chars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Returns raw data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public Object getObjectValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        return myValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Returns single int value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public int getIntValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        byte[] bufArray = (byte[])myValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if (bufArray != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            byte[] buf = new byte[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            for (int i=0; i<4; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                buf[i] = bufArray[i+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            return convertToInt(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Returns array of int values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public int[] getArrayOfIntValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        byte[] bufArray = (byte[])myValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (bufArray != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            //ArrayList valList = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            ByteArrayInputStream bufStream =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                new ByteArrayInputStream(bufArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            int available = bufStream.available();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            // total number of values is at the end of the stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            bufStream.mark(available);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            bufStream.skip(available-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            int length = bufStream.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            bufStream.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            int[] valueArray = new int[length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            for (int i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                // read length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                int valLength = bufStream.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                if (valLength != 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    // invalid data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                byte[] bufBytes = new byte[valLength];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                bufStream.read(bufBytes, 0, valLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                valueArray[i] = convertToInt(bufBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            return valueArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Returns 2 int values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public int[] getIntRangeValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        int[] range = {0, 0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        byte[] bufArray = (byte[])myValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (bufArray != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            int nBytes = 4; // 32-bit signed integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            for (int j=0; j<2; j++) { // 2 set of integers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                byte[] intBytes = new byte[nBytes];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                // REMIND: # bytes should be 8
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                for (int i=0; i< nBytes; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    //+ 1 because the 1st byte is length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    intBytes[i] = bufArray[i+(4*j)+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                range[j] = convertToInt(intBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return range;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Returns String value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public String getStringValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        //assumes only 1 attribute value.  Will get the first value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        // if > 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        String strVal = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        byte[] bufArray = (byte[])myValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (bufArray != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            ByteArrayInputStream bufStream =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                new ByteArrayInputStream(bufArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            int valLength = bufStream.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            byte[] strBytes = new byte[valLength];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            bufStream.read(strBytes, 0, valLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                strVal = new String(strBytes, "UTF-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            } catch (java.io.UnsupportedEncodingException uee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return strVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Returns array of String values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public String[] getArrayOfStringValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        byte[] bufArray = (byte[])myValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (bufArray != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            ByteArrayInputStream bufStream =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                new ByteArrayInputStream(bufArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            int available = bufStream.available();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            // total number of values is at the end of the stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            bufStream.mark(available);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            bufStream.skip(available-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            int length = bufStream.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            bufStream.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            String[] valueArray = new String[length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            for (int i = 0; i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                // read length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                int valLength = bufStream.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                byte[] bufBytes = new byte[valLength];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                bufStream.read(bufBytes, 0, valLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    valueArray[i] = new String(bufBytes, "UTF-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                } catch (java.io.UnsupportedEncodingException uee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            return valueArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Returns single byte value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public byte getByteValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        byte[] bufArray = (byte[])myValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if ((bufArray != null) && (bufArray.length>=2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            return bufArray[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Returns attribute name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return myName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
19419
67b5c7d91daa 8017109: Cleanup overrides warning in src/solaris/classes/sun/print/AttributeClass.java
dxu
parents: 5506
diff changeset
   252
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public boolean equals(Object obj) {
19419
67b5c7d91daa 8017109: Cleanup overrides warning in src/solaris/classes/sun/print/AttributeClass.java
dxu
parents: 5506
diff changeset
   254
        if (!(obj instanceof AttributeClass)) {
67b5c7d91daa 8017109: Cleanup overrides warning in src/solaris/classes/sun/print/AttributeClass.java
dxu
parents: 5506
diff changeset
   255
            return false;
67b5c7d91daa 8017109: Cleanup overrides warning in src/solaris/classes/sun/print/AttributeClass.java
dxu
parents: 5506
diff changeset
   256
        }
67b5c7d91daa 8017109: Cleanup overrides warning in src/solaris/classes/sun/print/AttributeClass.java
dxu
parents: 5506
diff changeset
   257
        if (this == obj) {
67b5c7d91daa 8017109: Cleanup overrides warning in src/solaris/classes/sun/print/AttributeClass.java
dxu
parents: 5506
diff changeset
   258
            return true;
67b5c7d91daa 8017109: Cleanup overrides warning in src/solaris/classes/sun/print/AttributeClass.java
dxu
parents: 5506
diff changeset
   259
        }
67b5c7d91daa 8017109: Cleanup overrides warning in src/solaris/classes/sun/print/AttributeClass.java
dxu
parents: 5506
diff changeset
   260
67b5c7d91daa 8017109: Cleanup overrides warning in src/solaris/classes/sun/print/AttributeClass.java
dxu
parents: 5506
diff changeset
   261
        AttributeClass acObj = (AttributeClass) obj;
67b5c7d91daa 8017109: Cleanup overrides warning in src/solaris/classes/sun/print/AttributeClass.java
dxu
parents: 5506
diff changeset
   262
        return myType == acObj.getType() &&
67b5c7d91daa 8017109: Cleanup overrides warning in src/solaris/classes/sun/print/AttributeClass.java
dxu
parents: 5506
diff changeset
   263
               Objects.equals(myName, acObj.getName()) &&
67b5c7d91daa 8017109: Cleanup overrides warning in src/solaris/classes/sun/print/AttributeClass.java
dxu
parents: 5506
diff changeset
   264
               Objects.equals(myValue, acObj.getObjectValue());
67b5c7d91daa 8017109: Cleanup overrides warning in src/solaris/classes/sun/print/AttributeClass.java
dxu
parents: 5506
diff changeset
   265
    }
67b5c7d91daa 8017109: Cleanup overrides warning in src/solaris/classes/sun/print/AttributeClass.java
dxu
parents: 5506
diff changeset
   266
67b5c7d91daa 8017109: Cleanup overrides warning in src/solaris/classes/sun/print/AttributeClass.java
dxu
parents: 5506
diff changeset
   267
    @Override
67b5c7d91daa 8017109: Cleanup overrides warning in src/solaris/classes/sun/print/AttributeClass.java
dxu
parents: 5506
diff changeset
   268
    public int hashCode() {
67b5c7d91daa 8017109: Cleanup overrides warning in src/solaris/classes/sun/print/AttributeClass.java
dxu
parents: 5506
diff changeset
   269
        return Objects.hash(myType, myName, myValue);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        return myName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    private int unsignedByteToInt(byte b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        return (int) (b & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    private int convertToInt(byte[] buf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        int intVal = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        int pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        intVal+= unsignedByteToInt(buf[pos++]) << 24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        intVal+= unsignedByteToInt(buf[pos++]) << 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        intVal+= unsignedByteToInt(buf[pos++]) << 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        intVal+= unsignedByteToInt(buf[pos++]) << 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        return intVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
}