1 2 package SOFA.SOFAnode.Made.TIR.Impl; 3 import java.io.BufferedWriter ; 4 import java.io.File ; 5 import java.io.FileWriter ; 6 import java.io.IOException ; 7 import java.rmi.RemoteException ; 8 9 import SOFA.SOFAnode.Made.TIR.AbsoluteName; 10 import SOFA.SOFAnode.Made.TIR.CDLType; 11 import SOFA.SOFAnode.Made.TIR.ConstantDef; 12 import SOFA.SOFAnode.Made.TIR.Contained; 13 import SOFA.SOFAnode.Made.TIR.Container; 14 import SOFA.SOFAnode.Made.TIR.DefinitionKind; 15 import SOFA.SOFAnode.Made.TIR.EnumDef; 16 import SOFA.SOFAnode.Made.TIR.ExceptionDef; 17 import SOFA.SOFAnode.Made.TIR.ExprOperDef; 18 import SOFA.SOFAnode.Made.TIR.FrameDef; 19 import SOFA.SOFAnode.Made.TIR.Identification; 20 import SOFA.SOFAnode.Made.TIR.InterfaceDef; 21 import SOFA.SOFAnode.Made.TIR.ModuleDef; 22 import SOFA.SOFAnode.Made.TIR.Repository; 23 import SOFA.SOFAnode.Made.TIR.StateKind; 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.TIRObject; 29 import SOFA.SOFAnode.Made.TIR.TypedefDef; 30 import SOFA.SOFAnode.Made.TIR.UnionDef; 31 32 public class ModuleDefImpl extends CDLContainerImpl implements ModuleDef, SContained { 33 protected Identification id; 34 protected Container parent; 35 protected Repository rep; 36 DefinitionKindImpl defKindImpl; 37 StateKindImpl stKindImpl; 38 39 ModuleDefImpl normal; 40 41 Lock lockCreate; 42 boolean lockForMe; public long lockFor; public long workId; 46 public ModuleDefImpl(Identification ident, Container in, Repository inrep, int state, long workId) throws RemoteException { 47 id = ident; 48 parent = in; 49 rep = inrep; 50 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Module); 51 stKindImpl = new StateKindImpl(state); 52 normal = null; 53 lockCreate = new Lock(false); 54 lockForMe = false; 55 lockFor = -1L; 56 this.workId = workId; 57 } 58 59 public ModuleDefImpl(Container in, Repository inrep) throws RemoteException { 60 parent = in; 61 rep = inrep; 62 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Module); 63 stKindImpl = new StateKindImpl(StateKind.sk_normal); 64 normal = null; 65 lockCreate = new Lock(false); 66 lockForMe = false; 67 workId = -1L; 68 lockFor = -1L; 69 } 70 71 public ModuleDefImpl(ModuleDefImpl a, Container in, Repository inrep, long workId) throws RemoteException { 72 normal = a; 73 parent = in; 74 rep = inrep; 75 defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Module); 76 stKindImpl = new StateKindImpl(StateKind.sk_work); 77 id = a.id; 78 lockCreate = a.lockCreate; 79 lockForMe = false; 80 this.workId = workId; 81 lockFor = -1L; 82 } 83 84 85 public Identification get_identification() throws RemoteException { 86 return id; 87 } 88 89 90 public Container get_defined_in() throws RemoteException { 91 return parent; 92 } 93 94 95 public Container get_containing_repository() throws RemoteException { 96 return rep; 97 } 98 99 100 public AbsoluteName get_absolute_name() throws RemoteException { 101 AbsoluteNameImpl absName; 102 if (rep == parent) { absName = new AbsoluteNameImpl("::"+id.name()); 104 } else { 105 absName = new AbsoluteNameImpl(((SContained)parent).get_absolute_name().name()+"::"+id.name()); 106 } 107 return (AbsoluteName) absName; 108 } 109 110 111 public DefinitionKind get_def_kind() throws RemoteException { 112 return (DefinitionKind) defKindImpl; 113 } 114 115 public void tag(String t) throws RemoteException , TIRExceptCreate, TIRExceptLock { 116 if (stKindImpl.value()!=StateKind.sk_work) 117 throw new TIRExceptCreate("you can call create method on work object"); 118 String ebt = id.branchTag(); 119 if (t.compareTo(ebt)==0) 120 throw new TIRExceptCreate("This tag exists"); 121 String [] et = id.tag(); 122 int i,j; 123 for (i=0;i<et.length;i++) { 124 if (t.compareTo(et[i])==0) 125 throw new TIRExceptCreate("This tag exists"); 126 } 127 Contained[] sibl = parent.lookup_name(id); 128 for (j=0;j<sibl.length;j++) { 129 Identification idl = sibl[j].get_identification(); 130 131 ebt = idl.branchTag(); 132 if (t.compareTo(ebt)==0) 133 throw new TIRExceptCreate("This tag exists"); 134 et = idl.tag(); 135 for (i=0;i<et.length;i++) { 136 if (t.compareTo(et[i])==0) 137 throw new TIRExceptCreate("This tag exists"); 138 } 139 } 140 ((SIdentification) id).tag(t); 141 } 142 143 private void fromNormObj() throws RemoteException , TIRExceptLock { 144 if (normal==null) 145 return; 146 if (((WorkRepositoryImpl)rep).lock.isLocked()) 147 throw new TIRExceptLock("Repository is locked"); 148 int i; 149 LiItem akt; 150 akt = normal.firstChild; 151 for(i=0;i<normal.numOfItems;i++) { 152 addListItem(WorkRepositoryImpl.newWorkFromNormal(akt.obj,rep,this,workId)); 153 akt = akt.next; 154 } 155 hasCont = true; 156 } 157 158 public Contained[] contents(DefinitionKind type) throws RemoteException , TIRExceptLock { 159 if (stKindImpl.value()==StateKind.sk_normal) { 160 if (((RepositoryImpl) rep).lock.isLocked()) 161 throw new TIRExceptLock("Repository is locked"); 162 else 163 return super.contents(type); 164 } else { 165 if (!hasCont) 166 fromNormObj(); 167 if (((WorkRepositoryImpl) rep).lock.isLocked()) 168 throw new TIRExceptLock("Repository is locked"); 169 else 170 return super.contents(type); 171 } 172 } 173 174 public Contained lookup(Identification id) throws RemoteException , TIRExceptLock { 175 if (stKindImpl.value()==StateKind.sk_normal) { 176 if (((RepositoryImpl) rep).lock.isLocked()) 177 throw new TIRExceptLock("Repository is locked"); 178 else 179 return super.lookup(id); 180 } else { 181 if (!hasCont) 182 fromNormObj(); 183 if (((WorkRepositoryImpl) rep).lock.isLocked()) 184 throw new TIRExceptLock("Repository is locked"); 185 else 186 return super.lookup(id); 187 } 188 } 189 190 public Contained lookup(String name, String version) throws RemoteException , TIRExceptLock { 191 if (stKindImpl.value()==StateKind.sk_normal) { 192 if (((RepositoryImpl) rep).lock.isLocked()) 193 throw new TIRExceptLock("Repository is locked"); 194 else 195 return super.lookup(name, version); 196 } else { 197 if (!hasCont) 198 fromNormObj(); 199 if (((WorkRepositoryImpl) rep).lock.isLocked()) 200 throw new TIRExceptLock("Repository is locked"); 201 else 202 return super.lookup(name, version); 203 } 204 } 205 206 public Contained[] lookup_name(Identification id) throws RemoteException , TIRExceptLock { 207 if (stKindImpl.value()==StateKind.sk_normal) { 208 if (((RepositoryImpl) rep).lock.isLocked()) 209 throw new TIRExceptLock("Repository is locked"); 210 else 211 return super.lookup_name(id); 212 } else { 213 if (!hasCont) 214 fromNormObj(); 215 if (((WorkRepositoryImpl) rep).lock.isLocked()) 216 throw new TIRExceptLock("Repository is locked"); 217 else 218 return super.lookup_name(id); 219 } 220 } 221 222 public Contained[] lookup_name(String name) throws RemoteException , TIRExceptLock { 223 if (stKindImpl.value()==StateKind.sk_normal) { 224 if (((RepositoryImpl) rep).lock.isLocked()) 225 throw new TIRExceptLock("Repository is locked"); 226 else 227 return super.lookup_name(name); 228 } else { 229 if (!hasCont) 230 fromNormObj(); 231 if (((WorkRepositoryImpl) rep).lock.isLocked()) 232 throw new TIRExceptLock("Repository is locked"); 233 else 234 return super.lookup_name(name); 235 } 236 } 237 238 public Contained lookup_tag(String name, String tag) throws RemoteException , TIRExceptLock { 239 if (stKindImpl.value()==StateKind.sk_normal) { 240 if (((RepositoryImpl) rep).lock.isLocked()) 241 throw new TIRExceptLock("Repository is locked"); 242 else 243 return super.lookup_tag(name, tag); 244 } else { 245 if (!hasCont) 246 fromNormObj(); 247 if (((WorkRepositoryImpl) rep).lock.isLocked()) 248 throw new TIRExceptLock("Repository is locked"); 249 else 250 return super.lookup_tag(name, tag); 251 } 252 } 253 254 public Contained[] lookup_branchtag(String name, String brtag) throws RemoteException , TIRExceptLock { 255 if (stKindImpl.value()==StateKind.sk_normal) { 256 if (((RepositoryImpl) rep).lock.isLocked()) 257 throw new TIRExceptLock("Repository is locked"); 258 else 259 return super.lookup_branchtag(name, brtag); 260 } else { 261 if (!hasCont) 262 fromNormObj(); 263 if (((WorkRepositoryImpl) rep).lock.isLocked()) 264 throw new TIRExceptLock("Repository is locked"); 265 else 266 return super.lookup_branchtag(name, brtag); 267 } 268 } 269 270 public Contained lookup_lastinbranch(String name, String brtag) throws RemoteException , TIRExceptLock { 271 if (stKindImpl.value()==StateKind.sk_normal) { 272 if (((RepositoryImpl) rep).lock.isLocked()) 273 throw new TIRExceptLock("Repository is locked"); 274 else 275 return super.lookup_lastinbranch(name, brtag); 276 } else { 277 if (!hasCont) 278 fromNormObj(); 279 if (((WorkRepositoryImpl) rep).lock.isLocked()) 280 throw new TIRExceptLock("Repository is locked"); 281 else 282 return super.lookup_lastinbranch(name, brtag); 283 } 284 } 285 286 public Contained lookup_lastfromversion(String name, String version) throws RemoteException , TIRExceptLock { 287 if (stKindImpl.value()==StateKind.sk_normal) { 288 if (((RepositoryImpl) rep).lock.isLocked()) 289 throw new TIRExceptLock("Repository is locked"); 290 else 291 return super.lookup_lastfromversion(name, version); 292 } else { 293 if (!hasCont) 294 fromNormObj(); 295 if (((WorkRepositoryImpl) rep).lock.isLocked()) 296 throw new TIRExceptLock("Repository is locked"); 297 else 298 return super.lookup_lastfromversion(name, version); 299 } 300 } 301 302 public Contained[] scontents(DefinitionKind type) throws RemoteException , TIRExceptLock { 303 if (stKindImpl.value()==StateKind.sk_normal) { 304 return super.scontents(type); 305 } else { 306 if (!hasCont) 307 fromNormObj(); 308 return super.scontents(type); 309 } 310 } 311 312 public Contained slookup(Identification id) throws RemoteException , TIRExceptLock { 313 if (stKindImpl.value()==StateKind.sk_normal) { 314 return super.slookup(id); 315 } else { 316 if (!hasCont) 317 fromNormObj(); 318 return super.slookup(id); 319 } 320 } 321 322 public Contained slookup(String name, String version) throws RemoteException , TIRExceptLock { 323 if (stKindImpl.value()==StateKind.sk_normal) { 324 return super.slookup(name, version); 325 } else { 326 if (!hasCont) 327 fromNormObj(); 328 return super.slookup(name, version); 329 } 330 } 331 332 public Contained[] slookup_name(Identification id) throws RemoteException , TIRExceptLock { 333 if (stKindImpl.value()==StateKind.sk_normal) { 334 return super.slookup_name(id); 335 } else { 336 if (!hasCont) 337 fromNormObj(); 338 return super.slookup_name(id); 339 } 340 } 341 342 public Contained[] slookup_name(String name) throws RemoteException , TIRExceptLock { 343 if (stKindImpl.value()==StateKind.sk_normal) { 344 return super.slookup_name(name); 345 } else { 346 if (!hasCont) 347 fromNormObj(); 348 return super.slookup_name(name); 349 } 350 } 351 352 353 public StateKind get_state() throws RemoteException { 354 return (StateKind) stKindImpl; 355 } 356 357 358 public void save(Storage st) throws RemoteException , TIRExceptStorage { 359 try { 360 String [][] childs = null; 361 try { 362 childs = st.listOfChilds(); 363 } catch (TIRExceptStorage e) { ; 365 } 366 File f = new File (st.current,Storage.indexFile); LiItem akt = firstChild; 369 File old = st.current; 370 BufferedWriter index = new BufferedWriter (new FileWriter (f.toString())); 371 index.write("CHILDS",0,6); index.newLine(); 372 for(int i=0;i<numOfItems;i++) { 373 String [] achild; IdentificationImpl idl; File nfile; if ((achild=st.existsChild(childs,idl = (IdentificationImpl)((Contained)akt.obj).get_identification()))!=null) { index.write(achild[0],0,achild[0].length()); index.write("?",0,1); 379 index.write(achild[1],0,achild[1].length()); index.write("?",0,1); 380 index.write(achild[2],0,achild[2].length()); index.write("?",0,1); 381 index.write(achild[3],0,achild[3].length()); index.newLine(); 382 nfile = new File (old,achild[0]); 383 384 } else { String hlp; 386 nfile = File.createTempFile("tir","",old); 390 nfile.delete(); 391 index.write(hlp = nfile.getName(),0,hlp.length()); index.write("?",0,1); 393 index.write(hlp=Integer.toString(akt.obj.get_def_kind().value()),0,hlp.length()); 394 index.write("?",0,1); 395 index.write(hlp = idl.name(),0,hlp.length()); index.write("?",0,1); 396 index.write(hlp = idl.version(),0,hlp.length()); index.newLine(); 397 } 398 if (akt.obj.get_def_kind().value()==DefinitionKind.dk_Module) { 399 st.current = nfile; if (!st.current.exists()) if (!st.current.mkdir()) 402 throw new TIRExceptStorage("Can't create directory "+st.current+"."); 403 } else { 404 st.currentFile = nfile; st.curOutFile = null; 406 } 407 408 ((TIRImplObject) akt.obj).save(st); akt = akt.next; st.current = old; 411 st.currentFile = null; 412 } index.close(); 414 st.current = old; 415 } catch (IOException e) { 416 throw new TIRExceptStorage("Access error in "+st.current+"."); 417 } 418 } 419 420 421 public void load(Storage st) throws RemoteException , TIRExceptStorage{ 422 String [][] childs = st.listOfChilds(); 423 File old = st.current; 424 TIRImplObject m; 425 for(int i=0;i<childs.length;i++) { 426 switch (Integer.parseInt(childs[i][1])) { 427 case DefinitionKind.dk_Module: 428 IdentificationImpl idl = new IdentificationImpl(((SIdentification)id).language(), this.id.absolute_name().name()+"::"+childs[i][2],""); 429 m = new ModuleDefImpl((Identification)idl,this, rep,StateKind.sk_normal,-1L); 430 st.current = new File (old,childs[i][0]); 431 m.load(st); 432 addListItem((TIRObject) m); 433 st.current = old; 434 break; 435 case DefinitionKind.dk_Struct: 436 st.currentFile = new File (old,childs[i][0]); 437 st.curInFile = null; 438 m = new StructDefImpl(this,rep); 439 m.load(st); 440 addListItem((TIRObject) m); 441 st.currentFile = null; 442 break; 443 case DefinitionKind.dk_Exception: 444 st.currentFile = new File (old,childs[i][0]); 445 st.curInFile = null; 446 m = new ExceptionDefImpl(this,rep); 447 m.load(st); 448 addListItem((TIRObject) m); 449 st.currentFile = null; 450 break; 451 case DefinitionKind.dk_Enum: 452 st.currentFile = new File (old,childs[i][0]); 453 st.curInFile = null; 454 m = new EnumDefImpl(this,rep); 455 m.load(st); 456 addListItem((TIRObject) m); 457 st.currentFile = null; 458 break; 459 case DefinitionKind.dk_Union: 460 st.currentFile = new File (old,childs[i][0]); 461 st.curInFile = null; 462 m = new UnionDefImpl(this,rep); 463 m.load(st); 464 addListItem((TIRObject) m); 465 st.currentFile = null; 466 break; 467 case DefinitionKind.dk_Constant: 468 st.currentFile = new File (old,childs[i][0]); 469 st.curInFile = null; 470 m = new ConstantDefImpl(this,rep); 471 m.load(st); 472 addListItem((TIRObject) m); 473 st.currentFile = null; 474 break; 475 case DefinitionKind.dk_Typedef: 476 st.currentFile = new File (old,childs[i][0]); 477 st.curInFile = null; 478 m = new TypedefDefImpl(this,rep); 479 m.load(st); 480 addListItem((TIRObject) m); 481 st.currentFile = null; 482 break; 483 case DefinitionKind.dk_Interface: 484 st.currentFile = new File (old,childs[i][0]); 485 st.curInFile = null; 486 m = new InterfaceDefImpl(this,rep); 487 m.load(st); 488 addListItem((TIRObject) m); 489 st.currentFile = null; 490 break; 491 case DefinitionKind.dk_Frame: 492 st.currentFile = new File (old,childs[i][0]); 493 st.curInFile = null; 494 m = new FrameDefImpl(this,rep); 495 m.load(st); 496 addListItem((TIRObject) m); 497 st.currentFile = null; 498 break; 499 default: 500 throw new TIRExceptStorage("Unexpected kind of object in \"" 501 +st.current+File.separator+childs[i]+"\"."); 502 } 503 } 504 } 505 506 public void postLoad(RepositoryImpl r) throws RemoteException , TIRExceptStorage { 507 LiItem akt = firstChild; 508 for(int i=0;i<numOfItems;i++) { 509 ((TIRImplObject) akt.obj).postLoad(r); 510 akt = akt.next; 511 } 512 } 513 514 private boolean testIdentification(Identification newId) throws RemoteException { 516 AbsoluteName newAbs = newId.lang_absolute_name(); 517 AbsoluteName abs = id.lang_absolute_name(); 518 if (newAbs.size() != (abs.size() + 1)) 519 return false; 520 int len = abs.size(); 521 for (int i=0;i<len;i++) { 522 if (abs.elementAt(i).compareTo(newAbs.elementAt(i))!=0) 523 return false; 524 } 525 return true; 526 } 527 528 public ModuleDef create_module(Identification id) throws RemoteException , TIRExceptCreate, TIRExceptLock { 529 if (stKindImpl.value()==StateKind.sk_normal) 530 throw new TIRExceptCreate("you can call create method on work object"); 531 if (id!=null) { 532 if (!testIdentification(id)) 533 throw new TIRExceptCreate("Wrong identification for this object."); 534 if (!getCreateLock()) 535 throw new TIRExceptLock("This part of repository is locked for creating."); 536 if (!hasCont) 537 fromNormObj(); 538 id = new IdentificationImpl(((SIdentification)id).language(), id.absolute_name().name(),""); 539 Contained[] a = lookup_name(id.name()); 540 if (a.length != 0) { 541 if (a[0].get_def_kind().value() != DefinitionKind.dk_Module) 542 throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository."); 543 boolean found = false; 544 for (int i=0;i<a.length;i++) { 545 if (((SIdentification) a[i].get_identification()).is_short_equal(id)) { 546 found = true; 547 break; 548 } 549 } 550 if (found) 551 throw new TIRExceptCreate("Object with same identification exists in repository."); 552 } 553 ModuleDef ret = new ModuleDefImpl(id, this, rep, StateKind.sk_work, workId); 555 addListItem(ret); return ret; } else 558 return null; 559 } 560 561 public ConstantDef create_constant(Identification id, CDLType type, ExprOperDef value) throws RemoteException , TIRExceptCreate, TIRExceptLock { 562 if (stKindImpl.value()==StateKind.sk_normal) 563 throw new TIRExceptCreate("you can call create method on work object"); 564 if (id==null || type==null || value==null) 565 return null; 566 else { 567 if (type.get_state().value()==StateKind.sk_work && 568 value.get_state().value()==StateKind.sk_work) { 569 if (!testIdentification(id)) 570 throw new TIRExceptCreate("Wrong identification for this object."); 571 if (!getCreateLock()) 572 throw new TIRExceptLock("This part of repository is locked for creating."); 573 if (!hasCont) 574 fromNormObj(); 575 id = new IdentificationImpl(id); 576 Contained[] a = lookup_name(id.name()); 577 if (a.length != 0) { 578 if (a[0].get_def_kind().value() != DefinitionKind.dk_Constant) 579 throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository."); 580 boolean found = false; 581 for (int i=0;i<a.length;i++) { 582 if (((SIdentification) a[i].get_identification()).is_short_equal(id)) { 583 found = true; 584 break; 585 } 586 } 587 if (found) 588 throw new TIRExceptCreate("Object with same identification exists in repository."); 589 } 590 ConstantDef ret = new ConstantDefImpl(id, this, rep,type, value, workId); 592 addListItem(ret); return ret; } else { 595 throw new TIRExceptCreate("Given objects aren't work."); 596 } 597 } 598 } 599 600 public StructDef create_struct(Identification id) throws RemoteException , TIRExceptCreate, TIRExceptLock { 601 if (stKindImpl.value()==StateKind.sk_normal) 602 throw new TIRExceptCreate("you can call create method on work object"); 603 if (id!=null) { 604 if (!testIdentification(id)) 605 throw new TIRExceptCreate("Wrong identification for this object."); 606 if (!getCreateLock()) 607 throw new TIRExceptLock("This part of repository is locked for creating."); 608 if (!hasCont) 609 fromNormObj(); 610 id = new IdentificationImpl(id); 611 Contained[] a = lookup_name(id.name()); 612 if (a.length != 0) { 613 if (a[0].get_def_kind().value() != DefinitionKind.dk_Struct) 614 throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository."); 615 boolean found = false; 616 for (int i=0;i<a.length;i++) { 617 if (((SIdentification) a[i].get_identification()).is_short_equal(id)) { 618 found = true; 619 break; 620 } 621 } 622 if (found) 623 throw new TIRExceptCreate("Object with same identification exists in repository."); 624 } 625 StructDef ret = new StructDefImpl(id, this, rep ,workId); 627 addListItem(ret); return ret; } else 630 return null; 631 } 632 633 public UnionDef create_union(Identification id, CDLType switch_type) throws RemoteException , TIRExceptCreate, TIRExceptLock { 634 if (stKindImpl.value()==StateKind.sk_normal) 635 throw new TIRExceptCreate("you can call create method on work object"); 636 if (id==null || switch_type==null) 637 return null; 638 else { 639 if (switch_type.get_state().value()==StateKind.sk_work ) { 640 if (!testIdentification(id)) 641 throw new TIRExceptCreate("Wrong identification for this object."); 642 if (!getCreateLock()) 643 throw new TIRExceptLock("This part of repository is locked for creating."); 644 if (!hasCont) 645 fromNormObj(); 646 id = new IdentificationImpl(id); 647 Contained[] a = lookup_name(id.name()); 648 if (a.length != 0) { 649 if (a[0].get_def_kind().value() != DefinitionKind.dk_Union) 650 throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository."); 651 boolean found = false; 652 for (int i=0;i<a.length;i++) { 653 if (((SIdentification) a[i].get_identification()).is_short_equal(id)) { 654 found = true; 655 break; 656 } 657 } 658 if (found) 659 throw new TIRExceptCreate("Object with same identification exists in repository."); 660 } 661 UnionDef ret = new UnionDefImpl(id, this, rep, switch_type, workId); 663 addListItem(ret); return ret; } else { 666 throw new TIRExceptCreate("Given object isn't work."); 667 } 668 } 669 } 670 671 public EnumDef create_enum(Identification id) throws RemoteException , TIRExceptCreate, TIRExceptLock { 672 if (stKindImpl.value()==StateKind.sk_normal) 673 throw new TIRExceptCreate("you can call create method on work object"); 674 if (id!=null) { 675 if (!testIdentification(id)) 676 throw new TIRExceptCreate("Wrong identification for this object."); 677 if (!getCreateLock()) 678 throw new TIRExceptLock("This part of repository is locked for creating."); 679 if (!hasCont) 680 fromNormObj(); 681 id = new IdentificationImpl(id); 682 Contained[] a = lookup_name(id.name()); 683 if (a.length != 0) { 684 if (a[0].get_def_kind().value() != DefinitionKind.dk_Enum) 685 throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository."); 686 boolean found = false; 687 for (int i=0;i<a.length;i++) { 688 if (((SIdentification) a[i].get_identification()).is_short_equal(id)) { 689 found = true; 690 break; 691 } 692 } 693 if (found) 694 throw new TIRExceptCreate("Object with same identification exists in repository."); 695 } 696 EnumDef ret = new EnumDefImpl(id, this, rep, workId); 698 addListItem(ret); return ret; } else 701 return null; 702 } 703 704 public TypedefDef create_typedef(Identification id, CDLType orig_type) throws RemoteException , TIRExceptCreate, TIRExceptLock { 705 if (stKindImpl.value()==StateKind.sk_normal) 706 throw new TIRExceptCreate("you can call create method on work object"); 707 if (id==null || orig_type==null) 708 return null; 709 else { 710 if (orig_type.get_state().value()==StateKind.sk_work ) { 711 if (!testIdentification(id)) 712 throw new TIRExceptCreate("Wrong identification for this object."); 713 if (!getCreateLock()) 714 throw new TIRExceptLock("This part of repository is locked for creating."); 715 if (!hasCont) 716 fromNormObj(); 717 id = new IdentificationImpl(id); 718 Contained[] a = lookup_name(id.name()); 719 if (a.length != 0) { 720 if (a[0].get_def_kind().value() != DefinitionKind.dk_Typedef) 721 throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository."); 722 boolean found = false; 723 for (int i=0;i<a.length;i++) { 724 if (((SIdentification) a[i].get_identification()).is_short_equal(id)) { 725 found = true; 726 break; 727 } 728 } 729 if (found) 730 throw new TIRExceptCreate("Object with same identification exists in repository."); 731 } 732 TypedefDef ret = new TypedefDefImpl(id, this, rep, orig_type, workId); 734 addListItem(ret); return ret; } else { 737 throw new TIRExceptCreate("Given object isn't work."); 738 } 739 } 740 } 741 742 public ExceptionDef create_exception(Identification id) throws RemoteException , TIRExceptCreate, TIRExceptLock { 743 if (stKindImpl.value()==StateKind.sk_normal) 744 throw new TIRExceptCreate("you can call create method on work object"); 745 if (id!=null) { 746 if (!testIdentification(id)) 747 throw new TIRExceptCreate("Wrong identification for this object."); 748 if (!getCreateLock()) 749 throw new TIRExceptLock("This part of repository is locked for creating."); 750 if (!hasCont) 751 fromNormObj(); 752 id = new IdentificationImpl(id); 753 Contained[] a = lookup_name(id.name()); 754 if (a.length != 0) { 755 if (a[0].get_def_kind().value() != DefinitionKind.dk_Exception) 756 throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository."); 757 boolean found = false; 758 for (int i=0;i<a.length;i++) { 759 if (((SIdentification) a[i].get_identification()).is_short_equal(id)) { 760 found = true; 761 break; 762 } 763 } 764 if (found) 765 throw new TIRExceptCreate("Object with same identification exists in repository."); 766 } 767 ExceptionDef ret = new ExceptionDefImpl(id, this, rep, workId); 769 addListItem(ret); return ret; } else 772 return null; 773 } 774 775 public InterfaceDef create_interface(Identification id, InterfaceDef[] base_interfaces) throws RemoteException , TIRExceptCreate, TIRExceptLock { 776 if (stKindImpl.value()==StateKind.sk_normal) 777 throw new TIRExceptCreate("you can call create method on work object"); 778 int i; 779 if (id==null || base_interfaces==null) { 780 return null; 781 } else { 782 if (!testIdentification(id)) 783 throw new TIRExceptCreate("Wrong identification for this object."); 784 if (!getCreateLock()) 785 throw new TIRExceptLock("This part of repository is locked for creating."); 786 if (!hasCont) 787 fromNormObj(); 788 id = new IdentificationImpl(id); 789 Contained[] a = lookup_name(id.name()); 790 if (a.length != 0) { 791 if (a[0].get_def_kind().value() != DefinitionKind.dk_Interface) 792 throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository."); 793 boolean found = false; 794 for (i=0;i<a.length;i++) { 795 if (((SIdentification) a[i].get_identification()).is_short_equal(id)) { 796 found = true; 797 break; 798 } 799 } 800 if (found) 801 throw new TIRExceptCreate("Object with same identification exists in repository."); 802 } 803 InterfaceDef[] bi = new InterfaceDef [base_interfaces.length]; 805 for (i=0;i<base_interfaces.length;i++) { 806 if (base_interfaces[i].get_state().value()==StateKind.sk_work) 807 bi[i]=base_interfaces[i]; 808 else 809 throw new TIRExceptCreate("Given objects aren't work."); 810 } 811 InterfaceDef ret = new InterfaceDefImpl(id, this, rep, bi, workId); 812 addListItem(ret); return ret; } 815 } 816 817 public InterfaceDef create_interface(Identification id) throws RemoteException , TIRExceptCreate, TIRExceptLock { 818 if (stKindImpl.value()==StateKind.sk_normal) 819 throw new TIRExceptCreate("you can call create method on work object"); 820 int i; 821 if (id==null) { 822 return null; 823 } else { 824 if (!testIdentification(id)) 825 throw new TIRExceptCreate("Wrong identification for this object."); 826 if (!getCreateLock()) 827 throw new TIRExceptLock("This part of repository is locked for creating."); 828 if (!hasCont) 829 fromNormObj(); 830 id = new IdentificationImpl(id); 831 Contained[] a = lookup_name(id.name()); 832 if (a.length != 0) { 833 if (a[0].get_def_kind().value() != DefinitionKind.dk_Interface) 834 throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository."); 835 boolean found = false; 836 for (i=0;i<a.length;i++) { 837 if (((SIdentification) a[i].get_identification()).is_short_equal(id)) { 838 found = true; 839 break; 840 } 841 } 842 if (found) 843 throw new TIRExceptCreate("Object with same identification exists in repository."); 844 } 845 InterfaceDef ret = new InterfaceDefImpl(id, this, rep, null, workId); 847 addListItem(ret); return ret; } 850 } 851 852 public FrameDef create_frame(Identification id, boolean system) throws RemoteException , TIRExceptCreate, TIRExceptLock { 853 if (stKindImpl.value()==StateKind.sk_normal) 854 throw new TIRExceptCreate("you can call create method on work object"); 855 if (id!=null) { 856 if (!testIdentification(id)) 857 throw new TIRExceptCreate("Wrong identification for this object."); 858 if (!getCreateLock()) 859 throw new TIRExceptLock("This part of repository is locked for creating."); 860 if (!hasCont) 861 fromNormObj(); 862 id = new IdentificationImpl(id); 863 Contained[] a = lookup_name(id.name()); 864 if (a.length != 0) { 865 if (a[0].get_def_kind().value() != DefinitionKind.dk_Frame) 866 throw new TIRExceptCreate("Name \""+id.name()+"\" exists in repository."); 867 boolean found = false; 868 for (int i=0;i<a.length;i++) { 869 if (((SIdentification) a[i].get_identification()).is_short_equal(id)) { 870 found = true; 871 break; 872 } 873 } 874 if (found) 875 throw new TIRExceptCreate("Object with same identification exists in repository."); 876 } 877 FrameDef ret = new FrameDefImpl(id, this, rep, system, workId); 879 addListItem(ret); return ret; } else 882 return null; 883 } 884 885 public boolean isNew() { 886 return ((stKindImpl.value()==StateKind.sk_work) && normal==null); 887 } 888 889 public void canCommit() throws RemoteException , TIRExceptCommit { 890 if (stKindImpl.value()==StateKind.sk_normal) 891 return; 892 LiItem akt; 893 int i,j; 894 akt = firstChild; 895 for (i=0;i<numOfItems;i++) { 896 if (((TIRImplObject)akt.obj).isNew() && !isNew()) { 897 LiItem nak = normal.firstChild; 898 for (j=0;j<normal.numOfItems;j++) { 899 if (((SIdentification) ((Contained)nak.obj).get_identification()).is_short_name_equal(((Contained)akt.obj).get_identification())) { 900 if (akt.obj.get_def_kind().value()!=nak.obj.get_def_kind().value()) 901 throw new TIRExceptCommit("Object with name \""+((SContained)nak.obj).get_absolute_name().name()+"\"exists."); 902 if (((SIdentification) ((Contained)nak.obj).get_identification()).is_short_equal(((Contained)akt.obj).get_identification())) 903 throw new TIRExceptCommit("Object with identification \""+((Contained)nak.obj).get_identification()+"\"in container \""+get_absolute_name().name()+"\" exists."); 904 } 905 nak = nak.next; 906 } 907 } 908 ((TIRImplObject)akt.obj).canCommit(); 909 akt = akt.next; 910 } 911 } 912 913 public void doAbort(long workId) throws RemoteException { 914 LiItem akt = firstChild; 915 for(int i=0;i<numOfItems;i++) { 916 ((TIRImplObject)akt.obj).doAbort(workId); 918 akt = akt.next; 919 } 920 if (lockForMe) { 921 normal.lockFor = -1L; 922 lockCreate.unlock(); 923 lockForMe = false; 924 928 } 929 } 930 931 public void doCommit(Container in, Repository rep) throws RemoteException { 932 if (stKindImpl.value()==StateKind.sk_normal) 933 return; 934 LiItem akt = firstChild; 935 boolean nn = false; 936 int i; 937 if (isNew()) { 938 stKindImpl.toNormal(); 939 for(i=0;i<numOfItems;i++) { 940 ((TIRImplObject)akt.obj).doCommit(this,rep); 941 akt = akt.next; 942 } 943 parent = in; 944 this.rep = rep; 945 } else { 946 for(i=0;i<numOfItems;i++) { 947 if (((TIRImplObject)akt.obj).isNew()) 948 nn = true; 949 ((TIRImplObject)akt.obj).doCommit(normal,rep); 950 if (nn) 951 normal.addListItem(akt.obj); 952 akt = akt.next; 953 nn = false; 954 } 955 if (lockForMe) { 956 normal.lockFor = -1L; 957 lockCreate.unlock(); 958 lockForMe = false; 959 } 960 } 961 966 967 } 968 969 970 public long isLockedForCreate() throws RemoteException { 971 if ((stKindImpl.value()==StateKind.sk_work)) 972 if (normal==null) 973 return -1L; 974 if (lockCreate.isLocked()) { 975 return normal.lockFor; 976 } 977 return -1L; 978 } 979 980 981 public long canLock() throws RemoteException { 982 long a; 983 if ((a=isLockedForCreate())!=-1L) return a; 985 Container con = parent; 987 while (con.get_def_kind().value()!=DefinitionKind.dk_Repository && 988 con.get_def_kind().value()!=DefinitionKind.dk_WorkRepository) { 989 if ((a=((SContainer)con).isLockedForCreate())!=-1L) 990 return a; 991 con = ((Contained)con).get_defined_in(); 992 } 993 if ((a=((SContainer)con).isLockedForCreate())!=-1L) 994 return a; 995 if ((a=canLockChild())!=-1L) 997 return a; 998 return -1L; 999 } 1000 1001 1002 public long canLockChild() throws RemoteException { 1003 LiItem akt = firstChild; 1004 long a; 1005 for(int i=0;i<numOfItems;i++) { 1006 if (akt.obj.get_def_kind().value()==DefinitionKind.dk_Module) { 1007 if ((a=((ModuleDefImpl)akt.obj).isLockedForCreate())!=-1L) 1008 return a; 1009 else { 1010 if ((a=((ModuleDefImpl)akt.obj).canLockChild())!=-1L) 1011 return a; 1012 } 1013 } 1014 } 1015 return -1L; 1016 } 1017 1018 1019 boolean getCreateLock() throws RemoteException { 1020 if (!isNew()) { 1021 if (lockForMe) 1022 return true; 1023 if (lockCreate.isLocked()) 1024 return false; 1025 ((WorkRepositoryImpl)rep).normalRep.lockGetCreate.lock(); 1026 long a = canLock(); 1027 if ((a==-1L) || (a==workId)) { 1028 lockForMe = true; 1029 lockCreate.lock(); 1030 normal.lockFor = workId; 1031 } 1032 ((WorkRepositoryImpl)rep).normalRep.lockGetCreate.unlock(); 1033 return true; 1034 } 1035 return true; 1036 } 1037} 1038 | Popular Tags |