1 package ist.coach.coachEmfCommon; 2 3 import org.omg.CosNaming.NameComponent ; 4 import intt.itu.itut_x780.UIDType; 5 import intt.itu.itut_x780.CreateError; 6 import intt.itu.itut_x780.ApplicationError; 7 8 9 public class CreateController { 10 11 public static synchronized CreateBindingInfo checkNameBinding(String nameBinding_str) 12 throws CreateError{ 13 14 short deletePolicy = -1; 15 boolean managerMayCreatePolicy = false; 16 String objectKind = new String (); 17 18 CreateBindingInfo info = new CreateBindingInfo(); 19 20 try { 21 Class deletePolicyClass = 22 Class.forName(nameBinding_str + ".deletePolicy"); 23 24 deletePolicy = 25 deletePolicyClass.getDeclaredField("value").getShort(null); 26 27 Class managerMayCreatePolicyClass = 28 Class.forName(nameBinding_str + ".managersMayCreate"); 29 managerMayCreatePolicy = 30 managerMayCreatePolicyClass.getDeclaredField("value").getBoolean(null); 31 32 Class objectKindClass = 33 Class.forName(nameBinding_str + ".kind"); 34 objectKind = ((String ) objectKindClass.getDeclaredField("value").get(null)).trim(); 35 36 } 40 catch(java.lang.ClassNotFoundException ex) { 41 System.err.println(nameBinding_str + " can not be found!" + ex.getMessage()); 42 CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl(); 43 error_code.error = new UIDType( 44 intt.itu.itut_x780.CreateErrorConst.moduleName.value, 45 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value); 46 error_code.details = ExceptionMessages.namebinding_exists_error; 47 throw new CreateError(error_code); 48 } 49 catch(java.lang.NoSuchFieldException ex_field) { 50 System.err.println("java.lang.NoSuchFieldException caught " + 51 ex_field.getMessage()); 52 CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl(); 53 error_code.error = new UIDType( 54 intt.itu.itut_x780.CreateErrorConst.moduleName.value, 55 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value); 56 57 error_code.details = ExceptionMessages.namebinding_field_error; 58 throw new CreateError(error_code); 59 } 60 catch(java.lang.IllegalAccessException ex_acc) { 61 System.err.println("java.lang.IllegalAccessException caught " + 62 ex_acc.getMessage()); 63 CreateErrorInfoTypeImpl error_code = new CreateErrorInfoTypeImpl(); 64 error_code.error = new UIDType( 65 intt.itu.itut_x780.CreateErrorConst.moduleName.value, 66 intt.itu.itut_x780.CreateErrorConst.invalidNameBinding.value); 67 68 error_code.details = ExceptionMessages.namebinding_field_error; 69 throw new CreateError(error_code); 70 } 71 72 info.objectKind = objectKind; 73 info.deletePolicy = deletePolicy; 74 return info; 75 } 77 78 public static synchronized String autoCreateId(NameComponent [][] siblings) { 79 80 String allocatedId = new String (); 81 82 86 boolean idFound = false; 87 int id = 0, name_length = 0; 88 89 while(! idFound) { 90 id++; 91 int i = 0; 92 for(i = 0; i < siblings.length; i++) { 93 if (siblings[i] !=null && (name_length=siblings[i].length) > 0) { 94 if (siblings[i][name_length -2].id.indexOf(Integer.toString(id)) >= 0) { 97 break; 98 } 99 } 100 } 101 if (i >= siblings.length) { 102 idFound = true; 103 } 104 } 105 allocatedId = Integer.toString(id); 106 return allocatedId; 107 } 108 109 110 public static synchronized NameComponent [] createFullName(NameComponent [] superior, 111 String allocatedId, 112 String facade_name, 113 String objectKind) { 114 115 org.omg.CosNaming.NameComponent [] name; 116 117 int index = 0; 118 if (superior.length == 1) { 119 name = new org.omg.CosNaming.NameComponent [superior.length + 2]; 120 index = 1; 121 } 122 else { 123 name = new org.omg.CosNaming.NameComponent [superior.length + 1]; 124 index = superior.length - 1; 125 } 126 int i = 0; 127 for(i = 0; i < index; i++) 128 name[i] = superior[i]; 129 name[i++] = new org.omg.CosNaming.NameComponent (allocatedId, objectKind); 131 132 name[i] = new org.omg.CosNaming.NameComponent ("", facade_name); 134 135 return name; 136 } 137 138 }; 139 | Popular Tags |