1. /*
  2. * @(#)OSFCodeSetRegistry.java 1.7 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.internal.core;
  8. /**
  9. *
  10. * Information from the OSF code set registry version 1.2g.
  11. *
  12. * Use the Entry corresponding to the desired code set.
  13. *
  14. * Consider rename to CodeSetRegistry since OSF is dead.
  15. */
  16. public final class OSFCodeSetRegistry
  17. {
  18. // Numbers from the OSF code set registry version 1.2g.
  19. //
  20. // Please see the individual Entry definitions for
  21. // more details.
  22. private static final int ISO_8859_1_VALUE = 0x00010001;
  23. private static final int UTF_16_VALUE = 0x00010109;
  24. private static final int UTF_8_VALUE = 0x05010001;
  25. private static final int UCS_2_VALUE = 0x00010100;
  26. private static final int ISO_646_VALUE = 0x00010020;
  27. private OSFCodeSetRegistry() {}
  28. /**
  29. * An entry in the OSF registry which allows users
  30. * to find out the equivalent Java character encoding
  31. * name as well as some other facts from the registry.
  32. */
  33. public final static class Entry
  34. {
  35. private String javaName;
  36. private int encodingNum;
  37. private boolean isFixedWidth;
  38. private int maxBytesPerChar;
  39. private Entry(String javaName,
  40. int encodingNum,
  41. boolean isFixedWidth,
  42. int maxBytesPerChar) {
  43. this.javaName = javaName;
  44. this.encodingNum = encodingNum;
  45. this.isFixedWidth = isFixedWidth;
  46. this.maxBytesPerChar = maxBytesPerChar;
  47. }
  48. /**
  49. * Returns the Java equivalent name. If the encoding has
  50. * an optional byte order marker, this name will map to the
  51. * Java encoding that includes the marker.
  52. */
  53. public String getName() {
  54. return javaName;
  55. }
  56. /**
  57. * Get the OSF registry number for this code set.
  58. */
  59. public int getNumber() {
  60. return encodingNum;
  61. }
  62. /**
  63. * Is this a fixed or variable width code set? (In CORBA
  64. * terms, "non-byte-oriented" or a "byte-oriented"
  65. * code set, respectively)
  66. */
  67. public boolean isFixedWidth() {
  68. return isFixedWidth;
  69. }
  70. public int getMaxBytesPerChar() {
  71. return maxBytesPerChar;
  72. }
  73. /**
  74. * First checks reference equality since it's expected
  75. * people will use the pre-defined constant Entries.
  76. */
  77. public boolean equals(Object obj) {
  78. if (this == obj)
  79. return true;
  80. if (!(obj instanceof OSFCodeSetRegistry.Entry))
  81. return false;
  82. OSFCodeSetRegistry.Entry other
  83. = (OSFCodeSetRegistry.Entry)obj;
  84. return (javaName.equals(other.javaName) &&
  85. encodingNum == other.encodingNum &&
  86. isFixedWidth == other.isFixedWidth &&
  87. maxBytesPerChar == other.maxBytesPerChar);
  88. }
  89. /**
  90. * Uses the registry number as the hash code.
  91. */
  92. public int hashCode() {
  93. return encodingNum;
  94. }
  95. }
  96. /**
  97. * 8-bit encoding required for GIOP 1.0, and used as the char set
  98. * when nothing else is specified.
  99. */
  100. public static final Entry ISO_8859_1
  101. = new Entry("ISO-8859-1",
  102. ISO_8859_1_VALUE,
  103. true,
  104. 1);
  105. /**
  106. * UTF-16 as specified in the OSF registry has an optional
  107. * byte order marker. UTF-16BE and UTF-16LE are not in the OSF
  108. * registry since it is no longer being developed. When the OMG
  109. * switches to the IANA registry, these can be public. Right
  110. * now, they're used internally by CodeSetConversion.
  111. */
  112. static final Entry UTF_16BE
  113. = new Entry("UTF-16BE",
  114. -1,
  115. true,
  116. 2);
  117. static final Entry UTF_16LE
  118. = new Entry("UTF-16LE",
  119. -2,
  120. true,
  121. 2);
  122. /**
  123. * Fallback wchar code set.
  124. *
  125. * In the resolution of issue 3405b, UTF-16 defaults to big endian, so
  126. * doesn't have to have a byte order marker. Unfortunately, this has to be
  127. * a special case for compatibility.
  128. */
  129. public static final Entry UTF_16
  130. = new Entry("UTF-16",
  131. UTF_16_VALUE,
  132. true,
  133. 4);
  134. /**
  135. * Fallback char code set. Also the code set for char data
  136. * in encapsulations. However, since CORBA says chars are
  137. * only one octet, it is really the same as Latin-1.
  138. */
  139. public static final Entry UTF_8
  140. = new Entry("UTF-8",
  141. UTF_8_VALUE,
  142. false,
  143. 6);
  144. /*
  145. * At least in JDK 1.3, UCS-2 isn't one of the mandatory Java character
  146. * encodings. However, our old ORBs require what they call UCS2, even
  147. * though they didn't necessarily do the correct encoding of it.
  148. *
  149. * This is a special case for our legacy ORBs, and put as the last thing
  150. * in our conversion list for wchar data.
  151. *
  152. * If a foreign ORB actually tries to speak UCS2 with us, it probably
  153. * won't work! Beware!
  154. */
  155. public static final Entry UCS_2
  156. = new Entry("UCS-2",
  157. UCS_2_VALUE,
  158. true,
  159. 2);
  160. /**
  161. * This is the encoding older JavaSoft ORBs advertised as their
  162. * CORBA char code set. Actually, they took the lower byte of
  163. * the Java char. This is a 7-bit encoding, so they
  164. * were really sending ISO8859-1.
  165. */
  166. public static final Entry ISO_646
  167. = new Entry("US-ASCII",
  168. ISO_646_VALUE,
  169. true,
  170. 1);
  171. /**
  172. * Given an OSF registry value, return the corresponding Entry.
  173. * Returns null if an Entry for that value is unavailable.
  174. */
  175. public static Entry lookupEntry(int encodingValue) {
  176. switch(encodingValue) {
  177. case ISO_8859_1_VALUE:
  178. return OSFCodeSetRegistry.ISO_8859_1;
  179. case UTF_16_VALUE:
  180. return OSFCodeSetRegistry.UTF_16;
  181. case UTF_8_VALUE:
  182. return OSFCodeSetRegistry.UTF_8;
  183. case ISO_646_VALUE:
  184. return OSFCodeSetRegistry.ISO_646;
  185. case UCS_2_VALUE:
  186. return OSFCodeSetRegistry.UCS_2;
  187. default:
  188. return null;
  189. }
  190. }
  191. }