* @author jimp Contains a collection of vamsas objects and reference to a
* specified ClientHandle's information.
*/
-public class ClientDocument implements IClientDocument {
+public class ClientDocument extends org.vamsas.client.ClientDocument implements IClientDocument {
protected IClient vorba;
protected org.vamsas.objects.core.VAMSAS[] roots;
protected byte[] appData;
-
- /**
- * collection of org.vamsas.client.object references
- */
- protected Hashtable vamsasObjects;
-
+ protected VamsasArchive archive = null;
/*
* (non-Javadoc)
*
*/
/**
- *
- * @param data
- * @param doc
- * @param objects
- * @param vorba
*/
- protected ClientDocument(byte[] data, VAMSAS[] roots, Hashtable objects, IClient vorba) {
- // TODO Auto-generated constructor stub
- appData = data;
- this.roots =roots;
- vamsasObjects = objects;
+ protected ClientDocument(VamsasArchive document, IdFactory Factory, IClient vorba) {
+ super(Factory.getVorbaIdHash(), Factory);
this.vorba = vorba;
+ archive = document;
+ roots = null;
}
public byte[] getApplicationData() {
/*
* (non-Javadoc)
*
- * @see org.vamsas.client.IClientDocument#registerObject(org.vamsas.client.object)
+ * @see org.vamsas.client.IClientDocument#setApplicationData(byte[])
*/
-public VorbaId registerObject(object unregistered) {
- if (!unregistered.isRegistered())
- unregistered.setVorbaId(unregistered.__vorba.makeVorbaId());
- return unregistered.getVorbaId();
+ public void setApplicationData(byte[] newData) {
+ appData = newData;
}
/*
* (non-Javadoc)
return null;
}
- /*
- * (non-Javadoc)
- *
- * @see org.vamsas.client.IClientDocument#setApplicationData(byte[])
+ /* (non-Javadoc)
+ * @see org.vamsas.client.IClientDocument#registerObject(org.vamsas.client.object)
*/
- public void setApplicationData(byte[] newData) {
- appData = newData;
+ public VorbaId registerObject(object unregistered) {
+ // TODO: add provenance stuff to newly registered object
+ return _registerObject(unregistered);
}
}
idstring = client.getClientUrn()+":"+unique.getValue()+"/";
extantids=new Hashtable();
}
-
+ /**
+ * values for keys in this hash can be used to reference the org.vamsas.client.object instance for the VorbaId string.
+ * @return the hash of all VorbaIds
+ */
+ protected Hashtable getVorbaIdHash() {
+ return extantids;
+ }
+
/* (non-Javadoc)
* @see org.vamsas.client.VorbaIdFactory#makeVorbaId()
*/
* @throws IOException if call to accessOriginal failed for updates, or openArchive failed.
*/
public VamsasArchive(File archive, boolean vamsasdocument) throws IOException {
+ this(archive, vamsasdocument, null);
+ }
+ public VamsasArchive(File archive, boolean vamsasdocument, Lock extantLock) throws IOException {
super();
+
if (archive==null || (archive!=null && !(archive.getParentFile().canWrite() && (!archive.exists() || archive.canWrite())))) {
log.fatal("Expect Badness! -- Invalid parameters for VamsasArchive constructor:"+((archive!=null)
? "File cannot be overwritten." : "Null Object not valid constructor parameter"));
this.vamsasdocument = vamsasdocument;
if (archive.exists()) {
this.original = archive;
+ this.odoclock = new SessionFile(archive); // lock the file *immediatly*
+ odoclock.lockFile(extantLock);
this.archive = null; // archive will be a temp file when the open method is called
virginArchive=false;
try {
} else {
this.original = null;
this.archive = archive; // archive is written in place.
+ if (archive!=null) {
+ archive.createNewFile();
+ rchive=new SessionFile(archive); // lock the file *immediatly*
+ rchive.lockFile(extantLock);
+ }
virginArchive = true;
}
this.openArchive(); // open archive
* opens the new archive ready for writing. If the new archive is replacing an existing one,
* then the existing archive will be locked, and the new archive written to a temporary file.
* The new archive will be put in place once close() is called.
+ * @param doclock TODO
* @throws IOException
*/
private void openArchive() throws IOException {
log.warn("New archive file name already in use! Possible lock failure imminent?");
}
- rchive = new SessionFile(archive);
- rchive.lockFile();
+ if (rchive==null)
+ rchive = new SessionFile(archive);
+ archive.createNewFile();
+ if (!rchive.lockFile())
+ throw new IOException("Failed to get lock on file "+archive);
+
newarchive = new JarOutputStream(new BufferedOutputStream(new java.io.FileOutputStream(archive)));
entries = new Hashtable();
}
*/
public AppDataOutputStream getAppDataStream(String appdataReference) throws IOException {
if (newarchive==null)
- openArchive();
+ throw new IOException("Attempt to write to closed VamsasArchive object.");
if (addValidEntry(appdataReference)) {
return new AppDataOutputStream(newarchive);
}
private void closeAndReset() {
if (rchive!=null) {
rchive.unlockFile();
- rchive = null;
+ rchive=null;
}
if (original!=null) {
if (odoc!=null) {
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.RandomAccessFile;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Vector;
public class VamsasArchiveReader {
private static Log log = LogFactory.getLog(VamsasArchiveReader.class);
JarFile jfile;
+ boolean stream=false; // true if we are seeking on the stream.
+ RandomAccessFile rfile;
+ JarInputStream jstream;
public VamsasArchiveReader(File vamsasfile) {
jfile=null;
if (vamsasfile.exists()) {
}
/**
+ * in an ideal world - this constructor will create a reader object
+ * for the locked file's random access stream.
+ *
+ * @param vamsaslock
+ */
+ public VamsasArchiveReader(Lock vamsaslock) {
+ rfile = vamsaslock.rafile;
+ stream = true;
+ // TODO: Implement stream based JarFile access
+ log.error("NOT IMPLEMENTED STREAM-BASED JAR ACCESS");
+ throw new Error("Can't access a locked VamsasArchive file as a random access stream yet.");
+ // rfile.seek(0);
+
+ }
+ /**
* the vamsas document version(s) handled by this Reader
*/
final public static String DOCUMENT_VERSION="0.1";
* gets a locked Reader for the vamsas document.
* @return reader for vamsasdocument.xml enrty
*/
+ public Lock getLock() {
+ while (!lockFile())
+ ;
+ return fileLock;
+ }
+
public java.io.Reader getDocumentReader() {
try {