4 package org.vamsas.client;
7 * Base class for all Vamsas objects extracted from an IClientDocument. An
8 * object maybe registered or unregistered.
13 public abstract class object {
16 * unique id for all vamsas objects allows unambiguous referencing to any
17 * object in the vamsas document
19 protected boolean __stored_in_document = false;
21 protected long __last_hash = 0;
23 protected boolean registerable = false;
25 protected VorbaId vorbaId = null;
27 protected IVorbaIdFactory __vorba = null;
34 testInstanceForIdField();
38 * set the isRegisterable flag based on the presence of a 'String id' field in
39 * the reflected class instance.
41 private void testInstanceForIdField() {
42 // look for the id field (should be an NCName string)
43 // TODO: decide if 'id' is an appropriate reserved attribute name for the
46 java.lang.reflect.Field fd = this.getClass().getField("id");
47 if (fd.getType().getClass().equals("astring".getClass())) {
48 this.setRegisterable(true);
50 } catch (SecurityException e) {
52 } catch (NoSuchFieldException e) {
53 this.setRegisterable(false);
58 * update the object instance's String id field, based on the contents of the
59 * VorbaId. Only call this if you mean to do it!
61 protected void setInstanceIdField() {
65 java.lang.reflect.Field fd = this.getClass().getField("id");
66 fd.set((Object) this, (Object) new String(vorbaId.id));
67 } catch (IllegalAccessException e) {
69 .println("SourceGeneration of "
70 + this.getClass().toString()
71 + "\n has resulted in an inaccessible 'id' field!\nCannot set ID from the vorbaId object.");
72 e.printStackTrace(System.err);
73 } catch (SecurityException e) {
74 e.printStackTrace(System.err);
75 } catch (NoSuchFieldException e) {
76 this.setRegisterable(false);
79 System.err.println("Client error. Trying to setInstanceIdField on a "
80 + this.getClass().toString() + " (which cannot be given a vorbaId)");
85 * calculate a hash for the object with all housekeeping fields at standard
86 * values. (isRegisterable is an immutable attribute property)
88 synchronized protected void doHash() {
90 VorbaId thisid = vorbaId;
91 IVorbaIdFactory factory = __vorba;
92 boolean stored = __stored_in_document;
95 __last_hash = this.hashCode();
98 __stored_in_document = stored;
102 * TODO: combine two versions of the same collection object to resolve
103 * asynchronous updates to the same vamsas object Merges two vamsas objects,
104 * one of which is a later version of the earlier (ie they have the same
105 * vorbaId but one is a later version recently read from the vamsasDocument
110 protected boolean merge(object laterCopy) {
116 * @return true if object is registered
118 public boolean isRegistered() {
119 return (registerable) ? (vorbaId != null) : false;
123 * Method to get fixed reference for the object in the vamsas document.
125 * @returns null if object is neither registered or not associated with a
126 * properly instantiated VorbaIdFactory.
128 public VorbaId getVorbaId() {
129 if (registerable && vorbaId == null) {
130 // Try to use the associated factory.
132 if ((vorbaId = __vorba.makeVorbaId()) == null)
133 return null; // Factory not valid.
135 this.setInstanceIdField();
143 * used by the IClient implementation to generate unique Id based on client
144 * applications current namespace.
146 protected void setVorbaId(VorbaId newid) {
151 * @return true if object is present in Vamsas Document.
153 public boolean is__stored_in_document() {
154 return __stored_in_document;
158 * for use by Vorba agent to reflect state of vamsas object to client
161 * @param __stored_in_document
162 * The __stored_in_document to set.
164 protected void set__stored_in_document(boolean __stored_in_document) {
165 this.__stored_in_document = __stored_in_document;
169 * __last_hash is the hash value computed when the object was last checked
170 * against a IClientDocument generated by the object's parent IClient
173 * @return Returns the __last_hash.
175 public long get__last_hash() {
180 * @return Returns the registerable.
182 public boolean isRegisterable() {
187 * Called during unmarshalling - if object has an id string, it is
190 * @param registerable
191 * The registerable to set.
193 protected void setRegisterable(boolean registerable) {
194 this.registerable = registerable;