Source code: org/alicebot/server/core/processor/loadtime/ListenerProcessor.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.processor.loadtime;
6
7 import java.lang.reflect.Constructor;
8 import java.lang.reflect.InvocationTargetException;
9 import org.alicebot.server.core.*;
10 import org.alicebot.server.core.logging.Log;
11 import org.alicebot.server.core.parser.StartupFileParser;
12 import org.alicebot.server.core.parser.XMLNode;
13 import org.alicebot.server.core.processor.ProcessorException;
14 import org.alicebot.server.core.util.*;
15 import org.alicebot.server.net.listener.AliceChatListener;
16 import org.alicebot.server.net.listener.AliceChatListenerRegistry;
17
18 // Referenced classes of package org.alicebot.server.core.processor.loadtime:
19 // StartupElementProcessor, InvalidStartupElementException
20
21 public class ListenerProcessor extends StartupElementProcessor
22 {
23
24 public ListenerProcessor()
25 {
26 }
27
28 public String process(int i, XMLNode xmlnode, StartupFileParser startupfileparser)
29 throws InvalidStartupElementException
30 {
31 String s = getHref(xmlnode);
32 if(s.length() > 0)
33 try
34 {
35 return startupfileparser.processResponse(Toolkit.getFileContents(s));
36 }
37 catch(ProcessorException processorexception)
38 {
39 throw new UserError(processorexception);
40 }
41 String s1 = Toolkit.getAttributeValue("type", xmlnode.XMLAttr);
42 if(s1 == null)
43 throw new UserError("You did not specify a type for a listener.");
44 Class class1 = (Class)AliceChatListenerRegistry.getSelf().get(s1);
45 if(class1 == null)
46 throw new UserError("You specified an unknown listener \"" + s1 + "\".");
47 String s2 = Toolkit.getAttributeValue("enabled", xmlnode.XMLAttr);
48 if(s2 == null)
49 throw new UserError("<listener type=\"" + s1 + "\"> is missing an enabled attribute.");
50 if(!s2.equals("true"))
51 return "";
52 Bot bot = startupfileparser.getCurrentBot();
53 AliceChatListener alicechatlistener;
54 try
55 {
56 alicechatlistener = (AliceChatListener)class1.getConstructor(new Class[] {
57 org.alicebot.server.core.Bot.class
58 }).newInstance(new Object[] {
59 bot
60 });
61 }
62 catch(IllegalAccessException illegalaccessexception)
63 {
64 throw new DeveloperError("The constructor for the \"" + s1 + "\" listener class is inaccessible.");
65 }
66 catch(IllegalArgumentException illegalargumentexception)
67 {
68 throw new DeveloperError("The constructor for the \"" + s1 + "\" listener class is incorrectly specifed.");
69 }
70 catch(InstantiationException instantiationexception)
71 {
72 throw new DeveloperError("The \"" + s1 + "\" listener class is abstract.");
73 }
74 catch(NoSuchMethodException nosuchmethodexception)
75 {
76 throw new DeveloperError("The constructor for the \"" + s1 + "\" listener class is incorrectly specifed.");
77 }
78 catch(InvocationTargetException invocationtargetexception)
79 {
80 throw new DeveloperError("The constructor for the \"" + s1 + "\" listener class threw an exception.", invocationtargetexception);
81 }
82 int j = startupfileparser.nodeCount("parameter", xmlnode.XMLChild, true);
83 for(int k = j; k > 0; k--)
84 {
85 XMLNode xmlnode1 = startupfileparser.getNode("parameter", xmlnode.XMLChild, k);
86 if(xmlnode1.XMLType == 1)
87 {
88 String s3 = Toolkit.getAttributeValue("name", xmlnode1.XMLAttr);
89 String s4 = Toolkit.getAttributeValue("value", xmlnode1.XMLAttr);
90 if(s3 != null && s4 != null)
91 alicechatlistener.setParameter(s3, s4);
92 } else
93 {
94 throw new InvalidStartupElementException("<" + xmlnode1.XMLData + "/> cannot have content!");
95 }
96 }
97
98 if(!alicechatlistener.checkParameters())
99 {
100 Log.userinfo("Listener \"" + s1 + "\" is incorrectly configured; will not be started.", Log.STARTUP);
101 return "";
102 }
103 BotProcesses.start(alicechatlistener, s1 + " : " + bot.getID());
104 if(Globals.showConsole())
105 Log.userinfo("Started \"" + s1 + "\" listener for bot \"" + bot.getID() + "\".", Log.STARTUP);
106 return "";
107 }
108
109 public static final String label = "listener";
110 private static final String PARAMETER = "parameter";
111 private static final String TYPE = "type";
112 private static final String ENABLED = "enabled";
113 private static final String NAME = "name";
114 private static final String VALUE = "value";
115 private static final String TRUE = "true";
116 private static final String SEPARATOR = " : ";
117 }