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