1 package org.jacorb.ir; 2 3 22 23 import java.util.*; 24 import java.io.*; 25 26 import org.omg.CORBA.INTF_REPOS ; 27 import org.omg.PortableServer.POA ; 28 29 import org.apache.avalon.framework.logger.Logger; 30 31 public class Container 32 extends IRObject 33 implements org.omg.CORBA.ContainerOperations 34 { 35 protected static char fileSeparator = 36 System.getProperty("file.separator").charAt(0); 37 38 protected IRObject delegator; 39 40 41 protected Hashtable contained = new Hashtable(); 42 43 44 protected Hashtable containedLocals = new Hashtable(); 45 46 protected File my_dir = null; 47 protected String path = null; 48 protected String full_name = null; 49 50 51 protected org.omg.CORBA.Container this_container; 52 53 54 protected org.omg.CORBA.Container defined_in; 55 protected org.omg.CORBA.Repository containing_repository; 56 57 protected boolean defined = false; 58 59 private ClassLoader loader; 60 private POA poa; 61 private Logger logger; 62 63 65 66 public Container( IRObject delegator, 67 String path, 68 String full_name, 69 ClassLoader loader, 70 POA poa, 71 Logger logger ) 72 { 73 this.loader = loader; 74 this.poa = poa; 75 this.logger = logger; 76 this.delegator = delegator; 77 this.path = path; 78 this.full_name = full_name; 79 80 my_dir = new File( path + fileSeparator + 81 ( full_name != null ? full_name : "" ) ); 82 83 if ( ! my_dir.isDirectory()) 84 { 85 throw new INTF_REPOS ("no directory : " + path + fileSeparator + full_name); 86 } 87 88 this.name = delegator.getName(); 89 90 if (this.logger.isDebugEnabled()) 91 { 92 this.logger.debug("New Container full_name " + 93 full_name + " name : " + name + 94 " path: " + path); 95 } 96 } 98 99 101 102 void loadContents() 103 { 104 this_container = 105 org.omg.CORBA.ContainerHelper.narrow( delegator.getReference()); 106 if (this_container == null) 107 { 108 throw new INTF_REPOS ("no container !"); 109 } 110 111 if( delegator instanceof Contained ) 112 { 113 containing_repository = ((Contained)delegator).containing_repository(); 114 defined_in = ((Contained)delegator).defined_in(); 115 } 116 else 117 { 118 containing_repository = org.omg.CORBA. 119 RepositoryHelper.narrow( delegator.getReference()); 120 defined_in = containing_repository; 121 } 122 123 if (containing_repository == null) 124 { 125 throw new INTF_REPOS ("no containing repository"); 126 } 127 128 String [] classes; 129 String [] dirs; 130 131 134 classes = my_dir.list( new IRFilenameFilter(".class") ); 135 dirs = my_dir.list( new IRFilenameFilter( null ) ); 136 137 if( classes != null) 139 { 140 String prefix = 141 ( full_name != null ? full_name + fileSeparator : ""); 142 143 for( int j = 0; j< classes.length; j++ ) 144 { 145 try 146 { 147 if (this.logger.isDebugEnabled()) 148 { 149 this.logger.debug("Container " +name+ " tries " + 150 prefix + 151 classes[j].substring( 0, classes[j].indexOf(".class"))); 152 } 153 154 Class cl = 155 this.loader.loadClass( 156 ( prefix + 157 classes[j].substring( 0, classes[j].indexOf(".class")) 158 ).replace( fileSeparator, '.') ); 159 160 Contained containedObject = 161 Contained.createContained( cl, 162 path, 163 this_container, 164 containing_repository, 165 this.logger, 166 this.loader, 167 this.poa ); 168 if( containedObject == null ) 169 { 170 if (this.logger.isDebugEnabled()) 171 { 172 this.logger.debug("Container: nothing created for " 173 + cl.getClass().getName()); 174 } 175 continue; 176 } 177 178 org.omg.CORBA.Contained containedRef = 179 Contained.createContainedReference(containedObject, 180 this.logger, 181 this.poa); 182 183 containedRef.move( this_container, 184 containedRef.name(), 185 containedRef.version() ); 186 187 if (this.logger.isDebugEnabled()) 188 { 189 this.logger.debug("Container " + prefix + 190 " loads "+ containedRef.name()); 191 } 192 193 contained.put( containedRef.name() , containedRef ); 194 containedLocals.put( containedRef.name(), containedObject ); 195 if( containedObject instanceof ContainerType ) 196 ((ContainerType)containedObject).loadContents(); 197 198 } 199 catch ( java.lang.Throwable e ) 200 { 201 this.logger.error("Caught exception", e); 202 } 203 } 204 } 205 206 if( dirs != null) 207 { 208 for( int k = 0; k < dirs.length; k++ ) 209 { 210 if( !dirs[k].endsWith("Package")) 211 { 212 File f = new File( my_dir.getAbsolutePath() + 213 fileSeparator + 214 dirs[k] ); 215 try 216 { 217 String [] classList = f.list(); 218 if( classList != null && classList.length > 0) 219 { 220 226 Class moduleClass = 227 this.loader.loadClass( 228 ( 229 ( full_name != null ? full_name + "." + dirs[k]: dirs[k] ) + 230 "." + "_" + dirs[k] + "Module" ).replace( fileSeparator, '.')); 231 232 ModuleDef m = 233 new ModuleDef( path, 234 ( full_name != null ? 235 full_name + fileSeparator : 236 "" 237 ) + dirs[k], 238 this_container, 239 containing_repository, 240 this.loader, 241 this.poa, 242 this.logger); 243 244 org.omg.CORBA.ModuleDef moduleRef = 245 org.omg.CORBA.ModuleDefHelper.narrow( 246 this.poa.servant_to_reference( 247 new org.omg.CORBA.ModuleDefPOATie( m ) )); 248 249 m.setReference( moduleRef ); 250 m.loadContents(); 251 252 if (this.logger.isDebugEnabled()) 253 { 254 this.logger.debug("Container " + 255 full_name + 256 " puts module " + dirs[k]); 257 } 258 259 m.move( this_container, m.name(), m.version() ); 260 contained.put( m.name() , moduleRef ); 261 containedLocals.put( m.name(), m ); 262 } 263 } 264 catch( ClassNotFoundException c ) 265 { 266 this.logger.error("No module meta data: " + 267 c.getMessage(), c ); 268 } 269 catch ( Exception e ) 270 { 271 this.logger.error("Caught Exception", e); 272 } 273 } 274 } 275 } 276 } 277 278 void define() 279 { 280 if (this.logger.isDebugEnabled()) 281 { 282 this.logger.debug("Container " + full_name + " defining..."); 283 } 284 285 for( Enumeration e = containedLocals.elements(); 286 e.hasMoreElements(); 287 ((IRObject)e.nextElement()).define()) 288 ; 289 290 defined = true; 291 292 if (this.logger.isDebugEnabled()) 293 { 294 this.logger.debug("Container " + full_name + " defined"); 295 } 296 } 297 298 299 public org.omg.CORBA.Contained [] contents(org.omg.CORBA.DefinitionKind limit_type, 300 boolean exclude_inherited) 301 { 302 if ( ! defined) 303 { 304 throw new INTF_REPOS ("contents undefined"); 305 } 306 307 Hashtable filtered = new Hashtable(); 308 309 if( limit_type.value() == org.omg.CORBA.DefinitionKind._dk_all ) 310 { 311 filtered = contained; 312 } 313 else 314 { 315 Enumeration f = contained.keys(); 316 while( f.hasMoreElements() ) 317 { 318 Object k = f.nextElement(); 319 org.omg.CORBA.Contained c = 320 (org.omg.CORBA.Contained )contained.get( k ); 321 if( c.def_kind().value() == limit_type.value() ) 322 filtered.put( k, c ); 323 } 324 } 325 326 Enumeration e = filtered.elements(); 327 org.omg.CORBA.Contained [] result = 328 new org.omg.CORBA.Contained [ filtered.size() ]; 329 330 for( int i = 0; i < filtered.size(); i++ ) 331 result[i] = (org.omg.CORBA.Contained )e.nextElement(); 332 333 return result; 334 } 335 336 339 340 public org.omg.CORBA.Contained lookup( String scopedname ) 341 { 342 String top_level_name; 343 String rest_of_name; 344 String name; 345 346 if( scopedname.startsWith("::") ) 347 { 348 name = scopedname.substring(2); 349 } 350 else 351 name = scopedname; 352 353 if( name.indexOf("::") > 0 ) 354 { 355 top_level_name = name.substring( 0, name.indexOf("::") ); 356 rest_of_name = name.substring( name.indexOf("::") + 2); 357 } 358 else 359 { 360 top_level_name = name; 361 rest_of_name = null; 362 } 363 364 org.omg.CORBA.Contained top = 365 (org.omg.CORBA.Contained )contained.get( top_level_name ); 366 367 if( top == null ) 368 { 369 if (this.logger.isDebugEnabled()) 370 { 371 this.logger.debug("Container " + this.name + 372 " top " + top_level_name + " not found "); 373 } 374 return null; 375 } 376 377 if( rest_of_name == null ) 378 { 379 return top; 380 } 381 else 382 { 383 org.omg.CORBA.Container topContainer = 384 org.omg.CORBA.ContainerHelper.narrow( top ); 385 if( topContainer != null ) 386 { 387 return topContainer.lookup( rest_of_name ); 388 } 389 else 390 { 391 if (this.logger.isDebugEnabled()) 392 { 393 this.logger.debug("Container " + this.name +" " + 394 scopedname + " not found, top " + 395 top.getClass().getName()); 396 } 397 return null; 398 } 399 } 400 } 401 402 public org.omg.CORBA.Contained [] lookup_name( String search_name, 403 int levels_to_search, 404 org.omg.CORBA.DefinitionKind limit_type, 405 boolean exclude_inherited) 406 { 407 if( levels_to_search == 0 ) 408 return null; 409 410 org.omg.CORBA.Contained [] c = 411 contents( limit_type, exclude_inherited ); 412 413 Hashtable found = new Hashtable(); 414 415 for( int i = 0; i < c.length; i++) 416 if( c[i].name().equals( search_name ) ) 417 found.put( c[i], "" ); 418 419 if( levels_to_search > 1 || levels_to_search == -1 ) 420 { 421 for( int i = 0; i < c.length; i++) 423 { 424 if( c[i] instanceof org.omg.CORBA.Container ) 425 { 426 org.omg.CORBA.Contained [] tmp_seq = 427 ((org.omg.CORBA.Container )c[i]).lookup_name( search_name, 428 levels_to_search-1, 429 limit_type, 430 exclude_inherited); 431 if( tmp_seq != null ) 432 for( int j = 0; j < tmp_seq.length; j++) 433 found.put( tmp_seq[j], "" ); 434 } 435 } 436 } 437 438 439 org.omg.CORBA.Contained [] result = new org.omg.CORBA.Contained [ found.size() ]; 440 int idx = 0; 441 442 for( Enumeration e = found.keys(); e.hasMoreElements(); ) 443 result[ idx++] = (org.omg.CORBA.Contained )e.nextElement(); 444 445 return result; 446 } 447 448 public org.omg.CORBA.ContainerPackage.Description[] describe_contents(org.omg.CORBA.DefinitionKind limit_type, boolean exclude_inherited, int max_returned_objs) 449 { 450 return null; 451 } 452 453 public org.omg.CORBA.ModuleDef create_module( String id, String name, String version){ 454 return null; 455 } 456 457 public org.omg.CORBA.ConstantDef create_constant( String id, String name, String version, org.omg.CORBA.IDLType type, org.omg.CORBA.Any value){ 458 return null; 459 } 460 461 public org.omg.CORBA.StructDef create_struct( String id, String name, String version, org.omg.CORBA.StructMember [] members){ 462 return null; 463 } 464 465 public org.omg.CORBA.UnionDef create_union( String id, String name, String version, org.omg.CORBA.IDLType discriminator_type, org.omg.CORBA.UnionMember [] members){ 466 return null; 467 } 468 469 public org.omg.CORBA.EnumDef create_enum( String id, String name, String version, String [] members){ 470 return null; 471 } 472 473 public org.omg.CORBA.AliasDef create_alias( String id, String name, String version, org.omg.CORBA.IDLType original_type){ 474 return null; 475 } 476 477 480 481 public org.omg.CORBA.ExceptionDef create_exception(java.lang.String id, java.lang.String name , java.lang.String version, org.omg.CORBA.StructMember [] member ) 482 { 483 return null; 484 } 485 486 489 490 public org.omg.CORBA.InterfaceDef create_interface( 491 String id, 492 String name, 493 String version, 494 org.omg.CORBA.InterfaceDef [] base_interfaces, 495 boolean is_abstract ) 496 { 497 return null; 498 } 499 500 503 504 public org.omg.CORBA.ValueBoxDef create_value_box(java.lang.String id, 505 java.lang.String name, 506 java.lang.String version, 507 org.omg.CORBA.IDLType type) 508 { 509 return null; 510 } 511 512 513 516 517 public org.omg.CORBA.ValueDef create_value( 518 java.lang.String id, 519 java.lang.String name, 520 java.lang.String version, 521 boolean is_custom, 522 boolean is_abstract, 523 org.omg.CORBA.ValueDef base_value, 524 boolean is_truncatable, 525 org.omg.CORBA.ValueDef [] abstract_base_values, 526 org.omg.CORBA.InterfaceDef [] supported_interfaces, 527 org.omg.CORBA.Initializer [] initializers) 528 { 529 return null; 530 } 531 532 533 536 537 public org.omg.CORBA.NativeDef create_native(java.lang.String id, 538 java.lang.String name, 539 java.lang.String version) 540 { 541 return null; 542 } 543 544 public void destroy(){} 545 546 547 } 548 | Popular Tags |