1 7 15 16 package com.sun.corba.se.impl.encoding; 17 18 import java.util.StringTokenizer ; 19 import java.util.ArrayList ; 20 import java.util.Arrays ; 21 import java.util.List ; 22 import java.util.NoSuchElementException ; 23 import org.omg.CORBA.INITIALIZE ; 24 import org.omg.CORBA.CompletionStatus ; 25 26 import com.sun.corba.se.spi.logging.CORBALogDomains; 27 import com.sun.corba.se.impl.logging.ORBUtilSystemException; 28 29 public final class CodeSetComponentInfo { 30 31 36 public static final class CodeSetComponent { 37 int nativeCodeSet; 38 int[] conversionCodeSets; 39 40 public boolean equals( Object obj ) 41 { 42 if (this == obj) 43 return true ; 44 45 if (!(obj instanceof CodeSetComponent)) 46 return false ; 47 48 CodeSetComponent other = (CodeSetComponent)obj ; 49 50 return (nativeCodeSet == other.nativeCodeSet) && 51 Arrays.equals( conversionCodeSets, other.conversionCodeSets ) ; 52 } 53 54 public int hashCode() 55 { 56 int result = nativeCodeSet ; 57 for (int ctr=0; ctr<conversionCodeSets.length; ctr++) 58 result = 37*result + conversionCodeSets[ctr] ; 59 return result ; 60 } 61 62 public CodeSetComponent() {} 63 64 public CodeSetComponent(int nativeCodeSet, int[] conversionCodeSets) { 65 this.nativeCodeSet = nativeCodeSet; 66 if (conversionCodeSets == null) 67 this.conversionCodeSets = new int[0]; 68 else 69 this.conversionCodeSets = conversionCodeSets; 70 } 71 72 public void read(MarshalInputStream in) { 73 nativeCodeSet = in.read_ulong(); 74 int len = in.read_long(); 75 conversionCodeSets = new int[len]; 76 in.read_ulong_array(conversionCodeSets, 0, len); 77 78 } 79 80 public void write(MarshalOutputStream out) { 81 out.write_ulong(nativeCodeSet); 82 out.write_long(conversionCodeSets.length); 83 out.write_ulong_array(conversionCodeSets, 0, conversionCodeSets.length); 84 } 85 86 public String toString() { 87 StringBuffer sbuf = new StringBuffer ("CodeSetComponent("); 88 89 sbuf.append("native:"); 90 sbuf.append(Integer.toHexString(nativeCodeSet)); 91 sbuf.append(" conversion:"); 92 if (conversionCodeSets == null) 93 sbuf.append("null"); 94 else { 95 for (int i = 0; i < conversionCodeSets.length; i++) { 96 sbuf.append(Integer.toHexString(conversionCodeSets[i])); 97 sbuf.append(' '); 98 } 99 } 100 sbuf.append( ")" ) ; 101 102 return sbuf.toString(); 103 } 104 } 105 106 private CodeSetComponent forCharData; 107 private CodeSetComponent forWCharData; 108 109 public boolean equals( Object obj ) 110 { 111 if (this == obj) 112 return true ; 113 114 if (!(obj instanceof CodeSetComponentInfo)) 115 return false ; 116 117 CodeSetComponentInfo other = (CodeSetComponentInfo)obj ; 118 return forCharData.equals( other.forCharData ) && 119 forWCharData.equals( other.forWCharData ) ; 120 } 121 122 public int hashCode() 123 { 124 return forCharData.hashCode() ^ forWCharData.hashCode() ; 125 } 126 127 public String toString() { 128 StringBuffer sbuf = new StringBuffer ("CodeSetComponentInfo("); 129 130 sbuf.append("char_data:"); 131 sbuf.append(forCharData.toString()); 132 sbuf.append(" wchar_data:"); 133 sbuf.append(forWCharData.toString()); 134 sbuf.append(")"); 135 136 return sbuf.toString(); 137 } 138 139 public CodeSetComponentInfo() { 140 forCharData = CodeSetComponentInfo.JAVASOFT_DEFAULT_CODESETS.forCharData; 141 forWCharData = CodeSetComponentInfo.JAVASOFT_DEFAULT_CODESETS.forWCharData; 142 } 143 144 public CodeSetComponentInfo(CodeSetComponent charData, 145 CodeSetComponent wcharData) { 146 forCharData = charData; 147 forWCharData = wcharData; 148 } 149 150 public void read(MarshalInputStream in) { 151 forCharData = new CodeSetComponent(); 152 forCharData.read(in); 153 forWCharData = new CodeSetComponent(); 154 forWCharData.read(in); 155 } 156 157 public void write(MarshalOutputStream out) { 158 forCharData.write(out); 159 forWCharData.write(out); 160 } 161 162 public CodeSetComponent getCharComponent() { 163 return forCharData; 164 } 165 166 public CodeSetComponent getWCharComponent() { 167 return forWCharData; 168 } 169 170 173 public static final class CodeSetContext { 174 private int char_data; 175 private int wchar_data; 176 177 public CodeSetContext() {} 178 179 public CodeSetContext(int charEncoding, int wcharEncoding) { 180 char_data = charEncoding; 181 wchar_data = wcharEncoding; 182 } 183 184 public void read(MarshalInputStream in) { 185 char_data = in.read_ulong(); 186 wchar_data = in.read_ulong(); 187 } 188 189 public void write(MarshalOutputStream out) { 190 out.write_ulong(char_data); 191 out.write_ulong(wchar_data); 192 } 193 194 public int getCharCodeSet() { 195 return char_data; 196 } 197 198 public int getWCharCodeSet() { 199 return wchar_data; 200 } 201 202 public String toString() { 203 StringBuffer sbuf = new StringBuffer (); 204 sbuf.append("CodeSetContext char set: "); 205 sbuf.append(Integer.toHexString(char_data)); 206 sbuf.append(" wchar set: "); 207 sbuf.append(Integer.toHexString(wchar_data)); 208 return sbuf.toString(); 209 } 210 } 211 212 238 public static final CodeSetComponentInfo JAVASOFT_DEFAULT_CODESETS; 239 static { 240 CodeSetComponent charData 241 = new CodeSetComponent(OSFCodeSetRegistry.ISO_8859_1.getNumber(), 242 new int[] { 243 OSFCodeSetRegistry.UTF_8.getNumber(), 244 OSFCodeSetRegistry.ISO_646.getNumber() 245 }); 246 247 CodeSetComponent wcharData 248 = new CodeSetComponent(OSFCodeSetRegistry.UTF_16.getNumber(), 249 new int[] 250 { 251 OSFCodeSetRegistry.UCS_2.getNumber() 252 }); 253 254 JAVASOFT_DEFAULT_CODESETS = new CodeSetComponentInfo(charData, wcharData); 255 } 256 257 268 public static CodeSetComponent createFromString(String str) { 269 ORBUtilSystemException wrapper = ORBUtilSystemException.get( 270 CORBALogDomains.RPC_ENCODING ) ; 271 272 if (str == null || str.length() == 0) 273 throw wrapper.badCodeSetString() ; 274 275 StringTokenizer stok = new StringTokenizer (str, ", ", false); 276 int nativeSet = 0; 277 int conversionInts[] = null; 278 279 try { 280 281 nativeSet = Integer.decode(stok.nextToken()).intValue(); 283 284 if (OSFCodeSetRegistry.lookupEntry(nativeSet) == null) 285 throw wrapper.unknownNativeCodeset( new Integer (nativeSet) ) ; 286 287 List conversionList = new ArrayList (10); 288 289 while (stok.hasMoreTokens()) { 292 293 Integer value = Integer.decode(stok.nextToken()); 295 296 if (OSFCodeSetRegistry.lookupEntry(value.intValue()) == null) 297 throw wrapper.unknownConversionCodeSet( value ) ; 298 299 conversionList.add(value); 300 } 301 302 conversionInts = new int[conversionList.size()]; 303 304 for (int i = 0; i < conversionInts.length; i++) 305 conversionInts[i] = ((Integer )conversionList.get(i)).intValue(); 306 307 } catch (NumberFormatException nfe) { 308 throw wrapper.invalidCodeSetNumber( nfe ) ; 309 } catch (NoSuchElementException nsee) { 310 throw wrapper.invalidCodeSetString( nsee, str ) ; 311 } 312 313 return new CodeSetComponent(nativeSet, conversionInts); 316 } 317 318 321 public static final CodeSetContext LOCAL_CODE_SETS 322 = new CodeSetContext(OSFCodeSetRegistry.ISO_8859_1.getNumber(), 323 OSFCodeSetRegistry.UTF_16.getNumber()); 324 } 325 326 | Popular Tags |