Merge from mainline.
[official-gcc.git] / libjava / classpath / gnu / CORBA / GIOP / CharSets_OSF.java
blobbffb02678aa019f2e9197fa867c99177f6cca930
1 /* CharSets_OSF.java --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu.CORBA.GIOP;
41 import java.nio.charset.Charset;
43 import java.util.Hashtable;
44 import java.util.Iterator;
45 import java.util.Set;
47 /**
48 * This class contains the codes, used to identify character sets
49 * in CORBA. These codes are defined in Open Software Foundation (OSF)
50 * code set registry.
52 * The name of this class specially sets "OSF" apart if somebody would start
53 * searching Open Software Foundation abbreviation.
55 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
57 public class CharSets_OSF
59 public static final int ASCII = 0x00010020;
60 public static final int ISO8859_1 = 0x00010001;
61 public static final int ISO8859_2 = 0x00010002;
62 public static final int ISO8859_3 = 0x00010003;
63 public static final int ISO8859_4 = 0x00010004;
64 public static final int ISO8859_5 = 0x00010005;
65 public static final int ISO8859_6 = 0x00010006;
66 public static final int ISO8859_7 = 0x00010007;
67 public static final int ISO8859_8 = 0x00010008;
68 public static final int ISO8859_9 = 0x00010009;
69 public static final int ISO8859_15_FDIS = 0x0001000F;
70 public static final int UTF8 = 0x05010001;
71 public static final int UTF16 = 0x00010109;
72 public static final int UCS2 = 0x00010100;
73 public static final int Cp1047 = 0x10020417;
74 public static final int Cp1250 = 0x100204E2;
75 public static final int Cp1251 = 0x100204E3;
76 public static final int Cp1252 = 0x100204E4;
77 public static final int Cp1253 = 0x100204E5;
78 public static final int Cp1254 = 0x100204E6;
79 public static final int Cp1255 = 0x100204E7;
80 public static final int Cp1256 = 0x100204E8;
81 public static final int Cp1257 = 0x100204E9;
82 public static final int Cp1363 = 0x10020553;
83 public static final int Cp1363C = 0x10020553;
84 public static final int Cp1381 = 0x10020565;
85 public static final int Cp1383 = 0x10020567;
86 public static final int Cp1386 = 0x1002056A;
87 public static final int Cp33722 = 0x100283BA;
88 public static final int Cp33722C = 0x100283BA;
89 public static final int Cp930 = 0x100203A2;
90 public static final int Cp943 = 0x100203AF;
91 public static final int Cp943C = 0x100203AF;
92 public static final int Cp949 = 0x100203B5;
93 public static final int Cp949C = 0x100203B5;
94 public static final int Cp950 = 0x100203B6;
95 public static final int Cp964 = 0x100203C4;
96 public static final int Cp970 = 0x100203CA;
97 public static final int EUC_JP = 0x00030010;
98 public static final int EUC_KR = 0x0004000A;
99 public static final int EUC_TW = 0x00050010;
102 * The native character set for the narrow character.
104 public static final int NATIVE_CHARACTER = ISO8859_1;
107 * The native character set for the wide character.
109 public static final int NATIVE_WIDE_CHARACTER = UTF16;
112 * Table to convert from the code to string name.
114 private static Hashtable code_to_string;
117 * Table to convert from the string name to code.
119 private static Hashtable string_to_code;
122 * Get the charset code from its name.
124 * @return the charset code of 0 if not defined.
126 public static int getCode(String name)
128 if (string_to_code == null)
129 makeMap();
131 Integer code = (Integer) string_to_code.get(name);
132 return code == null ? 0 : code.intValue();
136 * Get the charset name from its code.
138 * @return the code set name or nullfor the unknown code set.
140 public static String getName(int code)
142 if (code_to_string == null)
143 makeMap();
144 return (String) code_to_string.get(new Integer(code));
148 * Get the list of supported char sets for that the CORBA codes are
149 * also known.
151 public static int[] getSupportedCharSets()
153 Set supported_sets = Charset.availableCharsets().keySet();
154 int[] supported = new int[ supported_sets.size() ];
155 Iterator iter = supported_sets.iterator();
157 int i = 0;
158 int code;
159 while (iter.hasNext())
161 code = getCode(iter.next().toString());
162 if (code > 0)
163 supported [ i++ ] = code;
166 // Truncate the unused part.
167 int[] f = new int[ i ];
168 System.arraycopy(supported, 0, f, 0, f.length);
170 return f;
174 * Create a convertion map.
176 private static void makeMap()
178 code_to_string = new Hashtable();
179 string_to_code = new Hashtable();
181 // Put standard char sets.
182 put(ASCII, "US-ASCII");
183 put(ISO8859_1, "ISO-8859-1");
184 put(UTF16, "UTF-16");
186 // Put other known char sets.
187 put(ISO8859_2, "ISO-8859-2");
188 put(ISO8859_3, "ISO-8859-3");
189 put(ISO8859_4, "ISO-8859-4");
190 put(ISO8859_5, "ISO-8859-5");
191 put(ISO8859_6, "ISO-8859-6");
192 put(ISO8859_7, "ISO-8859-7");
193 put(ISO8859_8, "ISO-8859-8");
194 put(ISO8859_9, "ISO-8859-9");
196 put(UTF8, "UTF-8");
197 put(UCS2, "UCS-2");
199 put(ISO8859_15_FDIS, "ISO8859-15-FDIS");
201 put(Cp1047, "Cp1047");
202 put(Cp1250, "Cp1250");
203 put(Cp1251, "Cp1251");
204 put(Cp1252, "Cp1252");
205 put(Cp1253, "Cp1253");
206 put(Cp1254, "Cp1254");
207 put(Cp1255, "Cp1255");
208 put(Cp1256, "Cp1256");
209 put(Cp1257, "Cp1257");
210 put(Cp1363, "Cp1363");
211 put(Cp1363C, "Cp1363C");
212 put(Cp1381, "Cp1381");
213 put(Cp1383, "Cp1383");
214 put(Cp1386, "Cp1386");
215 put(Cp33722, "Cp33722");
216 put(Cp33722C, "Cp33722C");
217 put(Cp930, "Cp930");
218 put(Cp943, "Cp943");
219 put(Cp943C, "Cp943C");
220 put(Cp949, "Cp949");
221 put(Cp949C, "Cp949C");
222 put(Cp950, "Cp950");
223 put(Cp964, "Cp964");
224 put(Cp970, "Cp970");
226 put(EUC_JP, "EUC-JP");
227 put(EUC_KR, "EUC-KR");
228 put(EUC_TW, "EUC-TW");
231 private static void put(int code, String name)
233 Integer ic = new Integer(code);
235 code_to_string.put(ic, name);
236 string_to_code.put(name, ic);