KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Made > TIR > Impl > RepositoryImpl


1 /* $Id: RepositoryImpl.java,v 1.2 2004/05/20 14:23:52 bures Exp $ */
2 package SOFA.SOFAnode.Made.TIR.Impl;
3 import java.io.BufferedReader JavaDoc;
4 import java.io.BufferedWriter JavaDoc;
5 import java.io.File JavaDoc;
6 import java.io.FileReader JavaDoc;
7 import java.io.FileWriter JavaDoc;
8 import java.io.IOException JavaDoc;
9 import java.rmi.RemoteException JavaDoc;
10
11 import SOFA.SOFAnode.Made.TIR.ArrayDef;
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.ExprBinOperationDef;
19 import SOFA.SOFAnode.Made.TIR.ExprBoolean;
20 import SOFA.SOFAnode.Made.TIR.ExprChar;
21 import SOFA.SOFAnode.Made.TIR.ExprConstant;
22 import SOFA.SOFAnode.Made.TIR.ExprDefault;
23 import SOFA.SOFAnode.Made.TIR.ExprDouble;
24 import SOFA.SOFAnode.Made.TIR.ExprEnum;
25 import SOFA.SOFAnode.Made.TIR.ExprFixed;
26 import SOFA.SOFAnode.Made.TIR.ExprFloat;
27 import SOFA.SOFAnode.Made.TIR.ExprLong;
28 import SOFA.SOFAnode.Made.TIR.ExprLongDouble;
29 import SOFA.SOFAnode.Made.TIR.ExprLongLong;
30 import SOFA.SOFAnode.Made.TIR.ExprOctet;
31 import SOFA.SOFAnode.Made.TIR.ExprOperDef;
32 import SOFA.SOFAnode.Made.TIR.ExprProperty;
33 import SOFA.SOFAnode.Made.TIR.ExprShort;
34 import SOFA.SOFAnode.Made.TIR.ExprString;
35 import SOFA.SOFAnode.Made.TIR.ExprUnOperationDef;
36 import SOFA.SOFAnode.Made.TIR.ExprUnsigLong;
37 import SOFA.SOFAnode.Made.TIR.ExprUnsigLongLong;
38 import SOFA.SOFAnode.Made.TIR.ExprUnsigShort;
39 import SOFA.SOFAnode.Made.TIR.ExprWchar;
40 import SOFA.SOFAnode.Made.TIR.ExprWstring;
41 import SOFA.SOFAnode.Made.TIR.FixedDef;
42 import SOFA.SOFAnode.Made.TIR.Identification;
43 import SOFA.SOFAnode.Made.TIR.ManageProfiles;
44 import SOFA.SOFAnode.Made.TIR.ManageRepository;
45 import SOFA.SOFAnode.Made.TIR.PrimitiveDef;
46 import SOFA.SOFAnode.Made.TIR.ProfileDef;
47 import SOFA.SOFAnode.Made.TIR.ProviderDef;
48 import SOFA.SOFAnode.Made.TIR.Repository;
49 import SOFA.SOFAnode.Made.TIR.SequenceDef;
50 import SOFA.SOFAnode.Made.TIR.StateKind;
51 import SOFA.SOFAnode.Made.TIR.StringDef;
52 import SOFA.SOFAnode.Made.TIR.TIRExceptCreate;
53 import SOFA.SOFAnode.Made.TIR.TIRExceptLock;
54 import SOFA.SOFAnode.Made.TIR.TIRExceptSave;
55 import SOFA.SOFAnode.Made.TIR.TIRObject;
56 import SOFA.SOFAnode.Made.TIR.ValueGen;
57 import SOFA.SOFAnode.Made.TIR.WorkRepository;
58 import SOFA.SOFAnode.Made.TIR.WstringDef;
59
60 public class RepositoryImpl extends ContainerImpl implements Repository, ManageRepository, SRepository {
61   DefinitionKindImpl defKindImpl;
62   StateKindImpl stKindImpl;
63   //int numOfItems;
64
//LiItem firstChild;
65
//LiItem lastChild;
66
Lock lock; // lock for lookup, contents -- lock when commit
67
Lock lockGetCreate; // lock using for lockForCreate, if can lock
68
Lock lockCreate; // no more create or lockForCreate
69
long lockFor; // for which work object is lock for create
70
Storage storage;
71   PrimitiveDef[] primitives;
72
73   String JavaDoc sofaNodeName;
74   long uniq; // akt unique number
75

76   LiItem firstWork; // for active (not commited, not aborted) work repositories
77
LiItem lastWork;
78   int numOfWorks;
79
80   ManageProfilesImpl mProfiles;
81   Lock lockProfiles; // lock for ManageProfiles
82

83   // root == root directory of repository
84
public RepositoryImpl(String JavaDoc root, String JavaDoc sofaNodeName) throws RemoteException JavaDoc, TIRExceptStorage {
85     super();
86     System.out.print("Starting repository...");
87     lock = new Lock(false);
88     lockGetCreate = new Lock(false);
89     lockCreate = new Lock(false);
90     File JavaDoc f = new File JavaDoc(root);
91     if (!f.exists())
92       throw new TIRExceptStorage(root+" doesn't exit.");
93     if (!f.isDirectory())
94       throw new TIRExceptStorage(root+" isn't directory.");
95     File JavaDoc fc = new File JavaDoc(root);
96     storage = new Storage(f,fc);
97     defKindImpl = new DefinitionKindImpl(DefinitionKind.dk_Repository);
98     stKindImpl = new StateKindImpl(StateKind.sk_normal);
99     primitives = new PrimitiveDef [17];
100     for(int i=0;i<17;i++) {
101       primitives[i] = new PrimitiveDefImpl(i,StateKind.sk_normal);
102     }
103     mProfiles = new ManageProfilesImpl(this);
104     load(storage);
105     this.sofaNodeName = sofaNodeName;
106     System.out.println("OK");
107     lockFor = -1L;
108     firstWork = lastWork = null;
109     numOfWorks = 0;
110     lockProfiles = new Lock(false);
111   }
112
113   public PrimitiveDef get_prim(int pkind) throws RemoteException JavaDoc {
114     return primitives[pkind];
115   }
116   
117   /* from interface TIRImplObject */
118   public void load(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
119     /*String[][] childs;
120     try {
121       childs = st.listOfChilds();
122     } catch (TIRExceptStorage e) {
123       // there is nothing in repository
124       uniq = 0;
125       return;
126     }
127     try {
128     
129       BufferedReader index = new BufferedReader(new FileReader(new File(st.current,st.indexFile).toString()));
130       String un = index.readLine();
131       uniq = Long.parseLong(un);
132       index.close();
133       File old = st.current;
134       TIRImplObject m;
135       IdentificationImpl idl;
136       for(int i=0;i<childs.length;i++) {
137         switch (Integer.parseInt(childs[i][1])) {
138         case DefinitionKind.dk_Module:
139       idl = dentificationImpl("::"+childs[i][2],"");
140       m = new ModuleDefImpl(idl,this,this,StateKind.sk_normal,-1L);
141           st.current = new File(st.current,childs[i][0]);
142           m.load(st);
143       addListItem((TIRObject) m);
144       st.current = old;
145       break;
146
147         case DefinitionKind.dk_Provider:
148       idl = new IdentificationImpl("::"+childs[i][2],"");
149       m = new ProviderDefImpl(idl,this, this,StateKind.sk_normal,-1L);
150           st.current = new File(st.current,childs[i][0]);
151           m.load(st);
152       addListItem((TIRObject) m);
153       st.current = old;
154       break;
155     
156     case DefinitionKind.dk_Struct:
157       st.currentFile = new File(old,childs[i][0]);
158       st.curInFile = null;
159       m = new StructDefImpl(this,this);
160       m.load(st);
161           addListItem((TIRObject) m);
162       st.currentFile = null;
163       break;
164     case DefinitionKind.dk_Exception:
165       st.currentFile = new File(old,childs[i][0]);
166       st.curInFile = null;
167       m = new ExceptionDefImpl(this,this);
168       m.load(st);
169           addListItem((TIRObject) m);
170       st.currentFile = null;
171       break;
172     case DefinitionKind.dk_Enum:
173       st.currentFile = new File(old,childs[i][0]);
174       st.curInFile = null;
175       m = new EnumDefImpl(this,this);
176       m.load(st);
177           addListItem((TIRObject) m);
178       st.currentFile = null;
179       break;
180         case DefinitionKind.dk_Union:
181       st.currentFile = new File(old,childs[i][0]);
182       st.curInFile = null;
183       m = new UnionDefImpl(this,this);
184       m.load(st);
185           addListItem((TIRObject) m);
186       st.currentFile = null;
187       break;
188         case DefinitionKind.dk_Constant:
189       st.currentFile = new File(old,childs[i][0]);
190       st.curInFile = null;
191       m = new ConstantDefImpl(this,this);
192       m.load(st);
193           addListItem((TIRObject) m);
194       st.currentFile = null;
195       break;
196         case DefinitionKind.dk_Typedef:
197       st.currentFile = new File(old,childs[i][0]);
198       st.curInFile = null;
199       m = new TypedefDefImpl(this,this);
200       m.load(st);
201           addListItem((TIRObject) m);
202       st.currentFile = null;
203       break;
204         case DefinitionKind.dk_Interface:
205       st.currentFile = new File(old,childs[i][0]);
206       st.curInFile = null;
207       m = new InterfaceDefImpl(this,this);
208       m.load(st);
209           addListItem((TIRObject) m);
210       st.currentFile = null;
211       break;
212         case DefinitionKind.dk_Frame:
213       st.currentFile = new File(old,childs[i][0]);
214       st.curInFile = null;
215       m = new FrameDefImpl(this,this);
216       m.load(st);
217           addListItem((TIRObject) m);
218       st.currentFile = null;
219       break;
220     default:
221       throw new TIRExceptStorage("Unexpected kind of object in \""
222                                   +st.current+st.current.separator+childs[i]+"\".");
223         }
224       }
225       postLoad(this);
226       st.current = new File(old,"profiles");
227       mProfiles = new ManageProfilesImpl(this);
228       mProfiles.load(st);
229       st.current = old;
230       st.currentFile=null;
231     } catch (IOException e) {
232       throw new TIRExceptStorage("Access error in \""+st.current+"\".");
233     }*/

234     try {
235       File JavaDoc iname = new File JavaDoc(st.current, Storage.indexFile);
236       if ( ! iname.exists()) {
237         // first loading in new dir
238
uniq = 0;
239     addListItem(new CDLRepositoryImpl(this));
240     return;
241       }
242       BufferedReader JavaDoc index = new BufferedReader JavaDoc(new FileReader JavaDoc(iname.toString()));
243       String JavaDoc un = index.readLine();
244       uniq = Long.parseLong(un);
245       index.close();
246
247       boolean ex = true;
248       File JavaDoc old = st.current;
249       st.current = new File JavaDoc(st.current, "cdl");
250       if ( ! st.current.exists())
251         ex = false;
252       TIRImplObject m = new CDLRepositoryImpl(this);
253       if (ex)
254         m.load(st);
255       addListItem((TIRObject) m);
256       st.current = old;
257
258       // !!! if new languages will be added to TIR, saving of concrete LangRepository must be added
259

260       postLoad(this);
261       st.current = new File JavaDoc(old,"profiles");
262       mProfiles = new ManageProfilesImpl(this);
263       mProfiles.load(st);
264       st.current = old;
265       st.currentFile=null;
266     } catch (IOException JavaDoc e) {
267       throw new TIRExceptStorage("Access error in \""+st.current+"\".");
268     }
269   }
270
271   public void postLoad(RepositoryImpl r) throws RemoteException JavaDoc, TIRExceptStorage {
272     LiItem akt = firstChild;
273     for(int i=0;i<numOfItems;i++) {
274       ((TIRImplObject) akt.obj).postLoad(r);
275       akt = akt.next;
276     }
277   }
278   
279   /* from interface TIRImplObject */
280   public void save(Storage st) throws RemoteException JavaDoc, TIRExceptStorage {
281     try {
282      /* String[][] childs = null;
283       if (!st.current.exists()) { // first save of repository
284         if (!st.current.mkdir())
285           throw new TIRExceptStorage("Can't create directory "+st.current+".");
286       } else { // repository dir exists
287         try {
288           childs = st.listOfChilds();
289         } catch (TIRExceptStorage e) { // dir without index.tir
290           ;
291         }
292       }
293       File f = new File(st.current,st.indexFile); // name of index file
294       LiItem akt = firstChild;
295       File old = st.current;
296       BufferedWriter index = new BufferedWriter(new FileWriter(f.toString()));
297       String un = Long.toString(uniq);
298       index.write(un,0,un.length()); index.newLine();
299       index.write("CHILDS",0,6); index.newLine();
300       for(int i=0;i<numOfItems;i++) {
301         String[] achild; // actual child info
302         IdentificationImpl idl; // actual child id
303     File nfile; // path to child's current path
304         if ((achild=st.existsChild(childs,idl = (IdentificationImpl)((Contained)akt.obj).get_identification()))!=null) { // file (dir) exists
305       // saving info to index file
306           index.write(achild[0],0,achild[0].length()); index.write("?",0,1);
307           index.write(achild[1],0,achild[1].length()); index.write("?",0,1);
308           index.write(achild[2],0,achild[2].length()); index.write("?",0,1);
309           index.write(achild[3],0,achild[3].length()); index.newLine();
310       nfile = new File(old,achild[0]);
311       
312         } else { //file (dir) doesn't exist
313       String hlp;
314           //if (idl.name().length() <= Storage.maxLenFileName)
315       // nfile = new File(old,idl.name()); // file (dir) name same as id
316       //else
317             nfile = File.createTempFile("tir","",old);
318           nfile.delete();
319       // saving info to index file
320       index.write(hlp = nfile.getName(),0,hlp.length()); index.write("?",0,1);
321       index.write(hlp=Integer.toString(akt.obj.get_def_kind().value()),0,hlp.length());
322       index.write("?",0,1);
323       index.write(hlp = idl.name(),0,hlp.length()); index.write("?",0,1);
324           index.write(hlp = idl.version(),0,hlp.length()); index.newLine();
325         }
326         if ((akt.obj.get_def_kind().value()==DefinitionKind.dk_Module) ||
327         (akt.obj.get_def_kind().value()==DefinitionKind.dk_Provider)) {
328       st.current = nfile; // directory for module
329       if (!st.current.exists()) //create only if doesn't exist
330             if (!st.current.mkdir())
331           throw new TIRExceptStorage("Can't create directory "+st.current+".");
332     } else {
333       st.currentFile = nfile; // file for all except module
334           st.curOutFile = null;
335         }
336
337     ((TIRImplObject) akt.obj).save(st); // save akt object
338         akt = akt.next; // go to the next object
339         st.current = old;
340         st.currentFile = null;
341       } // -- end of for
342       index.close();
343       st.current = new File(old,"profiles");
344       if (!st.current.exists()) //create only if doesn't exist
345         if (!st.current.mkdir())
346           throw new TIRExceptStorage("Can't create directory "+st.current+".");
347       mProfiles.save(st);
348       st.current = old;*/

349
350       // saving unique number
351
File JavaDoc f = new File JavaDoc(st.current,Storage.indexFile); // name of index file
352
BufferedWriter JavaDoc index = new BufferedWriter JavaDoc(new FileWriter JavaDoc(f.toString()));
353       String JavaDoc un = Long.toString(uniq);
354       index.write(un,0,un.length()); index.newLine();
355       index.close();
356
357       // saving childs
358
LiItem akt = firstChild;
359       File JavaDoc old = st.current;
360       for(int i=0;i<numOfItems;i++) {
361         String JavaDoc lang = ((SIdentification) ((Contained) akt.obj).get_identification()).language();
362     f = new File JavaDoc(old, lang);
363     if ( ! f.exists()) {
364           if (!f.mkdir())
365             throw new TIRExceptStorage("Can't create directory "+f+".");
366     }
367     st.current = f;
368         ((TIRImplObject) akt.obj).save(st); // save akt object
369
akt = akt.next; // go to the next object
370
} // -- end of for
371

372       st.current = new File JavaDoc(old,"profiles");
373       if (!st.current.exists()) //create only if doesn't exist
374
if (!st.current.mkdir())
375           throw new TIRExceptStorage("Can't create directory "+st.current+".");
376       mProfiles.save(st);
377       st.current = old;
378     } catch (IOException JavaDoc e) {
379       throw new TIRExceptStorage("Access error in "+st.current+".");
380     }
381   }
382
383   /* call from commit() method of work repository */
384   void commitSave() throws RemoteException JavaDoc, TIRExceptSave {
385     try {
386       save(storage);
387        lock.unlock();
388     } catch (TIRExceptStorage e) {
389       throw new TIRExceptSave("Error occured when saving repository.\nError: "+e.getMessage());
390     }
391   }
392
393   public void save() throws RemoteException JavaDoc, TIRExceptSave {
394     try {
395       lock.lock();
396       save(storage);
397       lock.unlock();
398     } catch (TIRExceptStorage e) {
399       throw new TIRExceptSave("Error occured when saving repository.\nError: "+e.getMessage());
400     }
401   }
402  
403   public Contained[] contents(DefinitionKind type) throws RemoteException JavaDoc, TIRExceptLock {
404     if (lock.isLocked())
405       throw new TIRExceptLock("Repository is locked");
406     else
407       return super.contents(type);
408   }
409
410   public Contained lookup(Identification id) throws RemoteException JavaDoc, TIRExceptLock {
411     if (lock.isLocked())
412       throw new TIRExceptLock("Repository is locked");
413     else {
414       Contained ret = null;
415       LiItem akt = firstChild;
416       for(int i=0;i<numOfItems;i++) {
417         if (((SIdentification) ((Contained)akt.obj).get_identification()).language().compareTo(id.name())==0) {
418           ret = (Contained) akt.obj;
419      break;
420         } else {
421           akt = akt.next;
422         }
423       }
424       return ret;
425     }
426   }
427
428   public Contained lookup(String JavaDoc name, String JavaDoc version) throws RemoteException JavaDoc, TIRExceptLock {
429     if (lock.isLocked())
430       throw new TIRExceptLock("Repository is locked");
431     else {
432       Contained ret = null;
433       LiItem akt = firstChild;
434       for(int i=0;i<numOfItems;i++) {
435         if (((SIdentification) ((Contained)akt.obj).get_identification()).language().compareTo(name)==0) {
436           ret = (Contained) akt.obj;
437      break;
438         } else {
439           akt = akt.next;
440         }
441       }
442       return ret;
443     }
444   }
445
446   public Contained[] lookup_name(Identification id) throws RemoteException JavaDoc, TIRExceptLock {
447     if (lock.isLocked())
448       throw new TIRExceptLock("Repository is locked");
449     else
450       return super.lookup_name(id);
451   }
452
453   public Contained[] lookup_name(String JavaDoc id) throws RemoteException JavaDoc, TIRExceptLock {
454     if (lock.isLocked())
455       throw new TIRExceptLock("Repository is locked");
456     else
457       return super.lookup_name(id);
458   }
459
460   public Contained lookup_tag(String JavaDoc name, String JavaDoc tag) throws RemoteException JavaDoc, TIRExceptLock {
461     if (lock.isLocked())
462       throw new TIRExceptLock("Repository is locked");
463     else
464       return super.lookup_tag(name, tag);
465   }
466
467   public Contained[] lookup_branchtag(String JavaDoc name, String JavaDoc brtag) throws RemoteException JavaDoc, TIRExceptLock {
468     if (lock.isLocked())
469       throw new TIRExceptLock("Repository is locked");
470     else
471       return super.lookup_branchtag(name, brtag);
472   }
473
474   public Contained lookup_lastinbranch(String JavaDoc name, String JavaDoc brtag) throws RemoteException JavaDoc, TIRExceptLock {
475     if (lock.isLocked())
476       throw new TIRExceptLock("Repository is locked");
477     else
478       return super.lookup_lastinbranch(name, brtag);
479   }
480
481   public Contained lookup_lastfromversion(String JavaDoc name, String JavaDoc version) throws RemoteException JavaDoc, TIRExceptLock {
482     if (lock.isLocked())
483       throw new TIRExceptLock("Repository is locked");
484     else
485       return super.lookup_lastfromversion(name, version);
486   }
487
488   public Contained[] scontents(DefinitionKind type) throws RemoteException JavaDoc, TIRExceptLock {
489   /* if (lock.isLocked())
490       throw new TIRExceptLock("Repository is locked");
491     else */

492       return super.scontents(type);
493   }
494
495   public Contained slookup(Identification id) throws RemoteException JavaDoc, TIRExceptLock {
496    /* if (lock.isLocked())
497       throw new TIRExceptLock("Repository is locked");
498     else */

499       Contained ret = null;
500       LiItem akt = firstChild;
501       for(int i=0;i<numOfItems;i++) {
502         if (((SIdentification) ((Contained)akt.obj).get_identification()).language().compareTo(id.name())==0) {
503           ret = (Contained) akt.obj;
504      break;
505         } else {
506           akt = akt.next;
507         }
508       }
509       return ret;
510   }
511
512   public Contained slookup(String JavaDoc name, String JavaDoc version) throws RemoteException JavaDoc, TIRExceptLock {
513     /*if (lock.isLocked())
514       throw new TIRExceptLock("Repository is locked");
515     else */

516       Contained ret = null;
517       LiItem akt = firstChild;
518       for(int i=0;i<numOfItems;i++) {
519         if (((SIdentification) ((Contained)akt.obj).get_identification()).language().compareTo(name)==0) {
520           ret = (Contained) akt.obj;
521      break;
522         } else {
523           akt = akt.next;
524         }
525       }
526       return ret;
527   }
528
529   public Contained[] slookup_name(Identification id) throws RemoteException JavaDoc, TIRExceptLock {
530     /*if (lock.isLocked())
531       throw new TIRExceptLock("Repository is locked");
532     else */

533       Contained[] ret = null;
534       LiItem akt = firstChild;
535       for(int i=0;i<numOfItems;i++) {
536         if (((SIdentification) ((Contained)akt.obj).get_identification()).language().compareTo(id.name())==0) {
537       ret = new Contained [1];
538           ret[0] = (Contained) akt.obj;
539      break;
540         } else {
541           akt = akt.next;
542         }
543       }
544       return ret;
545   }
546
547   public Contained[] slookup_name(String JavaDoc name) throws RemoteException JavaDoc, TIRExceptLock {
548    /* if (lock.isLocked())
549       throw new TIRExceptLock("Repository is locked");
550     else */

551       Contained[] ret = null;
552       LiItem akt = firstChild;
553       for(int i=0;i<numOfItems;i++) {
554         if (((SIdentification) ((Contained)akt.obj).get_identification()).language().compareTo(name)==0) {
555       ret = new Contained [1];
556           ret[0] = (Contained) akt.obj;
557      break;
558         } else {
559           akt = akt.next;
560         }
561       }
562       return ret;
563   }
564   
565   /* from interface TIRObject */
566   public DefinitionKind get_def_kind() throws RemoteException JavaDoc {
567     return (DefinitionKind) defKindImpl;
568   }
569
570   /* from interface TIRObject */
571   public StateKind get_state() throws RemoteException JavaDoc {
572     return (StateKind) stKindImpl;
573   }
574
575   public DefinitionKind get_spec_def_kind(int kind) throws RemoteException JavaDoc {
576     return new DefinitionKindImpl(kind);
577   }
578  
579   /* from interface Repository */
580   public Identification create_identification(String JavaDoc lang, String JavaDoc name, String JavaDoc version) throws RemoteException JavaDoc, TIRExceptCreate {
581 // return (Identification) new IdentificationImpl(name, version);
582
throw new TIRExceptCreate("You can call create method on work object only");
583   }
584
585   /* from interface Repository */
586   public Identification create_nextversion(Identification id) throws RemoteException JavaDoc, TIRExceptCreate {
587     throw new TIRExceptCreate("You can call create method on work object only");
588   }
589
590 /* from interface Repository */
591   public Identification create_initialversion(String JavaDoc lang, String JavaDoc name) throws RemoteException JavaDoc, TIRExceptCreate {
592     throw new TIRExceptCreate("You can call create method on work object only");
593   }
594
595   public Identification create_branch(Identification from, String JavaDoc branchTag) throws RemoteException JavaDoc, TIRExceptCreate {
596     throw new TIRExceptCreate("You can call create method on work object only");
597   }
598
599   public PrimitiveDef get_primitive(int kind) throws RemoteException JavaDoc, TIRExceptCreate {
600     throw new TIRExceptCreate("You can call create method on work object only");
601   }
602
603   public StringDef create_string(ExprOperDef bound) throws RemoteException JavaDoc, TIRExceptCreate {
604     throw new TIRExceptCreate("You can call create method on work object only");
605   }
606   public WstringDef create_wstring(ExprOperDef bound) throws RemoteException JavaDoc, TIRExceptCreate {
607     throw new TIRExceptCreate("You can call create method on work object only");
608   }
609   public SequenceDef create_sequence(ExprOperDef bound, CDLType element) throws RemoteException JavaDoc, TIRExceptCreate {
610     throw new TIRExceptCreate("You can call create method on work object only");
611   }
612   public ArrayDef create_array(ExprOperDef length, CDLType element) throws RemoteException JavaDoc, TIRExceptCreate {
613     throw new TIRExceptCreate("You can call create method on work object only");
614   }
615   public FixedDef create_fixed(ExprOperDef digits, ExprOperDef scale) throws RemoteException JavaDoc, TIRExceptCreate {
616     throw new TIRExceptCreate("You can call create method on work object only");
617   }
618
619   public ProviderDef create_provider(Identification id) throws RemoteException JavaDoc, TIRExceptCreate {
620     throw new TIRExceptCreate("You can call create method on work object only");
621   }
622
623   public ExprBoolean create_exprboolean(boolean val) throws RemoteException JavaDoc, TIRExceptCreate {
624     throw new TIRExceptCreate("You can call create method on work object only");
625   }
626   public ExprShort create_exprshort(short val) throws RemoteException JavaDoc, TIRExceptCreate {
627     throw new TIRExceptCreate("You can call create method on work object only");
628   }
629   public ExprOctet create_exproctet(byte val) throws RemoteException JavaDoc, TIRExceptCreate {
630     throw new TIRExceptCreate("You can call create method on work object only");
631   }
632
633   public ExprLong create_exprlong(int val) throws RemoteException JavaDoc, TIRExceptCreate {
634     throw new TIRExceptCreate("You can call create method on work object only");
635   }
636   public ExprLongLong create_exprlonglong(long val) throws RemoteException JavaDoc, TIRExceptCreate {
637     throw new TIRExceptCreate("You can call create method on work object only");
638   }
639   public ExprUnsigShort create_exprunsigshort(short val) throws RemoteException JavaDoc, TIRExceptCreate {
640     throw new TIRExceptCreate("You can call create method on work object only");
641   }
642   public ExprUnsigLong create_exprunsiglong(int val) throws RemoteException JavaDoc, TIRExceptCreate {
643     throw new TIRExceptCreate("You can call create method on work object only");
644   }
645   public ExprUnsigLongLong create_exprunsiglonglong(long val) throws RemoteException JavaDoc, TIRExceptCreate {
646     throw new TIRExceptCreate("You can call create method on work object only");
647   }
648   public ExprFloat create_exprfloat(float val) throws RemoteException JavaDoc, TIRExceptCreate {
649     throw new TIRExceptCreate("You can call create method on work object only");
650   }
651   public ExprDouble create_exprdouble(double val) throws RemoteException JavaDoc, TIRExceptCreate {
652     throw new TIRExceptCreate("You can call create method on work object only");
653   }
654   public ExprLongDouble create_exprlongdouble(double val) throws RemoteException JavaDoc, TIRExceptCreate {
655     throw new TIRExceptCreate("You can call create method on work object only");
656   }
657   public ExprFixed create_exprfixed(java.math.BigDecimal JavaDoc val, int digits, int scale) throws RemoteException JavaDoc, TIRExceptCreate {
658     throw new TIRExceptCreate("You can call create method on work object only");
659   }
660   public ExprProperty create_exprproperty(String JavaDoc pr) throws RemoteException JavaDoc, TIRExceptCreate {
661     throw new TIRExceptCreate("You can call create method on work object only");
662   }
663   public ExprEnum create_exprenum(EnumDef en, String JavaDoc enMember) throws RemoteException JavaDoc, TIRExceptCreate {
664     throw new TIRExceptCreate("You can call create method on work object only");
665   }
666   public ExprDefault create_exprdefault() throws RemoteException JavaDoc, TIRExceptCreate {
667     throw new TIRExceptCreate("You can call create method on work object only");
668   }
669   public ExprChar create_exprchar(char val) throws RemoteException JavaDoc, TIRExceptCreate {
670     throw new TIRExceptCreate("You can call create method on work object only");
671   }
672   public ExprWchar create_exprwchar(char val) throws RemoteException JavaDoc, TIRExceptCreate {
673     throw new TIRExceptCreate("You can call create method on work object only");
674   }
675   public ExprString create_exprstring(String JavaDoc val) throws RemoteException JavaDoc, TIRExceptCreate {
676     throw new TIRExceptCreate("You can call create method on work object only");
677   }
678   public ExprWstring create_exprwstring(String JavaDoc val) throws RemoteException JavaDoc, TIRExceptCreate {
679     throw new TIRExceptCreate("You can call create method on work object only");
680   }
681   public ExprConstant create_exprconstant(ConstantDef val) throws RemoteException JavaDoc, TIRExceptCreate {
682     throw new TIRExceptCreate("You can call create method on work object only");
683   }
684   public ExprUnOperationDef create_exprunoperation(int kind, ExprOperDef op) throws RemoteException JavaDoc, TIRExceptCreate {
685     throw new TIRExceptCreate("You can call create method on work object only");
686   }
687   public ExprBinOperationDef create_exprbinoperation(int kind, ExprOperDef op1, ExprOperDef op2) throws RemoteException JavaDoc, TIRExceptCreate {
688     throw new TIRExceptCreate("You can call create method on work object only");
689   }
690   public ValueGen create_valuegen() throws RemoteException JavaDoc, TIRExceptCreate {
691     throw new TIRExceptCreate("You can call create method on work object only");
692   }
693
694   synchronized public WorkRepository beginChanges(ProfileDef p) throws RemoteException JavaDoc, TIRExceptCreate, TIRExceptLock {
695     WorkRepository wr = new WorkRepositoryImpl(this,p);
696     addWork(wr);
697     return wr;
698   }
699
700   public void addWork(WorkRepository wr) {
701     LiItem item = new LiItem(wr);
702     if (firstWork == null) {
703       firstWork = lastWork = item;
704     } else {
705       LiItem akt = firstWork;
706       while (akt.next != null) akt = akt.next;
707       akt.next = item;
708       item.prev = akt;
709       lastWork = item;
710     }
711     numOfWorks++;
712   }
713
714   public void removeWork(long workId) {
715     if (numOfWorks>0) {
716       LiItem akt = firstWork;
717       boolean found = false;
718       for (int i=0;i<numOfWorks;i++) {
719         if (((WorkRepositoryImpl)akt.obj).workId == workId) {
720           found = true;
721           break;
722         }
723         akt = akt.next;
724       }
725       if (!found)
726         return;
727       if (numOfWorks==1) {
728     firstWork = lastWork = null;
729     numOfWorks = 0;
730       } else {
731         if (akt == firstWork) {
732           firstWork = akt.next;
733       firstWork.prev = null;
734       akt.next = null;
735       //akt = firstWork;
736
} else {
737           if (lastWork == akt) {
738         lastWork = akt.prev;
739         lastWork.next = null;
740         akt.prev = null;
741         //akt = lastWork;
742
} else {
743         akt.prev.next = akt.next;
744         akt.next.prev = akt.prev;
745         //akt = akt.next;
746
}
747     }
748         numOfWorks--;
749       }
750     }
751   }
752
753   synchronized public long getUniqueNumber() {
754     long a = uniq;
755     uniq++;
756     return a;
757   }
758
759   public boolean isNew() {
760     return false;
761   }
762   
763   public void canCommit() {;}
764
765   public void doCommit(Container in, Repository rep) {;}
766   public void doAbort(long workId) throws RemoteException JavaDoc {}
767
768   public long isLockedForCreate() {
769     if (lockCreate.isLocked())
770       return lockFor;
771     return -1L;
772   }
773
774   public ManageRepository getManage() throws RemoteException JavaDoc {
775     return (ManageRepository) this;
776   }
777
778   public WorkRepository[] getActiveWork() throws RemoteException JavaDoc {
779     LiItem akt = firstWork;
780     WorkRepository[] ret = new WorkRepository [numOfWorks];
781     for (int i=0;i<numOfWorks;i++) {
782       ret[i] = (WorkRepository) akt.obj;
783       akt = akt.next;
784     }
785     return ret;
786   }
787
788   public ManageProfiles getProfiles() throws RemoteException JavaDoc {
789     return mProfiles;
790   }
791 }
792
Popular Tags