| 1 2 package SOFA.SOFAnode.Made.CDL; 3 import java.io.IOException ; 4 import java.rmi.Naming ; 5 import java.rmi.RemoteException ; 6 7 import SOFA.SOFAnode.Made.TIR.ArchitectureDef; 8 import SOFA.SOFAnode.Made.TIR.CDLContainer; 9 import SOFA.SOFAnode.Made.TIR.CDLRepository; 10 import SOFA.SOFAnode.Made.TIR.ConstantDef; 11 import SOFA.SOFAnode.Made.TIR.Contained; 12 import SOFA.SOFAnode.Made.TIR.Container; 13 import SOFA.SOFAnode.Made.TIR.DefinitionKind; 14 import SOFA.SOFAnode.Made.TIR.EnumDef; 15 import SOFA.SOFAnode.Made.TIR.EnumMember; 16 import SOFA.SOFAnode.Made.TIR.ExceptionDef; 17 import SOFA.SOFAnode.Made.TIR.FrameDef; 18 import SOFA.SOFAnode.Made.TIR.Identification; 19 import SOFA.SOFAnode.Made.TIR.InterfaceDef; 20 import SOFA.SOFAnode.Made.TIR.ModuleDef; 21 import SOFA.SOFAnode.Made.TIR.ProfileDef; 22 import SOFA.SOFAnode.Made.TIR.ProviderDef; 23 import SOFA.SOFAnode.Made.TIR.Repository; 24 import SOFA.SOFAnode.Made.TIR.StructDef; 25 import SOFA.SOFAnode.Made.TIR.TIRExceptCommit; 26 import SOFA.SOFAnode.Made.TIR.TIRExceptCreate; 27 import SOFA.SOFAnode.Made.TIR.TIRExceptLock; 28 import SOFA.SOFAnode.Made.TIR.TypedefDef; 29 import SOFA.SOFAnode.Made.TIR.UnionDef; 30 import SOFA.SOFAnode.Made.TIR.WorkRepository; 31 32 class CompRepository extends CompContainerIm { 33 class CompRepExcept extends Exception { 34 public CompRepExcept() { super(); } 35 public CompRepExcept(String s) { super(s); } 36 } 37 38 public Repository defRepository; 39 public WorkRepository workRepository; 40 public CDLRepository cdlRepository; public ProfileDef profile; 42 43 public Scopename aktScope; 44 45 public List defaultTypes; 46 47 public String searchError; 48 49 public boolean useProtocols; public boolean testProtocols; 52 public SOFA.SOFAnode.Util.BehaviorProtocolChecker protocolChecker; 53 54 public CompRepository(Scopename aktScope) throws Exception { 55 super(ObjectsKind.o_Repository); 56 this.aktScope = aktScope; 57 58 String rmiport = System.getProperty("tir.rmiport","1099"); 59 String rmihost = System.getProperty("tir.rmihost","localhost"); 60 defRepository = (Repository) Naming.lookup("//"+rmihost+":"+rmiport+"/Repository"); 61 62 boolean ok = false; 63 int i = 0; 64 65 String profName = System.getProperty("cdl.profile",null); 66 while (!ok) { 67 try { 68 if (profName==null) 69 profile = null; 70 else { 71 profile = defRepository.getProfiles().lookup(profName); 72 if (profile == null) 73 throw new CDLExceptBadName("Profile with name "+profName+" doesn't exist."); 74 } 75 ok = true; 76 } catch (TIRExceptLock e) { 77 if (i == Consts.repeatCount) 78 throw new CDLExceptLock("Repository is locked."); 79 else { 80 i++; 81 System.err.println("Repository is locked. Waiting for next attempt."); 82 Thread.sleep(Consts.repeatDelay); 83 } 84 } 85 } 86 87 ok = false; 88 i = 0; 89 while (!ok) { 90 try { 91 if (System.getProperty("cdl.debug","no").compareTo("yes")==0) { 92 System.out.println(java.util.Calendar.getInstance().getTime().getTime()); 93 workRepository = defRepository.beginChanges(profile); 94 System.out.println(java.util.Calendar.getInstance().getTime().getTime()); 95 } else { 96 workRepository = defRepository.beginChanges(profile); 97 } 98 profile = workRepository.profile(); 99 ok = true; 100 } catch (TIRExceptLock e) { 101 if (i == Consts.repeatCount) 102 throw new CDLExceptLock("Repository is locked."); 103 else { 104 i++; 105 System.err.println("Repository is locked. Waiting for next attempt."); 106 Thread.sleep(Consts.repeatDelay); 107 } 108 } 109 } 110 111 cdlRepository = (CDLRepository) workRepository.lookup("cdl",""); 112 113 useProtocols = false; 114 testProtocols = false; 115 String prot = System.getProperty("cdl.protocols","no"); 116 if (prot.compareTo("yes")==0) 117 useProtocols = true; 118 prot = System.getProperty("cdl.testprotocols","no"); 119 if (prot.compareTo("yes")==0) { 120 useProtocols = true; 121 testProtocols = true; 122 } 123 124 defaultTypes = new List(); 125 searchError = null; 126 127 protocolChecker = SOFA.SOFAnode.Util.BehaviorProtocolCheckerFactory.getChecker(System.getProperty("cdl.protocolChecker",null)); 128 } 129 130 131 public CompRepository(Scopename aktScope, Repository defRep, WorkRepository workRep, boolean useProt, boolean testProt) throws Exception { 132 super(ObjectsKind.o_Repository); 133 this.aktScope = aktScope; 134 135 defRepository = defRep; 136 137 workRepository = workRep; 138 profile = workRepository.profile(); 139 cdlRepository = (CDLRepository) workRepository.lookup("cdl",""); 140 141 useProtocols = useProt; 142 testProtocols = testProt; 143 if (testProt) { 144 useProtocols = true; 145 System.setProperty("cdl.protocols","yes"); 146 System.setProperty("cdl.testprotocols","yes"); 147 } else { 148 System.setProperty("cdl.testprotocols","no"); 149 if (useProtocols) 150 System.setProperty("cdl.protocols","yes"); 151 else 152 System.setProperty("cdl.protocols","no"); 153 } 154 155 defaultTypes = new List(); 156 searchError = null; 157 158 protocolChecker = SOFA.SOFAnode.Util.BehaviorProtocolCheckerFactory.getChecker(System.getProperty("cdl.protocolChecker",null)); 159 } 160 161 public void checkConsist(EnumList props, CompRepository rep) throws CDLExceptCheck, CDLExceptLock, CDLExceptRemote { 162 CompContained[] cont = contents(); 163 for (int i=0;i<cont.length;i++) { 164 switch (cont[i].objectKind()) { 165 case ObjectsKind.o_Module: 166 cont[i].checkConsist(null,rep); 167 break; 168 case ObjectsKind.o_Interface: 169 cont[i].checkConsist(null,rep); 170 break; 171 case ObjectsKind.o_Frame: 172 try { 173 cont[i].checkConsist(null,rep); 174 } catch (CDLExceptCheck e) { 175 throw new CDLExceptCheck(e.getMessage()+" in frame "+cont[i].fullName()); 176 } 177 break; 178 case ObjectsKind.o_Provider: 179 cont[i].checkConsist(null,rep); 180 } 181 } 182 } 183 184 249 250 public CompReffer searchReffer(String name, String version) throws CDLExceptLock, CDLExceptRemote { 251 if (name!=null && name.length()!=0) { 252 FullID id = null; 254 if (name.charAt(0)==':') { 255 if (aktScope.length()==0) 256 id = new FullID ("::"+name , version); 257 else 258 id = new FullID (aktScope.toString()+"::"+name , version); 259 } else { 260 id = new FullID (name, version); 261 } 262 return searchReffer(id); 263 } else 264 return null; 265 } 266 267 279 280 292 293 public CompReffer searchReffer(FullID id) throws CDLExceptLock, CDLExceptRemote { 294 return searchReffer(id, 0); 295 } 296 297 300 public CompReffer searchReffer(FullID id, int cancelNameSpace) throws CDLExceptLock, CDLExceptRemote { 301 int i,j; 302 long numPath = 0; 303 if (!id.isAbsolute) { 305 FullID nid = new FullID(true); 307 aktScope.names.toFirst(); 308 for(i=0;i<aktScope.length()-cancelNameSpace;i++) { 309 nid.sn.addScope((String )aktScope.names.aktual()); 310 aktScope.names.toNext(); 311 } 312 numPath = aktScope.length(); 313 id.sn.names.toFirst(); 314 for(i=0;i<id.sn.length();i++) { 315 nid.sn.addScope((String )id.sn.names.aktual()); 316 id.sn.names.toNext(); 317 } 318 nid.name = id.name; 319 nid.setVersion(id.version); 320 id = nid; 321 } 322 325 switch (id.isin) { 326 case IDKind.none : return searchRefferDefault(id, numPath); 327 case IDKind.version : return searchRefferVersion(id, numPath); 328 case IDKind.tag : return searchRefferTag(id, numPath); 329 } 330 return null; 331 } 332 333 private CompReffer searchRefferVersion(FullID id, long numPath) throws CDLExceptLock, CDLExceptRemote { 334 int i,j; 335 336 try { 337 CompContainer con = this; 339 id.sn.names.toFirst(); 340 for(i=0;i<id.sn.names.size();i++) { 341 CompContained[] a = con.lookup((String ) id.sn.names.aktual()); 342 if (a==null || a.length==0) 343 throw new CompRepExcept(); 344 if (a.length==1) { 345 if (a[0].isContainer()) con = (CompContainer) a[0]; 346 else throw new CompRepExcept(); 347 } else { 348 boolean found = false; 349 for(j=0;j<a.length;j++) { 350 if (a[j].getIdent().version.compareTo(id.version)==0) { 351 if ( ! a[j].isContainer()) throw new CompRepExcept(); 352 found = true; 353 con = (CompContainer) a[j]; 354 break; 355 } 356 } 357 if (!found) throw new CompRepExcept(); 358 } 359 id.sn.names.toNext(); 360 } 361 CompContained sec = con.lookup(id.name, id.version); 362 if (sec!=null) { 363 CompReffer ret = new CompReffer(); 364 ret.what = sec.objectKind(); 365 ret.ref = new FullID(true); 366 ret.ref.name = new String (id.name); 367 ret.ref.version = new String (id.version); 368 ret.ref.isin = IDKind.version; 369 ret.isNew = true; 370 id.sn.names.toFirst(); 371 for(j=0;j<id.sn.names.size();j++) { 372 ret.ref.sn.addScope(new String ((String )id.sn.names.aktual())); 373 id.sn.names.toNext(); 374 } 375 if (ret.what == ObjectsKind.o_Frame) 376 ret.isSystem = ((CompFrame)sec).isSystem; 377 if (ret.what == ObjectsKind.o_Architecture) 378 ret.isSystem = ((CompArchitecture)sec).isSystem; 379 return ret; 380 } 381 } catch (CompRepExcept e) {;} 383 384 try { 386 Container con = cdlRepository; 387 id.sn.names.toFirst(); 388 for(i=0;i<id.sn.names.size();i++) { 389 Contained[] a = con.lookup_name((String ) id.sn.names.aktual()); 390 if (a==null || a.length==0) 391 throw new CompRepExcept(); 392 if (a.length==1) { 393 if (a[0] instanceof Container) con = (Container) a[0]; 395 else throw new CompRepExcept(); 396 } else { 397 boolean found = false; 398 for(j=0;j<a.length;j++) { 399 if (a[j].get_identification().version().compareTo(id.version)==0) { 400 if ( !(a[j] instanceof Container)) throw new CompRepExcept(); 401 found = true; 402 con = (Container) a[j]; 403 break; 404 } 405 } 406 if (!found) throw new CompRepExcept(); 407 } 408 id.sn.names.toNext(); 409 } 410 Contained sec = con.lookup(id.name, id.version); 411 if (sec!=null) { 412 CompReffer ret = new CompReffer(); 413 ret.what = sec.get_def_kind().value(); 414 ret.ref = new FullID(true); 415 ret.ref.name = new String (id.name); 416 ret.ref.version = new String (id.version); 417 ret.ref.isin = IDKind.version; 418 ret.isNew = false; 419 id.sn.names.toFirst(); 420 for(j=0;j<id.sn.names.size();j++) { 421 ret.ref.sn.addScope(new String ((String )id.sn.names.aktual())); 422 id.sn.names.toNext(); 423 } 424 if (ret.what == DefinitionKind.dk_Frame) 425 ret.isSystem = ((FrameDef)sec).is_system(); 426 if (ret.what == DefinitionKind.dk_Architecture) 427 ret.isSystem = ((ArchitectureDef)sec).is_system(); 428 return ret; 429 } 430 431 } catch (TIRExceptLock e) { 432 throw new CDLExceptLock("Repository is locked."); 433 } catch (RemoteException e) { 434 throw new CDLExceptRemote("Remote exception occured: "+e.getMessage()); 435 } catch (CompRepExcept e) {;} 436 438 441 if (numPath > 0) { 443 id.sn.names.toFirst(); 444 for(i=1; i<numPath; i++) 445 id.sn.names.toNext(); 446 id.sn.names.removeAkt(); 447 return searchRefferVersion(id, numPath-1); 448 } else { 449 searchError = id.name + ":" + id.version + " doesn't exist"; 450 return null; 451 } 452 } 453 454 private CompReffer searchRefferTag(FullID id, long numPath) throws CDLExceptLock, CDLExceptRemote { 455 int i,j; 456 457 try { 458 CompContainer con = this; 460 id.sn.names.toFirst(); 461 for(i=0;i<id.sn.names.size();i++) { 462 CompContained[] a = con.lookup((String ) id.sn.names.aktual()); 463 if (a==null || a.length==0) 464 throw new CompRepExcept(); 465 if (a.length==1) { 466 if (a[0].isContainer()) con = (CompContainer) a[0]; 467 else throw new CompRepExcept(); 468 } else { 469 throw new CompRepExcept(); 470 } 471 id.sn.names.toNext(); 472 } 473 CompContained sec = con.lookupTag(id.name, id.tag); 474 if (sec!=null) { 475 CompReffer ret = new CompReffer(); 476 ret.what = sec.objectKind(); 477 ret.ref = new FullID(true); 478 ret.ref.name = new String (id.name); 479 ret.ref.version = new String (sec.getIdent().version); 480 ret.ref.isin = IDKind.version; 481 ret.isNew = true; 482 id.sn.names.toFirst(); 483 for(j=0;j<id.sn.names.size();j++) { 484 ret.ref.sn.addScope(new String ((String )id.sn.names.aktual())); 485 id.sn.names.toNext(); 486 } 487 if (ret.what == ObjectsKind.o_Frame) 488 ret.isSystem = ((CompFrame)sec).isSystem; 489 if (ret.what == ObjectsKind.o_Architecture) 490 ret.isSystem = ((CompArchitecture)sec).isSystem; 491 return ret; 492 } 493 } catch (CompRepExcept e) {;} 495 496 try { 498 Container con = cdlRepository; 499 id.sn.names.toFirst(); 500 for(i=0;i<id.sn.names.size();i++) { 501 Contained[] a = con.lookup_name((String ) id.sn.names.aktual()); 502 if (a==null || a.length==0) 503 throw new CompRepExcept(); 504 if (a.length==1) { 505 if (a[0] instanceof Container) con = (Container) a[0]; 506 else throw new CompRepExcept(); 507 } else { 508 throw new CompRepExcept(); 509 } 510 id.sn.names.toNext(); 511 } 512 Contained sec = con.lookup_tag(id.name, id.tag); 513 if (sec!=null) { 514 CompReffer ret = new CompReffer(); 515 ret.what = sec.get_def_kind().value(); 516 ret.ref = new FullID(true); 517 ret.ref.name = new String (id.name); 518 ret.ref.version = new String (sec.get_identification().version()); 519 ret.ref.isin = IDKind.version; 520 ret.isNew = false; 521 id.sn.names.toFirst(); 522 for(j=0;j<id.sn.names.size();j++) { 523 ret.ref.sn.addScope(new String ((String )id.sn.names.aktual())); 524 id.sn.names.toNext(); 525 } 526 if (ret.what == DefinitionKind.dk_Frame) 527 ret.isSystem = ((FrameDef)sec).is_system(); 528 if (ret.what == DefinitionKind.dk_Architecture) 529 ret.isSystem = ((ArchitectureDef)sec).is_system(); 530 return ret; 531 } 532 533 } catch (TIRExceptLock e) { 534 throw new CDLExceptLock("Repository is locked."); 535 } catch (RemoteException e) { 536 throw new CDLExceptRemote("Remote exception occured: "+e.getMessage()); 537 } catch (CompRepExcept e) {;} 538 540 if (numPath > 0) { 544 id.sn.names.toFirst(); 545 for(i=1; i<numPath; i++) 546 id.sn.names.toNext(); 547 id.sn.names.removeAkt(); 548 return searchRefferTag(id, numPath-1); 549 } else { 550 searchError = id.name + ":" + id.version + " doesn't exist"; 551 return null; 552 } 553 } 554 555 private CompReffer searchRefferDefault(FullID id, long numPath) throws CDLExceptLock, CDLExceptRemote { 556 int i,j; 558 559 try { 561 562 CompContainer con = this; 563 id.sn.names.toFirst(); 564 for(i=0;i<id.sn.names.size();i++) { 565 CompContained[] a = con.lookup((String ) id.sn.names.aktual()); 566 if (a==null || a.length==0) 567 throw new CompRepExcept(); 568 if (a.length==1) { 569 if (a[0].isContainer()) con = (CompContainer) a[0]; 570 else throw new CompRepExcept(); 571 } else { 572 throw new CompRepExcept(); 573 } 574 id.sn.names.toNext(); 575 } 576 CompContained[] sec = con.lookup(id.name); 577 if (sec!=null && sec.length!=0) { 578 if (sec.length==1) { 579 CompReffer ret = new CompReffer(); 580 ret.what = sec[0].objectKind(); 581 ret.ref = new FullID(true); 582 ret.ref.name = new String (id.name); 583 ret.ref.version = new String (sec[0].getIdent().version); 584 ret.ref.isin = IDKind.version; 585 ret.isNew = true; 586 id.sn.names.toFirst(); 587 for(j=0;j<id.sn.names.size();j++) { 588 ret.ref.sn.addScope(new String ((String )id.sn.names.aktual())); 589 id.sn.names.toNext(); 590 } 591 if (ret.what == ObjectsKind.o_Frame) 592 ret.isSystem = ((CompFrame)sec[0]).isSystem; 593 if (ret.what == ObjectsKind.o_Architecture) 594 ret.isSystem = ((CompArchitecture)sec[0]).isSystem; 595 596 return ret; 597 } else { 598 searchError = "it never should be here"; 599 return null; 600 } 601 } 602 } catch (CompRepExcept e) {;} 604 605 try { 607 if (profile != null) { 608 Identification idl = profile.lookup(id.langToString()); 609 if (idl != null) { 610 CompReffer ret = new CompReffer(); 611 ret.ref = new FullID(true); 612 ret.ref.name = new String (idl.name()); 613 ret.ref.version = new String (idl.version()); 614 ret.ref.isin = IDKind.version; 615 ret.isNew = false; 616 id.sn.names.toFirst(); 617 for(j=0;j<id.sn.names.size();j++) { 618 ret.ref.sn.addScope(new String ((String )id.sn.names.aktual())); 619 id.sn.names.toNext(); 620 } 621 try { Container con = cdlRepository; 623 id.sn.names.toFirst(); 624 for(i=0;i<id.sn.names.size();i++) { 625 Contained[] a = con.lookup_name((String ) id.sn.names.aktual()); 626 if (a==null || a.length==0) { 627 throw new CompRepExcept(); 628 } 629 if (a.length==1) { 630 if (a[0] instanceof Container) con = (Container) a[0]; 631 else { 632 throw new CompRepExcept(); 633 } 634 } else { 635 boolean found = false; 636 for(j=0;j<a.length;j++) { 637 if (a[j].get_identification().version().compareTo(idl.version())==0) { 638 if ( !(a[j] instanceof Container)) { 639 throw new CompRepExcept(); 640 } 641 found = true; 642 con = (Container) a[j]; 643 break; 644 } 645 } 646 if (!found) { 647 throw new CompRepExcept(); 648 } 649 } 650 id.sn.names.toNext(); 651 } 652 Contained sec = con.lookup_lastinbranch(id.name, ""); 653 if (sec!=null) { 654 ret.what = sec.get_def_kind().value(); 655 } 656 if (ret.what == DefinitionKind.dk_Frame) 657 ret.isSystem = ((FrameDef)sec).is_system(); 658 if (ret.what == DefinitionKind.dk_Architecture) 659 ret.isSystem = ((ArchitectureDef)sec).is_system(); 660 } catch (TIRExceptLock e) { 661 throw new CDLExceptLock("Repository is locked."); 662 } catch (RemoteException e) { 663 throw new CDLExceptRemote("Remote exception occured: "+e.getMessage()); 664 } catch (CompRepExcept e) { 665 searchError = "error in profile"; 666 return null; 667 } 668 return ret; 669 } 670 } 671 } catch (TIRExceptLock e) { 672 throw new CDLExceptLock("Repository is locked."); 673 } catch (RemoteException e) { 674 throw new CDLExceptRemote("Remote exception occured: "+e.getMessage()); 675 } 676 678 try { 680 Container con = cdlRepository; 681 id.sn.names.toFirst(); 682 for(i=0;i<id.sn.names.size();i++) { 683 Contained[] a = con.lookup_name((String ) id.sn.names.aktual()); 684 if (a==null || a.length==0) 685 throw new CompRepExcept(); 686 if (a.length==1) { 687 if (a[0] instanceof Container) con = (Container) a[0]; 688 else throw new CompRepExcept(); 689 } else { 690 Contained last = con.lookup_lastinbranch((String ) id.sn.names.aktual(),""); 691 if (last == null) 692 throw new CompRepExcept(); 693 else 694 con = (Container) last; 695 705 } 706 id.sn.names.toNext(); 707 } 708 Contained sec = con.lookup_lastinbranch(id.name, ""); 709 if (sec!=null) { 710 CompReffer ret = new CompReffer(); 711 ret.what = sec.get_def_kind().value(); 712 ret.ref = new FullID(true); 713 ret.ref.name = new String (id.name); 714 ret.ref.version = new String (sec.get_identification().version()); 715 ret.ref.isin = IDKind.version; 716 ret.isNew = false; 717 id.sn.names.toFirst(); 718 for(j=0;j<id.sn.names.size();j++) { 719 ret.ref.sn.addScope(new String ((String )id.sn.names.aktual())); 720 id.sn.names.toNext(); 721 } 722 if (ret.what == DefinitionKind.dk_Frame) 723 ret.isSystem = ((FrameDef)sec).is_system(); 724 if (ret.what == DefinitionKind.dk_Architecture) 725 ret.isSystem = ((ArchitectureDef)sec).is_system(); 726 return ret; 727 } 728 729 } catch (TIRExceptLock e) { 730 throw new CDLExceptLock("Repository is locked."); 731 } catch (RemoteException e) { 732 throw new CDLExceptRemote("Remote exception occured: "+e.getMessage()); 733 } catch (CompRepExcept e) {;} 734 735 if (numPath > 0) { 737 id.sn.names.toFirst(); 738 for(i=1; i<numPath; i++) 739 id.sn.names.toNext(); 740 id.sn.names.removeAkt(); 741 742 CompReffer ret = searchRefferDefault(id, numPath-1); 743 744 747 return ret; 748 } else { 749 searchError = id.name + ":" + id.version + " doesn't exist"; 750 return null; 751 } 752 } 753 754 public CompModule searchExistNewMod(String name) { 755 Scopename fullname = new Scopename(); 756 int i; 757 aktScope.names.toFirst(); 758 for (i=0;i<aktScope.length();i++) { 759 fullname.addScope((String )aktScope.names.aktual()); 760 aktScope.names.toNext(); 761 } 762 fullname.addScope(name); 763 764 CompContainer con = this; 765 fullname.names.toFirst(); 766 for(i=0;i<fullname.names.size()-1;i++) { 767 CompContained[] a = con.lookup((String ) fullname.names.aktual()); 768 if (a==null || a.length==0) 769 return null; 770 if (a.length==1) { 771 if (a[0].isContainer()) con = (CompContainer) a[0]; 772 else { 773 return null; 774 } 775 } else { 776 return null; 777 } 778 fullname.names.toNext(); 779 } 780 <
|