Last commit for vem/VemNotif.java: fdb247f0b552329755d4eaab9cfa9203340eccfa

Fixed some bugs in Shen's code. Added a few more rooms to chime client. Fixed some bugs in VEM. Need

daa82 [2001-06-02 20:32:48]
Fixed some bugs in Shen's code. Added a few more rooms to chime client. Fixed some bugs in VEM. Need
to change objects associated with file types.
  1. package psl.chime.vem;
  2.  
  3. import java.lang.*;
  4. import java.util.*;
  5. import java.io.*;
  6. import siena.*;
  7.  
  8. // Part of VEM client on the Data Server Side
  9. // Used to parse the recieved events from the
  10. // siena server and then take the appropriate action
  11. public class VemNotif implements Notifiable
  12. {
  13. public static VemNode Default [];
  14. VemUtil util;
  15. public Siena siena;
  16. private static VemNotif myself;
  17.  
  18. //create the Vem Notification buffer
  19. public static synchronized VemNotif getInstance() {
  20. if (myself == null)
  21. myself = new VemNotif();
  22. return myself;
  23. }
  24.  
  25.  
  26. //create the Vem Notification buffer from Christian's Subscriber
  27. public static synchronized VemNotif getInstance(Siena s) {
  28. if (myself == null)
  29. myself = new VemNotif();
  30.  
  31. myself.setSiena(s);
  32. return myself;
  33. }
  34.  
  35. //create a VEM object - the Singleton object we're going to keep around
  36. private VemNotif()
  37. {
  38. util = new VemUtil ();
  39. Default = util.GetDefault ();
  40. myself = this;
  41. }
  42.  
  43.  
  44. //set the siena of this notification
  45. private void setSiena(Siena s) {
  46. siena = s;
  47. }
  48.  
  49. //get the shape associated with some object
  50. //otherwise you will get null
  51. public VemObject getShape(String protocol, String url) {
  52. for (int i = 0; i < Default.length; i++) {
  53. if (url.indexOf(Default[i].file) != -1) {
  54. VemObject obj = new VemObject();
  55. obj.setUrl(url);
  56. obj.setProtocol(protocol);
  57. obj.setShape(Default[i].object);
  58. obj.setShape2D(Default[i].object);
  59. obj.setClasstype(Default[i].type);
  60. obj.setSubclass(Default[i].sub);
  61. return obj;
  62. }
  63. }
  64.  
  65.  
  66. //return null; this doesn't seem to be adequate according to Shen's standard so I am making a default
  67. //first object in the list as the default
  68. VemObject obj = new VemObject();
  69. obj.setUrl(url);
  70. System.err.println("&&&&&&&&&&DEFAULT[0] is: " + Default[0].object);
  71. obj.setProtocol(protocol);
  72. obj.setShape(Default[0].object);
  73. obj.setShape2D(Default[0].object);
  74. obj.setClasstype(Default[0].type);
  75. obj.setSubclass(Default[0].sub);
  76. return obj;
  77. }
  78.  
  79.  
  80. //get the shape description associated with this object url
  81. public VemObject getLinkShape(String roomUrl, String objUrl) {
  82. for (int i = 0; i < Default.length; i++) {
  83. if (objUrl.indexOf(Default[i].file) != -1) {
  84. VemObject obj = new VemObject();
  85. obj.setRoomUrl(roomUrl);
  86. obj.setObjUrl(objUrl);
  87. obj.setShape(Default[i].object);
  88. obj.setShape2D(Default[i].object);
  89. obj.setClasstype(Default[i].type);
  90. obj.setSubclass(Default[i].sub);
  91. return obj;
  92. }
  93. }
  94.  
  95. //return null; this doesn't seem to be adequate according to Shen's standard so I am making a default
  96. //first object in the list is the default
  97. VemObject obj = new VemObject();
  98. obj.setRoomUrl(roomUrl);
  99. obj.setObjUrl(objUrl);
  100. obj.setUrl(objUrl);
  101. obj.setShape(Default[0].object);
  102. obj.setShape2D(Default[0].object);
  103. obj.setClasstype(Default[0].type);
  104. obj.setSubclass(Default[0].sub);
  105. return obj;
  106. }
  107.  
  108.  
  109.  
  110. // Recieves the incoming events from the client
  111. public void notify (Notification e)
  112. {
  113. String n, file = "", type = "", sub = "", object = "";
  114.  
  115. n = e.toString ();
  116.  
  117. n = n.replace ('=', ' ');
  118. n = n.replace ('"', ' ');
  119. n = n.replace ('{', ' ');
  120. n = n.replace ('}', ' ');
  121. n = n.replace (':', ' ');
  122.  
  123. t = new StringTokenizer (n, " \n\t\r");
  124.  
  125. if (t.countTokens () != 11)
  126. System.out.println ("Incorrect Number of Event Type");
  127. else
  128. {
  129. // Parse out the four necessary parameters
  130. t.nextToken ();
  131. t.nextToken ();
  132. t.nextToken ();
  133. t.nextToken ();
  134. file = t.nextToken ();
  135. t.nextToken ();
  136. object = t.nextToken ();
  137. t.nextToken ();
  138. sub = t.nextToken ();
  139. t.nextToken ();
  140. type = t.nextToken ();
  141.  
  142. if (UpdateNode (file, type, sub, object))
  143. System.out.println ("Update Made"); // Call data server method and pass along new parameters
  144. else
  145. System.out.println ("Update Not Made"); // Do nothing
  146. }
  147. }
  148.  
  149. // Used when more than one Notification is recieved
  150. public void notify (Notification [] s)
  151. {
  152. for (int i = 0; i < s.length; i++)
  153. notify (s [i]);
  154. }
  155.  
  156. // Updates the Default table when an event is recieved from the client
  157. // Checks if the recieved info is different from the existing settings
  158. // Returns true if a change was made and false if no change was made
  159. public static boolean UpdateNode (String file, String type, String sub, String object)
  160. {
  161. boolean flag = false;
  162. int i;
  163.  
  164. for (i = 0; i < Default.length; i++)
  165. {
  166. // First the file is found
  167. // Works for both *.any and for file.any
  168. if (Default [i].file.indexOf (file) != -1) // First the file is found
  169. {
  170. if (Default [i].type.compareTo (type) != 0) // If type does not match then update
  171. {
  172. Default [i].type = type;
  173. flag = true;
  174. }
  175.  
  176. if (Default [i].sub.compareTo (sub) != 0) // If sub-type does not match then update
  177. {
  178. Default [i].sub = sub;
  179. flag = true;
  180. }
  181.  
  182. if (Default [i].object.compareTo (object) != 0) // If object does not match then update
  183. {
  184. Default [i].object = object;
  185. flag = true;
  186. }
  187. }
  188. }
  189.  
  190. return flag;
  191. }
  192.  
  193. }