1 2 package SOFA.SOFAnode.Made.CDL; 3 import java.rmi.RemoteException ; 4 5 import SOFA.SOFAnode.Made.TIR.AttributeDef; 6 import SOFA.SOFAnode.Made.TIR.CDLRepository; 7 import SOFA.SOFAnode.Made.TIR.CDLType; 8 import SOFA.SOFAnode.Made.TIR.ConstantDef; 9 import SOFA.SOFAnode.Made.TIR.Contained; 10 import SOFA.SOFAnode.Made.TIR.Container; 11 import SOFA.SOFAnode.Made.TIR.DefinitionKind; 12 import SOFA.SOFAnode.Made.TIR.EnumDef; 13 import SOFA.SOFAnode.Made.TIR.ExceptionDef; 14 import SOFA.SOFAnode.Made.TIR.ExprFixed; 15 import SOFA.SOFAnode.Made.TIR.ExprOperDef; 16 import SOFA.SOFAnode.Made.TIR.InterfaceDef; 17 import SOFA.SOFAnode.Made.TIR.OperationDef; 18 import SOFA.SOFAnode.Made.TIR.ProtocolDef; 19 import SOFA.SOFAnode.Made.TIR.ProtocolOperDef; 20 import SOFA.SOFAnode.Made.TIR.StructDef; 21 import SOFA.SOFAnode.Made.TIR.TIRExceptCalculate; 22 import SOFA.SOFAnode.Made.TIR.TIRExceptCreate; 23 import SOFA.SOFAnode.Made.TIR.TIRExceptLock; 24 import SOFA.SOFAnode.Made.TIR.TypedefDef; 25 import SOFA.SOFAnode.Made.TIR.UnionDef; 26 27 class CompInterface extends CompContainedContainerIm implements CompType { 28 class NName { 29 String iface; String name; 31 boolean isOper; public NName(String iface, String name, boolean isOper) { 33 this.iface = iface; 34 this.name = name; 35 this.isOper = isOper; 36 } 37 } 38 39 class Names extends List { 40 public Names() { super(); } 41 public boolean isIn(String iface, String name) { 42 akt = first; 43 for (int i=0;i<count;i++) { 44 if (name.compareTo(((NName)akt.item).name)==0 && iface.compareTo(((NName)akt.item).iface)!=0) 45 return true; 46 toNext(); 47 } 48 return false; 49 } 50 51 public void addName(String iface, String name, boolean isOper) { 52 add(new NName(iface,name,isOper)); 53 } 54 } 55 56 boolean forwarddcl; 57 boolean wasforwarddcl; 58 List baseIfaces; 59 CompProtOper protocol; 60 Names names; 62 public CompInterface(ID id, CompContainer in, CompRepository inRep, boolean fwd) { 63 super(ObjectsKind.o_Interface, id, in, inRep); 64 forwarddcl = fwd; 65 wasforwarddcl = false; 66 baseIfaces = new List(); 67 protocol = null; 68 names = new Names(); 69 } 71 72 public boolean setBaseIfaces(List bi) throws CDLExceptLock, CDLExceptRemote { 73 int i; 74 bi.toFirst(); 75 for (int k=0;k<bi.size();k++) { 76 CompReffer ref = (CompReffer) bi.aktual(); 77 if (ref.isNew) { 78 CompContainer con = rep; 79 ref.ref.sn.names.toFirst(); 80 for(i=0;i<ref.ref.sn.names.size();i++) { 81 CompContained[] a = con.lookup((String ) ref.ref.sn.names.aktual()); 82 if (a==null || a.length==0) 83 return false; 84 if (a.length==1) { 85 if (a[0].isContainer()) con = (CompContainer) a[0]; 86 else return false; 87 } else { 88 return false; 89 } 90 ref.ref.sn.names.toNext(); 91 } 92 CompContained sec = con.lookup(ref.ref.name, ref.ref.version); 93 if (sec!=null) { 94 if (sec.objectKind() != ObjectsKind.o_Interface) 95 return false; 96 Names obj = ((CompInterface) sec).names; 97 obj.toFirst(); 98 for (int j=0;j<obj.size();j++) { 99 if (names.isIn(((NName) obj.aktual()).iface, ((NName) obj.aktual()).name)) 100 return false; 101 names.addName(((NName) obj.aktual()).iface,((NName) obj.aktual()).name,((NName) obj.aktual()).isOper); 102 obj.toNext(); 103 } 104 109 CompReffer nb = new CompReffer(); 111 nb.what = sec.objectKind(); 112 nb.ref = new FullID(true); 113 nb.ref.name = new String (ref.ref.name); 114 nb.ref.version = new String (ref.ref.version); 115 nb.ref.isin = IDKind.version; 116 nb.isNew = true; 117 ref.ref.sn.names.toFirst(); 118 for(int j=0;j<ref.ref.sn.names.size();j++) { 119 nb.ref.sn.addScope(new String ((String )ref.ref.sn.names.aktual())); 120 ref.ref.sn.names.toNext(); 121 } 122 baseIfaces.add(nb); 123 } 125 } else { 126 try { 127 Container con = rep.cdlRepository; 128 ref.ref.sn.names.toFirst(); 129 for(i=0;i<ref.ref.sn.names.size();i++) { 130 Contained[] a = con.lookup_name((String ) ref.ref.sn.names.aktual()); 131 if (a==null || a.length==0) 132 return false; 133 if (a.length==1) { 134 if (a[0] instanceof Container) con = (Container) a[0]; 135 else return false; 136 } else { 137 boolean found = false; 138 for(int j=0;j<a.length;j++) { 139 if (a[j].get_identification().version().compareTo(ref.ref.version)==0) { 140 if ( !(a[j] instanceof Container)) return false; 141 found = true; 142 con = (Container) a[j]; 143 break; 144 } 145 } 146 if (!found) return false; 147 } 148 ref.ref.sn.names.toNext(); 149 } 150 Contained sec = con.lookup(ref.ref.name, ref.ref.version); 151 if (sec!=null) { 152 if (sec.get_def_kind().value() != DefinitionKind.dk_Interface) 153 return false; 154 int j; 155 Contained[] obj = ((InterfaceDef) sec).contents(null); 156 for (j=0;j<obj.length;j++) { 157 boolean isOper = false; 158 if (names.isIn(ref.ref.name, obj[j].get_identification().name())) 159 return false; 160 if (obj[j].get_def_kind().value() == DefinitionKind.dk_Operation) 161 isOper = true; 162 names.addName(ref.ref.name, new String (obj[j].get_identification().name()),isOper); 163 } 164 if (!testSetBaseIfaces((InterfaceDef)sec)) 166 return false; 167 173 174 CompReffer nb = new CompReffer(); 176 nb.what = sec.get_def_kind().value(); 177 nb.ref = new FullID(true); 178 nb.ref.name = new String (ref.ref.name); 179 nb.ref.version = new String (ref.ref.version); 180 nb.ref.isin = IDKind.version; 181 nb.isNew = false; 182 ref.ref.sn.names.toFirst(); 183 for(int l=0;l<ref.ref.sn.names.size();l++) { 184 nb.ref.sn.addScope(new String ((String )ref.ref.sn.names.aktual())); 185 ref.ref.sn.names.toNext(); 186 } 187 baseIfaces.add(nb); 188 190 } 191 } catch (TIRExceptLock e) { 192 throw new CDLExceptLock("Repository is locked."); 193 } catch (RemoteException e) { 194 throw new CDLExceptRemote("Remote exception occured: "+e.getMessage()); 195 } 196 } 197 198 bi.toNext(); 199 } 200 return true; 201 } 202 203 private boolean testSetBaseIfaces(InterfaceDef iface) throws TIRExceptLock, RemoteException { 204 InterfaceDef[] bbase = ((InterfaceDef) iface).base_interfaces(); 205 for (int i=0;i<bbase.length;i++) { 206 Contained[] obj = ((InterfaceDef) bbase[i]).contents(null); 207 for (int j=0;j<obj.length;j++) { 208 boolean isOper = false; 209 if (names.isIn(((InterfaceDef) bbase[i]).get_identification().name(),obj[j].get_identification().name())) 210 return false; 211 if (obj[j].get_def_kind().value() == DefinitionKind.dk_Operation) 212 isOper = true; 213 names.addName(((InterfaceDef) bbase[i]).get_identification().name(),new String (obj[j].get_identification().name()),isOper); 214 } 215 if (!testSetBaseIfaces(bbase[i])) 216 return false; 217 } 218 return true; 219 } 220 221 234 235 public boolean addObject(CompContained o) { 236 ((CompContained) o).getIdent().version = id.version; 237 String nm = o.getIdent().name; 239 if (names.isIn(id.name, nm)) 240 return false; 241 boolean isOper = false; 242 if (o.objectKind()==ObjectsKind.o_Operation) 243 isOper = true; 244 names.addName(id.name,nm,isOper); 245 return super.addObject(o); 246 } 247 248 public boolean isOperationName(String name) { 249 names.toFirst(); 250 for (int i=0;i<names.size();i++) { 251 if ((((NName) names.aktual()).name.compareTo(name)==0) && (((NName) names.aktual()).isOper)) 252 return true; 253 names.toNext(); 254 } 255 return false; 256 } 257 258 259 public EnumList operationNames() { 260 EnumList ret = new EnumList(); 261 names.toFirst(); 262 for (int i=0;i<names.size();i++) { 263 if (((NName) names.aktual()).isOper) 264 ret.addName(((NName) names.aktual()).name); 265 names.toNext(); 266 } 267 return ret; 268 } 269 270 public void checkConsist(EnumList props, CompRepository rep) throws CDLExceptCheck, CDLExceptLock, CDLExceptRemote { 271 if (forwarddcl) 273 throw new CDLExceptCheck("Forward declaration of interface "+fullName()+" only."); 274 if (props == null) { 275 ; 276 } else { 277 CompContained[] cont = contents(); 279 for (int i=0;i<cont.length;i++) { 280 cont[i].checkConsist(props, rep); 281 } 282 } 283 284 if (rep.useProtocols) { 285 if (protocol == null && contents().length!=0) 286 throw new CDLExceptCheck("No protocol for interface "+fullName()); 287 } 288 289 } 290 291 public void addToNormal(Container obj, CDLRepository normRep, java.util.ArrayList delayed) throws CDLExceptToNormal, CDLExceptRemote, CDLExceptLock { 292 299 300 delayed.add(this); 301 delayed.add(obj); 302 return; 303 453 454 455 456 } 457 458 459 public void addToNormalDelayed(Container obj, CDLRepository normRep, java.util.ArrayList delayed) throws CDLExceptToNormal, CDLExceptRemote, CDLExceptLock { 460 try { 461 InterfaceDef[] base = null; 462 if (baseIfaces != null) { 463 baseIfaces.toFirst(); 464 base = new InterfaceDef [baseIfaces.size()]; 465 for (int j=0;j<baseIfaces.size();j++) { 466 base[j] = (InterfaceDef) ((CompType) baseIfaces.aktual()).toNormal(normRep); 467 baseIfaces.toNext(); 468 } 469 ((InterfaceDef) obj).setBaseInterfaces(base); 472 } 473 474 } catch (RemoteException e) { 475 throw new CDLExceptRemote("Remote exception occured: "+e.getMessage()); 476 } catch (TIRExceptCreate ecr) { 477 throw new CDLExceptToNormal("Can't create interface "+fullName()); 478 } 479 480 if (id.isin == IDKind.versiontag) { 481 try { 482 ((Contained)obj).tag(id.tag); 483 } catch (RemoteException e) { 484 throw new CDLExceptRemote("Remote exception occured: "+e.getMessage()); 485 } catch (TIRExceptLock e) { 486 throw new CDLExceptLock("Repository is locked."); 487 } catch (TIRExceptCreate ecr) { 488 throw new CDLExceptToNormal("Can't set tag for "+ fullName()); 489 } 490 } 491 cont.toFirst(); 492 try { 493 for (int i=0;i<cont.size(); i++) { 494 CompContained akt = (CompContained) cont.aktual(); 495 switch (akt.objectKind()) { 496 case ObjectsKind.o_Typedef: 498 try { 499 TypedefDef td = ((InterfaceDef) obj).create_typedef(akt.getIdent().id, ((CompTypedef) akt).type.toNormal(normRep)); 500 if (td == null) 501 throw new CDLExceptToNormal("Can't create typedef "+((CompContained)akt).fullName()); 502 } catch (TIRExceptCreate ecr) { 503 throw new CDLExceptToNormal("Can't create typedef "+((CompContained)akt).fullName()); 504 } 505 break; 506 case ObjectsKind.o_Enum: 508 try { 509 EnumDef en = ((InterfaceDef) obj).create_enum(akt.getIdent().id); 510 if (en == null) 511 throw new CDLExceptToNormal("Can't create enum "+((CompContained)akt).fullName()); 512 ((CompEnum) akt).addToNormal(en); 513 } catch (TIRExceptCreate ecr) { 514 throw new CDLExceptToNormal("Can't create enum "+((CompContained)akt).fullName()); 515 } 516 break; 517 case ObjectsKind.o_Struct: 519 try { 520 StructDef str = ((InterfaceDef) obj).create_struct(akt.getIdent().id); 521 if (str == null) 522 throw new CDLExceptToNormal("Can't create struct "+((CompContained)akt).fullName()); 523 ((CompStruct) akt).addToNormal(str, normRep, delayed); 524 } catch (TIRExceptCreate ecr) { 525 throw new CDLExceptToNormal("Can't create struct "+((CompContained)akt).fullName()); 526 } 527 break; 528 case ObjectsKind.o_Union: 530 try { 531 UnionDef un = ((InterfaceDef) obj).create_union(akt.getIdent().id, ((CompUnion) akt).switch_type.toNormal(normRep)); 532 if (un == null) 533 throw new CDLExceptToNormal("Can't create union "+((CompContained)akt).fullName()); 534 ((CompUnion) akt).addToNormal(un, normRep, delayed); 535 } catch (TIRExceptCreate ecr) { 536 throw new CDLExceptToNormal("Can't create union "+((CompContained)akt).fullName()); 537 } 538 break; 539 case ObjectsKind.o_Exception: 541 try { 542 ExceptionDef str = ((InterfaceDef) obj).create_exception(akt.getIdent().id); 543 if (str == null) 544 throw new CDLExceptToNormal("Can't create exception "+((CompContained)akt).fullName()); 545 ((CompException) akt).addToNormal(str, normRep, delayed); 546 } catch (TIRExceptCreate ecr) { 547 throw new CDLExceptToNormal("Can't create exception "+((CompContained)akt).fullName()); 548 } 549 break; 550 case ObjectsKind.o_Constant: 552 try { 553 ConstantDef cnst; 554 if (((CompConstant) akt).type.objectKind() == ObjectsKind.o_Fixed) { 555 ExprOperDef expr = ((CompExprOper) ((CompConstant)akt).expr).toNormal(normRep); 556 ExprOperDef cexpr = null; 557 try { 558 cexpr = expr.calculate(); 559 } catch (TIRExceptCalculate e) { 560 throw new CDLExceptToNormal("Bad expression in the constant "+((CompContained)akt).fullName()); 561 } 562 ((CompFixed) ((CompConstant) akt).type).digits = new CompExprInteger(((ExprFixed) cexpr).digits()); 563 ((CompFixed) ((CompConstant) akt).type).scale = new CompExprInteger(((ExprFixed) cexpr).scale()); 564 cnst = ((InterfaceDef) obj).create_constant(akt.getIdent().id, ((CompConstant) akt).type.toNormal(normRep), expr); 565 } else { 566 cnst = ((InterfaceDef) obj).create_constant(akt.getIdent().id, ((CompConstant) akt).type.toNormal(normRep), ((CompExprOper) ((CompConstant)akt).expr).toNormal(normRep)); 567 } 568 if (cnst == null) 569 throw new CDLExceptToNormal("Can't create constant "+((CompContained)akt).fullName()); 570 } catch (TIRExceptCreate ecr) { 571 throw new CDLExceptToNormal("Can't create constant "+((CompContained)akt).fullName()); 572 } 573 break; 574 case ObjectsKind.o_Attribute: 576 try { 577 AttributeDef attr = ((InterfaceDef) obj).create_attribute(akt.getIdent().id, ((CompAttribute) akt).type.toNormal(normRep), ((CompAttribute)akt).mode); 578 if (attr == null) 579 throw new CDLExceptToNormal("Can't create attribute "+((CompContained)akt).fullName()); 580 } catch (TIRExceptCreate ecr) { 581 throw new CDLExceptToNormal("Can't create attribute "+((CompContained)akt).fullName()+"\n"+ 582 ecr.getMessage()); 583 } 584 break; 585 case ObjectsKind.o_Operation: 587 try { 588 ExceptionDef[] raises = null; 589 if (((CompOperation) akt).raises != null) { 590 ((CompOperation) akt).raises.toFirst(); 591 raises = new ExceptionDef [((CompOperation) akt).raises.size()]; 592 for (int j=0;j<((CompOperation) akt).raises.size();j++) { 593 raises[j] = (ExceptionDef) ((CompType) ((CompOperation) akt).raises.aktual()).toNormal(normRep); 594 ((CompOperation) akt).raises.toNext(); 595 } 596 } else { 597 raises = new ExceptionDef [0]; 598 } 599 OperationDef oper = ((InterfaceDef) obj).create_operation(akt.getIdent().id, ((CompOperation) akt).type.toNormal(normRep) , raises); 600 if (oper == null) 601 throw new CDLExceptToNormal("Can't create operation "+((CompContained)akt).fullName()); 602 ((CompOperation) akt).addToNormal(oper, normRep); 603 } catch (TIRExceptCreate ecr) { 604 throw new CDLExceptToNormal("Can't create operation "+((CompContained)akt).fullName()+"\n"+ 605 ecr.getMessage()); 606 } 607 break; 608 default: 609 throw new CDLExceptToNormal("Unexcepted kind of object"); 610 } 611 cont.toNext(); 612 } 613 if (protocol != null) { 614 try { 615 ProtocolDef newProt = ((InterfaceDef) obj).create_protocol(); 616 ProtocolOperDef p = CompProtOper.toNormalIface(protocol, newProt); 617 newProt.protocol(p); 618 } catch (TIRExceptCreate ecr) { 619 throw new CDLExceptToNormal("Can't create protocol in "+ fullName()+"\n"+ 620 ecr.getMessage()); 621 } 622 } 623 624 } catch (RemoteException e) { 625 throw new CDLExceptRemote("Remote exception occured: "+e.getMessage()); 626 } catch (TIRExceptLock e) { 627 throw new CDLExceptLock("Repository is locked."); 628 } 629 } 630 631 632 public CDLType toNormal(CDLRepository newRep) throws CDLExceptToNormal { 633 throw new CDLExceptToNormal("It should never throw"); 635 } 636 637 public String protocolToText() { 638 if (protocol != null) { 639 return protocol.toText(); 640 } 641 return "-- no protocol --"; 642 } 643 } 644 | Popular Tags |