1 package org.jacorb.ir; 2 3 22 23 import org.omg.CORBA.*; 24 import org.omg.PortableServer.POA ; 25 26 import java.lang.reflect.*; 27 28 import org.apache.avalon.framework.logger.Logger; 29 30 33 34 public abstract class Contained 35 extends IRObject 36 implements org.omg.CORBA.ContainedOperations 37 { 38 protected String id; 39 40 41 protected String absolute_name; 42 43 String full_name; 44 protected String version = "1.0"; 45 46 protected org.omg.CORBA.Container defined_in; 47 protected org.omg.CORBA.Repository containing_repository; 48 49 private static Class intfClass; 50 private static Class idlClass; 51 private static Class stubClass; 52 private static Class exceptClass; 53 private static boolean class_init; 54 55 public Contained() 56 { 57 } 58 59 public Contained( String _id, 60 String _name, 61 String _version, 62 org.omg.CORBA.Container _defined_in, 63 String _absolute_name, 64 org.omg.CORBA.Repository _containing_repository ) 65 { 66 id = _id; 67 name = _name; 68 version = _version; 69 defined_in = _defined_in; 70 absolute_name = _absolute_name; 71 containing_repository = _containing_repository; 72 } 73 74 75 public static Contained createContained( Class c, 76 String path, 77 org.omg.CORBA.Container _defined_in, 78 org.omg.CORBA.Repository ir, 79 Logger logger, 80 ClassLoader loader, 81 POA poa ) 82 { 83 if( !class_init ) 84 { 85 try 86 { 87 intfClass = 88 loader.loadClass("org.omg.CORBA.Object"); 89 idlClass = 90 loader.loadClass("org.omg.CORBA.portable.IDLEntity"); 91 stubClass = 92 loader.loadClass("org.omg.CORBA.portable.ObjectImpl"); 93 exceptClass = 94 loader.loadClass("org.omg.CORBA.UserException"); 95 class_init = true; 96 } 97 catch ( ClassNotFoundException cnf ) 98 { 99 } 101 } 102 103 if( stubClass.isAssignableFrom( c ) ) 104 { 105 return null; } 107 else if( c.isInterface()) 108 { 109 if( intfClass.isAssignableFrom( c ) ) 110 { 111 try 112 { 113 Class helperClass = 114 loader.loadClass(c.getName() + "Helper"); 115 116 if( helperClass == null ) 117 { 118 return null; 119 } 120 121 org.jacorb.ir.InterfaceDef idef = 122 new org.jacorb.ir.InterfaceDef( c, 123 helperClass, 124 path, 125 _defined_in, 126 ir, 127 loader, 128 poa, 129 logger); 130 131 return idef; 132 } 133 catch ( ClassNotFoundException e ) 134 { 135 return null; 137 } 138 } 139 else 140 { 141 try 142 { 143 Field f = c.getDeclaredField("value"); 144 return new org.jacorb.ir.ConstantDef( c, 145 _defined_in, 146 ir, 147 logger); 148 } 149 catch( NoSuchFieldException nsfe ) 150 { 151 return null; 153 } 154 } 155 } 156 else if( exceptClass.isAssignableFrom( c )) 157 { 158 162 return new org.jacorb.ir.ExceptionDef(c, 163 _defined_in, 164 ir, 165 loader, 166 poa, 167 logger); 168 177 } 178 else if( idlClass.isAssignableFrom( c ) ) 179 { 180 try 181 { 182 Class helperClass = 183 loader.loadClass( c.getName()+"Helper"); 184 185 org.omg.CORBA.TypeCode tc = 186 (org.omg.CORBA.TypeCode )helperClass.getDeclaredMethod("type", (Class []) null).invoke(null, (java.lang.Object []) null); 187 switch( tc.kind().value()) 188 { 189 case org.omg.CORBA.TCKind._tk_struct: 190 return new org.jacorb.ir.StructDef( c, 191 path, 192 _defined_in, 193 ir, 194 logger, 195 loader, 196 poa ); 197 case org.omg.CORBA.TCKind._tk_enum: 198 return new org.jacorb.ir.EnumDef( 199 c, 200 _defined_in, 201 ir, 202 loader ); 203 case org.omg.CORBA.TCKind._tk_union: 204 return new org.jacorb.ir.UnionDef( c, 205 path, 206 _defined_in, 207 ir, 208 loader, 209 logger, 210 poa); 211 default: 212 return null; 213 } 214 } 215 catch( ClassNotFoundException e ) 216 { 217 logger.warn("Caught Exception", e); 219 } 220 catch( Exception e ) 221 { 222 logger.error("Caught Exception", e); 223 } 224 return null; 225 } 226 else if( c.getName().endsWith("Helper")) 227 { 228 try 229 { 230 org.omg.CORBA.TypeCode tc = 231 (org.omg.CORBA.TypeCode )c.getDeclaredMethod("type", (Class []) null).invoke(null, (java.lang.Object []) null); 232 if( tc.kind() == org.omg.CORBA.TCKind.tk_alias ) 233 { 234 return new AliasDef(tc, 235 _defined_in, 236 ir, 237 logger, 238 poa); 239 } 240 } 241 catch( Exception e ) 242 { 243 } 244 return null; 245 } 246 else 247 { 248 return null; 249 } 250 } 251 252 public static org.omg.CORBA.Contained createContainedReference( 253 Contained containedObject, 254 Logger logger, 255 POA poa ) 256 { 257 if ( containedObject == null) 258 { 259 throw new INTF_REPOS ("Precondition violated in Contained createContainedReference"); 260 } 261 262 org.omg.PortableServer.Servant servant = null; 263 264 switch ( containedObject.def_kind().value() ) 265 { 266 case org.omg.CORBA.DefinitionKind._dk_Interface: 267 servant = 268 new org.omg.CORBA.InterfaceDefPOATie( (org.omg.CORBA.InterfaceDefOperations )containedObject ); 269 break; 270 case org.omg.CORBA.DefinitionKind._dk_Exception: 271 servant = 272 new org.omg.CORBA.ExceptionDefPOATie( (org.omg.CORBA.ExceptionDefOperations )containedObject ); 273 break; 274 case org.omg.CORBA.DefinitionKind._dk_Struct: 275 servant = 276 new org.omg.CORBA.StructDefPOATie( (org.omg.CORBA.StructDefOperations )containedObject ); 277 break; 278 case org.omg.CORBA.DefinitionKind._dk_Enum: 279 servant = 280 new org.omg.CORBA.EnumDefPOATie( (org.omg.CORBA.EnumDefOperations )containedObject ); 281 break; 282 case org.omg.CORBA.DefinitionKind._dk_Union: 283 servant = 284 new org.omg.CORBA.UnionDefPOATie( (org.omg.CORBA.UnionDefOperations )containedObject ); 285 break; 286 case org.omg.CORBA.DefinitionKind._dk_Module: 287 servant = 288 new org.omg.CORBA.ModuleDefPOATie( (org.omg.CORBA.ModuleDefOperations )containedObject ); 289 break; 290 case org.omg.CORBA.DefinitionKind._dk_Alias: 291 servant = 292 new org.omg.CORBA.AliasDefPOATie( (org.omg.CORBA.AliasDefOperations )containedObject ); 293 break; 294 case org.omg.CORBA.DefinitionKind._dk_Constant: 295 servant = 296 new org.omg.CORBA.ConstantDefPOATie( (org.omg.CORBA.ConstantDefOperations )containedObject ); 297 break; 298 default: 299 logger.warn("WARNING, createContainedReference returns null for dk " + 300 containedObject.def_kind().value() ); 301 return null; 302 } 303 304 try 305 { 306 org.omg.CORBA.Contained containedRef = 307 org.omg.CORBA.ContainedHelper.narrow(poa.servant_to_reference( servant )); 308 309 containedObject.setReference( containedRef ); 310 return containedRef; 311 } 312 catch( Exception e ) 313 { 314 e.printStackTrace(); 315 return null; 316 } 317 } 318 319 320 public java.lang.String id() 321 { 322 return id; 323 } 324 public void id(java.lang.String a) 325 { 326 id = a; 327 } 328 329 public java.lang.String name() 330 { 331 return name; 332 } 333 334 public void name(java.lang.String a) 335 { 336 name = a; 337 } 338 339 public java.lang.String version() 340 { 341 return version; 342 } 343 344 public void version(java.lang.String a) 345 { 346 version = a; 347 } 348 349 public org.omg.CORBA.Container defined_in() 350 { 351 return defined_in; 352 } 353 354 public java.lang.String absolute_name() 355 { 356 return absolute_name; 357 } 358 359 public org.omg.CORBA.Repository containing_repository() 360 { 361 return containing_repository; 362 } 363 364 public abstract org.omg.CORBA.ContainedPackage.Description describe(); 365 366 367 public void move(org.omg.CORBA.Container new_container, 368 java.lang.String new_name, 369 java.lang.String new_version) 370 { 371 if( defined_in != null ) 372 ; 374 defined_in = new_container; 375 version = new_version; 376 name = new_name; 377 } 378 } 379 | Popular Tags |