1 20 package org.objectweb.modfact.corba.provider; 21 22 import org.omg.CORBA.TCKind ; 23 import org.omg.CORBA.TypeCode ; 24 import org.omg.CORBA.TypeCodePackage.BadKind ; 25 import org.omg.mof.Model.Association; 26 import org.omg.mof.Model.ClassHelper; 27 import org.omg.mof.Model.Classifier; 28 import org.omg.mof.Model.DataType; 29 import org.omg.mof.Model.DataTypeHelper; 30 import org.omg.mof.Model.Import; 31 import org.omg.mof.Model.MofAttribute; 32 import org.omg.mof.Model.MultiplicityType; 33 import org.omg.mof.Model.Namespace; 34 import org.omg.mof.Model.PackageHelper; 35 import org.omg.mof.Reflective.MofError; 36 import org.omg.mof.Reflective.NotSet; 37 38 import org.objectweb.modfact.corba.helper.JMICommon; 39 import org.objectweb.modfact.corba.helper.MOFCommon; 40 41 45 public class JMIProvider implements JMICommon { 46 47 MOFCommon mofHelper; 48 49 public JMIProvider(MOFCommon mofHelper) { 50 this.mofHelper = mofHelper; 51 } 52 53 56 public String jmiPackageName(org.omg.mof.Model.Package _package) 57 throws MofError { 58 return _package.name().toLowerCase(); 59 } 60 61 64 public String jmiPackageQualifiedName(org.omg.mof.Model.Package _package) 65 throws MofError, NotSet { 66 String res = ""; 68 69 String [] names = _package.qualified_name(); 70 for (int i = 0; i < names.length; i++) { 71 res = names[i].toLowerCase() + res; 72 if (i != (names.length - 1)) 73 res = "." + res; 74 } 75 76 org.omg.mof.Model.Package outerPackage = 77 mofHelper.outermostPackageOfModelElement(_package); 78 String packagePrefix = mofHelper.jmiPrefixForPackage(_package); 80 if (packagePrefix.compareTo("") != 0) 81 res = packagePrefix + "." + res; 82 83 return res; 84 } 85 86 89 public String jmiClassName(org.omg.mof.Model.Class clazz) 90 throws MofError, NotSet { 91 if (mofHelper.jmiSubstituteIdentifierForClass(clazz).compareTo("") 92 != 0) 93 return mofHelper.jmiSubstituteIdentifierForClass(clazz); 94 char[] res = clazz.name().toCharArray(); 95 if (res.length != 0) { 96 res[0] = Character.toUpperCase(res[0]); 97 } 98 return new String (res); 99 } 100 101 104 public String jmiClassQualifiedName(org.omg.mof.Model.Class clazz) 105 throws MofError, NotSet { 106 String res = jmiClassName(clazz); 107 108 org.omg.mof.Model.Package _package = 109 PackageHelper.narrow(clazz.container()); 110 return jmiPackageQualifiedName(_package) + "." + res; 111 } 112 113 116 public String jmiAssociationName(Association association) 117 throws MofError, NotSet { 118 char[] res = association.name().toCharArray(); 119 if (res.length != 0) { 120 res[0] = Character.toUpperCase(res[0]); 121 } 122 return new String (res); 123 } 124 125 128 public String jmiAssociationQualifiedName(Association association) 129 throws MofError, NotSet { 130 char[] res = association.name().toCharArray(); 131 if (res.length != 0) { 132 res[0] = Character.toUpperCase(res[0]); 133 } 134 org.omg.mof.Model.Package _package = 135 PackageHelper.narrow(association.container()); 136 return jmiPackageQualifiedName(_package) + "." + new String (res); 137 } 138 139 142 public String jmiAttributeName(MofAttribute attribute) throws MofError { 143 char[] res = attribute.name().toCharArray(); 144 if (res.length != 0) { 145 res[0] = Character.toLowerCase(res[0]); 146 } 147 return new String (res); 148 } 149 150 153 public String jmiTypeCodeName(TypeCode _type) throws BadKind { 154 switch (_type.kind().value()) { 155 case org.omg.CORBA.TCKind._tk_boolean : 156 { 157 return "boolean"; 158 159 } 160 case org.omg.CORBA.TCKind._tk_octet : 161 { 162 return "byte"; 163 164 } 165 case org.omg.CORBA.TCKind._tk_char : 166 { 167 return "char"; 168 169 } 170 case org.omg.CORBA.TCKind._tk_wchar : 171 { 172 return "char"; 173 174 } 175 case org.omg.CORBA.TCKind._tk_short : 176 { 177 return "short"; 178 179 } 180 case org.omg.CORBA.TCKind._tk_ushort : 181 { 182 return "short"; 183 184 } 185 case org.omg.CORBA.TCKind._tk_long : 186 { 187 return "int"; 188 189 } 190 case org.omg.CORBA.TCKind._tk_ulong : 191 { 192 return "int"; 193 194 } 195 case org.omg.CORBA.TCKind._tk_longlong : 196 { 197 return "long"; 198 199 } 200 case org.omg.CORBA.TCKind._tk_ulonglong : 201 { 202 return "long"; 203 204 } 205 case org.omg.CORBA.TCKind._tk_double : 206 { 207 return "double"; 208 209 } 210 case org.omg.CORBA.TCKind._tk_float : 211 { 212 return "float"; 213 214 } 215 case org.omg.CORBA.TCKind._tk_string : 216 { 217 return "String"; 218 219 } 220 case org.omg.CORBA.TCKind._tk_wstring : 221 { 222 return "String"; 223 224 } 225 case org.omg.CORBA.TCKind._tk_TypeCode : 226 { 227 return "org.omg.CORBA.TypeCode"; 228 229 } 230 case org.omg.CORBA.TCKind._tk_any : 231 { 232 return "org.omg.CORBA.Any"; 233 234 } 235 case org.omg.CORBA.TCKind._tk_objref : 236 { 237 return "org.omg.CORBA.Object"; 238 239 } 240 } 241 return _type.name(); 242 } 243 244 247 public String jmiNullableTypeCodeName(TypeCode _type) throws BadKind { 248 switch (_type.kind().value()) { 249 case org.omg.CORBA.TCKind._tk_boolean : 250 { 251 return "Boolean"; 252 253 } 254 case org.omg.CORBA.TCKind._tk_octet : 255 { 256 return "Byte"; 257 258 } 259 case org.omg.CORBA.TCKind._tk_char : 260 { 261 return "Char"; 262 263 } 264 case org.omg.CORBA.TCKind._tk_wchar : 265 { 266 return "Char"; 267 268 } 269 case org.omg.CORBA.TCKind._tk_short : 270 { 271 return "Short"; 272 273 } 274 case org.omg.CORBA.TCKind._tk_ushort : 275 { 276 return "Short"; 277 278 } 279 case org.omg.CORBA.TCKind._tk_long : 280 { 281 return "Integer"; 282 283 } 284 case org.omg.CORBA.TCKind._tk_ulong : 285 { 286 return "Integer"; 287 288 } 289 case org.omg.CORBA.TCKind._tk_longlong : 290 { 291 return "Long"; 292 293 } 294 case org.omg.CORBA.TCKind._tk_ulonglong : 295 { 296 return "Long"; 297 298 } 299 case org.omg.CORBA.TCKind._tk_double : 300 { 301 return "Double"; 302 303 } 304 case org.omg.CORBA.TCKind._tk_float : 305 { 306 return "Float"; 307 } 308 case org.omg.CORBA.TCKind._tk_string : 309 { 310 return "String"; 311 312 } 313 case org.omg.CORBA.TCKind._tk_wstring : 314 { 315 return "String"; 316 317 } 318 case org.omg.CORBA.TCKind._tk_TypeCode : 319 { 320 return "org.omg.CORBA.TypeCode"; 321 322 } 323 case org.omg.CORBA.TCKind._tk_any : 324 { 325 return "org.omg.CORBA.Any"; 326 327 } 328 case org.omg.CORBA.TCKind._tk_objref : 329 { 330 return "org.omg.CORBA.Object"; 331 332 } 333 } 334 return _type.name(); 335 } 336 337 340 public String jmiImportName(Import _import) throws MofError, NotSet { 341 return jmiPackageQualifiedName( 342 PackageHelper.narrow(_import.imported_namespace())); 343 } 344 345 348 public String jmiClassifierName(Classifier _classifier) 349 throws MofError, BadKind , NotSet { 350 if (_classifier._is_a(org.omg.mof.Model.ClassHelper.id())) 351 return jmiClassName( 352 (org.omg.mof.Model.Class) org.omg.mof.Model.ClassHelper.narrow( 353 _classifier)); 354 else if (_classifier._is_a(org.omg.mof.Model.DataTypeHelper.id())) { 355 DataType dt = (DataType) DataTypeHelper.narrow(_classifier); 356 String resu = jmiTypeCodeName(dt.type_code()); 357 return resu; 358 } else 359 return _classifier.name(); 360 } 361 362 365 public String jmiClassifierQualifiedName(Classifier _classifier) 366 throws MofError, BadKind , NotSet { 367 368 if (_classifier._is_a(org.omg.mof.Model.ClassHelper.id())) 369 return jmiClassQualifiedName( 370 (org.omg.mof.Model.Class) org.omg.mof.Model.ClassHelper.narrow( 371 _classifier)); 372 else if (_classifier._is_a(org.omg.mof.Model.DataTypeHelper.id())) { 373 DataType dt = (DataType) DataTypeHelper.narrow(_classifier); 374 Namespace ns = dt.container(); 375 String resu = jmiTypeCodeName(dt.type_code()); 376 377 if ((dt.type_code().kind().value() == TCKind._tk_struct) 378 || (dt.type_code().kind().value() == TCKind._tk_enum)) { 379 if (ns._is_a(PackageHelper.id())) { 380 org.omg.mof.Model.Package _package = 381 PackageHelper.narrow(ns); 382 resu = jmiPackageQualifiedName(_package) + "." + resu; 383 } else if (ns._is_a(ClassHelper.id())) { 384 org.omg.mof.Model.Class clazz = ClassHelper.narrow(ns); 385 org.omg.mof.Model.Package _package = 386 PackageHelper.narrow(ns.container()); 387 resu = jmiPackageQualifiedName(_package) + "." + resu; 388 } 389 } 390 return resu; 391 } else 392 return _classifier.name(); 393 } 394 395 440 public String jmiFormat1(String name) throws MofError { 441 char[] res = name.toCharArray(); 442 if (res.length != 0) { 443 res[0] = Character.toUpperCase(res[0]); 444 } 445 return new String (res); 446 } 447 448 451 public String jmiNullableClassifierName(Classifier classifier) 452 throws MofError, BadKind , NotSet { 453 if (classifier._is_a(org.omg.mof.Model.ClassHelper.id())) 454 return jmiClassName( 455 (org.omg.mof.Model.Class) org.omg.mof.Model.ClassHelper.narrow( 456 classifier)); 457 else if (classifier._is_a(org.omg.mof.Model.DataTypeHelper.id())) { 458 DataType dt = (DataType) DataTypeHelper.narrow(classifier); 459 String resu = jmiNullableTypeCodeName(dt.type_code()); 460 return resu; 461 } else 462 return classifier.name(); 463 } 466 public String jmiNullableClassifierQualifiedName(Classifier classifier) 467 throws MofError, BadKind , NotSet { 468 if (classifier._is_a(org.omg.mof.Model.ClassHelper.id())) 469 return jmiClassName( 470 (org.omg.mof.Model.Class) org.omg.mof.Model.ClassHelper.narrow( 471 classifier)); 472 else if (classifier._is_a(org.omg.mof.Model.DataTypeHelper.id())) { 473 DataType dt = (DataType) DataTypeHelper.narrow(classifier); 474 Namespace ns = dt.container(); 475 String resu = jmiNullableTypeCodeName(dt.type_code()); 476 477 if ((dt.type_code().kind().value() == TCKind._tk_struct) 478 || (dt.type_code().kind().value() == TCKind._tk_enum)) { 479 if (ns._is_a(PackageHelper.id())) { 480 org.omg.mof.Model.Package _package = 481 PackageHelper.narrow(ns); 482 resu = jmiPackageQualifiedName(_package) + "." + resu; 483 } else if (ns._is_a(ClassHelper.id())) { 484 org.omg.mof.Model.Class clazz = ClassHelper.narrow(ns); 485 org.omg.mof.Model.Package _package = 486 PackageHelper.narrow(ns.container()); 487 resu = jmiPackageQualifiedName(_package) + "." + resu; 488 } 489 } 490 return resu; 491 } else 492 return classifier.name(); 493 } 494 495 public String jmiAccessorName(MofAttribute attribute) throws MofError { 496 String accessorName = jmiFormat1(attribute.name()); 497 MultiplicityType mult = attribute.multiplicity(); 498 boolean isBoolean = false; 500 if (attribute.type()._is_a(DataTypeHelper.id())) { 501 DataType type = DataTypeHelper.narrow(attribute.type()); 502 if (type.type_code().kind().equals(TCKind.tk_boolean)) 503 isBoolean = true; 504 } 505 if (mult.lower == 0 && mult.upper == 1 && isBoolean) { 506 if (attribute.name().toLowerCase().startsWith("is")) 507 return attribute.name(); 508 else 509 return "is" + accessorName; 510 } else 511 return "get" + accessorName; 512 } 513 514 public String jmiMutatorName(MofAttribute attribute) throws MofError { 515 String mutatorName = ""; 516 MultiplicityType mult = attribute.multiplicity(); 517 boolean isBoolean = false; 519 if (attribute.type()._is_a(DataTypeHelper.id())) { 520 DataType type = DataTypeHelper.narrow(attribute.type()); 521 if (type.type_code().kind().equals(TCKind.tk_boolean)) 522 isBoolean = true; 523 } 524 if (isBoolean 525 && (mult.lower == 0 || mult.lower == 1) 526 && mult.upper == 1 527 && attribute.name().toLowerCase().startsWith("is")) { 528 return "set" + jmiFormat1(attribute.name().substring(2)); 529 } else 530 return "set" + jmiFormat1(attribute.name()); 531 } 532 533 public String valueOfConstant(org.omg.CORBA.Any _value) 534 throws org.omg.CORBA.TypeCodePackage.BadKind { 535 return mofHelper.valueOfConstant(_value); 536 } 537 538 } 539 | Popular Tags |