1 11 12 package org.jivesoftware.messenger; 13 14 import org.xmpp.packet.Packet; 15 import org.xmpp.packet.Message; 16 import org.xmpp.packet.Presence; 17 import org.xmpp.packet.IQ; 18 import org.jivesoftware.messenger.container.BasicModule; 19 20 27 public class PacketRouter extends BasicModule { 28 29 private IQRouter iqRouter; 30 private PresenceRouter presenceRouter; 31 private MessageRouter messageRouter; 32 33 36 public PacketRouter() { 37 super("XMPP Packet Router"); 38 } 39 40 49 public void route(Packet packet) { 50 if (packet instanceof Message) { 51 route((Message)packet); 52 } 53 else if (packet instanceof Presence) { 54 route((Presence)packet); 55 } 56 else if (packet instanceof IQ) { 57 route((IQ)packet); 58 } 59 else { 60 throw new IllegalArgumentException (); 61 } 62 } 63 64 public void route(IQ packet) { 65 iqRouter.route(packet); 66 } 67 68 public void route(Message packet) { 69 messageRouter.route(packet); 70 } 71 72 public void route(Presence packet) { 73 presenceRouter.route(packet); 74 } 75 76 public void initialize(XMPPServer server) { 77 super.initialize(server); 78 iqRouter = server.getIQRouter(); 79 messageRouter = server.getMessageRouter(); 80 presenceRouter = server.getPresenceRouter(); 81 } 82 } | Popular Tags |