1 28 29 package ist.coach.itut_x780Components.ManagedObjectFactoryProviderComposition; 30 31 import ist.coach.coachEmfCommon.Utils; 32 import ist.coach.coachEmfCommon.ExceptionMessages; 33 import intt.itu.itut_x780.UIDType; 34 import intt.itu.itut_x780.CreateError; 35 import intt.itu.itut_x780.ApplicationError; 36 37 import intt.itu.itut_x780.ManagedObjectFactory; 38 import intt.itu.itut_x780.ManagedObjectFactoryHelper; 39 import ist.coach.coachEmfCommon.CreateErrorInfoTypeImpl; 40 import ist.coach.coachEmfCommon.ApplicationErrorInfoTypeImpl; 41 42 import ist.coach.itut_x780Components.CCM_ManagedObjectFactoryProvider_Context; 43 import ist.coach.itut_x780Components.ManagedObjectMgmt; 44 import ist.coach.coachEmfServices.EmfBasicLog.*; 45 46 47 53 public class ManagedObjectFactoryProviderImpl 54 extends ist.coach.itut_x780Components.ManagedObjectFactoryProviderComposition.ManagedObjectFactoryProvider_impl 55 { 56 62 63 intt.itu.itut_q816.ContainmentComponent c_admin = null; 64 intt.itu.itut_q816.Containment c_query = null; 65 66 private static final String FACTORY_CLASS = "ManagedObjectFactory"; 67 ManagedObjectMgmt facade = null; 68 private BasicLog logSupport; 69 75 public ManagedObjectFactoryProviderImpl() 76 { 77 78 } 79 80 94 public void 95 configuration_complete() 96 throws org.omg.Components.InvalidConfiguration 97 { 98 if ((facade = get_context().get_connection_facade()) == null) 102 throw new org.omg.Components.InvalidConfiguration(); 103 104 if ((c_admin = get_context().get_connection_containment_admin()) == null) 105 throw new org.omg.Components.InvalidConfiguration(); 106 107 if ((c_query = get_context().get_connection_containment_query()) == null) 108 throw new org.omg.Components.InvalidConfiguration(); 109 110 if ((logSupport = get_context().get_connection_basic_log()) == null) 111 throw new org.omg.Components.InvalidConfiguration(); 112 113 intt.itu.itut_q816.FactoryFinderComponent factoryfinder_admin = 116 get_context().get_connection_factoryfinder_admin(); 117 118 org.omg.CORBA.Object myself_o; 119 ManagedObjectFactory myself = null; 120 121 try { 122 myself_o = ((org.omg.Components.SessionContext) get_context()).get_CCM_object(); 123 myself = ManagedObjectFactoryHelper.narrow(myself_o); 124 125 factoryfinder_admin.register(FACTORY_CLASS, myself); 126 } 128 catch(intt.itu.itut_x780.ApplicationError ex) { 129 130 throw new org.omg.Components.InvalidConfiguration(); 131 } 132 catch(Exception e) { 133 } 135 136 137 System.err.println("ManagedObjectFactoryProvider configuration completed..."); 138 } 139 140 150 public void 151 ccm_remove() 152 throws org.omg.Components.CCMException 153 { 154 } 158 164 167 public org.omg.CosNaming.NameComponent [] 168 create_base(String nameBinding, org.omg.CosNaming.NameComponent [] superior, String reqId) 169 throws intt.itu.itut_x780.CreateError, 170 171 intt.itu.itut_x780.ApplicationError 172 { 173 short deletePolicy = -1; 174 boolean managerMayCreatePolicy = false; 175 String objectKind = new String (); 176 String nameBinding_str = "intt.itu.itut_x780.NameBindings." + 177 nameBinding; 178 try { 179 Class deletePolicyClass = 180 Class.forName(nameBinding_str + ".deletePolicy"); 181 182 deletePolicy = 183 deletePolicyClass.getDeclaredField("value").getShort(null); 184 185 Class managerMayCreatePolicyClass = 186 Class.forName(nameBinding_str + ".managersMayCreate"); 187 managerMayCreatePolicy = 188 managerMayCreatePolicyClass.getDeclaredField("value").getBoolean(null); 189 190 Class objectKindClass = 191 Class.forName(nameBinding_str + ".kind"); 192 objectKind = (String ) objectKindClass.getDeclaredField("value").get(null); 193 194 199 200 } 201 catch(java.lang.ClassNotFoundException ex) { 202 System.err.println(nameBinding_str + " can not be found!" + ex.getMessage()); 203 CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl(); 204 error_code.error = new UIDType( 205 intt.itu.itut_x780.CreateErrorConst.moduleName.value, 206 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value); 207 208 error_code.details = ExceptionMessages.namebinding_exists_error; 209 throw new CreateError(error_code); 210 211 } 212 catch(java.lang.NoSuchFieldException ex_field) { 213 System.err.println("java.lang.NoSuchFieldException caught " + 214 ex_field.getMessage()); 215 CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl(); 216 error_code.error = new UIDType( 217 intt.itu.itut_x780.CreateErrorConst.moduleName.value, 218 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value); 219 220 error_code.details = ExceptionMessages.namebinding_field_error; 221 throw new CreateError(error_code); 222 223 } 224 catch(java.lang.IllegalAccessException ex_acc) { 225 System.err.println("java.lang.IllegalAccessException caught " + 226 ex_acc.getMessage()); 227 CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl(); 228 error_code.error = new UIDType( 229 intt.itu.itut_x780.CreateErrorConst.moduleName.value, 230 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value); 231 232 error_code.details = ExceptionMessages.namebinding_field_error; 233 throw new CreateError(error_code); 234 235 } 236 if (!managerMayCreatePolicy) { 238 CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl(); 239 error_code.error = new UIDType( 240 intt.itu.itut_x780.CreateErrorConst.moduleName.value, 241 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value); 242 243 error_code.details = ExceptionMessages.manager_create_error; 244 throw new CreateError(error_code); 245 } 246 247 if (! c_query.exists(superior)) { 249 ApplicationErrorInfoTypeImpl error_code = new ApplicationErrorInfoTypeImpl(); 250 error_code.error = new UIDType( 251 intt.itu.itut_x780.ApplicationErrorConst.moduleName.value, 252 intt.itu.itut_x780.ApplicationErrorConst.objectNotFound.value); 253 254 error_code.details = Utils.name2string(superior) + 255 ExceptionMessages.parent_object_error; 256 257 throw new ApplicationError(error_code); 258 } 259 260 String allocatedId = reqId; 262 if (reqId == null || reqId.length() == 0) { 263 264 System.err.println("Auto-naming gets activated.."); 265 org.omg.CosNaming.NameComponent [][] siblings = 266 c_query.getContained(superior); 267 System.err.println("Parent has " + siblings.length + 268 " children"); 269 270 boolean idFound = false; 271 int id = 0, name_length = 0; 272 while(! idFound) { 273 id++; 274 int i = 0; 275 for(i = 0; i < siblings.length; i++) { 276 if (siblings[i] !=null && (name_length=siblings[i].length) > 0) { 277 if (siblings[i][name_length -2].id.equals(Integer.toString(id))) { 278 break; 279 } 280 } 281 } 282 if (i >= siblings.length) { 283 idFound = true; 284 } 285 } 286 allocatedId = Integer.toString(id); 287 } 288 289 org.omg.CosNaming.NameComponent [] name; 291 292 int index = 0; 293 if (superior.length == 1) { 294 name = new org.omg.CosNaming.NameComponent [superior.length + 2]; 295 index = 1; 296 } 297 else { 298 name = new org.omg.CosNaming.NameComponent [superior.length + 1]; 299 index = superior.length - 1; 300 } 301 int i = 0; 302 for(i = 0; i < index; i++) 303 name[i] = superior[i]; 304 305 name[i++] = new org.omg.CosNaming.NameComponent (allocatedId, objectKind); 307 308 name[i] = new org.omg.CosNaming.NameComponent ("", Utils.name2facade(facade.facade_name())); 310 Utils.pretty_log(logSupport, FACTORY_CLASS, "Factory", (short) LogSeverity._Info, 311 "proceed to create " + Utils.name2string(name)); 312 facade.create(name, objectKind, new String [0], deletePolicy, 315 intt.itu.itut_x780.SourceIndicatorType.managementOperation); 316 c_admin.addName(name, superior); 318 Utils.pretty_log(logSupport, FACTORY_CLASS, "Factory", (short) LogSeverity._Info, 319 "successfully created " + Utils.name2string(name)); 320 return name; 322 } 323 324 } 325 | Popular Tags |