Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/alicebot/server/core/targeting/TargetsReader.java


1   // Decompiled by Jad v1.5.8c. Copyright 2001 Pavel Kouznetsov.
2   // Jad home page: http://www.geocities.com/kpdus/jad.html
3   // Decompiler options: packimports(3) 
4   
5   package org.alicebot.server.core.targeting;
6   
7   import java.awt.Component;
8   import java.io.BufferedReader;
9   import java.lang.reflect.Field;
10  import javax.swing.ProgressMonitor;
11  import org.alicebot.server.core.parser.GenericReader;
12  import org.alicebot.server.core.util.DeveloperError;
13  
14  // Referenced classes of package org.alicebot.server.core.targeting:
15  //            TargetsReaderListener
16  
17  public class TargetsReader extends GenericReader
18      implements Runnable
19  {
20  
21      public TargetsReader(String s, BufferedReader bufferedreader, TargetsReaderListener targetsreaderlistener, String s1, long l, Component component)
22      {
23          super(s, bufferedreader, s1, true, targetsreaderlistener);
24          matchPattern = "*";
25          matchThat = "*";
26          matchTopic = "*";
27          matchTemplate = "";
28          inputText = "";
29          inputThat = "";
30          inputTopic = "";
31          reply = "";
32          progress = 0.0D;
33          super.readerInstance = this;
34          state = 1;
35          monitor = new ProgressMonitor(component, "Reading targets from \"" + s + "\"", null, 0, 100);
36          monitor.setProgress(0);
37          monitor.setMillisToPopup(0);
38          progressScaleFactor = 100D / (double)l;
39      }
40  
41      public void run()
42      {
43          super.read();
44      }
45  
46      protected void initialize()
47      {
48          try
49          {
50              patternField = getClass().getDeclaredField("inputText");
51              thatField = getClass().getDeclaredField("inputThat");
52              topicField = getClass().getDeclaredField("inputTopic");
53              templateField = getClass().getDeclaredField("reply");
54          }
55          catch(NoSuchFieldException nosuchfieldexception)
56          {
57              throw new DeveloperError("The developer has specified a field that does not exist in TargetsReader.");
58          }
59          catch(SecurityException securityexception)
60          {
61              throw new DeveloperError("Security manager prevents TargetsReader from functioning.");
62          }
63      }
64  
65      protected void tryStates()
66          throws org.alicebot.server.core.parser.GenericReader.TransitionMade
67      {
68          if(monitor != null)
69          {
70              if(monitor.isCanceled())
71              {
72                  monitor.close();
73                  done = true;
74                  return;
75              }
76              monitor.setProgress((int)((double)byteCount * progressScaleFactor));
77          }
78          switch(state)
79          {
80          case 1: // '\001'
81              transition("<targets>", 2);
82              break;
83  
84          case 2: // '\002'
85              transition("<target>", 4);
86              break;
87  
88          case 4: // '\004'
89              transition("<input>", 6, 0);
90              transition("<match>", 10, 1);
91              transition("<reply>", 20, 2);
92              transition("</target>", 5, 3);
93              break;
94  
95          case 6: // '\006'
96              transition("<text>", 8);
97              break;
98  
99          case 8: // '\b'
100             transition("</text>", 9, patternField);
101             break;
102 
103         case 10: // '\n'
104             transition("<pattern>", 12);
105             break;
106 
107         case 12: // '\f'
108             transition("</pattern>", 13, patternField);
109             break;
110 
111         case 9: // '\t'
112         case 13: // '\r'
113             transition("<that>", 14);
114             break;
115 
116         case 14: // '\016'
117             transition("</that>", 15, thatField);
118             break;
119 
120         case 15: // '\017'
121             transition("<topic>", 16);
122             break;
123 
124         case 16: // '\020'
125             transition("</topic>", 17, topicField);
126             break;
127 
128         case 17: // '\021'
129             transition("</input>", 4);
130             transition("<template>", 18);
131             break;
132 
133         case 18: // '\022'
134             transition("</template>", 19, templateField);
135             break;
136 
137         case 19: // '\023'
138             transition("</match>", 4);
139             break;
140 
141         case 20: // '\024'
142             transition("</reply>", 4, templateField);
143             break;
144 
145         case 5: // '\005'
146             transition("<target>", 4);
147             transition("</targets>", 4);
148             break;
149         }
150     }
151 
152     private void transition(String s, int i, int j)
153         throws org.alicebot.server.core.parser.GenericReader.TransitionMade
154     {
155         if(succeed(s, i))
156         {
157             switch(j)
158             {
159             default:
160                 break;
161 
162             case 3: // '\003'
163                 ((TargetsReaderListener)super.listener).loadTarget(matchPattern, matchThat, matchTopic, matchTemplate, inputText, inputThat, inputTopic, reply);
164                 matchPattern = matchThat = matchTopic = "*";
165                 inputText = inputThat = inputTopic = matchTemplate = reply = "";
166                 buffer = new StringBuffer(Math.max(GenericReader.bufferStartCapacity, buffer.length()));
167                 buffer.append(bufferString);
168                 searchStart = 0;
169                 break;
170 
171             case 4: // '\004'
172                 done = true;
173                 break;
174 
175             case 0: // '\0'
176                 try
177                 {
178                     patternField = getClass().getDeclaredField("inputText");
179                     thatField = getClass().getDeclaredField("inputThat");
180                     topicField = getClass().getDeclaredField("inputTopic");
181                     templateField = null;
182                 }
183                 catch(NoSuchFieldException nosuchfieldexception)
184                 {
185                     throw new DeveloperError("The developer has specified a field that does not exist in TargetsReader.");
186                 }
187                 catch(SecurityException securityexception)
188                 {
189                     throw new DeveloperError("Security manager prevents TargetsReader from functioning.");
190                 }
191                 break;
192 
193             case 1: // '\001'
194                 try
195                 {
196                     patternField = getClass().getDeclaredField("matchPattern");
197                     thatField = getClass().getDeclaredField("matchThat");
198                     topicField = getClass().getDeclaredField("matchTopic");
199                     templateField = getClass().getDeclaredField("matchTemplate");
200                 }
201                 catch(NoSuchFieldException nosuchfieldexception1)
202                 {
203                     throw new DeveloperError("The developer has specified a field that does not exist in TargetsReader.");
204                 }
205                 catch(SecurityException securityexception1)
206                 {
207                     throw new DeveloperError("Security manager prevents TargetsReader from functioning.");
208                 }
209                 break;
210 
211             case 2: // '\002'
212                 try
213                 {
214                     patternField = null;
215                     thatField = null;
216                     topicField = null;
217                     templateField = getClass().getDeclaredField("reply");
218                 }
219                 catch(NoSuchFieldException nosuchfieldexception2)
220                 {
221                     throw new DeveloperError("The developer has specified a field that does not exist in TargetsReader.");
222                 }
223                 catch(SecurityException securityexception2)
224                 {
225                     throw new DeveloperError("Security manager prevents TargetsReader from functioning.");
226                 }
227                 break;
228             }
229             throw super.TRANSITION_MADE;
230         } else
231         {
232             return;
233         }
234     }
235 
236     public void closeMonitor()
237     {
238         if(monitor != null)
239             monitor.close();
240     }
241 
242     private static final String INPUT_TEXT = "inputText";
243     private static final String INPUT_THAT = "inputThat";
244     private static final String INPUT_TOPIC = "inputTopic";
245     private static final String MATCH_PATTERN = "matchPattern";
246     private static final String MATCH_THAT = "matchThat";
247     private static final String MATCH_TOPIC = "matchTopic";
248     private static final String MATCH_TEMPLATE = "matchTemplate";
249     private static final String REPLY = "reply";
250     private final int S_NONE = 1;
251     private final int S_IN_TARGETS = 2;
252     private final int S_OUT_TARGETS = 3;
253     private final int S_IN_TARGET = 4;
254     private final int S_OUT_TARGET = 5;
255     private final int S_IN_INPUT = 6;
256     private final int S_OUT_INPUT = 7;
257     private final int S_IN_TEXT = 8;
258     private final int S_OUT_TEXT = 9;
259     private final int S_IN_MATCH = 10;
260     private final int S_OUT_MATCH = 11;
261     private final int S_IN_PATTERN = 12;
262     private final int S_OUT_PATTERN = 13;
263     private final int S_IN_THAT = 14;
264     private final int S_OUT_THAT = 15;
265     private final int S_IN_TOPIC = 16;
266     private final int S_OUT_TOPIC = 17;
267     private final int S_IN_TEMPLATE = 18;
268     private final int S_OUT_TEMPLATE = 19;
269     private final int S_IN_REPLY = 20;
270     private final int S_OUT_REPLY = 21;
271     private final int SET_INPUT_CONTEXT = 0;
272     private final int SET_MATCH_CONTEXT = 1;
273     private final int SET_REPLY_CONTEXT = 2;
274     private final int DELIVER_TARGET = 3;
275     private final int SET_DONE = 4;
276     private final int ABORT = 5;
277     public String matchPattern;
278     public String matchThat;
279     public String matchTopic;
280     public String matchTemplate;
281     public String inputText;
282     public String inputThat;
283     public String inputTopic;
284     public String reply;
285     public Field patternField;
286     public Field thatField;
287     public Field topicField;
288     public Field templateField;
289     private ProgressMonitor monitor;
290     private double progress;
291     private double progressScaleFactor;
292 }