KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > encoding > OSFCodeSetRegistry


1 /*
2  * @(#)OSFCodeSetRegistry.java 1.9 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package com.sun.corba.se.impl.encoding;
8
9 /**
10  *
11  * Information from the OSF code set registry version 1.2g.
12  *
13  * Use the Entry corresponding to the desired code set.
14  *
15  * Consider rename to CodeSetRegistry since OSF is dead.
16  */

17 public final class OSFCodeSetRegistry
18 {
19     // Numbers from the OSF code set registry version 1.2g.
20
//
21
// Please see the individual Entry definitions for
22
// more details.
23
public static final int ISO_8859_1_VALUE = 0x00010001;
24     public static final int UTF_16_VALUE = 0x00010109;
25     public static final int UTF_8_VALUE = 0x05010001;
26     public static final int UCS_2_VALUE = 0x00010100;
27     public static final int ISO_646_VALUE = 0x00010020;
28
29     private OSFCodeSetRegistry() {}
30
31     /**
32      * An entry in the OSF registry which allows users
33      * to find out the equivalent Java character encoding
34      * name as well as some other facts from the registry.
35      */

36     public final static class Entry
37     {
38         private String JavaDoc javaName;
39         private int encodingNum;
40         private boolean isFixedWidth;
41         private int maxBytesPerChar;
42
43         private Entry(String JavaDoc javaName,
44                       int encodingNum,
45                       boolean isFixedWidth,
46                       int maxBytesPerChar) {
47             this.javaName = javaName;
48             this.encodingNum = encodingNum;
49             this.isFixedWidth = isFixedWidth;
50             this.maxBytesPerChar = maxBytesPerChar;
51         }
52
53         /**
54          * Returns the Java equivalent name. If the encoding has
55          * an optional byte order marker, this name will map to the
56          * Java encoding that includes the marker.
57          */

58         public String JavaDoc getName() {
59             return javaName;
60         }
61
62         /**
63          * Get the OSF registry number for this code set.
64          */

65         public int getNumber() {
66             return encodingNum;
67         }
68
69         /**
70          * Is this a fixed or variable width code set? (In CORBA
71          * terms, "non-byte-oriented" or a "byte-oriented"
72          * code set, respectively)
73          */

74         public boolean isFixedWidth() {
75             return isFixedWidth;
76         }
77
78         public int getMaxBytesPerChar() {
79             return maxBytesPerChar;
80         }
81         
82         /**
83          * First checks reference equality since it's expected
84          * people will use the pre-defined constant Entries.
85          */

86         public boolean equals(Object JavaDoc obj) {
87             if (this == obj)
88                 return true;
89
90             if (!(obj instanceof OSFCodeSetRegistry.Entry))
91                 return false;
92
93             OSFCodeSetRegistry.Entry other
94                 = (OSFCodeSetRegistry.Entry)obj;
95
96             return (javaName.equals(other.javaName) &&
97                     encodingNum == other.encodingNum &&
98                     isFixedWidth == other.isFixedWidth &&
99                     maxBytesPerChar == other.maxBytesPerChar);
100         }
101
102         /**
103          * Uses the registry number as the hash code.
104          */

105         public int hashCode() {
106             return encodingNum;
107         }
108     }
109
110     /**
111      * 8-bit encoding required for GIOP 1.0, and used as the char set
112      * when nothing else is specified.
113      */

114     public static final Entry ISO_8859_1
115         = new Entry("ISO-8859-1",
116                     ISO_8859_1_VALUE,
117                     true,
118                     1);
119
120     /**
121      * UTF-16 as specified in the OSF registry has an optional
122      * byte order marker. UTF-16BE and UTF-16LE are not in the OSF
123      * registry since it is no longer being developed. When the OMG
124      * switches to the IANA registry, these can be public. Right
125      * now, they're used internally by CodeSetConversion.
126      */

127     static final Entry UTF_16BE
128         = new Entry("UTF-16BE",
129                     -1,
130                     true,
131                     2);
132
133     static final Entry UTF_16LE
134         = new Entry("UTF-16LE",
135                     -2,
136                     true,
137                     2);
138
139     /**
140      * Fallback wchar code set.
141      *
142      * In the resolution of issue 3405b, UTF-16 defaults to big endian, so
143      * doesn't have to have a byte order marker. Unfortunately, this has to be
144      * a special case for compatibility.
145      */

146     public static final Entry UTF_16
147         = new Entry("UTF-16",
148                     UTF_16_VALUE,
149                     true,
150                     4);
151
152     /**
153      * Fallback char code set. Also the code set for char data
154      * in encapsulations. However, since CORBA says chars are
155      * only one octet, it is really the same as Latin-1.
156      */

157     public static final Entry UTF_8
158         = new Entry("UTF-8",
159                     UTF_8_VALUE,
160                     false,
161                     6);
162
163     /*
164      * At least in JDK 1.3, UCS-2 isn't one of the mandatory Java character
165      * encodings. However, our old ORBs require what they call UCS2, even
166      * though they didn't necessarily do the correct encoding of it.
167      *
168      * This is a special case for our legacy ORBs, and put as the last thing
169      * in our conversion list for wchar data.
170      *
171      * If a foreign ORB actually tries to speak UCS2 with us, it probably
172      * won't work! Beware!
173      */

174     public static final Entry UCS_2
175         = new Entry("UCS-2",
176                     UCS_2_VALUE,
177                     true,
178                     2);
179
180     /**
181      * This is the encoding older JavaSoft ORBs advertised as their
182      * CORBA char code set. Actually, they took the lower byte of
183      * the Java char. This is a 7-bit encoding, so they
184      * were really sending ISO8859-1.
185      */

186     public static final Entry ISO_646
187         = new Entry("US-ASCII",
188                     ISO_646_VALUE,
189                     true,
190                     1);
191
192     /**
193      * Given an OSF registry value, return the corresponding Entry.
194      * Returns null if an Entry for that value is unavailable.
195      */

196     public static Entry lookupEntry(int encodingValue) {
197         switch(encodingValue) {
198             case ISO_8859_1_VALUE:
199                 return OSFCodeSetRegistry.ISO_8859_1;
200             case UTF_16_VALUE:
201                 return OSFCodeSetRegistry.UTF_16;
202             case UTF_8_VALUE:
203                 return OSFCodeSetRegistry.UTF_8;
204             case ISO_646_VALUE:
205                 return OSFCodeSetRegistry.ISO_646;
206             case UCS_2_VALUE:
207                 return OSFCodeSetRegistry.UCS_2;
208             default:
209                 return null;
210         }
211     }
212 }
213
Popular Tags