1 20 package org.objectweb.modfact.corba.provider; 21 22 import java.util.Enumeration ; 23 import java.util.Hashtable ; 24 import java.util.StringTokenizer ; 25 import java.util.Vector ; 26 import org.omg.mof.Model.*; 27 import org.omg.mof.Reflective.*; 28 29 import org.objectweb.modfact.corba.helper.MOFCommon; 30 31 34 public class MOFCachedProvider implements MOFCommon { 35 36 39 public String valueOfConstant(org.omg.CORBA.Any _value) 40 throws org.omg.CORBA.TypeCodePackage.BadKind { 41 org.omg.CORBA.TypeCode _typecode = _value.type(); 42 switch (_typecode.kind().value()) { 43 case org.omg.CORBA.TCKind._tk_boolean : 44 return String.valueOf(_value.extract_boolean()); 45 46 case org.omg.CORBA.TCKind._tk_octet : 47 return String.valueOf( 48 (new Byte (_value.extract_octet())).toString()); 49 50 case org.omg.CORBA.TCKind._tk_char : 51 return String.valueOf(_value.extract_char()); 52 53 case org.omg.CORBA.TCKind._tk_wchar : 54 return String.valueOf(_value.extract_wchar()); 55 56 case org.omg.CORBA.TCKind._tk_short : 57 return String.valueOf( 58 (new Short (_value.extract_short())).toString()); 59 60 case org.omg.CORBA.TCKind._tk_ushort : 61 return String.valueOf( 62 (new Short (_value.extract_ushort())).toString()); 63 64 case org.omg.CORBA.TCKind._tk_long : 65 return String.valueOf(_value.extract_long()); 66 67 case org.omg.CORBA.TCKind._tk_ulong : 68 return String.valueOf(_value.extract_ulong()); 69 70 case org.omg.CORBA.TCKind._tk_longlong : 71 return String.valueOf(_value.extract_longlong()); 72 73 case org.omg.CORBA.TCKind._tk_ulonglong : 74 return String.valueOf(_value.extract_ulonglong()); 75 76 case org.omg.CORBA.TCKind._tk_double : 77 return String.valueOf(_value.extract_double()); 78 79 case org.omg.CORBA.TCKind._tk_float : 80 return String.valueOf(_value.extract_float()); 81 82 case org.omg.CORBA.TCKind._tk_string : 83 return _value.extract_string(); 84 85 case org.omg.CORBA.TCKind._tk_wstring : 86 return _value.extract_wstring(); 87 88 default : 89 throw new org.omg.CORBA.TypeCodePackage.BadKind (); 90 } 91 } 92 93 96 public org.omg.mof.Model.MofAttribute[] attributesOfClass( 97 org.omg.mof.Model.Class _class, 98 org.omg.mof.Model.ScopeKind _scope, 99 boolean _test_of_derived) 100 throws org.omg.mof.Reflective.MofError { 101 String key = _class.ref_mof_id(); 102 MOFClassCached classCached = 103 (MOFClassCached) _contentsOfClasses.get(key); 104 Vector res; 105 if (_scope.equals(org.omg.mof.Model.ScopeKind.classifier_level)) { 106 if (_test_of_derived) 107 res = classCached.attributesClass; 108 else 109 res = classCached.attributesClassNd; 110 } else { 111 if (_test_of_derived) 112 res = classCached.attributesInst; 113 else 114 res = classCached.attributesInstNd; 115 } 116 org.omg.mof.Model.MofAttribute[] resT = 117 new org.omg.mof.Model.MofAttribute[res.size()]; 118 for (int i = 0; i < resT.length; i++) 119 resT[i] = (org.omg.mof.Model.MofAttribute) res.elementAt(i); 120 return resT; 121 122 } 123 124 130 private void addElement(Vector vector, org.omg.CORBA.Object object){ 131 boolean find = false; 132 java.util.Iterator it = vector.iterator(); 133 while (it.hasNext() && !find) { 134 org.omg.CORBA.Object obj = (org.omg.CORBA.Object ) it.next(); 135 if (obj._is_equivalent(object)) 136 find = true; 137 } 138 if (!find) 139 vector.addElement(object); 140 } 141 142 145 public org.omg.mof.Model.MofAttribute[] allAttributesOfClass( 146 org.omg.mof.Model.Class _class, 147 org.omg.mof.Model.ScopeKind _scope, 148 boolean isDerived) 149 throws org.omg.mof.Reflective.MofError { 150 Vector allSuperClasses = superClassesOrdered(_class); 152 153 Vector attributesVector = new Vector (); 155 156 for (int i = 0; i < allSuperClasses.size(); i++) { 157 158 String classId = 160 ((org.omg.mof.Model.Class) allSuperClasses.elementAt(i)) 161 .ref_mof_id(); 162 163 if (_scope.equals(ScopeKind.classifier_level)) { 164 if (!isDerived) { 165 Vector _temp = 166 ( 167 (MOFClassCached) _contentsOfClasses.get( 168 classId)).attributesClassNd; 169 for (int j = 0; j < _temp.size(); j++) 170 addElement(attributesVector, 171 (org.omg.mof.Model.MofAttribute) _temp.elementAt( 172 j)); 173 } else { 174 Vector _temp = 175 ( 176 (MOFClassCached) _contentsOfClasses.get( 177 classId)).attributesClass; 178 for (int j = 0; j < _temp.size(); j++) 179 addElement(attributesVector, 180 (org.omg.mof.Model.MofAttribute) _temp.elementAt( 181 j)); 182 } 183 } else { 184 if (!isDerived) { 185 Vector _temp = 186 ( 187 (MOFClassCached) _contentsOfClasses.get( 188 classId)).attributesInstNd; 189 for (int j = 0; j < _temp.size(); j++) 190 addElement(attributesVector, 191 (org.omg.mof.Model.MofAttribute) _temp.elementAt( 192 j)); 193 } else { 194 Vector _temp = 195 ( 196 (MOFClassCached) _contentsOfClasses.get( 197 classId)).attributesInst; 198 for (int j = 0; j < _temp.size(); j++) 199 addElement(attributesVector, 200 (org.omg.mof.Model.MofAttribute) _temp.elementAt( 201 j)); 202 } 203 } 204 } 205 org.omg.mof.Model.MofAttribute[] res = 206 new org.omg.mof.Model.MofAttribute[attributesVector.size()]; 207 for (int i = 0; i < res.length; i++) 208 res[i] = 209 (org.omg.mof.Model.MofAttribute) attributesVector.elementAt(i); 210 return res; 211 212 } 213 214 217 public org.omg.mof.Model.Operation[] operationsOfClass( 218 org.omg.mof.Model.Class _class, 219 org.omg.mof.Model.ScopeKind _scope) 220 throws org.omg.mof.Reflective.MofError { 221 Vector operationVector; 222 MOFClassCached classCached = 223 (MOFClassCached) _contentsOfClasses.get(_class.ref_mof_id()); 224 if (_scope.equals(org.omg.mof.Model.ScopeKind.classifier_level)) 225 operationVector = classCached.operationsClass; 226 else 227 operationVector = classCached.operationsInst; 228 org.omg.mof.Model.Operation[] res = 229 new org.omg.mof.Model.Operation[operationVector.size()]; 230 for (int i = 0; i < res.length; i++) 231 res[i] = (org.omg.mof.Model.Operation) operationVector.elementAt(i); 232 return res; 233 234 } 235 236 239 public org.omg.mof.Model.Operation[] allOperationsOfClass( 240 org.omg.mof.Model.Class _class, 241 org.omg.mof.Model.ScopeKind _scope) 242 throws org.omg.mof.Reflective.MofError { 243 Vector allSuperclasses = superClassesOrdered(_class); 245 246 Vector operationsVector = new Vector (); 248 249 for (int i = 0; i < allSuperclasses.size(); i++) { 250 251 String classId = 253 ((org.omg.mof.Model.Class) allSuperclasses.elementAt(i)) 254 .ref_mof_id(); 255 if (_scope.equals(ScopeKind.classifier_level)) { 256 Vector _temp = 257 ( 258 (MOFClassCached) _contentsOfClasses.get( 259 classId)).operationsClass; 260 for (int j = 0; j < _temp.size(); j++) 261 addElement(operationsVector, (Operation) _temp.elementAt(j)); 262 } else { 263 Vector _temp = 264 ( 265 (MOFClassCached) _contentsOfClasses.get( 266 classId)).operationsInst; 267 for (int j = 0; j < _temp.size(); j++) 268 addElement(operationsVector, (Operation) _temp.elementAt(j)); 269 } 270 } 271 org.omg.mof.Model.Operation[] res = 272 new org.omg.mof.Model.Operation[operationsVector.size()]; 273 for (int i = 0; i < res.length; i++) 274 res[i] = 275 (org.omg.mof.Model.Operation) operationsVector.elementAt(i); 276 return res; 277 278 } 279 280 283 public org.omg.mof.Model.Reference[] referencesOfClass( 284 org.omg.mof.Model.Class _class) 285 throws org.omg.mof.Reflective.MofError { 286 MOFClassCached classCached = 287 (MOFClassCached) _contentsOfClasses.get(_class.ref_mof_id()); 288 Vector references = classCached.refrences; 289 org.omg.mof.Model.Reference[] res = 290 new org.omg.mof.Model.Reference[references.size()]; 291 for (int i = 0; i < res.length; i++) 292 res[i] = (org.omg.mof.Model.Reference) references.elementAt(i); 293 return res; 294 295 } 296 297 300 public org.omg.mof.Model.Reference[] allReferencesOfClass( 301 org.omg.mof.Model.Class _class) 302 throws org.omg.mof.Reflective.MofError { 303 Vector allSuperClasses = superClassesOrdered(_class); 305 306 Vector referencesVector = new Vector (); 308 309 for (int i = 0; i < allSuperClasses.size(); i++) { 310 String classId = 312 ((org.omg.mof.Model.Class) allSuperClasses.elementAt(i)) 313 .ref_mof_id(); 314 315 Vector _temp = 316 ((MOFClassCached) _contentsOfClasses.get(classId)).refrences; 317 for (int j = 0; j < _temp.size(); j++) 318 addElement(referencesVector, (Reference) _temp.elementAt(j)); 319 } 320 org.omg.mof.Model.Reference[] res = 321 new org.omg.mof.Model.Reference[referencesVector.size()]; 322 for (int i = 0; i < res.length; i++) 323 res[i] = 324 (org.omg.mof.Model.Reference) referencesVector.elementAt(i); 325 return res; 326 } 327 328 331 public org.omg.mof.Model.Constant[] constantsOfClass( 332 org.omg.mof.Model.Class _class) 333 throws org.omg.mof.Reflective.MofError { 334 MOFClassCached classCached = 335 (MOFClassCached) _contentsOfClasses.get(_class.ref_mof_id()); 336 Vector constants = classCached.mofConstants; 337 org.omg.mof.Model.Constant[] res = 338 new org.omg.mof.Model.Constant[constants.size()]; 339 for (int i = 0; i < res.length; i++) 340 res[i] = (org.omg.mof.Model.Constant) constants.elementAt(i); 341 return res; 342 } 343 344 347 public org.omg.mof.Model.DataType[] datatypesOfClass( 348 org.omg.mof.Model.Class _class) 349 throws org.omg.mof.Reflective.MofError { 350 MOFClassCached classCached = 351 (MOFClassCached) _contentsOfClasses.get(_class.ref_mof_id()); 352 Vector datatypes = classCached.mofDatatypes; 353 org.omg.mof.Model.DataType[] res = 354 new org.omg.mof.Model.DataType[datatypes.size()]; 355 for (int i = 0; i < res.length; i++) 356 res[i] = (org.omg.mof.Model.DataType) datatypes.elementAt(i); 357 return res; 358 } 359 360 363 public org.omg.mof.Model.MofException[] exceptionsOfClass( 364 org.omg.mof.Model.Class _class) 365 throws org.omg.mof.Reflective.MofError { 366 MOFClassCached classCached = 367 (MOFClassCached) _contentsOfClasses.get(_class.ref_mof_id()); 368 Vector exceptions = classCached.mofExcepion; 369 org.omg.mof.Model.MofException[] res = 370 new org.omg.mof.Model.MofException[exceptions.size()]; 371 for (int i = 0; i < res.length; i++) 372 res[i] = (org.omg.mof.Model.MofException) exceptions.elementAt(i); 373 return res; 374 } 375 376 379 public org.omg.mof.Model.Constraint[] constraintsOfClass( 380 org.omg.mof.Model.Class _class) 381 throws org.omg.mof.Reflective.MofError { 382 MOFClassCached classCached = 383 (MOFClassCached) _contentsOfClasses.get(_class.ref_mof_id()); 384 Vector constraints = classCached.mofConstraints; 385 org.omg.mof.Model.Constraint[] res = 386 new org.omg.mof.Model.Constraint[constraints.size()]; 387 for (int i = 0; i < res.length; i++) 388 res[i] = (org.omg.mof.Model.Constraint) constraints.elementAt(i); 389 return res; 390 } 391 392 395 public org.omg.mof.Model.AssociationEnd[] associationEndsOfAssociation( 396 org.omg.mof.Model.Association _association) 397 throws org.omg.mof.Reflective.MofError { 398 AssociationEnd[] associationEnds = new AssociationEnd[2]; 399 ModelElement[] contents = _association.contents(); 400 401 for (int i = 0; i < contents.length; i++) { 402 if (contents[i]._is_a(AssociationEndHelper.id())) 403 associationEnds[i] = 404 (org 405 .omg 406 .mof 407 .Model 408 .AssociationEndHelper 409 .narrow(contents[i])); 410 } 411 return associationEnds; 412 } 413 414 417 public org.omg.mof.Model.AssociationEnd oppositeAssociationEnd( 418 org.omg.mof.Model.AssociationEnd _association_end) 419 throws org.omg.mof.Reflective.MofError { 420 try { 421 org.omg.mof.Model.Association asso = org.omg.mof.Model.AssociationHelper.narrow(_association_end.container()); 422 org.omg.mof.Model.AssociationEnd[] ends = associationEndsOfAssociation(asso); 423 if (ends[0]._is_equivalent(_association_end)) 424 return ends[1]; 425 else 426 return ends[0]; 427 } catch (org.omg.mof.Reflective.NotSet notSet) { 428 return null; 429 } 430 } 431 432 435 public org.omg.mof.Model.Class[] classesOfPackage( 436 org.omg.mof.Model.Package _package) 437 throws org.omg.mof.Reflective.MofError { 438 Hashtable disorderedClasses = new Hashtable (); 440 441 ModelElement[] contents = _package.contents(); 443 for (int i = 0; i < contents.length; i++) { 444 ModelElement current = contents[i]; 445 if (current._is_a(ClassHelper.id())) { 446 org.omg.mof.Model.Class _class = ClassHelper.narrow(current); 447 if (!disorderedClasses.containsKey(_class.ref_mof_id())) 448 disorderedClasses.put(_class.ref_mof_id(), _class); 449 } 450 } 451 org.omg.mof.Model.Class[] res = 452 new org.omg.mof.Model.Class[disorderedClasses.size()]; 453 int i = 0; 454 for (Enumeration e = disorderedClasses.elements(); 455 e.hasMoreElements(); 456 ) { 457 res[i++] = (org.omg.mof.Model.Class) e.nextElement(); 458 } 459 return res; 460 461 } 462 463 466 public org.omg.mof.Model.Class[] classesOfPackageOrderedByInheritance( 467 org.omg.mof.Model.Package _package) 468 throws org.omg.mof.Reflective.MofError { 469 org.omg.mof.Model.Class[] classesUnordered = classesOfPackage(_package); 470 471 Vector classesUnorderedV = new Vector (); 472 Vector classesOrderedV = new Vector (); 473 for (int i = 0; i < classesUnordered.length; i++) 474 classesUnorderedV.addElement(classesUnordered[i]); 475 476 int courant = 0; 477 while (classesUnorderedV.size() != 0) { 478 org.omg.mof.Model.Class _courant = null; 479 _courant = 480 (org.omg.mof.Model.Class) classesUnorderedV.elementAt(courant); 481 org.omg.mof.Model.GeneralizableElement[] supertypes = 482 _courant.supertypes(); 483 484 boolean _is_top = true; 485 int j = 0; 486 while (_is_top && j < supertypes.length) { 487 for (int i=0 ; i<classesUnorderedV.size() ; i++) { 491 org.omg.CORBA.Object o = (org.omg.CORBA.Object ) classesUnorderedV.elementAt(i); 492 if (o._is_equivalent(supertypes[j])) 493 _is_top = false; 494 } 495 496 j++; 497 } 498 if (_is_top) { 499 classesOrderedV.addElement(_courant); 500 classesUnorderedV.removeElement(_courant); 501 courant = 0; 502 } else 503 courant++; 504 } 505 org.omg.mof.Model.Class[] resu = 506 new org.omg.mof.Model.Class[classesOrderedV.size()]; 507 for (int i = 0; i < resu.length; i++) 508 resu[i] = (org.omg.mof.Model.Class) classesOrderedV.elementAt(i); 509 return resu; 510 } 511 512 515 public org.omg.mof.Model.Class[] allClassesOfPackage( 516 org.omg.mof.Model.Package _package) 517 throws org.omg.mof.Reflective.MofError { 518 Hashtable disorderedClasses = new Hashtable (); 520 521 ModelElement[] contents = _package.contents(); 523 for (int i = 0; i < contents.length; i++) { 524 ModelElement current = contents[i]; 525 if (current._is_a(ClassHelper.id())) { 526 org.omg.mof.Model.Class _class = ClassHelper.narrow(current); 527 if (!disorderedClasses.containsKey(_class.ref_mof_id())) 528 disorderedClasses.put(_class.ref_mof_id(), _class); 529 } else if (current._is_a(ImportHelper.id())) { 530 Import _import = ImportHelper.narrow(current); 531 532 boolean isClustered = _import.is_clustered(); 534 Namespace namespace = _import.imported_namespace(); 535 536 if (isClustered) { 538 if (namespace._is_a(ClassHelper.id())) { 539 org.omg.mof.Model.Class _class = 540 ClassHelper.narrow(namespace); 541 if (!disorderedClasses 542 .containsKey(_class.ref_mof_id())) 543 disorderedClasses.put(_class.ref_mof_id(), _class); 544 } else if (namespace._is_a(PackageHelper.id())) { 545 org.omg.mof.Model.Package clusteredPacakge = 547 PackageHelper.narrow(namespace); 548 549 org.omg.mof.Model.Class[] contentsCluster = 550 classesOfPackage(clusteredPacakge); 551 for (int j = 0; j < contentsCluster.length; j++) { 552 String key = 553 (String ) contentsCluster[j].ref_mof_id(); 554 if (!disorderedClasses.containsKey(key)) 555 disorderedClasses.put(key, contentsCluster[j]); 556 557 } 558 } 559 } 560 } else 561 if (contents[i]._is_a(PackageHelper.id())) { 563 org.omg.mof.Model.Package nestedPackage = 564 PackageHelper.narrow(contents[i]); 565 566 org.omg.mof.Model.Class[] contentsNest = 567 classesOfPackage(nestedPackage); 568 for (int j = 0; j < contentsNest.length; j++) { 569 String key = (String ) contentsNest[j].ref_mof_id(); 570 if (!disorderedClasses.containsKey(key)) 571 disorderedClasses.put(key, contentsNest[j]); 572 } 573 } 574 } 575 org.omg.mof.Model.Class[] res = 576 new org.omg.mof.Model.Class[disorderedClasses.size()]; 577 int i = 0; 578 for (Enumeration e = disorderedClasses.elements(); 579 e.hasMoreElements(); 580 ) { 581 res[i++] = (org.omg.mof.Model.Class) e.nextElement(); 582 } 583 return res; 584 } 585 586 589 public org.omg.mof.Model.Class[] allClassesOfPackageOrderedByInheritance( 590 org.omg.mof.Model.Package _package) 591 throws org.omg.mof.Reflective.MofError { 592 org.omg.mof.Model.Class[] classesUnordered = 593 allClassesOfPackage(_package); 594 595 Vector classesUnorderedV = new Vector (); 596 Vector classesOrderedV = new Vector (); 597 for (int i = 0; i < classesUnordered.length; i++) 598 classesUnorderedV.addElement(classesUnordered[i]); 599 600 int courant = 0; 601 while (classesUnorderedV.size() != 0) { 602 org.omg.mof.Model.Class _courant = null; 603 _courant = 604 (org.omg.mof.Model.Class) classesUnorderedV.elementAt(courant); 605 org.omg.mof.Model.GeneralizableElement[] supertypes = 606 _courant.supertypes(); 607 boolean _is_top = true; 608 int j = 0; 609 while (_is_top && j < supertypes.length) { 610 if (classesUnorderedV.contains(supertypes[j])) 611 _is_top = false; 612 j++; 613 } 614 if (_is_top) { 615 classesOrderedV.addElement(_courant); 616 classesUnorderedV.removeElement(_courant); 617 courant = 0; 618 } else 619 courant++; 620 } 621 org.omg.mof.Model.Class[] resu = 622 new org.omg.mof.Model.Class[classesOrderedV.size()]; 623 for (int i = 0; i < resu.length; i++) 624 resu[i] = (org.omg.mof.Model.Class) classesOrderedV.elementAt(i); 625 return resu; 626 } 627 628 631 public org.omg.mof.Model.Class[] subClassesOfClass( 632 org.omg.mof.Model.Classifier _class) 633 throws org.omg.mof.Reflective.MofError, org.omg.mof.Reflective.NotSet { 634 Vector subClasses = new Vector (); 636 637 Enumeration keysSet = _contentsOfPackages.keys(); 639 640 while (keysSet.hasMoreElements()) { 641 642 String packageId = (String ) keysSet.nextElement(); 644 Vector classesPackage = 645 ( 646 (MOFPackageCached) _contentsOfPackages.get( 647 packageId)).mofClasses; 648 649 for (int i = 0; i < classesPackage.size(); i++) { 650 org.omg.mof.Model.Class testedClass = 651 (org.omg.mof.Model.Class) classesPackage.elementAt(i); 652 653 GeneralizableElement[] superClasses = 654 testedClass.all_supertypes(); 655 656 int j = 0; 657 boolean sub = false; 658 659 while ((j < superClasses.length) && !sub) { 660 if (superClasses[j] 661 .ref_mof_id() 662 .equals(_class.ref_mof_id())) { 663 sub = true; 664 665 addElement(subClasses, testedClass); 669 } 670 j++; 671 } 672 } 673 } 674 675 org.omg.mof.Model.Class[] subTable = 676 new org.omg.mof.Model.Class[subClasses.size()]; 677 for (int i = 0; i < subClasses.size(); i++) 678 subTable[i] = (org.omg.mof.Model.Class) subClasses.elementAt(i); 679 return subTable; 680 681 } 682 683 686 public org.omg.mof.Model.Package[] packagesOfPackage( 687 org.omg.mof.Model.Package _package) 688 throws org.omg.mof.Reflective.MofError { 689 MOFPackageCached packageCached = 690 (MOFPackageCached) _contentsOfPackages.get(_package.ref_mof_id()); 691 Vector packages = packageCached.mofPackages; 692 org.omg.mof.Model.Package[] res = 693 new org.omg.mof.Model.Package[packages.size()]; 694 for (int i = 0; i < res.length; i++) 695 res[i] = (org.omg.mof.Model.Package) packages.elementAt(i); 696 return res; 697 } 698 699 702 public org.omg.mof.Model.Association[] allAssociationsOfPackage( 703 org.omg.mof.Model.Package _package) 704 throws org.omg.mof.Reflective.MofError { 705 Hashtable disorderedAssociations = new Hashtable (); 707 708 ModelElement[] contents = _package.contents(); 710 for (int i = 0; i < contents.length; i++) { 711 ModelElement current = contents[i]; 712 if (current._is_a(AssociationHelper.id())) { 713 org.omg.mof.Model.Association _association = AssociationHelper.narrow(current); 714 if (!disorderedAssociations.containsKey(_association.ref_mof_id())) 715 disorderedAssociations.put(_association.ref_mof_id(), _association); 716 } else if (current._is_a(ImportHelper.id())) { 717 Import _import = ImportHelper.narrow(current); 718 boolean isClustered = _import.is_clustered(); 720 Namespace namespace = _import.imported_namespace(); 721 if (isClustered) { 723 if (namespace._is_a(AssociationHelper.id())) { 724 org.omg.mof.Model.Association _association = 725 AssociationHelper.narrow(namespace); 726 if (!disorderedAssociations 727 .containsKey(_association.ref_mof_id())) 728 disorderedAssociations.put(_association.ref_mof_id(), _association); 729 } else if (namespace._is_a(PackageHelper.id())) { 730 org.omg.mof.Model.Package clusteredPacakge = 732 PackageHelper.narrow(namespace); 733 org.omg.mof.Model.Association[] contentsCluster = 734 associationsOfPackage(clusteredPacakge); 735 for (int j = 0; j < contentsCluster.length; j++) { 736 String key = 737 (String ) contentsCluster[j].ref_mof_id(); 738 if (!disorderedAssociations.containsKey(key)) 739 disorderedAssociations.put(key, contentsCluster[j]); 740 } 741 } 742 } 743 } else 744 if (contents[i]._is_a(PackageHelper.id())) { 746 org.omg.mof.Model.Package nestedPackage = 747 PackageHelper.narrow(contents[i]); 748 org.omg.mof.Model.Association[] contentsNest = 749 associationsOfPackage(nestedPackage); 750 for (int j = 0; j < contentsNest.length; j++) { 751 String key = (String ) contentsNest[j].ref_mof_id(); 752 if (!disorderedAssociations.containsKey(key)) 753 disorderedAssociations.put(key, contentsNest[j]); 754 } 755 } 756 } 757 org.omg.mof.Model.Association[] res = 758 new org.omg.mof.Model.Association[disorderedAssociations.size()]; 759 int i = 0; 760 for (Enumeration e = disorderedAssociations.elements(); 761 e.hasMoreElements(); 762 ) { 763 res[i++] = (org.omg.mof.Model.Association) e.nextElement(); 764 } 765 return res; 766 } 767 768 771 public org.omg.mof.Model.Association[] associationsOfPackage( 772 org.omg.mof.Model.Package _package) 773 throws org.omg.mof.Reflective.MofError { 774 MOFPackageCached packageCached = 775 (MOFPackageCached) _contentsOfPackages.get(_package.ref_mof_id()); 776 Vector associations = packageCached.mofAssociations; 777 org.omg.mof.Model.Association[] res = 778 new org.omg.mof.Model.Association[associations.size()]; 779 for (int i = 0; i < res.length; i++) 780 res[i] = (org.omg.mof.Model.Association) associations.elementAt(i); 781 return res; 782 } 783 784 787 public org.omg.mof.Model.Import[] importsOfPackage( 788 org.omg.mof.Model.Package _package) 789 throws org.omg.mof.Reflective.MofError { 790 MOFPackageCached packageCached = 791 (MOFPackageCached) _contentsOfPackages.get(_package.ref_mof_id()); 792 Vector imports = packageCached.mofImports; 793 org.omg.mof.Model.Import[] res = 794 new org.omg.mof.Model.Import[imports.size()]; 795 for (int i = 0; i < res.length; i++) 796 res[i] = (org.omg.mof.Model.Import) imports.elementAt(i); 797 return res; 798 } 799 800 803 public org.omg.mof.Model.Tag[] tagsOfPackage( 804 org.omg.mof.Model.Package _package) 805 throws org.omg.mof.Reflective.MofError { 806 MOFPackageCached packageCached = 807 (MOFPackageCached) _contentsOfPackages.get(_package.ref_mof_id()); 808 Vector tags = packageCached.mofTags; 809 org.omg.mof.Model.Tag[] res = new org.omg.mof.Model.Tag[tags.size()]; 810 for (int i = 0; i < res.length; i++) 811 res[i] = (org.omg.mof.Model.Tag) tags.elementAt(i); 812 return res; 813 } 814 815 818 public org.omg.mof.Model.MofException[] exceptionsOfPackage( 819 org.omg.mof.Model.Package _package) 820 throws org.omg.mof.Reflective.MofError { 821 MOFPackageCached packageCached = 822 (MOFPackageCached) _contentsOfPackages.get(_package.ref_mof_id()); 823 Vector exceptions = packageCached.mofExceptions; 824 org.omg.mof.Model.MofException[] res = 825 new org.omg.mof.Model.MofException[exceptions.size()]; 826 for (int i = 0; i < res.length; i++) 827 res[i] = (org.omg.mof.Model.MofException) exceptions.elementAt(i); 828 return res; 829 } 830 831 834 public org.omg.mof.Model.Constraint[] constraintsOfPackage( 835 org.omg.mof.Model.Package _package) 836 throws org.omg.mof.Reflective.MofError { 837 MOFPackageCached packageCached = 838 (MOFPackageCached) _contentsOfPackages.get(_package.ref_mof_id()); 839 Vector constraints = packageCached.mofConstraints; 840 org.omg.mof.Model.Constraint[] res = 841 new org.omg.mof.Model.Constraint[constraints.size()]; 842 for (int i = 0; i < res.length; i++) 843 res[i] = (org.omg.mof.Model.Constraint) constraints.elementAt(i); 844 return res; 845 } 846 847 850 public org.omg.mof.Model.Constant[] constantsOfPackage( 851 org.omg.mof.Model.Package _package) 852 throws org.omg.mof.Reflective.MofError { 853 MOFPackageCached packageCached = 854 (MOFPackageCached) _contentsOfPackages.get(_package.ref_mof_id()); 855 Vector constants = packageCached.mofConstants; 856 org.omg.mof.Model.Constant[] res = 857 new org.omg.mof.Model.Constant[constants.size()]; 858 for (int i = 0; i < res.length; i++) 859 res[i] = (org.omg.mof.Model.Constant) constants.elementAt(i); 860 return res; 861 } 862 863 866 public org.omg.mof.Model.DataType[] datatypesOfPackage( 867 org.omg.mof.Model.Package _package) 868 throws org.omg.mof.Reflective.MofError { 869 MOFPackageCached packageCached = 870 (MOFPackageCached) _contentsOfPackages.get(_package.ref_mof_id()); 871 Vector datatypes = packageCached.mofDataType; 872 org.omg.mof.Model.DataType[] res = 873 new org.omg.mof.Model.DataType[datatypes.size()]; 874 for (int i = 0; i < res.length; i++) 875 res[i] = (org.omg.mof.Model.DataType) datatypes.elementAt(i); 876 return res; 877 } 878 879 882 public org.omg.mof.Model.Reference[] referencesOfAssociation( 883 org.omg.mof.Model.Association _association) 884 throws org.omg.mof.Reflective.MofError, org.omg.mof.Reflective.NotSet { 885 Vector referencesVector = new Vector (); 886 887 org.omg.mof.Model.Package containerPackage = 889 PackageHelper.narrow(_association.container()); 890 891 MOFPackageCached packageTuple = 893 (MOFPackageCached) _contentsOfPackages.get( 894 containerPackage.ref_mof_id()); 895 896 Vector classesOfPackage = packageTuple.mofClasses; 897 898 AssociationEnd[] association_ends = 900 associationEndsOfAssociation(_association); 901 902 for (int i = 0; i < classesOfPackage.size(); i++) { 904 905 org.omg.mof.Model.Class _class = 906 (org.omg.mof.Model.Class) classesOfPackage.elementAt(i); 907 908 MOFClassCached classTuple = 910 (MOFClassCached) _contentsOfClasses.get(_class.ref_mof_id()); 911 Vector references = classTuple.refrences; 912 913 for (int j = 0; j < references.size(); j++) { 914 Reference _reference = (Reference) references.elementAt(j); 915 916 AssociationEnd _association_end = _reference.referenced_end(); 917 918 if (_association_end.equals(association_ends[0]) 920 || _association_end._is_equivalent(association_ends[1])) { 921 referencesVector.addElement(_reference); 922 } 923 } 924 } 925 926 Reference[] referencesTable = new Reference[referencesVector.size()]; 927 for (int i = 0; i < referencesTable.length; i++) 928 referencesTable[i] = (Reference) referencesVector.elementAt(i); 929 return referencesTable; 930 931 } 932 933 private boolean contains( 934 java.util.Vector _vector, 935 org.omg.mof.Reflective.RefBaseObject _object) { 936 if (_vector.size() == 0) 937 return false; 938 int i = 0; 939 boolean _is_contained = false; 940 while (!_is_contained && (i < _vector.size())) { 941 org.omg.mof.Reflective.RefBaseObject _current = 942 (org.omg.mof.Reflective.RefBaseObject) _vector.elementAt(i); 943 if (_current.ref_itself(_object)) 944 _is_contained = true; 945 else 946 i++; 947 } 948 return _is_contained; 949 } 950 951 954 public org.omg.mof.Model.Package outermostPackageOfModelElement( 955 org.omg.mof.Model.ModelElement _element) 956 throws org.omg.mof.Reflective.MofError, org.omg.mof.Reflective.NotSet { 957 org.omg.mof.Model.Package _package = null; 958 959 ModelElement container = _element; 960 961 boolean find = false; 962 while (!find) { 963 if (container._is_a(PackageHelper.id())) { 964 _package = PackageHelper.narrow(container); 965 if (isOutermostPackage(_package)) 966 find = true; 967 else 968 container = container.container(); 969 970 } else 971 container = container.container(); 972 } 973 return _package; 974 } 975 976 979 public boolean isOutermostPackage(org.omg.mof.Model.Namespace _package) { 980 boolean isOutermost = false; 981 if (_outermostPackages.containsKey(_package.ref_mof_id())) 982 isOutermost = true; 983 return isOutermost; 984 } 985 986 989 public String idlPrefixForPackage(org.omg.mof.Model.Package _package) 990 throws MofError { 991 992 String _prefix_mof = ""; 993 994 MOFPackageCached _packageTuple = 995 (MOFPackageCached) _contentsOfPackages.get(_package.ref_mof_id()); 996 997 Vector tags = _packageTuple.mofTags; 998 999 boolean end = false; 1000 int index = 0; 1001 while (!end && (index < tags.size())) { 1002 Tag _tag = (Tag) tags.elementAt(index); 1003 ModelElement[] _elements = _tag.elements(); 1004 if (_elements[0].ref_itself(_package)) 1005 end = true; 1006 else 1007 index++; 1008 } 1009 if (end) { 1010 Tag _the_tag = (Tag) tags.elementAt(index); 1011 if (_the_tag.tag_id().equals("org.omg.mof.idl_prefix")) { 1012 StringTokenizer _prefix_inv = 1013 new StringTokenizer ( 1014 _the_tag.values()[0].extract_string(), 1015 "."); 1016 String [] _temp = new String [_prefix_inv.countTokens()]; 1017 for (int i = 0; i < _temp.length; i++) 1018 _temp[i] = _prefix_inv.nextToken(); 1019 String _prefix = ""; 1020 for (int i = _temp.length - 1; i > -1; i--) { 1021 _prefix = _prefix + _temp[i]; 1022 if (i != 0) 1023 _prefix = _prefix + "."; 1024 } 1025 _prefix_mof = _prefix; 1026 } 1027 } 1028 return _prefix_mof; 1029 } 1030 1031 1034 public String idlSubstituteIdentifierForClass( 1035 org.omg.mof.Model.Classifier clazz) 1036 throws MofError, NotSet { 1037 org.omg.mof.Model.Package _package = 1038 PackageHelper.narrow(clazz.container()); 1039 Tag[] tags = tagsOfPackage(_package); 1040 boolean idlSubstituteB = false; 1041 String idlSubstitute = ""; 1042 int i = 0; 1043 while (!idlSubstituteB 1044 && i < tags.length) { if (tags[i].tag_id().compareTo("org.omg.mof.idl_substitute_name") 1046 == 0) { 1047 String name = tags[i].elements().toString(); 1048 String name2 = tags[i].name(); 1049 if (tags[i].elements().length > 0) { 1051 if ((tags[i].elements()[0]!=null) && (tags[i].elements()[0]._is_a(org.omg.mof.Model.ClassifierHelper.id()))) { 1052 if (tags[i].elements()[0].ref_itself(clazz)) { 1053 idlSubstitute = tags[i].values()[0].extract_string(); 1054 idlSubstituteB = true; 1055 }} 1056 } 1057 } 1058 i++; 1059 } 1060 return idlSubstitute; 1061 } 1062 1063 1066 public String jmiPrefixForPackage(org.omg.mof.Model.Package _package) 1067 throws MofError { 1068 Tag[] tags = tagsOfPackage(_package); 1069 boolean jmiPrefix = false; 1070 String jmi_prefix = ""; 1071 int i = 0; 1072 while (!jmiPrefix && i < tags.length) { if ((tags[i].tag_id().compareTo("javax.jmi.packagePrefix") == 0 1074 || tags[i].tag_id().compareTo("com.urep.jcr.java_prefix") == 0) 1075 && tags[i].elements()[0].ref_itself(_package)) { 1076 jmi_prefix = tags[i].values()[0].extract_string(); 1077 jmiPrefix = true; 1078 } else 1079 i++; 1080 } 1081 return jmi_prefix; 1082 } 1083 1084 1087 public String jmiSubstituteIdentifierForClass( 1088 org.omg.mof.Model.Class clazz) 1089 throws MofError, NotSet { 1090 org.omg.mof.Model.Package _package = 1091 PackageHelper.narrow(clazz.container()); 1092 Tag[] tags = tagsOfPackage(_package); 1093 boolean jmiSubstituteB = false; 1094 String jmiSubstitute = ""; 1095 int i = 0; 1096 while (!jmiSubstituteB && i < tags.length) { if (tags[i].tag_id().compareTo("javax.jmi.substituteName") == 0 1098 || tags[i].tag_id().compareTo("com.urep.jcr.java_substitute_name") 1099 == 0) { 1100 String name = tags[i].elements()[0].name(); 1101 if (tags[i].elements()[0].ref_itself(clazz)) { 1102 jmiSubstitute = tags[i].values()[0].extract_string(); 1103 jmiSubstituteB = true; 1104 } 1105 } 1106 i++; 1107 } 1108 return jmiSubstitute; 1109 } 1110 1111 1114 public boolean isInSameExtent( 1115 org.omg.mof.Model.Class innerExtent, 1116 org.omg.mof.Model.Class outerExtent) 1117 throws NotSet, MofError { 1118 boolean isInSameExtent = false; 1119 org.omg.mof.Model.Package packageOfOuterClass = 1120 PackageHelper.narrow(innerExtent.container()); 1121 org.omg.mof.Model.Package packageOfInnerClass = 1122 PackageHelper.narrow(outerExtent.container()); 1123 1124 if (packageOfOuterClass.ref_itself(packageOfInnerClass)) 1126 return true; 1127 1128 if (isNested(packageOfOuterClass, packageOfInnerClass)) 1130 return true; 1131 1132 Import[] imports = importsOfPackage(packageOfInnerClass); 1134 int i = 0; 1135 while (!isInSameExtent && i < imports.length) { 1136 if (imports[i].is_clustered() 1137 && packageOfOuterClass.ref_itself( 1138 imports[i].imported_namespace())) 1139 isInSameExtent = true; 1140 else 1141 i++; 1142 } 1143 1144 return isInSameExtent; 1145 } 1146 1147 public boolean isNested( 1148 org.omg.mof.Model.Package nestedPackage, 1149 org.omg.mof.Model.Package nestingPackage) 1150 throws MofError { 1151 boolean isNested = false; 1152 org.omg.mof.Model.Package nestedPackages[] = 1153 packagesOfPackage(nestingPackage); 1154 int i = 0; 1155 while (!isNested && i < nestedPackages.length) { 1156 if (nestedPackage.ref_itself(nestedPackages[i])) 1157 isNested = true; 1158 else { 1159 isNested = isNested(nestedPackage, nestedPackages[i]); 1160 i++; 1161 } 1162 } 1163 return isNested; 1164 } 1165 1166 1172 private Hashtable _outermostPackages = new Hashtable (); 1174 private Hashtable _packagesOfMetamodel = new Hashtable (); 1175 private Hashtable _contentsOfPackages = new Hashtable (); 1176 private Hashtable _contentsOfClasses = new Hashtable (); 1177 1178 1181 public void init(org.omg.mof.Model.Package[] outermostPackages) 1182 throws NotSet, MofError { 1183 for (int i = 0; i < outermostPackages.length; i++) { 1184 org.omg.mof.Model.Package _package = outermostPackages[i]; 1185 String key = _package.ref_mof_id(); 1186 _packagesOfMetamodel.put(key, _package); 1187 _outermostPackages.put(key, ""); 1188 contentsOfPackage(_package); 1189 } 1190 } 1191 1192 1195 private void contentsOfPackage(org.omg.mof.Model.Package _package) 1196 throws MofError { 1197 1198 MOFPackageCached current = new MOFPackageCached(); 1199 1200 ModelElement[] _contents = _package.contents(); 1202 1203 for (int i = 0; i < _contents.length; i++) { 1204 if (_contents[i]._is_a(ClassHelper.id())) { 1205 org.omg.mof.Model.Class _class = 1206 ClassHelper.narrow(_contents[i]); 1207 current.mofClasses.addElement(_class); 1208 contentsOfClass(_class); 1209 } else if (_contents[i]._is_a(AssociationHelper.id())) { 1210 Association _association = 1211 AssociationHelper.narrow(_contents[i]); 1212 current.mofAssociations.addElement(_association); 1213 } else if (_contents[i]._is_a(TagHelper.id())) { 1214 Tag _tag = TagHelper.narrow(_contents[i]); 1215 current.mofTags.addElement(_tag); 1216 } else if (_contents[i]._is_a(ImportHelper.id())) { 1217 Import _import = ImportHelper.narrow(_contents[i]); 1218 current.mofImports.addElement(_import); 1219 } else if (_contents[i]._is_a(ConstantHelper.id())) { 1220 Constant _constant = ConstantHelper.narrow(_contents[i]); 1221 current.mofConstants.addElement(_constant); 1222 } else if (_contents[i]._is_a(DataTypeHelper.id())) { 1223 DataType _datatype = DataTypeHelper.narrow(_contents[i]); 1224 current.mofDataType.addElement(_datatype); 1225 } else if (_contents[i]._is_a(ConstraintHelper.id())) { 1226 Constraint _constraint = ConstraintHelper.narrow(_contents[i]); 1227 current.mofConstraints.addElement(_constraint); 1228 } else if (_contents[i]._is_a(MofExceptionHelper.id())) { 1229 MofException _exception = 1230 MofExceptionHelper.narrow(_contents[i]); 1231 current.mofExceptions.addElement(_exception); 1232 } else if (_contents[i]._is_a(PackageHelper.id())) { 1233 org.omg.mof.Model.Package _nestedPackage = 1234 PackageHelper.narrow(_contents[i]); 1235 current.mofPackages.addElement(_nestedPackage); 1236 contentsOfPackage(_nestedPackage); 1237 } 1238 } 1239 1240 String key = _package.ref_mof_id(); 1242 _contentsOfPackages.put(key, current); 1243 1244 } 1245 1246 1249 private void contentsOfClass(org.omg.mof.Model.Class _class) 1250 throws MofError { 1251 1252 MOFClassCached current = new MOFClassCached(); 1253 1254 1256 ModelElement[] _contents = _class.contents(); 1257 1258 for (int i = 0; i < _contents.length; i++) { 1259 1260 if (_contents[i]._is_a(MofAttributeHelper.id())) { 1262 MofAttribute _attribute = 1263 MofAttributeHelper.narrow(_contents[i]); 1264 if (_attribute.visibility() == VisibilityKind.public_vis) { 1265 1266 if (_attribute.scope() == ScopeKind.classifier_level) { 1267 if (!_attribute.is_derived() == true) 1268 current.attributesClassNd.addElement(_attribute); 1269 current.attributesClass.addElement(_attribute); 1270 } else { 1271 if (!_attribute.is_derived() == true) 1272 current.attributesInstNd.addElement(_attribute); 1273 current.attributesInst.addElement(_attribute); 1274 } 1275 } 1276 } 1277 else if (_contents[i]._is_a(OperationHelper.id())) { 1279 Operation _operation = OperationHelper.narrow(_contents[i]); 1280 1281 if (_operation.visibility() == VisibilityKind.public_vis) { 1282 if (_operation.scope() == ScopeKind.classifier_level) 1283 current.operationsClass.addElement(_operation); 1284 else 1285 current.operationsInst.addElement(_operation); 1286 } 1287 } 1288 1289 else if (_contents[i]._is_a(ReferenceHelper.id())) { 1291 Reference _reference = ReferenceHelper.narrow(_contents[i]); 1292 1293 if (_reference.visibility() == VisibilityKind.public_vis) 1294 current.refrences.addElement(_reference); 1295 } 1296 1297 else if (_contents[i]._is_a(ConstantHelper.id())) { 1299 Constant _constant = ConstantHelper.narrow(_contents[i]); 1300 1301 current.mofConstants.addElement(_constant); 1302 } 1303 else if (_contents[i]._is_a(ConstraintHelper.id())) { 1305 Constraint _constraint = ConstraintHelper.narrow(_contents[i]); 1306 1307 current.mofConstraints.addElement(_constraint); 1308 } 1309 else if (_contents[i]._is_a(TagHelper.id())) { 1311 Tag _tag = TagHelper.narrow(_contents[i]); 1312 1313 current.mofTags.addElement(_tag); 1314 } 1315 else if (_contents[i]._is_a(MofExceptionHelper.id())) { 1317 MofException _exception = 1318 MofExceptionHelper.narrow(_contents[i]); 1319 1320 current.mofExcepion.addElement(_exception); 1321 } 1322 1323 else if (_contents[i]._is_a(DataTypeHelper.id())) { 1325 DataType _datatype = DataTypeHelper.narrow(_contents[i]); 1326 1327 current.mofDatatypes.addElement(_datatype); 1328 } 1329 1330 } 1331 1332 String classId = _class.ref_mof_id(); 1334 1335 _contentsOfClasses.put(classId, current); 1336 } 1337 1338 1341 public Vector superClassesOrdered(org.omg.mof.Model.Class _class) 1342 throws MofError { 1343 1344 Vector superClasses = new Vector (); 1345 1346 1348 GeneralizableElement[] allSuperClasses = _class.all_supertypes(); 1349 for (int i = 0; i < allSuperClasses.length; i++) 1350 addElement(superClasses, ClassHelper.narrow(allSuperClasses[i])); 1351 1352 superClasses.addElement(_class); 1353 1354 return superClasses; 1355 } 1356 1357 public MOFCachedProvider(org.omg.mof.Model.Package[] outermost) 1358 throws NotSet, MofError { 1359 init(outermost); 1361 } 1362} 1363 | Popular Tags |