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) {
68 System.err.println("SourceGeneration of "+this.getClass().toString()
69 +"\n has resulted in an inaccessible 'id' field!\nCannot set ID from the vorbaId object.")
70 e.printStackTrace(System.err);
72 catch (SecurityException e) {
73 e.printStackTrace(System.err);
74 } catch (NoSuchFieldException e) {
75 this.setRegisterable(false);
78 System.err.println("Client error. Trying to setInstanceIdField on a "
79 +this.getClass().toString()+" (which cannot be given a vorbaId)");
83 * calculate a hash for the object with all housekeeping fields at standard
84 * values. (isRegisterable is an immutable attribute property)
86 synchronized protected void doHash() {
88 VorbaId thisid = vorbaId;
89 IVorbaIdFactory factory = __vorba;
90 boolean stored = __stored_in_document;
93 __last_hash = this.hashCode();
96 __stored_in_document = stored;
101 * @return true if object is registered
103 public boolean isRegistered() {
104 return (registerable) ? (vorbaId != null) : false;
108 * Method to get fixed reference for the object in the vamsas document.
110 * @returns null if object is neither registered or not associated with a
111 * properly instantiated VorbaIdFactory.
113 public VorbaId getVorbaId() {
114 if (registerable && vorbaId == null) {
115 // Try to use the associated factory.
117 if ((vorbaId = __vorba.makeVorbaId()) == null)
118 return null; // Factory not valid.
120 this.setInstanceIdField();
128 * used by the IClient implementation to generate unique Id based on client
129 * applications current namespace.
131 protected void setVorbaId(VorbaId newid) {
136 * @return true if object is present in Vamsas Document.
138 public boolean is__stored_in_document() {
139 return __stored_in_document;
143 * for use by Vorba agent to reflect state of vamsas object to client
146 * @param __stored_in_document
147 * The __stored_in_document to set.
149 protected void set__stored_in_document(boolean __stored_in_document) {
150 this.__stored_in_document = __stored_in_document;
154 * __last_hash is the hash value computed when the object was last checked
155 * against a IClientDocument generated by the object's parent IClient
158 * @return Returns the __last_hash.
160 public long get__last_hash() {
165 * @return Returns the registerable.
167 public boolean isRegisterable() {
172 * Called during unmarshalling - if object has an id string, it is
175 * @param registerable
176 * The registerable to set.
178 protected void setRegisterable(boolean registerable) {
179 this.registerable = registerable;