1 22 package org.jboss.iiop.rmi.ir; 23 24 import org.omg.CORBA.Repository ; 25 import org.omg.CORBA.RepositoryPOATie; 26 import org.omg.CORBA.ORB ; 27 import org.omg.CORBA.IRObject ; 28 import org.omg.CORBA.DefinitionKind ; 29 import org.omg.CORBA.RepositoryOperations ; 30 import org.omg.CORBA.Contained ; 31 import org.omg.CORBA.ContainedHelper; 32 import org.omg.CORBA.TypeCode ; 33 import org.omg.CORBA.PrimitiveDef ; 34 import org.omg.CORBA.StringDef ; 35 import org.omg.CORBA.WstringDef ; 36 import org.omg.CORBA.SequenceDef ; 37 import org.omg.CORBA.ArrayDef ; 38 import org.omg.CORBA.FixedDef ; 39 import org.omg.CORBA.BAD_INV_ORDER ; 40 import org.omg.PortableServer.POA ; 41 42 import java.util.Map ; 43 import java.util.HashMap ; 44 import java.util.Iterator ; 45 46 import java.io.UnsupportedEncodingException ; 47 48 54 class RepositoryImpl 55 extends ContainerImpl 56 implements RepositoryOperations , LocalContainer 57 { 58 60 62 64 private static final org.jboss.logging.Logger logger = 65 org.jboss.logging.Logger.getLogger(RepositoryImpl.class); 66 67 69 public RepositoryImpl(ORB orb, POA poa, String name) 70 { 71 super(DefinitionKind.dk_Repository, null); 72 73 this.orb = orb; 74 this.poa = poa; 75 try { 76 oid = (name).getBytes("UTF-8"); 77 } catch (UnsupportedEncodingException ex) { 78 throw new RuntimeException ("UTF-8 encoding not supported."); 79 } 80 oidPrefix = name + ":"; 81 anonOidPrefix = oidPrefix + "anon"; 82 83 repository = this; 84 } 85 86 88 90 public IRObject getReference() 91 { 92 if (ref == null) { 93 ref = org.omg.CORBA.RepositoryHelper.narrow( 94 servantToReference(new RepositoryPOATie(this)) ); 95 } 96 return ref; 97 } 98 99 public void allDone() 100 throws IRConstructionException 101 { 102 super.allDone(); 103 104 Iterator iter = sequenceMap.values().iterator(); 106 while (iter.hasNext()) 107 ((SequenceDefImpl)iter.next()).allDone(); 108 } 109 110 public void shutdown() 111 { 112 for (long i = 1; i < nextPOAId; i++) { 114 try { 115 getPOA().deactivate_object(getAnonymousObjectId(i)); 116 } catch (org.omg.CORBA.UserException ex) { 117 logger.warn("Could not deactivate anonymous IR object", ex); 118 } 119 } 120 121 super.shutdown(); 123 } 124 125 127 public Contained lookup_id(java.lang.String search_id) 128 { 129 logger.debug("RepositoryImpl.lookup_id(\"" + search_id + "\") entered."); 130 LocalContained c = _lookup_id(search_id); 131 132 if (c == null) 133 return null; 134 135 return ContainedHelper.narrow(c.getReference()); 136 } 137 138 public TypeCode get_canonical_typecode(org.omg.CORBA.TypeCode tc) 139 { 140 logger.debug("RepositoryImpl.get_canonical_typecode() entered."); 141 return null; 143 } 144 145 public PrimitiveDef get_primitive(org.omg.CORBA.PrimitiveKind kind) 146 { 147 logger.debug("RepositoryImpl.get_primitive() entered."); 148 return null; 150 } 151 152 public StringDef create_string(int bound) 153 { 154 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 155 } 156 157 public WstringDef create_wstring(int bound) 158 { 159 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 160 } 161 162 public SequenceDef create_sequence(int bound, org.omg.CORBA.IDLType element_type) 163 { 164 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 165 } 166 167 public ArrayDef create_array(int length, org.omg.CORBA.IDLType element_type) 168 { 169 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 170 } 171 172 public FixedDef create_fixed(short digits, short scale) 173 { 174 throw new BAD_INV_ORDER ("Cannot change RMI/IIOP mapping."); 175 } 176 177 178 179 181 183 186 ORB orb = null; 187 188 191 POA poa = null; 192 193 196 private byte[] oid = null; 197 198 201 private String oidPrefix = null; 202 203 206 private String anonOidPrefix = null; 207 208 211 Map sequenceMap = new HashMap (); 212 213 216 Map sequenceIdMap = new HashMap (); 217 218 219 LocalContained _lookup_id(java.lang.String search_id) 220 { 221 logger.debug("RepositoryImpl._lookup_id(\"" + search_id + 222 "\") entered."); 223 if (search_id.startsWith("RMI:[")) 225 return (ValueBoxDefImpl)sequenceIdMap.get(search_id); 226 227 String name = scopedName(search_id); 229 logger.debug("RepositoryImpl._lookup_id(): scopedName=\"" + 230 scopedName(search_id) + "\""); 231 232 LocalContained ret = (name == null) ? null : _lookup(name); 235 logger.debug("RepositoryImpl._lookup_id(): returning " + 236 ((ret == null) ? "null" : "NOT null") ); 237 return ret; 238 } 239 240 SequenceDefImpl getSequenceImpl(TypeCode typeCode) 241 { 242 return (SequenceDefImpl)sequenceMap.get(typeCode); 243 } 244 245 void putSequenceImpl(String id, TypeCode typeCode, SequenceDefImpl sequence, 246 ValueBoxDefImpl valueBox) 247 { 248 sequenceIdMap.put(id, valueBox); 249 sequenceMap.put(typeCode, sequence); 250 } 251 252 String getObjectIdPrefix() 253 { 254 return oidPrefix; 255 } 256 257 259 262 protected byte[] getObjectId() 263 { 264 return (byte[])oid.clone(); 265 } 266 267 270 protected byte[] getAnonymousObjectId(long n) 271 { 272 String s = anonOidPrefix + Long.toString(n); 273 try { 274 return s.getBytes("UTF-8"); 275 } catch (UnsupportedEncodingException ex) { 276 throw new RuntimeException ("UTF-8 encoding not supported."); 277 } 278 } 279 280 286 protected byte[] getNextObjectId() 287 { 288 return getAnonymousObjectId(nextPOAId++); 289 } 290 291 292 294 297 private Repository ref = null; 298 299 302 private long nextPOAId = 1; 303 304 308 private String scopedName(String id) 309 { 310 if (id == null) 311 return null; 312 313 if (id.startsWith("IDL:")) { 314 316 if ("IDL:omg.org/CORBA/Object:1.0".equals(id) || 318 "IDL:omg.org/CORBA/ValueBase:1.0".equals(id)) 319 return null; 320 321 int idx2 = id.indexOf(':', 4); if (idx2 == -1) 324 return null; String base = id.substring(4, id.indexOf(':', 4)); 326 327 if (base.startsWith("omg.org")) 329 base = "org/omg" + base.substring(7); 330 if (base.startsWith("w3c.org")) 331 base = "org/w3c" + base.substring(7); 332 333 StringBuffer b = new StringBuffer (); 335 for (int i = 0; i < base.length(); ++i) { 336 char c = base.charAt(i); 337 338 if (c != '/') 339 b.append(c); 340 else 341 b.append("::"); 342 } 343 344 return b.toString(); 345 } else if (id.startsWith("RMI:")) { 346 348 int idx2 = id.indexOf(':', 4); if (idx2 == -1) 351 return null; String base = id.substring(4, id.indexOf(':', 4)); 353 354 StringBuffer b = new StringBuffer (); 356 for (int i = 0; i < base.length(); ++i) { 357 char c = base.charAt(i); 358 359 if (c != '.') 360 b.append(c); 361 else 362 b.append("::"); 363 } 364 365 return b.toString(); 366 } else 367 return null; 368 } 369 370 371 } 373 | Popular Tags |