refactoring org to uk
[vamsas.git] / src / uk / ac / vamsas / client / simpleclient / VamsasFile.java
1
2 package uk.ac.vamsas.client.simpleclient;
3
4 import java.io.File;
5 import java.io.FileOutputStream;
6 import java.io.FileReader;
7 import java.io.IOException;
8 import java.io.InputStream;
9 import java.io.InputStreamReader;
10 import java.io.PrintWriter;
11 import java.util.Timer;
12 import java.util.jar.JarEntry;
13 import java.util.jar.JarFile;
14 import java.util.jar.JarInputStream;
15 import java.util.jar.JarOutputStream;
16
17 import uk.ac.vamsas.objects.core.LockFileDescriptor;
18
19 /**
20  * low level vamsas document management routines
21  * analogous to ClientsFile
22  * Grew out of io tests on VamsasArchive class in org.vamsas.test.simpleclient.VamsasArchive
23  * This class is not thread safe.
24  * @author jimp
25  *
26  */
27 public class VamsasFile extends SessionFile {
28   /**
29    * 
30    * Connect to an existing Vamsas document in a given sessionDir
31    * or create a new one.
32    * 
33    * @param sessionDir
34    * @throws java.io.IOException
35    */
36   public VamsasFile(File sessionFile) throws java.io.IOException {
37     super(sessionFile);
38   }
39   /**
40    * 
41    * @return the VamsasFile
42    */
43   public File getVamsasFile() {
44     return sessionFile;
45   }
46   /**
47    * Expand a previously stored session into the sessionDir
48    * @param sessionDir
49    * @param storedSession
50    
51    public VamsasFile(File sessionDir, JarFile storedSession) throws IOException {
52     // check if sessionDir is live or not
53     if (!sessionDir.exists()) {
54       sessionDir.mkdir();
55     }
56     
57     {
58       // check its actually a writable directory
59     }
60     
61     File sfile = new File(sessionDir, "vamsas.jar");
62     VamsasFile(sfile);
63     // if live - try to merge storedSession with sessionDir
64     //  - will probably fail through duplicate Vobject references needing to be dereferenced.
65     // TODO: think of a way of specifying vorba_id scope for an application's references to allow merging of one vamsasDocument with another.
66     
67   }
68   */
69   /**
70    * public interface for getting a lock.
71    * The lock object is internally referenced 
72    * so the lock will persist even after the
73    * return value of the method goes out of scope.
74    * @return null if lock couldn't be got or a valid Lock object.
75    */
76   public Lock getLock() {
77     if (lockFile())
78       return fileLock;
79     return null;
80   }
81   /**
82    * 
83    * @param extantLock
84    * @return null, extantLock or new Lock.
85    */
86   public Lock getLock(Lock extantLock) {
87     if (lockFile(extantLock))
88       return fileLock;
89     return null;
90   }
91   /**
92    * explicitly unlocks vamsas file.
93    * if you have called getLock() you *must* 
94    * call this to release the lock.
95    */
96   public void unLock() {
97     this.unlockFile();
98   }
99   
100 }