5f495378d959b2dfeb921314e4a19d5315a47650
[vamsas.git] / src / org / vamsas / client / object.java
1 /**
2  * 
3  */
4 package org.vamsas.client;
5 /**
6  * Base class for all Vamsas objects extracted 
7  * from an IClientDocument. 
8  * An object maybe registered or unregistered.
9  * 
10  * @author jimp
11  *
12  */
13 public abstract class object {
14
15     /**
16      * unique id for all vamsas objects
17      * allows unambiguous referencing
18      * to any object in the vamsas document
19      */
20         protected boolean __stored_in_document=false;
21     protected long __last_hash=0;
22     
23     protected VorbaId vorbaId=null;
24     protected IVorbaIdFactory __vorba=null;
25     /**
26      * calculate a hash
27      * for the object with all housekeeping
28      * fields at standard values.
29      */
30     synchronized protected void doHash() {
31       __last_hash = 0;
32       VorbaId thisid = vorbaId;
33       IVorbaIdFactory factory = __vorba;
34       boolean stored = __stored_in_document;
35       vorbaId = null;
36       __vorba = null;
37       __last_hash = this.hashCode();
38       vorbaId = thisid;
39       __vorba = factory;
40       __stored_in_document = stored;
41     }
42     
43     /**
44      * 
45      * @return true if object is registered
46      */
47     public boolean isRegistered() {
48       return (vorbaId!=null);
49     }
50     /**
51      * Method to get fixed reference for
52      * the object in the vamsas document.
53      * @returns null if object is neither registered 
54      * or not associated with a properly instantiated 
55      * VorbaIdFactory.
56      */
57     public VorbaId getVorbaId() {
58       if (vorbaId==null) {
59         // Try to use the associated factory.
60         if (__vorba!=null) 
61           if ((vorbaId = __vorba.makeVorbaId())==null)
62             return null; // Factory not valid.
63         else
64           return null;
65       }
66       return vorbaId;
67     }
68     /**
69      * used by the IClient implementation
70      * to generate unique Id based on
71      * client applications current namespace.
72      */
73     protected void setVorbaId(VorbaId newid) {
74       vorbaId = newid;
75     }
76     
77     /**
78      * @return true if object is present in Vamsas Document.
79      */
80     public boolean is__stored_in_document() {
81       return __stored_in_document;
82     }
83     /**
84      * for use by Vorba agent to reflect state of 
85      * vamsas object to client application.
86      * @param __stored_in_document The __stored_in_document to set.
87      */
88     protected void set__stored_in_document(boolean __stored_in_document) {
89       this.__stored_in_document = __stored_in_document;
90     }
91     /**
92      * __last_hash is the hash value computed 
93      * when the object was last checked against 
94      * a IClientDocument generated by the 
95      * object's parent IClient instance.
96      * @return Returns the __last_hash.
97      */
98     public long get__last_hash() {
99       return __last_hash;
100     }
101 }