1 package ist.coach.coachEmfCommon; 2 3 import org.omg.CosNaming.NameComponent ; 4 5 public class Utils { 6 7 private static org.omg.CORBA.ORB orb = org.objectweb.ccm.CORBA.TheORB.getORB(); 8 9 public static NameComponent [] string2name(String name_s) { 10 11 java.util.StringTokenizer depth_st, kind_st; 12 depth_st = new java.util.StringTokenizer (name_s, "/"); 13 14 java.util.Vector name_seq_v = new java.util.Vector (); 15 String token_str = null, token_name = null, token_kind = null; 16 for(int pos = 0; depth_st.hasMoreTokens(); pos++) { 17 18 token_str = depth_st.nextToken(); 19 kind_st = new java.util.StringTokenizer (token_str, "."); 20 21 if (token_str.startsWith(".")) { 22 token_name = new String (); 23 token_kind = kind_st.nextToken(); 24 } 25 else { 26 if (kind_st.hasMoreTokens()) 27 token_name = kind_st.nextToken(); 28 else 29 token_name = new String (); 30 31 if (kind_st.hasMoreTokens()) 32 token_kind = kind_st.nextToken(); 33 else 34 token_kind = new String (); 35 } 36 37 name_seq_v.add(new NameComponent (token_name, token_kind)); 38 } 40 41 NameComponent [] name_seq = new NameComponent [name_seq_v.size()]; 42 name_seq_v.copyInto(name_seq); 43 return name_seq; 44 } 45 public static String name2string(NameComponent [] name) { 46 47 String name_str = new String (); 48 for (int i = 0; i < name.length; i++) { 49 name_str = name_str.concat(name[i].id + "." + name[i].kind); 50 if (i < name.length -1 ) { 51 name_str = name_str.concat("/"); 52 } 53 } 54 return name_str; 55 } 56 57 61 public static String name2kind(String name) { 62 63 int delimEnd = name.lastIndexOf("/"); 64 if (delimEnd < 0) { 65 return new String ("Organization"); 68 } 69 70 int delimStart = name.substring(0, delimEnd).lastIndexOf("."); 71 72 if (delimStart < 0) 73 return new String (); 74 75 return name.substring(delimStart+1, delimEnd); 76 } 77 78 public static String name2id(String name) { 79 80 int delimEnd = name.lastIndexOf("/"); 81 if (delimEnd < 0) { 82 return new String (); 83 } 84 delimEnd = name.substring(0, delimEnd).lastIndexOf("."); 85 int delimStart = name.substring(0, delimEnd).lastIndexOf("/"); 86 87 if (delimStart < 0) 88 return new String (); 89 90 return name.substring(delimStart+1, delimEnd); 91 92 } 93 94 99 public static String name2facade(String name) { 100 101 int delimEnd = name.lastIndexOf("/"); 102 if (delimEnd < 0) { 103 return new String (); 104 } 106 107 int delimStart = name.lastIndexOf("."); 108 return name.substring(delimStart+1); 109 } 110 111 public static boolean isChild(NameComponent [] child, NameComponent [] parent) { 112 113 for (int i = 0; i < parent.length - 2; i++) { 114 if (! (child[i].id.equals(parent[i].id)) || 115 ! (child[i].kind.equals(parent[i].kind))) { 116 117 return false; 118 } 119 } 120 121 return true; 122 } 123 124 public static boolean packageIsSupported( 125 String packageName, 126 String [] supportedPackages) { 127 128 boolean isSupported = false; 129 for (int i = 0; i < supportedPackages.length; i++) { 130 if (supportedPackages[i].equals(packageName)) { 131 isSupported = true; 132 break; 133 } 134 } 135 136 return isSupported; 137 138 139 } 140 141 public static synchronized void 142 pretty_log(ist.coach.coachEmfServices.EmfBasicLog.BasicLog logger, 143 String source, String sourceClass, short severity, String info) { 144 145 org.omg.CORBA.Any record = orb.create_any(); 146 record.insert_string(info); 147 ist.coach.coachEmfServices.EmfBasicLog.NVPair[] log_data = new ist.coach.coachEmfServices.EmfBasicLog.NVPair[3]; 148 149 log_data[0] = new ist.coach.coachEmfServices.EmfBasicLog.NVPair(); 150 log_data[0].name = "Source"; 151 org.omg.CORBA.Any name_value = orb.create_any(); 152 name_value.insert_string(source); 153 log_data[0].value = name_value; 154 155 log_data[1] = new ist.coach.coachEmfServices.EmfBasicLog.NVPair(); 156 log_data[1].name = "EventType"; 157 org.omg.CORBA.Any type_value = orb.create_any(); 158 type_value.insert_short(severity); 159 log_data[1].value = type_value; 160 161 log_data[2] = new ist.coach.coachEmfServices.EmfBasicLog.NVPair(); 162 log_data[2].name = "SourceClass"; 163 org.omg.CORBA.Any class_value = orb.create_any(); 164 class_value.insert_string(sourceClass); 165 log_data[2].value = class_value; 166 167 try { 168 logger.write_record(record, log_data); 169 } 171 catch(ist.coach.coachEmfServices.EmfBasicLog.LogFull fullEx) { 172 System.err.println("EmfBasicLog.LogFull Exception caught"); 173 } 174 catch(ist.coach.coachEmfServices.EmfBasicLog.LogOffDuty dutyEx) { 175 System.err.println("EmfBasicLog.LogOffDuty Exception caught"); 176 } 177 catch(ist.coach.coachEmfServices.EmfBasicLog.LogLocked lockedEx) { 178 System.err.println("EmfBasicLog.LogLocked Exception caught"); 179 } 180 catch(ist.coach.coachEmfServices.EmfBasicLog.LogDisabled disabledEx) { 181 System.err.println("EmfBasicLog.LogDisabled Exception caught"); 182 } 183 184 185 } 186 } 187 | Popular Tags |