1 2 package SOFA.SOFAnode.Made.TIR.Impl; 3 import java.io.DataInputStream ; 4 import java.io.DataOutputStream ; 5 import java.io.FileInputStream ; 6 import java.io.FileOutputStream ; 7 import java.io.IOException ; 8 import java.rmi.RemoteException ; 9 10 import SOFA.SOFAnode.Made.TIR.AbsoluteName; 11 import SOFA.SOFAnode.Made.TIR.AttributeDef; 12 import SOFA.SOFAnode.Made.TIR.CDLType; 13 import SOFA.SOFAnode.Made.TIR.ConstantDef; 14 import SOFA.SOFAnode.Made.TIR.Contained; 15 import SOFA.SOFAnode.Made.TIR.Container; 16 import SOFA.SOFAnode.Made.TIR.DefinitionKind; 17 import SOFA.SOFAnode.Made.TIR.EnumDef; 18 import SOFA.SOFAnode.Made.TIR.ExceptionDef; 19 import SOFA.SOFAnode.Made.TIR.ExprOperDef; 20 import SOFA.SOFAnode.Made.TIR.Identification; 21 import SOFA.SOFAnode.Made.TIR.InterfaceDef; 22 import SOFA.SOFAnode.Made.TIR.OperationDef; 23 import SOFA.SOFAnode.Made.TIR.ProtocolDef; 24 import SOFA.SOFAnode.Made.TIR.Repository; 25 import SOFA.SOFAnode.Made.TIR.StateKind; 26 import SOFA.SOFAnode.Made.TIR.StructDef; 27 import SOFA.SOFAnode.Made.TIR.TIRExceptCommit; 28 import SOFA.SOFAnode.Made.TIR.TIRExceptCreate; 29 import SOFA.SOFAnode.Made.TIR.TIRExceptLock; 30 import SOFA.SOFAnode.Made.TIR.TIRObject; 31 import SOFA.SOFAnode.Made.TIR.TypedefDef; 32 import SOFA.SOFAnode.Made.TIR.UnionDef; 33 34 public class InterfaceDefImpl extends ContainerImpl implements InterfaceDef, SContained { 35 protected Identification id; 36 protected Container parent; 37 protected Repository rep; 38 DefinitionKindImpl defKindImpl; 39 StateKindImpl stKindImpl; 40 InterfaceDef[] base; 41 CDLType[] loadBase; ProtocolDef prot; 43 44 InterfaceDefImpl normal; 45 long workId; 46 47 public InterfaceDefImpl(Identification ident, Container in, Repository inrep, InterfaceDef[] baseIf, long workId) throws RemoteException { 48 id = ident; 49 parent = in; 50 rep = inrep; 51 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Interface); 52 stKindImpl = new StateKindImpl(StateKind.sk_work); 53 if (baseIf==null) 54 base = new InterfaceDef [0]; 55 else 56 base = baseIf; 57 prot = null; 58 normal = null; 59 this.workId = workId; 60 } 61 62 public InterfaceDefImpl(Container in, Repository inrep) throws RemoteException { 63 id = null; 64 parent = in; 65 rep = inrep; 66 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Interface); 67 stKindImpl = new StateKindImpl(StateKind.sk_normal); 68 base = null; 69 prot = null; 70 normal = null; 71 this.workId = -1L; 72 } 73 74 public InterfaceDefImpl(InterfaceDefImpl a, Container in, Repository inrep, long workId) throws RemoteException { 75 id = a.id; 76 parent = in; 77 rep = inrep; 78 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Interface); 79 stKindImpl = new StateKindImpl(StateKind.sk_work); 80 base = a.base; 81 prot = a.prot; 82 normal = a; 83 this.workId = workId; 84 } 85 86 public InterfaceDef[] base_interfaces() throws RemoteException { 87 return base; 88 } 89 90 public ProtocolDef protocol() throws RemoteException { 91 return prot; 92 } 93 94 95 public Identification get_identification() throws RemoteException { 96 return id; 97 } 98 99 100 public Container get_defined_in() throws RemoteException { 101 return parent; 102 } 103 104 105 public Container get_containing_repository() throws RemoteException { 106 return rep; 107 } 108 109 110 public AbsoluteName get_absolute_name() throws RemoteException { 111 AbsoluteNameImpl absName; 112 if (rep == parent) { absName = new AbsoluteNameImpl("::"+id.name()); 114 } else { 115 absName = new AbsoluteNameImpl(((SContained)parent).get_absolute_name().name()+"::"+id.name()); 116 } 117 return (AbsoluteName) absName; 118 } 119 120 121 public DefinitionKind get_def_kind() throws RemoteException { 122 return (DefinitionKind) defKindImpl; 123 } 124 125 126 public StateKind get_state() throws RemoteException { 127 return (StateKind) stKindImpl; 128 } 129 130 public void tag(String t) throws RemoteException , TIRExceptCreate, TIRExceptLock { 131 if (stKindImpl.value()!=StateKind.sk_work) 132 throw new TIRExceptCreate("you can call create method on work object"); 133 String ebt = id.branchTag(); 134 if (t.compareTo(ebt)==0) 135 throw new TIRExceptCreate("This tag exists"); 136 String [] et = id.tag(); 137 int i,j; 138 for (i=0;i<et.length;i++) { 139 if (t.compareTo(et[i])==0) 140 throw new TIRExceptCreate("This tag exists"); 141 } 142 Contained[] sibl = parent.lookup_name(id); 143 for (j=0;j<sibl.length;j++) { 144 Identification idl = sibl[j].get_identification(); 145 146 ebt = idl.branchTag(); 147 if (t.compareTo(ebt)==0) 148 throw new TIRExceptCreate("This tag exists"); 149 et = idl.tag(); 150 for (i=0;i<et.length;i++) { 151 if (t.compareTo(et[i])==0) 152 throw new TIRExceptCreate("This tag exists"); 153 } 154 } 155 ((SIdentification) id).tag(t); 156 } 157 158 private void fromNormObj() throws RemoteException , TIRExceptLock { 159 if (normal==null) 160 return; 161 if (((WorkRepositoryImpl)rep).lock.isLocked()) 162 throw new TIRExceptLock("Repository is locked"); 163 int i; 164 LiItem akt; 165 akt = normal.firstChild; 166 for(i=0;i<normal.numOfItems;i++) { 167 addListItem(WorkRepositoryImpl.newWorkFromNormal(akt.obj,rep,this,workId)); 168 akt = akt.next; 169 } 170 hasCont = true; 171 } 172 173 public Contained[] contents(DefinitionKind type) throws RemoteException , TIRExceptLock { 174 if (stKindImpl.value()==StateKind.sk_normal) { 175 if (((RepositoryImpl) rep).lock.isLocked()) 176 throw new TIRExceptLock("Repository is locked"); 177 else 178 return super.contents(type); 179 } else { 180 if (!hasCont) 181 fromNormObj(); 182 if (((WorkRepositoryImpl) rep).lock.isLocked()) 183 throw new TIRExceptLock("Repository is locked"); 184 else 185 return super.contents(type); 186 } 187 } 188 189 public Contained lookup(Identification id) throws RemoteException , TIRExceptLock { 190 if (stKindImpl.value()==StateKind.sk_normal) { 191 if (((RepositoryImpl) rep).lock.isLocked()) 192 throw new TIRExceptLock("Repository is locked"); 193 else 194 return super.lookup(id); 195 } else { 196 if (!hasCont) 197 fromNormObj(); 198 if (((WorkRepositoryImpl) rep).lock.isLocked()) 199 throw new TIRExceptLock("Repository is locked"); 200 else 201 return super.lookup(id); 202 } 203 } 204 205 public Contained lookup(String name, String ver) throws RemoteException , TIRExceptLock { 206 if (stKindImpl.value()==StateKind.sk_normal) { 207 if (((RepositoryImpl) rep).lock.isLocked()) 208 throw new TIRExceptLock("Repository is locked"); 209 else 210 return super.lookup(name, ver); 211 } else { 212 if (!hasCont) 213 fromNormObj(); 214 if (((WorkRepositoryImpl) rep).lock.isLocked()) 215 throw new TIRExceptLock("Repository is locked"); 216 else 217 return super.lookup(name, ver); 218 } 219 } 220 221 public Contained[] lookup_name(Identification id) throws RemoteException , TIRExceptLock { 222 if (stKindImpl.value()==StateKind.sk_normal) { 223 if (((RepositoryImpl) rep).lock.isLocked()) 224 throw new TIRExceptLock("Repository is locked"); 225 else 226 return super.lookup_name(id); 227 } else { 228 if (!hasCont) 229 fromNormObj(); 230 if (((WorkRepositoryImpl) rep).lock.isLocked()) 231 throw new TIRExceptLock("Repository is locked"); 232 else 233 return super.lookup_name(id); 234 } 235 } 236 237 public Contained[] lookup_name(String id) throws RemoteException , TIRExceptLock { 238 if (stKindImpl.value()==StateKind.sk_normal) { 239 if (((RepositoryImpl) rep).lock.isLocked()) 240 throw new TIRExceptLock("Repository is locked"); 241 else 242 return super.lookup_name(id); 243 } else { 244 if (!hasCont) 245 fromNormObj(); 246 if (((WorkRepositoryImpl) rep).lock.isLocked()) 247 throw new TIRExceptLock("Repository is locked"); 248 else 249 return super.lookup_name(id); 250 } 251 } 252 253 public Contained lookup_tag(String name, String tag) throws RemoteException , TIRExceptLock { 254 if (stKindImpl.value()==StateKind.sk_normal) { 255 if (((RepositoryImpl) rep).lock.isLocked()) 256 throw new TIRExceptLock("Repository is locked"); 257 else 258 return super.lookup_tag(name, tag); 259 } else { 260 if (!hasCont) 261 fromNormObj(); 262 if (((WorkRepositoryImpl) rep).lock.isLocked()) 263 throw new TIRExceptLock("Repository is locked"); 264 else 265 return super.lookup_tag(name, tag); 266 } 267 } 268 269 public Contained[] lookup_branchtag(String name, String brtag) throws RemoteException , TIRExceptLock { 270 if (stKindImpl.value()==StateKind.sk_normal) { 271 if (((RepositoryImpl) rep).lock.isLocked()) 272 throw new TIRExceptLock("Repository is locked"); 273 else 274 return super.lookup_branchtag(name, brtag); 275 } else { 276 if (!hasCont) 277 fromNormObj(); 278 if (((WorkRepositoryImpl) rep).lock.isLocked()) 279 throw new TIRExceptLock("Repository is locked"); 280 else 281 return super.lookup_branchtag(name, brtag); 282 } 283 } 284 285 public Contained lookup_lastinbranch(String name, String brtag) throws RemoteException , TIRExceptLock { 286 if (stKindImpl.value()==StateKind.sk_normal) { 287 if (((RepositoryImpl) rep).lock.isLocked()) 288 throw new TIRExceptLock("Repository is locked"); 289 else 290 return super.lookup_lastinbranch(name, brtag); 291 } else { 292 if (!hasCont) 293 fromNormObj(); 294 if (((WorkRepositoryImpl) rep).lock.isLocked()) 295 throw new TIRExceptLock("Repository is locked"); 296 else 297 return super.lookup_lastinbranch(name, brtag); 298 } 299 } 300 301 public Contained lookup_lastfromversion(String name, String version) throws RemoteException , TIRExceptLock { 302 if (stKindImpl.value()==StateKind.sk_normal) { 303 if (((RepositoryImpl) rep).lock.isLocked()) 304 throw new TIRExceptLock("Repository is locked"); 305 else 306 return super.lookup_lastfromversion(name, version); 307 } else { 308 if (!hasCont) 309 fromNormObj(); 310 if (((WorkRepositoryImpl) rep).lock.isLocked()) 311 throw new TIRExceptLock("Repository is locked"); 312 else 313 return super.lookup_lastfromversion(name, version); 314 } 315 } 316 317 public Contained[] scontents(DefinitionKind type) throws RemoteException , TIRExceptLock { 318 if (stKindImpl.value()==StateKind.sk_normal) { 319 return super.scontents(type); 320 } else { 321 if (!hasCont) 322 fromNormObj(); 323 return super.scontents(type); 324 } 325 } 326 327 public Contained slookup(Identification id) throws RemoteException , TIRExceptLock { 328 if (stKindImpl.value()==StateKind.sk_normal) { 329 return super.slookup(id); 330 } else { 331 if (!hasCont) 332 fromNormObj(); 333 return super.slookup(id); 334 } 335 } 336 337 public Contained slookup(String name, String version) throws RemoteException , TIRExceptLock { 338 if (stKindImpl.value()==StateKind.sk_normal) { 339 return super.slookup(name, version); 340 } else { 341 if (!hasCont) 342 fromNormObj(); 343 return super.slookup(name, version); 344 } 345 } 346 347 public Contained[] slookup_name(Identification id) throws RemoteException , TIRExceptLock { 348 if (stKindImpl.value()==StateKind.sk_normal) { 349 return super.slookup_name(id); 350 } else { 351 if (!hasCont) 352 fromNormObj(); 353 return super.slookup_name(id); 354 } 355 } 356 357 public Contained[] slookup_name(String name) throws RemoteException , TIRExceptLock { 358 if (stKindImpl.value()==StateKind.sk_normal) { 359 return super.slookup_name(name); 360 } else { 361 if (!hasCont) 362 fromNormObj(); 363 return super.slookup_name(name); 364 } 365 } 366 367 public StructDef create_struct(Identification id) throws RemoteException , TIRExceptCreate, TIRExceptLock { 368 if (!isNew()) 369 throw new TIRExceptCreate("you can call create method on work object"); 370 if (id!=null) { 371 if (!hasCont) 372 fromNormObj(); 373 id = new IdentificationImpl(((SIdentification)id).language(), id.absolute_name().name(),this.id.version()); 375 Contained[] a = lookup_name(id.name()); 376 if (a.length != 0) { 377 if (a[0].get_def_kind().value() != DefinitionKind.dk_Struct) 378 throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository."); 379 boolean found = false; 380 for (int i=0;i<a.length;i++) { 381 if (((SIdentification) a[i].get_identification()).is_short_equal(id)) { 382 found = true; 383 break; 384 } 385 } 386 if (found) 387 throw new TIRExceptCreate("Object with same identification exists in repository."); 388 } 389 StructDef ret = new StructDefImpl(id, this, rep,workId); 391 addListItem(ret); return ret; } else 394 return null; 395 } 396 397 public UnionDef create_union(Identification id, CDLType switch_type) throws RemoteException , TIRExceptCreate, TIRExceptLock { 398 if (!isNew()) 399 throw new TIRExceptCreate("you can call create method on work object"); 400 if (id==null || switch_type==null) 401 return null; 402 else { 403 if (switch_type.get_state().value()==StateKind.sk_work ) { 404 if (!hasCont) 405 fromNormObj(); 406 id = new IdentificationImpl(((SIdentification)id).language(), id.absolute_name().name(),this.id.version()); 408 Contained[] a = lookup_name(id.name()); 409 if (a.length != 0) { 410 if (a[0].get_def_kind().value() != DefinitionKind.dk_Union) 411 throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository."); 412 boolean found = false; 413 for (int i=0;i<a.length;i++) { 414 if (((SIdentification) a[i].get_identification()).is_short_equal(id)) { 415 found = true; 416 break; 417 } 418 } 419 if (found) 420 throw new TIRExceptCreate("Object with same identification exists in repository."); 421 } 422 UnionDef ret = new UnionDefImpl(id, this, rep, switch_type,workId); 424 addListItem(ret); return ret; } else { 427 throw new TIRExceptCreate("Given object isn't work."); 428 } 429 } 430 } 431 432 public EnumDef create_enum(Identification id) throws RemoteException , TIRExceptCreate, TIRExceptLock { 433 if (!isNew()) 434 throw new TIRExceptCreate("you can call create method on work object"); 435 if (id!=null) { 436 if (!hasCont) 437 fromNormObj(); 438 id = new IdentificationImpl(((SIdentification)id).language(), id.absolute_name().name(),this.id.version()); 440 Contained[] a = lookup_name(id.name()); 441 if (a.length != 0) { 442 if (a[0].get_def_kind().value() != DefinitionKind.dk_Enum) 443 throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository."); 444 boolean found = false; 445 for (int i=0;i<a.length;i++) { 446 if (((SIdentification) a[i].get_identification()).is_short_equal(id)) { 447 found = true; 448 break; 449 } 450 } 451 if (found) 452 throw new TIRExceptCreate("Object with same identification exists in repository."); 453 } 454 EnumDef ret = new EnumDefImpl(id, this, rep, workId); 456 addListItem(ret); return ret; } else 459 return null; 460 } 461 462 public AttributeDef create_attribute(Identification name, CDLType type, int mode) throws RemoteException , TIRExceptCreate, TIRExceptLock { 463 if (!isNew()) 464 throw new TIRExceptCreate("you can call create method on work object"); 465 if (type==null) 466 return null; 467 if (type.get_state().value()==StateKind.sk_work) { 468 Identification id = new IdentificationImpl(((SIdentification)name).language(), name.absolute_name().name(),this.id.version()); 470 Contained[] a = lookup_name(name.name()); 471 if (a.length != 0) 472 throw new TIRExceptCreate("Name \""+name.name()+"\" exists in repository."); 473 AttributeDef ret = new AttributeDefImpl(id, this, rep, type, new AttrModeImpl(mode), workId); 475 addListItem(ret); return ret; } else { 478 throw new TIRExceptCreate("Given object isn't work."); 479 } 480 } 481 482 public OperationDef create_operation(Identification name, CDLType result, ExceptionDef[] exceptions) throws RemoteException , TIRExceptCreate, TIRExceptLock { 483 if (!isNew()) 484 throw new TIRExceptCreate("you can call create method on work object"); 485 if (result==null || exceptions==null) 486 return null; 487 int i; 488 for (i=0;i<exceptions.length;i++) 489 if (exceptions[i]==null) 490 return null; 491 if (result.get_state().value()==StateKind.sk_normal) 492 throw new TIRExceptCreate("Given object isn't work."); 493 for (i=0;i<exceptions.length;i++) 494 if (exceptions[i].get_state().value()==StateKind.sk_normal) 495 throw new TIRExceptCreate("Given object isn't work."); 496 Identification id = new IdentificationImpl(((SIdentification)name).language(), name.absolute_name().name(),this.id.version()); 498 Contained[] a = lookup_name(name.name()); 499 if (a.length != 0) 500 throw new TIRExceptCreate("Name \""+name.name()+"\" exists in repository."); 501 ExceptionDef[] ne = new ExceptionDef [exceptions.length]; 503 for (i=0;i<exceptions.length;i++) 504 ne[i]=exceptions[i]; 505 OperationDef ret = new OperationDefImpl(id, this, rep, result, ne, workId); 506 addListItem(ret); return ret; } 509 510 public ProtocolDef create_protocol() throws RemoteException , TIRExceptCreate, TIRExceptLock { 511 if (!isNew()) 512 throw new TIRExceptCreate("You can call create method on work object only"); 513 if (prot!=null) 514 throw new TIRExceptCreate("Protocol already exists"); 515 prot = new ProtocolDefImpl(StateKind.sk_work); 516 return prot; 517 } 518 519 public ConstantDef create_constant(Identification id, CDLType type, ExprOperDef value) throws RemoteException , TIRExceptCreate, TIRExceptLock { 520 if (!isNew()) 521 throw new TIRExceptCreate("you can call create method on work object"); 522 if (id==null || type==null || value==null) 523 return null; 524 else { 525 if (type.get_state().value()==StateKind.sk_work && 526 value.get_state().value()==StateKind.sk_work) { 527 if (!hasCont) 528 fromNormObj(); 529 id = new IdentificationImpl(((SIdentification)id).language(), id.absolute_name().name(),this.id.version()); 531 Contained[] a = lookup_name(id.name()); 532 if (a.length != 0) { 533 if (a[0].get_def_kind().value() != DefinitionKind.dk_Constant) 534 throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository."); 535 boolean found = false; 536 for (int i=0;i<a.length;i++) { 537 if (((SIdentification) a[i].get_identification()).is_short_equal(id)) { 538 found = true; 539 break; 540 } 541 } 542 if (found) 543 throw new TIRExceptCreate("Object with same identification exists in repository."); 544 } 545 ConstantDef ret = new ConstantDefImpl(id, this, rep,type, value, workId); 547 addListItem(ret); return ret; } else { 550 throw new TIRExceptCreate("Given objects aren't work."); 551 } 552 } 553 } 554 555 public TypedefDef create_typedef(Identification id, CDLType orig_type) throws RemoteException , TIRExceptCreate, TIRExceptLock { 556 if (!isNew()) 557 throw new TIRExceptCreate("you can call create method on work object"); 558 if (id==null || orig_type==null) 559 return null; 560 else { 561 if (orig_type.get_state().value()==StateKind.sk_work ) { 562 if (!hasCont) 563 fromNormObj(); 564 id = new IdentificationImpl(((SIdentification)id).language(), id.absolute_name().name(),this.id.version()); 566 Contained[] a = lookup_name(id.name()); 567 if (a.length != 0) { 568 if (a[0].get_def_kind().value() != DefinitionKind.dk_Typedef) 569 throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository."); 570 boolean found = false; 571 for (int i=0;i<a.length;i++) { 572 if (((SIdentification) a[i].get_identification()).is_short_equal(id)) { 573 found = true; 574 break; 575 } 576 } 577 if (found) 578 throw new TIRExceptCreate("Object with same identification exists in repository."); 579 } 580 TypedefDef ret = new TypedefDefImpl(id, this, rep, orig_type,workId); 582 addListItem(ret); return ret; } else { 585 throw new TIRExceptCreate("Given object isn't work."); 586 } 587 } 588 } 589 590 public ExceptionDef create_exception(Identification id) throws RemoteException , TIRExceptCreate, TIRExceptLock { 591 if (!isNew()) 592 throw new TIRExceptCreate("you can call create method on work object"); 593 if (id!=null) { 594 if (!hasCont) 595 fromNormObj(); 596 id = new IdentificationImpl(((SIdentification)id).language(), id.absolute_name().name(),this.id.version()); 598 Contained[] a = lookup_name(id.name()); 599 if (a.length != 0) { 600 if (a[0].get_def_kind().value() != DefinitionKind.dk_Exception) 601 throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository."); 602 boolean found = false; 603 for (int i=0;i<a.length;i++) { 604 if (((SIdentification) a[i].get_identification()).is_short_equal(id)) { 605 found = true; 606 break; 607 } 608 } 609 if (found) 610 throw new TIRExceptCreate("Object with same identification exists in repository."); 611 } 612 ExceptionDef ret = new ExceptionDefImpl(id, this, rep,workId); 614 addListItem(ret); return ret; } else 617 return null; 618 } 619 620 621 public void save(Storage st) throws RemoteException , TIRExceptStorage { 622 try { 623 int i; 624 st.curOutFile = new DataOutputStream (new FileOutputStream (st.currentFile)); 625 ((IdentificationImpl)id).save(st.curOutFile); if (prot != null) { 628 st.curOutFile.writeBoolean(true); 629 ((TIRImplObject) prot).save(st); 630 } else { 631 st.curOutFile.writeBoolean(false); 632 } 633 st.curOutFile.writeInt(base.length); 635 for(i=0;i<base.length;i++) { 636 Storage.writeCDLType(st, base[i]); 637 } 638 st.curOutFile.writeInt(numOfItems); 639 LiItem akt = firstChild; 640 for(i=0;i<numOfItems;i++) { st.curOutFile.writeInt(akt.obj.get_def_kind().value()); 642 ((TIRImplObject)(akt.obj)).save(st); 643 akt = akt.next; 644 } 645 st.curOutFile.close(); 646 } catch (IOException e) { 647 throw new TIRExceptStorage("Access error in "+st.currentFile+"."); 648 } 649 } 650 651 652 public void load(Storage st) throws RemoteException , TIRExceptStorage{ 653 try { 654 int num,i; 655 st.curInFile = new DataInputStream (new FileInputStream (st.currentFile)); 656 id = new IdentificationImpl(); 657 ((IdentificationImpl)id).load(st.curInFile); 658 if (st.curInFile.readBoolean()) { 660 prot = new ProtocolDefImpl(StateKind.sk_normal); 661 ((TIRImplObject) prot).load(st); 662 } else { 663 prot = null; 664 } 665 num = st.curInFile.readInt(); 667 loadBase = new CDLType [num]; 668 for(i=0;i<num;i++) { 669 loadBase[i] = Storage.readCDLType(st); 670 } 671 num = st.curInFile.readInt(); 672 int dkind; 673 TIRImplObject obj; 674 for (i=0;i<num;i++) { 675 dkind = st.curInFile.readInt(); 676 switch (dkind) { 677 case DefinitionKind.dk_Struct: 678 obj = new StructDefImpl(this, rep); 679 obj.load(st); 680 addListItem((TIRObject)obj); 681 break; 682 case DefinitionKind.dk_Enum: 683 obj = new EnumDefImpl(this, rep); 684 obj.load(st); 685 addListItem((TIRObject)obj); 686 break; 687 case DefinitionKind.dk_Union: 688 obj = new UnionDefImpl(this, rep); 689 obj.load(st); 690 addListItem((TIRObject)obj); 691 break; 692 case DefinitionKind.dk_Exception: 693 obj = new ExceptionDefImpl(this, rep); 694 obj.load(st); 695 addListItem((TIRObject)obj); 696 break; 697 case DefinitionKind.dk_Constant: 698 obj = new ConstantDefImpl(this, rep); 699 obj.load(st); 700 addListItem((TIRObject)obj); 701 break; 702 case DefinitionKind.dk_Typedef: 703 obj = new TypedefDefImpl(this, rep); 704 obj.load(st); 705 addListItem((TIRObject)obj); 706 break; 707 case DefinitionKind.dk_Attribute: 708 obj = new AttributeDefImpl(this, rep); 709 obj.load(st); 710 addListItem((TIRObject)obj); 711 break; 712 case DefinitionKind.dk_Operation: 713 obj = new OperationDefImpl(this, rep); 714 obj.load(st); 715 addListItem((TIRObject)obj); 716 break; 717 default: 718 throw new TIRExceptStorage("Unexpected kind of object in \"" 719 +st.currentFile+"\"."); 720 } } 722 st.curInFile.close(); 723 } catch (IOException e) { 724 throw new TIRExceptStorage("Access error in "+st.current+"."); 725 } 726 } 727 728 public void postLoad(RepositoryImpl r) throws RemoteException , TIRExceptStorage { 729 try { 730 731 int i,k; 732 733 if (prot != null) 734 ((TIRImplObject) prot).postLoad(r); 735 736 LiItem akt = firstChild; 737 for(i=0;i<numOfItems;i++) { 738 ((TIRImplObject) akt.obj).postLoad(r); 739 akt = akt.next; 740 } 741 742 Container con; 744 Contained[] rt; 745 Contained ret; 746 IdentificationImpl id; 747 AbsoluteName nm; 748 boolean found; 749 base = new InterfaceDef [loadBase.length]; 750 for (int j=0;j<loadBase.length;j++) { 751 if (loadBase[j].get_def_kind().value() == DefinitionKind.dk_none) { nm = ((NotYetInRep) loadBase[j]).nm; 753 con = r; for (i=0;i<nm.size()-1;i++) { id = new IdentificationImpl(nm.elementAt(0),"::"+nm.elementAt(i),""); 756 rt = ((SContainer)con).slookup_name(id); 757 if (rt.length==0) throw new TIRExceptStorage("Can't find interface " + nm.name()); 758 if (rt.length==1) { 759 con = (Container) rt[0]; 760 } else { 761 found = false; 762 id.version(((NotYetInRep) loadBase[j]).id.version()); 763 for (k=0;k<rt.length;k++) { 764 if (id.is_short_equal(rt[k].get_identification())) { 765 found = true; 766 break; } 768 } if (!found) throw new TIRExceptStorage("Can't find interface " + nm.name()); 770 con = (Container) rt[k]; 771 } 772 } 773 if ((ret = ((SContainer)con).slookup(((NotYetInRep) loadBase[j]).id))==null) 774 throw new TIRExceptStorage("Can't find interface " + nm.name()); 775 base[j] = (InterfaceDef) ret; 776 if (base[j].get_def_kind().value()==DefinitionKind.dk_Array || 777 base[j].get_def_kind().value()==DefinitionKind.dk_Sequence) 778 ((TIRImplObject) base[j]).postLoad(r); 779 } 780 } 781 782 } catch (TIRExceptLock e) {;} 783 } 784 785 public boolean isNew() { 786 return ((stKindImpl.value()==StateKind.sk_work) && normal==null); 787 } 788 789 public void canCommit() throws RemoteException , TIRExceptCommit { 790 if (stKindImpl.value()==StateKind.sk_normal) 791 return; 792 LiItem akt; 793 int i; 794 akt = firstChild; 795 for (i=0;i<numOfItems;i++) { 796 ((TIRImplObject)akt.obj).canCommit(); 797 akt = akt.next; 798 } 799 if (prot != null) 800 ((TIRImplObject)prot).canCommit(); 801 } 802 803 public void doCommit(Container in, Repository rep) throws RemoteException { 804 if (stKindImpl.value()==StateKind.sk_normal) 805 return; 806 if (isNew()) { 807 int i; 808 stKindImpl.toNormal(); 809 LiItem akt = firstChild; 810 for (i=0;i<numOfItems;i++) { 811 ((TIRImplObject)akt.obj).doCommit(this,rep); 812 akt = akt.next; 813 } 814 loadBase = new CDLType [base.length]; 815 for (i=0;i<base.length;i++) { 816 Identification idl = ((Contained)base[i]).get_identification(); 817 loadBase[i] = new NotYetInRep(idl.lang_absolute_name().name(), idl.name(), idl.version()); 818 } 819 if (prot != null) 820 ((TIRImplObject)prot).doCommit(this, rep); 821 base = null; 822 parent = in; 823 this.rep = rep; 824 } else { 825 normal = null; 826 } 827 } 828 829 public void doAbort(long workId) throws RemoteException { 830 LiItem akt = firstChild; 831 for(int i=0;i<numOfItems;i++) { 832 if (((TIRImplObject)akt.obj).isNew()) 833 ((TIRImplObject)akt.obj).doAbort(workId); 834 akt = akt.next; 835 } 836 } 837 838 public void setBaseInterfaces(InterfaceDef[] base_interfaces) throws RemoteException , TIRExceptCreate { 839 if (base_interfaces == null) 840 base = new InterfaceDef [0]; 841 else { 842 base = new InterfaceDef [base_interfaces.length]; 843 for (int i=0;i<base_interfaces.length;i++) { 844 if (base_interfaces[i].get_state().value()==StateKind.sk_work) 845 base[i]=base_interfaces[i]; 846 else 847 throw new TIRExceptCreate("Given objects aren't work."); 848 } 849 } 850 } 851 } 852 | Popular Tags |