From 8fbb1b0a0bb42d855fdde1f54fc732bb68f12e54 Mon Sep 17 00:00:00 2001 From: jprocter Date: Tue, 24 Jan 2006 16:29:56 +0000 Subject: [PATCH] updated example application to handle IClient.getDocument() exceptions and ensured IVorbaIdFactory actually has object reference for the object it is registering. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@170 be28352e-c001-0410-b1a7-c7978e42abec --- src/org/vamsas/client/IVorbaIdFactory.java | 3 ++- src/org/vamsas/client/VorbaId.java | 10 ++++++++-- src/org/vamsas/client/VorbaIdFactory.java | 2 +- src/org/vamsas/client/object.java | 2 +- src/org/vamsas/client/simpleclient/IdFactory.java | 4 +++- src/org/vamsas/client/simpleclient/VamsasArchive.java | 2 +- src/org/vamsas/test/ExampleApplication.java | 9 ++++++++- 7 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/org/vamsas/client/IVorbaIdFactory.java b/src/org/vamsas/client/IVorbaIdFactory.java index 5463391..03deb58 100644 --- a/src/org/vamsas/client/IVorbaIdFactory.java +++ b/src/org/vamsas/client/IVorbaIdFactory.java @@ -15,11 +15,12 @@ package org.vamsas.client; public interface IVorbaIdFactory { /** * construct a new id appropriate for this client in the vamsas session. + * @param vobject TODO * * @return valid VorbaId for session, or null if VorbaIdFactory not configured * correctly. */ - public abstract VorbaId makeVorbaId(); + public abstract VorbaId makeVorbaId(object vobject); public abstract SessionHandle getSessionHandle(); diff --git a/src/org/vamsas/client/VorbaId.java b/src/org/vamsas/client/VorbaId.java index 84cfb09..a12010f 100644 --- a/src/org/vamsas/client/VorbaId.java +++ b/src/org/vamsas/client/VorbaId.java @@ -25,10 +25,16 @@ public class VorbaId { super(); id = Id; } - protected static VorbaId newId(IVorbaIdFactory vorbaObject) { + /** + * + * @param vorbaObject the source of vorba Ids + * @param vobject the object to be registered with a new vorba id + * @return + */ + protected static VorbaId newId(IVorbaIdFactory vorbaObject, object vobject) { // Make unique id from appSpace info in vorbaObject synchronized (vorbaObject) { - return vorbaObject.makeVorbaId(); + return vorbaObject.makeVorbaId(vobject); } } protected static VorbaId newId(String id) { diff --git a/src/org/vamsas/client/VorbaIdFactory.java b/src/org/vamsas/client/VorbaIdFactory.java index 335c710..5c8b65d 100644 --- a/src/org/vamsas/client/VorbaIdFactory.java +++ b/src/org/vamsas/client/VorbaIdFactory.java @@ -23,7 +23,7 @@ public abstract class VorbaIdFactory implements IVorbaIdFactory { * @return valid VorbaId for session, or null if VorbaIdFactory not configured * correctly. */ - public abstract VorbaId makeVorbaId(); + public abstract VorbaId makeVorbaId(object vobject); /** * internal method to access the protected VorbaId object constructor diff --git a/src/org/vamsas/client/object.java b/src/org/vamsas/client/object.java index b4fb8ef..18054b7 100644 --- a/src/org/vamsas/client/object.java +++ b/src/org/vamsas/client/object.java @@ -163,7 +163,7 @@ public abstract class object { if (registerable && vorbaId == null) { // Try to use the associated factory. if (__vorba != null) - if ((vorbaId = __vorba.makeVorbaId()) == null) + if ((vorbaId = __vorba.makeVorbaId(this)) == null) return null; // Factory not valid. else { this.setInstanceIdField(); diff --git a/src/org/vamsas/client/simpleclient/IdFactory.java b/src/org/vamsas/client/simpleclient/IdFactory.java index 543730e..28834c7 100644 --- a/src/org/vamsas/client/simpleclient/IdFactory.java +++ b/src/org/vamsas/client/simpleclient/IdFactory.java @@ -10,6 +10,7 @@ import org.vamsas.client.SessionHandle; import org.vamsas.client.UserHandle; import org.vamsas.client.VorbaId; import org.vamsas.client.VorbaIdFactory; +import org.vamsas.client.object; import org.vamsas.objects.utils.document.VersionEntries; import java.util.Hashtable; @@ -62,7 +63,7 @@ public class IdFactory extends VorbaIdFactory { /* (non-Javadoc) * @see org.vamsas.client.VorbaIdFactory#makeVorbaId() */ - public VorbaId makeVorbaId() { + public VorbaId makeVorbaId(object vobject) { if (session==null) throw new Error("makeVorbaId called on improperly initialised IdFactory object!"); String newidstring; @@ -75,6 +76,7 @@ public class IdFactory extends VorbaIdFactory { } newidstring=idstring+Integer.toString(sequence); } while (extantids.containsKey(newidstring)); + extantids.put(newidstring, vobject); // hash the object by its new Id VorbaId id = newId(newidstring); return id; } diff --git a/src/org/vamsas/client/simpleclient/VamsasArchive.java b/src/org/vamsas/client/simpleclient/VamsasArchive.java index 7ff24b1..528d517 100644 --- a/src/org/vamsas/client/simpleclient/VamsasArchive.java +++ b/src/org/vamsas/client/simpleclient/VamsasArchive.java @@ -457,7 +457,7 @@ public class VamsasArchive { if (provenance_user==null) provenance_user = "org.vamsas.simpleclient.VamsasArchive"; if (provenance_action == null) - provenance_action="Created new empty document"); + provenance_action="Created new empty document"; if (version==null) version = VersionEntries.latestVersion(); // Create a new document and return it diff --git a/src/org/vamsas/test/ExampleApplication.java b/src/org/vamsas/test/ExampleApplication.java index 520f668..8118295 100644 --- a/src/org/vamsas/test/ExampleApplication.java +++ b/src/org/vamsas/test/ExampleApplication.java @@ -126,7 +126,14 @@ public class ExampleApplication { } // register an update listener and a close listener. // get document data - processVamsasDocument(vorbaclient.getClientDocument()); + try { + IClientDocument cdoc = vorbaclient.getClientDocument(); + processVamsasDocument(cdoc); + } catch (Exception e) { + System.err.println("Unexpected exception when retrieving the client document for the first time!"); + e.printStackTrace(System.err); + System.exit(1); + } // Main application event loop - wait around and do stuff... while (!isShuttingdown) { -- 1.7.10.2