1 2 3 package Jt; 4 import java.util.*; 5 import java.lang.reflect.*; 6 import java.beans.*; 7 import java.io.*; 8 9 12 13 14 public class JtIterator extends JtObject { 15 Iterator iterator; 18 JtCollection col; 19 20 21 public JtIterator() { 22 } 23 24 25 26 29 30 public void setIterator (Iterator iterator) { 31 this.iterator = iterator; } 33 34 35 38 39 public Iterator getIterator () { 40 return (iterator); 41 } 42 43 44 46 private Object next () { 47 if (iterator == null) return (null); 49 if (iterator.hasNext()) { 50 return (iterator.next ()); 51 } 52 53 return (null); 54 } 55 56 62 63 public Object processMessage (Object event) { 64 65 String msgid = null; 66 JtMessage e = (JtMessage) event; 67 Object content; 68 Object data; 69 70 71 if (e == null) 72 return null; 73 74 msgid = (String ) e.getMsgId (); 75 76 if (msgid == null) 77 return null; 78 79 content = e.getMsgContent(); 80 data = e.getMsgData (); 81 82 if (msgid.equals ("JtREMOVE")) { 84 return (null); 85 } 86 87 if (msgid.equals ("JtNEXT")) { 88 return (next ()); 89 } 90 91 return (super.processMessage (event)); 92 93 96 } 97 98 99 102 103 public static void main(String [] args) { 104 105 JtObject main = new JtObject (); 106 JtMessage msg, msg1; 107 Integer count; 108 JtIterator it; 109 Object obj; 110 111 114 115 117 main.createObject ("Jt.JtCollection", "collection"); 118 119 120 msg = (JtMessage) main.createObject ("Jt.JtMessage", "message"); 121 main.setValue (msg, "msgId", "JtADD"); 122 main.setValue (msg, "msgContent", new Integer (1)); 123 124 126 main.sendMessage ("collection", msg); 127 128 130 main.setValue (msg, "msgId", "JtADD"); 131 main.setValue (msg, "msgContent", new Integer (2)); 132 main.sendMessage ("collection", msg); 133 134 it = (JtIterator) main.getValue ("collection", "iterator"); 135 136 137 main.setValue (msg, "msgId", "JtNEXT"); 138 139 while ((obj = main.sendMessage (it, msg)) != null) 140 System.out.println ("Object=" + obj); 141 142 main.removeObject ("collection"); 143 144 145 146 } 147 148 } 149 150 151
| Popular Tags
|