1 21 package ist.coach.itut_x780Components; 22 23 import ist.coach.coachEmfCommon.Utils; 24 import ist.coach.coachEmfCommon.ExceptionMessages; 25 import intt.itu.itut_x780.UIDType; 26 import intt.itu.itut_x780.CreateError; 27 import intt.itu.itut_x780.ApplicationError; 28 29 import intt.itu.itut_x780.ManagedObjectFactory; 30 import intt.itu.itut_x780.ManagedObjectFactoryHelper; 31 import ist.coach.coachEmfCommon.CreateErrorInfoTypeImpl; 32 import ist.coach.coachEmfCommon.ApplicationErrorInfoTypeImpl; 33 34 35 38 public class ManagedObjectFactoryProviderMonolithicImpl 39 extends org.omg.CORBA.LocalObject 40 implements CCM_ManagedObjectFactoryProvider, 41 org.omg.Components.SessionComponent 42 { 43 51 private CCM_ManagedObjectFactoryProvider_Context the_context_; 52 53 intt.itu.itut_q816.ContainmentComponent c_admin = null; 54 intt.itu.itut_q816.Containment c_query = null; 55 56 private static final String FACTORY_CLASS = "ManagedObjectFactory"; 57 ManagedObjectMgmt facade = null; 58 66 public 67 ManagedObjectFactoryProviderMonolithicImpl() 68 { 69 the_context_ = null; 70 } 71 87 public CCM_ManagedObjectFactoryProvider_Context 88 getContext() 89 { 90 return the_context_; 91 } 92 106 public void 107 configuration_complete() 108 throws org.omg.Components.InvalidConfiguration 109 { 110 if ((facade = the_context_.get_connection_facade()) == null) 114 throw new org.omg.Components.InvalidConfiguration(); 115 116 if ((c_admin = the_context_.get_connection_containment_admin()) == null) 117 throw new org.omg.Components.InvalidConfiguration(); 118 119 if ((c_query = the_context_.get_connection_containment_query()) == null) 120 throw new org.omg.Components.InvalidConfiguration(); 121 122 intt.itu.itut_q816.FactoryFinderComponent factoryfinder_admin = 125 the_context_.get_connection_factoryfinder_admin(); 126 127 org.omg.CORBA.Object myself_o; 128 ManagedObjectFactory myself = null; 129 130 try { 131 myself_o = ((org.omg.Components.SessionContext) the_context_).get_CCM_object(); 132 myself = ManagedObjectFactoryHelper.narrow(myself_o); 133 134 factoryfinder_admin.register(FACTORY_CLASS, myself); 135 } 137 catch(intt.itu.itut_x780.ApplicationError ex) { 138 throw new org.omg.Components.InvalidConfiguration(); 139 } 140 catch(Exception e) { 141 System.err.println("ManagedObjectFactory has problems retrieving CCM component"); 142 } 143 144 145 System.err.println("ManagedObjectFactoryProvider configuration completed..."); 146 } 147 163 public void 164 set_session_context(org.omg.Components.SessionContext context) 165 throws org.omg.Components.CCMException 166 { 167 the_context_ = (CCM_ManagedObjectFactoryProvider_Context)context; 168 } 169 179 public void 180 ccm_activate() 181 throws org.omg.Components.CCMException 182 { 183 } 187 197 public void 198 ccm_passivate() 199 throws org.omg.Components.CCMException 200 { 201 } 205 215 public void 216 ccm_remove() 217 throws org.omg.Components.CCMException 218 { 219 } 223 public org.omg.CosNaming.NameComponent [] 229 create_base(String nameBinding, 230 org.omg.CosNaming.NameComponent [] superior, 231 String reqId) 232 throws intt.itu.itut_x780.ApplicationError, intt.itu.itut_x780.CreateError { 233 234 short deletePolicy = -1; 235 boolean managerMayCreatePolicy = false; 236 String objectKind = new String (); 237 String nameBinding_str = "intt.itu.itut_x780.NameBindings." + 238 nameBinding; 239 try { 240 Class deletePolicyClass = 241 Class.forName(nameBinding_str + ".deletePolicy"); 242 243 deletePolicy = 244 deletePolicyClass.getDeclaredField("value").getShort(null); 245 246 Class managerMayCreatePolicyClass = 247 Class.forName(nameBinding_str + ".managersMayCreate"); 248 managerMayCreatePolicy = 249 managerMayCreatePolicyClass.getDeclaredField("value").getBoolean(null); 250 251 Class objectKindClass = 252 Class.forName(nameBinding_str + ".kind"); 253 objectKind = (String ) objectKindClass.getDeclaredField("value").get(null); 254 255 260 261 } 262 catch(java.lang.ClassNotFoundException ex) { 263 System.err.println(nameBinding_str + " can not be found!" + ex.getMessage()); 264 CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl(); 265 error_code.error = new UIDType( 266 intt.itu.itut_x780.CreateErrorConst.moduleName.value, 267 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value); 268 269 error_code.details = ExceptionMessages.namebinding_exists_error; 270 throw new CreateError(error_code); 271 272 } 273 catch(java.lang.NoSuchFieldException ex_field) { 274 System.err.println("java.lang.NoSuchFieldException caught " + 275 ex_field.getMessage()); 276 CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl(); 277 error_code.error = new UIDType( 278 intt.itu.itut_x780.CreateErrorConst.moduleName.value, 279 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value); 280 281 error_code.details = ExceptionMessages.namebinding_field_error; 282 throw new CreateError(error_code); 283 284 } 285 catch(java.lang.IllegalAccessException ex_acc) { 286 System.err.println("java.lang.IllegalAccessException caught " + 287 ex_acc.getMessage()); 288 CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl(); 289 error_code.error = new UIDType( 290 intt.itu.itut_x780.CreateErrorConst.moduleName.value, 291 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value); 292 293 error_code.details = ExceptionMessages.namebinding_field_error; 294 throw new CreateError(error_code); 295 296 } 297 if (!managerMayCreatePolicy) { 299 CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl(); 300 error_code.error = new UIDType( 301 intt.itu.itut_x780.CreateErrorConst.moduleName.value, 302 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value); 303 304 error_code.details = ExceptionMessages.manager_create_error; 305 throw new CreateError(error_code); 306 } 307 308 if (! c_query.exists(superior)) { 310 ApplicationErrorInfoTypeImpl error_code = new ApplicationErrorInfoTypeImpl(); 311 error_code.error = new UIDType( 312 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 313 intt.itu.itut_x780.ApplicationErrorConst.objectNotFound.value); 314 315 error_code.details = Utils.name2string(superior) + 316 ExceptionMessages.parent_object_error; 317 318 throw new ApplicationError(error_code); 319 } 320 321 String allocatedId = reqId; 323 if (reqId == null || reqId.length() == 0) { 324 325 System.err.println("Auto-naming gets activated.."); 326 org.omg.CosNaming.NameComponent [][] siblings = 327 c_query.getContained(superior); 328 System.err.println("Parent has " + siblings.length + 329 " children"); 330 331 boolean idFound = false; 332 int id = 0, name_length = 0; 333 while(! idFound) { 334 id++; 335 int i = 0; 336 for(i = 0; i < siblings.length; i++) { 337 if (siblings[i] !=null && (name_length=siblings[i].length) > 0) { 338 if (siblings[i][name_length -2].id.equals(Integer.toString(id))) { 339 break; 340 } 341 } 342 } 343 if (i >= siblings.length) { 344 idFound = true; 345 } 346 } 347 allocatedId = Integer.toString(id); 348 } 349 350 org.omg.CosNaming.NameComponent [] name; 352 353 int index = 0; 354 if (superior.length == 1) { 355 name = new org.omg.CosNaming.NameComponent [superior.length + 2]; 356 index = 1; 357 } 358 else { 359 name = new org.omg.CosNaming.NameComponent [superior.length + 1]; 360 index = superior.length - 1; 361 } 362 int i = 0; 363 for(i = 0; i < index; i++) 364 name[i] = superior[i]; 365 366 name[i++] = new org.omg.CosNaming.NameComponent (allocatedId, objectKind); 368 369 name[i] = new org.omg.CosNaming.NameComponent ("", Utils.name2facade(facade.facade_name())); 371 372 System.err.println("Before invoking the facade " + 373 Utils.name2facade(facade.facade_name()) + " to create " + Utils.name2string(name)); 374 facade.create(name, objectKind, new String [0], deletePolicy, 375 intt.itu.itut_x780.SourceIndicatorType.managementOperation); 376 377 c_admin.addName(name, superior); 378 379 System.err.println("create_base returns for " + Utils.name2string(name)); 380 return name; 381 } 382 } 383 | Popular Tags |