49f949c630e7f4e887cb0dc3defc7625e39d0de1
[vamsas.git] / src / uk / ac / vamsas / client / ClientDocument.java
1 /*
2  *
3  */
4 package uk.ac.vamsas.client;
5
6 import java.util.Hashtable;
7
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10
11 import uk.ac.vamsas.objects.core.VAMSAS;
12
13 /**
14  * skeleton abstract class to allow client implementations 
15  * access to vamsas.client.Vobject registry mechanism.
16  */
17 public abstract class ClientDocument implements IClientDocument {
18   static Log log = LogFactory.getLog(ClientDocument.class);
19   
20   /**
21    * collection of uk.ac.vamsas.client.Vobject references
22    */
23   protected Hashtable vamsasObjects;
24   protected IVorbaIdFactory vorbafactory;
25   
26   protected ClientDocument(Hashtable objects, IVorbaIdFactory factory) {
27     vamsasObjects = objects;
28     vorbafactory = factory;
29   }
30   
31   /**
32    * @see IClientHandle.registerObject(Vobject unregistered)
33    */
34   protected VorbaId _registerObject(Vobject unregistered) {
35     // be ultra safe here because the user may be trying to mix different factories
36     if (unregistered.__vorba==null)
37         unregistered.__vorba = vorbafactory;
38     else
39       if (unregistered.__vorba!=vorbafactory) {
40         // LATER: decide if this is allowed - it isn't for the moment.
41         log.error("Attempt to overwrite info in a registered vorba Vobject (under a different IVorbaIdFactory) ! - Implementation fix needed.");
42         return null;
43       } else {
44         // probably didn't need to call registerObject.
45         log.debug("Redundant call to registerObject");
46       }
47     // TODO: add default provenance.
48     // TODO: decide if we need to do call __ensure_instance_ids here
49     // TODO: check if __ensure_instance_ids works correctly with new 'visit flag' mechanism
50     unregistered.__ensure_instance_ids(); // call cascade method here : 
51     return unregistered.getVorbaId();
52   }
53 }