corba/src/share/classes/com/sun/corba/se/impl/encoding/OSFCodeSetRegistry.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
package com.sun.corba.se.impl.encoding;
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
 * Information from the OSF code set registry version 1.2g.
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
 * Use the Entry corresponding to the desired code set.
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
 * Consider rename to CodeSetRegistry since OSF is dead.
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
public final class OSFCodeSetRegistry
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
    // Numbers from the OSF code set registry version 1.2g.
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
    // Please see the individual Entry definitions for
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
    // more details.
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
    public static final int ISO_8859_1_VALUE = 0x00010001;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
    public static final int UTF_16_VALUE = 0x00010109;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
    public static final int UTF_8_VALUE = 0x05010001;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
    public static final int UCS_2_VALUE = 0x00010100;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
    public static final int ISO_646_VALUE = 0x00010020;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
    private OSFCodeSetRegistry() {}
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
     * An entry in the OSF registry which allows users
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
     * to find out the equivalent Java character encoding
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
     * name as well as some other facts from the registry.
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
    public final static class Entry
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
        private String javaName;
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
        private int encodingNum;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
        private boolean isFixedWidth;
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
        private int maxBytesPerChar;
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
        private Entry(String javaName,
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
                      int encodingNum,
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
                      boolean isFixedWidth,
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
                      int maxBytesPerChar) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
            this.javaName = javaName;
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
            this.encodingNum = encodingNum;
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
            this.isFixedWidth = isFixedWidth;
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
            this.maxBytesPerChar = maxBytesPerChar;
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
         * Returns the Java equivalent name.  If the encoding has
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
         * an optional byte order marker, this name will map to the
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
         * Java encoding that includes the marker.
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
        public String getName() {
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
            return javaName;
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
         * Get the OSF registry number for this code set.
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
        public int getNumber() {
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
            return encodingNum;
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
         * Is this a fixed or variable width code set?  (In CORBA
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
         * terms, "non-byte-oriented" or a "byte-oriented"
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
         * code set, respectively)
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
        public boolean isFixedWidth() {
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
            return isFixedWidth;
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
        public int getMaxBytesPerChar() {
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
            return maxBytesPerChar;
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
         * First checks reference equality since it's expected
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
         * people will use the pre-defined constant Entries.
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
        public boolean equals(Object obj) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
            if (this == obj)
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
                return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
            if (!(obj instanceof OSFCodeSetRegistry.Entry))
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
                return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
            OSFCodeSetRegistry.Entry other
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
                = (OSFCodeSetRegistry.Entry)obj;
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
            return (javaName.equals(other.javaName) &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
                    encodingNum == other.encodingNum &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
                    isFixedWidth == other.isFixedWidth &&
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
                    maxBytesPerChar == other.maxBytesPerChar);
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
        /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
         * Uses the registry number as the hash code.
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
         */
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
        public int hashCode() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
            return encodingNum;
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
     * 8-bit encoding required for GIOP 1.0, and used as the char set
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
     * when nothing else is specified.
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
    public static final Entry ISO_8859_1
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
        = new Entry("ISO-8859-1",
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
                    ISO_8859_1_VALUE,
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
                    true,
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
                    1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
     * UTF-16 as specified in the OSF registry has an optional
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
     * byte order marker.  UTF-16BE and UTF-16LE are not in the OSF
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
     * registry since it is no longer being developed.  When the OMG
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
     * switches to the IANA registry, these can be public.  Right
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
     * now, they're used internally by CodeSetConversion.
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
    static final Entry UTF_16BE
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
        = new Entry("UTF-16BE",
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
                    -1,
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
                    true,
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
                    2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
    static final Entry UTF_16LE
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
        = new Entry("UTF-16LE",
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
                    -2,
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
                    true,
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
                    2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
     * Fallback wchar code set.
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
     * In the resolution of issue 3405b, UTF-16 defaults to big endian, so
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
     * doesn't have to have a byte order marker.  Unfortunately, this has to be
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
     * a special case for compatibility.
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
    public static final Entry UTF_16
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
        = new Entry("UTF-16",
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
                    UTF_16_VALUE,
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
                    true,
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
                    4);
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
     * Fallback char code set.  Also the code set for char data
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
     * in encapsulations.  However, since CORBA says chars are
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
     * only one octet, it is really the same as Latin-1.
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
    public static final Entry UTF_8
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
        = new Entry("UTF-8",
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
                    UTF_8_VALUE,
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
                    false,
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
                    6);
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
    /*
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
     * At least in JDK 1.3, UCS-2 isn't one of the mandatory Java character
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
     * encodings.  However, our old ORBs require what they call UCS2, even
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
     * though they didn't necessarily do the correct encoding of it.
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
     * This is a special case for our legacy ORBs, and put as the last thing
02bb8761fcce Initial load
duke
parents:
diff changeset
   187
     * in our conversion list for wchar data.
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
     *
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
     * If a foreign ORB actually tries to speak UCS2 with us, it probably
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
     * won't work!  Beware!
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
    public static final Entry UCS_2
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
        = new Entry("UCS-2",
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
                    UCS_2_VALUE,
02bb8761fcce Initial load
duke
parents:
diff changeset
   195
                    true,
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
                    2);
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
     * This is the encoding older JavaSoft ORBs advertised as their
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
     * CORBA char code set.  Actually, they took the lower byte of
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
     * the Java char.  This is a 7-bit encoding, so they
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
     * were really sending ISO8859-1.
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
    public static final Entry ISO_646
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
        = new Entry("US-ASCII",
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
                    ISO_646_VALUE,
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
                    true,
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
                    1);
02bb8761fcce Initial load
duke
parents:
diff changeset
   209
02bb8761fcce Initial load
duke
parents:
diff changeset
   210
    /**
02bb8761fcce Initial load
duke
parents:
diff changeset
   211
     * Given an OSF registry value, return the corresponding Entry.
02bb8761fcce Initial load
duke
parents:
diff changeset
   212
     * Returns null if an Entry for that value is unavailable.
02bb8761fcce Initial load
duke
parents:
diff changeset
   213
     */
02bb8761fcce Initial load
duke
parents:
diff changeset
   214
    public static Entry lookupEntry(int encodingValue) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   215
        switch(encodingValue) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   216
            case ISO_8859_1_VALUE:
02bb8761fcce Initial load
duke
parents:
diff changeset
   217
                return OSFCodeSetRegistry.ISO_8859_1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   218
            case UTF_16_VALUE:
02bb8761fcce Initial load
duke
parents:
diff changeset
   219
                return OSFCodeSetRegistry.UTF_16;
02bb8761fcce Initial load
duke
parents:
diff changeset
   220
            case UTF_8_VALUE:
02bb8761fcce Initial load
duke
parents:
diff changeset
   221
                return OSFCodeSetRegistry.UTF_8;
02bb8761fcce Initial load
duke
parents:
diff changeset
   222
            case ISO_646_VALUE:
02bb8761fcce Initial load
duke
parents:
diff changeset
   223
                return OSFCodeSetRegistry.ISO_646;
02bb8761fcce Initial load
duke
parents:
diff changeset
   224
            case UCS_2_VALUE:
02bb8761fcce Initial load
duke
parents:
diff changeset
   225
                return OSFCodeSetRegistry.UCS_2;
02bb8761fcce Initial load
duke
parents:
diff changeset
   226
            default:
02bb8761fcce Initial load
duke
parents:
diff changeset
   227
                return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   228
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   229
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   230
}