}
}
-
+ /**
+ * the vamsas document version(s) handled by this Reader
+ */
+ final public static String DOCUMENT_VERSION="0.1";
/**
* name of the jarEntry containing a well formatted vamsas XML Document
*/
*/
public boolean isValid() {
if (jfile!=null)
- // TODO: check if VAMSASDOC is well formed, follows www.vamsas.ac.uk/schemas/vamsasDocument.xsd, and all appData references are resolvable - preferably as jar entries
+ // TODO: check if VAMSASDOC is well formed (follows www.vamsas.ac.uk/schemas/vamsasDocument.xsd) and all appData references are resolvable - preferably as jar entries
return (getVamsasDocumentEntry()!=null);
return false;
}
+
+ protected JarEntry getAppdataEntry(String AppdataRef) {
+ JarEntry entry;
+ if (jfile==null || !isValid() || (entry=jfile.getJarEntry(AppdataRef))==null)
+ return null;
+ return entry;
+ }
+
+ public InputStream getAppdataStream(String AppdataRef) {
+ JarEntry entry=getAppdataEntry(AppdataRef);
+ try {
+ if (entry!=null)
+ return jfile.getInputStream(entry);
+ } catch (IOException e) {
+ System.err.println("Failed when opening AppdataStream for "+AppdataRef);
+ e.printStackTrace(System.err);
+ }
+ return null;
+ }
/**
* get the VamsasDocument input stream, if it exists.
* @return null or valid input stream
* @author jimp
*
*/
-public class VamsasFile {
- /**
- * Locked IO methods for vamsas Document.
- *
- * Vamsas client is intialised with a path to create live session directories.
- * This path may contain a vamsas.properties file
- * that sets additional parameters (otherwise client
- * just uses the one on the classpath).
- *
- * A vamsas session consists of :
- * SessionDir - translates to urn of a live session.
- * Contains: Vamsas Document (as a jar), Session client list file,
- * both of which may be locked, and additional
- * temporary versions of these files when write
- * operations are taking place.
- *
- * Zip file entries
- * - vamsasdocument.xml : core info
- * one or more:
- * - <applicationname>.version.sessionnumber.raw (string given in vamsasdocument.xml applicationData entry)
- *
- * Lockfile
- * - filename given in the vamsasdocument.xml. Should be checked for validity by any client and rewritten if necessary.
- * The lockfile can point to the jar itself.
- * Mode of operation.
- * Initially - documentHandler either:
- * - creates a zip for a new session for the client
- * - connect to an existing session zip
- * 1. reads session urn file
- * 2. waits for lock
- * 3. examines session - decide whether to create new application data slice or connect to one stored in session.
- * 4. writes info into session file
- * 5. releases lock and generates local client events.
- * 6. Creates Watcher thread to generate events.
- *
- * During the session
- * - Update watcher checks for file change -
- *
- */
- private File vamsasJar;
- private Lock newVamsasJarLock;
- private File newVamsasJar; // file which client application is writing to.
- private File lockfile;
- private Lock lock;
- private File newSessionDir; // where new sessions (or copies of existing sessions) can be safely created
- private long timeout=1000; // time in milliseconds before we give up getting a lock
- private long interval=100; // time between attempts to lock
- private PrintWriter vamsasWriterStream; // non null if there is a write to a new Document in progress.
+public class VamsasFile extends SessionFile {
/**
*
* Connect to an existing Vamsas document in a given sessionDir
* @param sessionDir
* @throws java.io.IOException
*/
- public VamsasFile(File sessionDir) throws java.io.IOException {
- // check if directory exists. if not, create it.
- // check if vamsas jar exists, if not, create it.
+ public VamsasFile(File sessionFile) throws java.io.IOException {
}
/**
public java.io.Reader getDocumentReader() {
try {
- JarFile session = new JarFile(vamsasJar);
- JarEntry vamsasDocument = session.getJarEntry("vamsasDocument.xml");
- return new InputStreamReader(session.getInputStream(vamsasDocument));
+ JarFile session = new JarFile("vamsasJar");
+ //JarEntry vamsasDocument = session.getJarEntry("vamsasDocument.xml");
+ //return new InputStreamReader(session.getInputStream(vamsasDocument));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
package org.vamsas.client.simpleclient;
import java.io.File;
+/**
+ *
+ * Vamsas client is intialised with a path to create live session directories.
+ * This path may contain a vamsas.properties file
+ * that sets additional parameters (otherwise client
+ * just uses the one on the classpath).
+ *
+ * A vamsas session consists of :
+ * SessionDir - translates to urn of a live session.
+ * Contains: Vamsas Document (as a jar), Session client list file,
+ * both of which may be locked, and additional
+ * temporary versions of these files when write
+ * operations are taking place.
+ *
+ * Zip file entries
+ * - vamsasdocument.xml : core info
+ * one or more:
+ * - <applicationname>.version.sessionnumber.raw (string given in vamsasdocument.xml applicationData entry)
+ *
+ * Lockfile
+ * - filename given in the vamsasdocument.xml. Should be checked for validity by any client and rewritten if necessary.
+ * The lockfile can point to the jar itself.
+ * Mode of operation.
+ * Initially - documentHandler either:
+ * - creates a zip for a new session for the client
+ * - connect to an existing session zip
+ * 1. reads session urn file
+ * 2. waits for lock
+ * 3. examines session - decide whether to create new application data slice or connect to one stored in session.
+ * 4. writes info into session file
+ * 5. releases lock and generates local client events.
+ * 6. Creates Watcher thread to generate events.
+ *
+ * During the session
+ * - Update watcher checks for file change -
+ *
+ */
public class VamsasSession {
/**