1 20 package org.objectweb.modfact.corba.provider; 21 22 import java.util.*; 23 24 import org.omg.CORBA.TCKind ; 25 import org.omg.CORBA.TypeCodePackage.BadKind ; 26 import org.omg.mof.Reflective.MofError; 27 import org.omg.mof.Reflective.NotSet; 28 29 import org.objectweb.modfact.corba.helper.IDLCommon; 30 import org.objectweb.modfact.corba.helper.MOFCommon; 31 32 36 public class IDLProvider implements IDLCommon { 37 38 MOFCommon mofHelper; 39 40 public IDLProvider(MOFCommon mofHelper) { 41 this.mofHelper = mofHelper; 42 } 43 44 public IDLProvider() { 45 } 46 47 50 public String format1(String input) { 51 Vector s1 = splitAndDelete(input); 52 String buffer = " "; 53 for (int i = 0; i < s1.size(); i++) { 54 char[] s2 = s1.elementAt(i).toString().toCharArray(); 55 s2[0] = Character.toUpperCase(s1.elementAt(i).toString().charAt(0)); 56 String s3 = String.valueOf(s2); 57 buffer = buffer.concat(s3); 58 } 59 return buffer.trim(); 60 } 61 62 65 public String format1FirstMin(String _input) { 66 String format1FirstMin = format1(_input); 67 if (format1FirstMin.length() > 1) { 68 return format1FirstMin.substring(0, 1).toLowerCase() + format1FirstMin.substring(1); 69 } else { 70 return format1FirstMin.toLowerCase(); 71 } 72 } 73 74 77 public String format2(String input) { 78 Vector s1 = splitAndDelete(input); 79 String buffer = " "; 80 for (int i = 0; i < s1.size(); i++) { 81 String s2 = s1.elementAt(i).toString().toLowerCase(); 82 buffer = buffer.concat(s2); 83 if (i != (s1.size() - 1)) 84 buffer = buffer.concat("_"); 85 } 86 87 return buffer.trim(); 88 } 89 90 93 public String format3(String input) { 94 Vector s1 = splitAndDelete(input); 95 String buffer = " "; 96 int i; 97 for (i = 0; i < s1.size(); i++) { 98 String s2 = s1.elementAt(i).toString().toUpperCase(); 99 buffer = buffer.concat(s2); 100 if (i != (s1.size() - 1)) 101 buffer = buffer.concat("_"); 102 } 103 return buffer.trim(); 104 } 105 106 107 110 public String qualifiedName(org.omg.mof.Model.ModelElement modelElement) 111 throws org.omg.mof.Reflective.MofError , NotSet{ 112 boolean bool = false; 113 String elementName = ""; 114 115 if (modelElement._is_a(org.omg.mof.Model.ClassHelper.id())) { 116 elementName = 117 className(org.omg.mof.Model.ClassHelper.narrow(modelElement)); 118 } else { 119 elementName = modelElement.name(); 120 if (elementName.startsWith("*")) 121 elementName = elementName.substring(1); 122 elementName = format1(elementName); 124 } 125 126 String _namespacestring = elementName; 127 128 org.omg.mof.Model.ModelElement current = modelElement; 129 while (!bool) { 130 try { 131 current = current.container(); 132 _namespacestring = 133 format1(current.name()) + "::" + _namespacestring; 134 } catch (org.omg.mof.Reflective.NotSet ex) { 135 bool = true; 136 } 137 138 } 139 return _namespacestring; 140 } 141 142 public String className(org.omg.mof.Model.Class clazz) 143 throws NotSet, MofError { 144 String idlSubstitute = mofHelper.idlSubstituteIdentifierForClass(clazz); 145 if (idlSubstitute.compareTo("") == 0) 146 return format1(clazz.name()); 147 else return idlSubstitute; 148 } 149 150 public boolean isBaseType(org.omg.CORBA.TypeCode _typecode) 151 throws BadKind , org.omg.CORBA.TypeCodePackage.Bounds { 152 int val = _typecode.kind().value(); 154 if (val == TCKind._tk_alias 155 || val == TCKind._tk_struct 156 || val == TCKind._tk_enum 157 || val == TCKind._tk_sequence) 158 return false; 159 else 160 return true; 161 } 162 163 169 Vector splitAndDelete(String _input) { 170 Vector parts = new Vector(); 171 String delim = "-_ ."; 172 StringTokenizer _sstring = new StringTokenizer(_input, delim); 173 while (_sstring.hasMoreTokens()) { 174 String part = _sstring.nextToken(); 175 int i = 0; 176 int j = 0; 177 boolean isPart = false; 178 boolean beginPart = true; 179 while (i < part.length()) { 180 if (beginPart) { 181 if ((Character.isDigit(part.charAt(i))) 182 || (Character.isUpperCase(part.charAt(i)))) 183 i++; 184 else 185 beginPart = false; 186 } else { 187 if ((Character.isDigit(part.charAt(i))) 188 || (Character.isLowerCase(part.charAt(i)))) 189 i++; 190 else 191 isPart = true; 192 } 193 if (isPart) { 194 parts.addElement(part.substring(j, i)); 195 j = i; 196 isPart = false; 197 beginPart = true; 198 } 199 if (i == j) 200 i++; } 202 if (i != j) 203 parts.addElement(part.substring(j, i)); 204 } 205 return parts; 206 } 207 208 213 public String testIdlConflict(String input) { 214 String keywordsIDL2 = "abstract|any|attribute|boolean|case|char|const|context|custom|default|double|exception|enum|factory|false|fixed|float|in|include|inout|interface|local|long|module|native|object|octet|oneway|out|private|public|raises|readonly|sequence|short|string|struct|supports|switch|true|truncatable|typedef|unsigned|union|valuebase|valuetype|void|wchar|wstring"; 215 String keywordsIDL3 = "component|consumes|emits|eventtype|finder|getraises|home|import|multiple|primarykey|provides|publishes|setraises|typeid|typeprefix|uses"; 216 if (input.toLowerCase().matches(keywordsIDL2 + "|" + keywordsIDL3)) 217 return "_" + input; 218 else 219 return input; 220 } 221 222 226 public String format2IdlConflict(String input) { 227 return testIdlConflict(format2(input).trim()); 228 } 229 230 } 231 | Popular Tags |