1 26 package org.objectweb.openccm.explorer.CORBA; 27 28 import org.objectweb.util.explorer.core.common.lib.ClassResolver; 29 30 38 39 46 47 final class ModestInputStream { 48 private byte bytes[]; 49 private int index; 50 private boolean little_endian; 51 52 public ModestInputStream(byte bytes[]) { 53 this.bytes = bytes; 54 little_endian = bytes[0] != 0; 55 index = 1; 56 } 57 58 public boolean getEndian() { 59 return little_endian; 60 } 61 62 public byte readOctet() { 63 return bytes[index++]; 64 } 65 66 public int readULong() { 67 int al = index % 4; 68 if (al != 0) 69 index += 4 - al; 70 if (little_endian) 71 return ((bytes[index++]) & 0x000000ff) | ((bytes[index++] << 8) & 0x0000ff00) | ((bytes[index++] << 16) & 0x00ff0000) | ((bytes[index++] << 24) & 0xff000000); 72 else 73 return ((bytes[index++] << 24) & 0xff000000) | ((bytes[index++] << 16) & 0x00ff0000) | ((bytes[index++] << 8) & 0x0000ff00) | ((bytes[index++]) & 0x000000ff); 74 } 75 76 public String readString() { 77 int len = readULong() - 1; 78 String str = new String (bytes, index, len); 79 index += len; 80 if (readOctet() != 0) 81 throw new org.omg.CORBA.INV_OBJREF ("String should end with byte 0"); 82 return str; 83 } 84 } 85 86 92 99 public class TypageCORBA { 100 public static String fixName(String name) { 118 return name; 120 } 121 122 public static String idToClassName(String id, String suffix) { 127 String result = null; 128 129 if (id != null) { 130 if (id.startsWith("IDL:")) { 131 try { 132 StringBuffer buf = new StringBuffer (); 133 134 int end = id.lastIndexOf(':'); 135 String s; 136 if (end < 0) 137 s = id.substring(4); 138 else 139 s = id.substring(4, end); 140 141 int slash = s.indexOf('/'); 146 if (slash > 0) { 147 String prefix = s.substring(0, slash); 148 String rest = s.substring(slash + 1); 149 java.util.StringTokenizer tokenizer = new java.util.StringTokenizer (prefix, "."); 150 while (tokenizer.hasMoreTokens()) { 151 String tok = tokenizer.nextToken(); 152 buf.insert(0, fixName(tok) + "."); 153 } 154 155 s = rest; 156 } 157 158 java.util.StringTokenizer tokenizer = new java.util.StringTokenizer (s, "/"); 162 while (tokenizer.hasMoreTokens()) { 163 String tok = tokenizer.nextToken(); 164 buf.append(fixName(tok)); 165 if (tokenizer.hasMoreTokens()) 166 buf.append('.'); 167 } 168 169 result = buf.toString() + suffix; 170 } catch (IndexOutOfBoundsException ex) { result = null; 172 } 173 } 174 } 175 176 return result; 177 } 178 179 public static Class idToClass(String id, String suffix) { 184 Class result = null; 185 String className = idToClassName(id, suffix); 186 187 if (className != null) { 188 try { 189 result = ClassResolver.resolve(className); 190 } catch (ClassNotFoundException ex) { 191 } 193 } 194 195 return result; 196 } 197 198 202 static String decode_type_id(String ior) { 203 int nbytes = ior.length() - 4; 204 if ((nbytes & 1) == 1) 205 throw new org.omg.CORBA.INV_OBJREF ("Bad string length"); 206 nbytes /= 2; 207 byte bytes[] = new byte[nbytes]; 208 for (int i = 0, j = 4; i < nbytes; i++, j += 2) { 209 String bstr = ior.substring(j, j + 2); 210 try { 211 bytes[i] = (byte) Integer.parseInt(bstr, 16); 212 } catch (NumberFormatException exc) { 213 throw new org.omg.CORBA.INV_OBJREF ("Bad byte value: " + bstr); 214 } 215 } 216 217 ModestInputStream in = new ModestInputStream(bytes); 218 219 String result = in.readString(); 220 221 if((result == null) || (result.length() == 0)) 223 result = "IDL:omg.org/CORBA/Object:1.0"; 224 225 return result; 226 } 227 228 232 protected String type_id_; 233 234 public TypageCORBA(org.omg.CORBA.Object objref, org.omg.CORBA.ORB orb) { 235 String ior = null; 236 try { 237 ior = orb.object_to_string(objref); 238 } catch (Exception e) { 239 throw new ObjectToStringNotSupportedException(); 240 } 241 type_id_ = decode_type_id(ior); 242 } 243 244 public TypageCORBA(String ior) { 245 type_id_ = decode_type_id(ior); 246 } 247 248 public String getTypeID() { 249 return type_id_; 250 } 251 252 public String getJavaInterfaceName() { 253 return idToClassName(type_id_, ""); 254 } 255 256 public Class getJavaInterface() { 257 return idToClass(type_id_, ""); 258 } 259 260 public String getJavaHelperClassName() { 261 return idToClassName(type_id_, "Helper"); 262 } 263 264 public Class getJavaHelperClass() { 265 return idToClass(type_id_, "Helper"); 266 } 267 268 } 269 | Popular Tags |