1 20 21 package org.jacorb.orb.giop; 22 23 import org.omg.CONV_FRAME.*; 24 import org.omg.IOP.*; 25 26 import org.jacorb.orb.CDRInputStream; 27 import org.jacorb.orb.CDROutputStream; 28 29 public class CodeSet 30 { 31 public static final int ISO8859_1=0x00010001; 32 public static final int UTF16= 0x00010109; 35 public static final int UTF8 = 0x05010001; 37 38 public static String csName(int cs) 39 { 40 switch(cs) 41 { 42 case ISO8859_1: return "ISO-8859-1"; 43 case UTF16: return "UTF-16"; 44 case UTF8: return "UTF-8"; 45 } 46 return "Unknown TCS: " + Integer.toHexString(cs); 47 } 48 49 public static int getTCSDefault() 50 { 51 return ISO8859_1; 52 } 53 54 public static int getTCSWDefault() 55 { 56 return UTF16; 57 } 58 59 public static int getConversionDefault() 60 { 61 return UTF8; 62 } 63 64 68 public static int selectTCS( CodeSetComponentInfo cs_info ) 69 { 70 int with_native = selectCodeSet( cs_info.ForCharData, 71 getTCSDefault() ); 72 73 if( with_native == -1 ) 74 { 75 78 return selectCodeSet( cs_info.ForCharData, getConversionDefault() ); 79 } 80 else 81 { 82 return with_native; 83 } 84 } 85 86 90 public static int selectTCSW( CodeSetComponentInfo cs_info ) 91 { 92 int with_native = selectCodeSet( cs_info.ForWcharData, 93 getTCSWDefault() ); 94 95 if( with_native == -1 ) 96 { 97 100 return selectCodeSet( cs_info.ForWcharData, 101 getConversionDefault() ); 102 } 103 else 104 { 105 return with_native; 106 } 107 } 108 109 private static int selectCodeSet( CodeSetComponent cs_component, 110 int native_cs ) 111 { 112 if( cs_component.native_code_set == native_cs ) 114 { 115 return native_cs; 116 } 117 118 for( int i = 0; i < cs_component.conversion_code_sets.length; i++ ) 120 { 121 if( cs_component.conversion_code_sets[i] == native_cs ) 122 { 123 return native_cs; 124 } 125 } 126 127 return -1; 129 } 130 131 public static ServiceContext createCodesetContext( int tcs, int tcsw ) 132 { 133 CDROutputStream os = new CDROutputStream(); 135 os.beginEncapsulatedArray(); 136 CodeSetContextHelper.write( os, new CodeSetContext( tcs, tcsw )); 137 138 return new ServiceContext( TAG_CODE_SETS.value, 139 os.getBufferCopy() ); 140 } 141 142 public static CodeSetContext getCodeSetContext( ServiceContext[] contexts ) 143 { 144 for( int i = 0; i < contexts.length; i++ ) 145 { 146 if( contexts[i].context_id == TAG_CODE_SETS.value ) 147 { 148 CDRInputStream is = 150 new CDRInputStream( (org.omg.CORBA.ORB ) null, 151 contexts[i].context_data ); 152 is.openEncapsulatedArray(); 153 154 return CodeSetContextHelper.read( is ); 155 } 156 } 157 158 return null; 159 } 160 } 161 | Popular Tags |