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