ecacdb9b4793b3c77bf053b27581735ee8b40b22
[vamsas.git] / src / org / vamsas / client / simpleclient / VamsasFile.java
1
2 package org.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 org.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    * Expand a previously stored session into the sessionDir
41    * @param sessionDir
42    * @param storedSession
43    
44    public VamsasFile(File sessionDir, JarFile storedSession) throws IOException {
45     // check if sessionDir is live or not
46     if (!sessionDir.exists()) {
47       sessionDir.mkdir();
48     }
49     
50     {
51       // check its actually a writable directory
52     }
53     
54     File sfile = new File(sessionDir, "vamsas.jar");
55     VamsasFile(sfile);
56     // if live - try to merge storedSession with sessionDir
57     //  - will probably fail through duplicate Vobject references needing to be dereferenced.
58     // TODO: think of a way of specifying vorba_id scope for an application's references to allow merging of one vamsasDocument with another.
59     
60   }
61   */
62   /**
63    * public interface for getting a lock.
64    * The lock object is internally referenced 
65    * so the lock will persist even after the
66    * return value of the method goes out of scope.
67    * @return null if lock couldn't be got or a valid Lock object.
68    */
69   public Lock getLock() {
70     if (lockFile())
71       return fileLock;
72     return null;
73   }
74   /**
75    * explicitly unlocks vamsas file.
76    * if you have called getLock() you *must* 
77    * call this to release the lock.
78    */
79   public void unLock() {
80     this.unlockFile();
81   }
82   
83 }