1 package org.jacorb.ir; 2 3 22 23 import org.omg.CORBA.ORB ; 24 import org.omg.PortableServer.*; 25 26 import java.util.*; 27 import java.io.*; 28 29 import org.apache.avalon.framework.logger.Logger; 30 import org.apache.avalon.framework.configuration.*; 31 32 45 46 public class RepositoryImpl 47 extends IRObject 48 implements org.omg.CORBA.RepositoryOperations , Configurable 49 50 { 51 private String classpath; 52 private Hashtable contained = new Hashtable(); 53 private Container[] containers ; 54 private Container delegate ; 55 56 private POA poa; 57 private ClassLoader loader; 58 59 public static char fileSeparator = 60 System.getProperty("file.separator").charAt(0); 61 62 public static String pathSeparator = 63 System.getProperty("path.separator"); 64 65 66 private org.jacorb.config.Configuration configuration = null; 67 68 69 private Logger logger = null; 70 71 76 77 public RepositoryImpl( String classpath, 78 String outfile, 79 java.net.URLClassLoader loader ) 81 throws Exception 85 { 86 this.classpath = classpath; 87 this.loader = loader; 88 def_kind = org.omg.CORBA.DefinitionKind.dk_Repository; 89 name = "Repository"; 90 91 94 StringTokenizer strtok = 95 new StringTokenizer( classpath , java.io.File.pathSeparator ); 96 98 String [] paths = 99 new String [ strtok.countTokens() ]; 100 101 containers = 102 new Container[ paths.length ]; 103 104 org.omg.CORBA.Object obj; 105 106 org.omg.CORBA.ORB orb = 107 org.omg.CORBA.ORB.init( new String [0], null ); 108 109 this.configure(((org.jacorb.orb.ORB) orb).getConfiguration()); 110 111 poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); 112 113 org.omg.CORBA.Repository myRef = 114 org.omg.CORBA.RepositoryHelper.narrow( 115 poa.servant_to_reference( new org.omg.CORBA.RepositoryPOATie( this ) ) ); 116 117 118 for( int i = 0; strtok.hasMoreTokens(); i++ ) 119 { 120 paths[i] = strtok.nextToken(); 121 122 if (this.logger.isDebugEnabled()) 123 { 124 logger.debug("found path: " + paths[i]); 125 } 126 127 containers[i] = new Container( this, paths[i], null, 128 loader, poa, logger ); 129 } 130 131 delegate = containers[0]; 133 134 PrintWriter out = new PrintWriter( new FileOutputStream( outfile ), true); 135 out.println( orb.object_to_string( myRef ) ); 136 setReference( myRef ); 137 out.close(); 138 poa.the_POAManager().activate(); 139 140 if (this.logger.isInfoEnabled()) 141 { 142 java.net.URL urls[] = loader.getURLs(); 144 StringBuffer sb = 148 new StringBuffer ("IR configured for class path: "); 149 for( int i = 0; i < urls.length; i++ ) 150 { 151 sb.append( urls[i].toString() + "\n"); 152 } 153 154 logger.info(sb.toString()); 155 } 156 } 157 158 public void configure(Configuration myConfiguration) 159 throws ConfigurationException 160 { 161 this.configuration = (org.jacorb.config.Configuration)myConfiguration; 162 this.logger = configuration.getNamedLogger("jacorb.ir"); 163 } 164 165 167 173 174 private String idToScopedName( String id ) 175 { 176 String scoped = ""; 177 178 if( !id.startsWith("IDL:") || 179 !id.endsWith( ":1.0")) 180 return null; 181 182 184 String base = id.substring( id.indexOf(':')+1, 185 id.lastIndexOf(':')).replace( fileSeparator, '/' ); 186 187 if( base.startsWith( "omg.org") ) 188 base = "org/omg" + base.substring( 7 ); 189 190 StringTokenizer strtok = new StringTokenizer( base, "/" ); 191 192 for( int i = 0; strtok.hasMoreTokens(); i++ ) 193 scoped = scoped + "::" + strtok.nextToken(); 194 195 return scoped; 196 197 } 198 199 205 206 public org.omg.CORBA.Contained lookup_id( String search_id ) 207 { 208 if (this.logger.isDebugEnabled()) 209 { 210 this.logger.debug("IR lookup_id: " + search_id ); 211 } 212 213 String name = idToScopedName( search_id ); 214 if( name == null ) 215 return null; 216 else 217 return lookup( name ); 218 } 219 220 public org.omg.CORBA.PrimitiveDef get_primitive(org.omg.CORBA.PrimitiveKind kind) 221 { 222 try 223 { 224 return org.omg.CORBA.PrimitiveDefHelper.narrow( 225 poa.servant_to_reference( 226 new org.omg.CORBA.PrimitiveDefPOATie( 227 new org.jacorb.ir.PrimitiveDef( kind.value() )))); 228 } 229 catch( Exception e ) 230 { 231 e.printStackTrace(); 232 return null; 233 } 234 } 235 236 239 240 public org.omg.CORBA.StringDef create_string(int bound) 241 { 242 return null; 243 } 244 245 248 249 public org.omg.CORBA.WstringDef create_wstring(int bound) 250 { 251 return null; 252 } 253 254 257 258 public org.omg.CORBA.FixedDef create_fixed(short digits, short scale) 259 { 260 return null; 261 } 262 263 266 267 public org.omg.CORBA.SequenceDef create_sequence(int bound, 268 org.omg.CORBA.IDLType element_type) 269 { 270 return null; 271 } 272 273 276 277 public org.omg.CORBA.ArrayDef create_array(int length, 278 org.omg.CORBA.IDLType element_type) 279 { 280 return null; 281 } 282 283 284 285 public org.omg.CORBA.TypeCode get_canonical_typecode(org.omg.CORBA.TypeCode tc) 286 { 287 return null; 288 } 289 290 291 293 300 301 302 public org.omg.CORBA.Contained lookup( String name ) 303 { 304 if (this.logger.isDebugEnabled()) 305 { 306 this.logger.debug("IR lookup : " + name ); 307 } 308 309 org.omg.CORBA.Contained result = null; 310 for( int i = 0; i < containers.length; i++ ) 311 { 312 result = containers[i].lookup( name ); 313 if( result != null ) 314 break; 315 } 316 return result; 317 } 318 319 331 332 public org.omg.CORBA.Contained [] lookup_name( 333 String search_name, 334 int levels_to_search, 335 org.omg.CORBA.DefinitionKind limit_type, 336 boolean exclude_inherited ) 337 { 338 if (this.logger.isDebugEnabled()) 339 { 340 this.logger.debug("IR lookup_name: " + search_name); 341 } 342 343 org.omg.CORBA.Contained [] result = null; 344 Vector intermediate = new Vector(); 345 346 for( int i = 0; i < containers.length; i++ ) 347 { 348 intermediate.addElement( containers[i].lookup_name( search_name, 349 levels_to_search, 350 limit_type, 351 exclude_inherited )); 352 } 353 354 int size = 0; 355 for( int i = 0; i < intermediate.size(); i++ ) 356 { 357 size += ((Object [])intermediate.elementAt(i)).length; 358 } 359 result = new org.omg.CORBA.Contained [size]; 360 int start = 0; 361 362 for( int i = 0; i < intermediate.size(); i++ ) 363 { 364 org.omg.CORBA.Contained [] src = 365 (org.omg.CORBA.Contained [])intermediate.elementAt(i); 366 367 System.arraycopy( src, 0, result, start, src.length ); 368 start += src.length; 369 } 370 371 return result; 372 } 373 374 375 381 382 public org.omg.CORBA.Contained [] contents(org.omg.CORBA.DefinitionKind limit_type, 383 boolean exclude_inherited) 384 { 385 org.omg.CORBA.Contained [] result = null; 386 Vector intermediate = new Vector(); 387 for( int i = 0; i < containers.length; i++ ) 388 { 389 intermediate.addElement( containers[i].contents( limit_type, 390 exclude_inherited )); 391 } 392 393 int size = 0; 394 for( int i = 0; i < intermediate.size(); i++ ) 395 { 396 size += ((Object [])intermediate.elementAt(i)).length; 397 } 398 399 result = new org.omg.CORBA.Contained [size]; 400 int start = 0; 401 402 for( int i = 0; i < intermediate.size(); i++ ) 404 { 405 org.omg.CORBA.Contained [] src = 406 (org.omg.CORBA.Contained [])intermediate.elementAt(i); 407 408 System.arraycopy( src, 0, result, start, src.length ); 409 start += src.length; 410 } 411 412 return result; 413 } 414 415 416 423 424 public org.omg.CORBA.ContainerPackage.Description[] describe_contents( 425 org.omg.CORBA.DefinitionKind limit_type, 426 boolean exclude_inherited, 427 int max_returned_objs) 428 { 429 org.omg.CORBA.Contained [] c = contents( limit_type, exclude_inherited ); 430 int size; 431 if( max_returned_objs > c.length ) 432 size = max_returned_objs; 433 else 434 size = c.length; 435 org.omg.CORBA.ContainerPackage.Description[] result = 436 new org.omg.CORBA.ContainerPackage.Description[size]; 437 for( int i = 0; i < size; i++ ) 438 { 439 result[i] = new org.omg.CORBA.ContainerPackage.Description(); 440 org.omg.CORBA.ContainedPackage.Description cd_descr = c[i].describe(); 441 result[i].contained_object = c[i]; 442 result[i].kind = cd_descr.kind; 443 result[i].value = cd_descr.value; 444 } 445 return result; 446 } 447 448 449 void define() 450 { 451 } 453 454 public void loadContents() 455 { 456 if (this.logger.isInfoEnabled()) 457 { 458 this.logger.info("Repository loads contents..."); 459 } 460 461 for( int i = 0; i < containers.length; i++ ) 462 { 463 containers[i].loadContents(); 464 } 465 for( int i = 0; i < containers.length; i++ ) 466 { 467 containers[i].define(); 468 } 469 470 if (this.logger.isInfoEnabled()) 471 { 472 this.logger.info("Repository contents loaded"); 473 } 474 } 475 476 public org.omg.CORBA.ModuleDef create_module( String id, 477 String name, 478 String version) 479 { 480 return delegate.create_module( id, name, version); 481 } 482 483 public org.omg.CORBA.ConstantDef create_constant( String id, String name, 484 String version, 485 org.omg.CORBA.IDLType type, 486 org.omg.CORBA.Any value) 487 { 488 return delegate.create_constant( id, name, version, type, value); 489 } 490 491 public org.omg.CORBA.StructDef create_struct( String id, 492 String name, 493 String version, 494 org.omg.CORBA.StructMember [] members) 495 { 496 return delegate.create_struct( id, name, version, members); 497 } 498 499 public org.omg.CORBA.UnionDef create_union( String id, 500 String name, 501 String version, 502 org.omg.CORBA.IDLType 503 discriminator_type, 504 org.omg.CORBA.UnionMember [] members) 505 { 506 return delegate.create_union( id, name, version, discriminator_type, members); 507 } 508 509 public org.omg.CORBA.EnumDef create_enum( String id, 510 String name, 511 String version, 512 String [] members) 513 { 514 return delegate.create_enum( id, name, version, members); 515 } 516 517 public org.omg.CORBA.AliasDef create_alias( String id, 518 String name, 519 String version, 520 org.omg.CORBA.IDLType original_type) 521 { 522 return delegate.create_alias( id, name, version, original_type); 523 } 524 525 public org.omg.CORBA.ExceptionDef create_exception( String id, 526 String name, 527 String version, 528 org.omg.CORBA.StructMember [] member ) 529 { 530 return delegate.create_exception(id, name, version, member); 531 } 532 533 536 537 public org.omg.CORBA.InterfaceDef create_interface(String id, 538 String name, 539 String version, 540 org.omg.CORBA.InterfaceDef [] base_interfaces, 541 boolean is_abstract ) 542 { 543 return delegate.create_interface( id, name, version, 544 base_interfaces, is_abstract ); 545 } 546 547 550 551 public org.omg.CORBA.ValueBoxDef create_value_box(String id, 552 String name, 553 String version, 554 org.omg.CORBA.IDLType type) 555 { 556 return delegate.create_value_box(id, name, version, type); 557 } 558 559 562 563 public org.omg.CORBA.ValueDef create_value( 564 String id, 565 String name, 566 String version, 567 boolean is_custom, 568 boolean is_abstract, 569 org.omg.CORBA.ValueDef base_value, 570 boolean is_truncatable, 571 org.omg.CORBA.ValueDef [] abstract_base_values, 572 org.omg.CORBA.InterfaceDef [] supported_interfaces, 573 org.omg.CORBA.Initializer [] initializers) 574 { 575 return delegate.create_value(id, name, version,is_custom, is_abstract, base_value, is_truncatable, 576 abstract_base_values, supported_interfaces, initializers); 577 } 578 579 580 583 584 public org.omg.CORBA.NativeDef create_native(String id, 585 String name, 586 String version) 587 { 588 return delegate.create_native( id, name, version); 589 } 590 591 592 public void destroy() 593 { 594 delegate.destroy(); 595 } 596 597 598 } 599 600 601 602 603 604 605 606 607 608 609 | Popular Tags |