From: jprocter Date: Fri, 11 Nov 2005 18:05:29 +0000 (+0000) Subject: access for vamsas.xml style vamsas archive X-Git-Tag: Release_0.2~429 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=fe819ce06899d32e1ad64ea6e4d3f9c51b7c15ff;p=vamsas.git access for vamsas.xml style vamsas archive git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@91 be28352e-c001-0410-b1a7-c7978e42abec --- diff --git a/src/org/vamsas/client/simpleclient/VamsasArchiveReader.java b/src/org/vamsas/client/simpleclient/VamsasArchiveReader.java index 3ca1288..e04e7c9 100644 --- a/src/org/vamsas/client/simpleclient/VamsasArchiveReader.java +++ b/src/org/vamsas/client/simpleclient/VamsasArchiveReader.java @@ -29,7 +29,10 @@ public class VamsasArchiveReader { } } - + /** + * 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 */ @@ -67,11 +70,30 @@ public class VamsasArchiveReader { */ 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 diff --git a/src/org/vamsas/client/simpleclient/VamsasFile.java b/src/org/vamsas/client/simpleclient/VamsasFile.java index 2ac7e5f..1c3a224 100644 --- a/src/org/vamsas/client/simpleclient/VamsasFile.java +++ b/src/org/vamsas/client/simpleclient/VamsasFile.java @@ -23,54 +23,7 @@ import org.vamsas.objects.core.LockFileDescriptor; * @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: - * - .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 @@ -79,9 +32,7 @@ public class VamsasFile { * @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 { } /** @@ -104,9 +55,9 @@ public class VamsasFile { 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(); diff --git a/src/org/vamsas/client/simpleclient/VamsasSession.java b/src/org/vamsas/client/simpleclient/VamsasSession.java index e74c458..ef76d71 100644 --- a/src/org/vamsas/client/simpleclient/VamsasSession.java +++ b/src/org/vamsas/client/simpleclient/VamsasSession.java @@ -1,6 +1,43 @@ 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: + * - .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 { /**