/** * <code>receivedPacket</code> of PacketListener handler, this filters for jabber:iq:auth * extensions, then broadcasts those events on a special RosterListener interface. * * @param p incoming <code>PacketEvent</code> */ public void receivedPacket(PacketEvent p) { if (!(p.getPacket() instanceof InfoQuery)) return; Enumeration e = ((InfoQuery) p.getPacket()).Extensions(); Extension ext; if ((e == null) || (!e.hasMoreElements())) return; ext = (Extension) e.nextElement(); if (!(ext instanceof Roster)) return; // TODO: add code to modify current roster image based on // new data. Replacement is basically shown by if the type is not // 'result' of the IQ Roster rext = (Roster) ext; if (((InfoQuery) p.getPacket()).getType().equals("result")) { // the results of a get will be the results of a full fetch Enumeration enumx = rext.items(); currentRoster.clear(); while (enumx.hasMoreElements()) { RosterItem ri = (RosterItem) enumx.nextElement(); currentRoster.put(ri.getJID(), ri); } fireUserRosterReplaced(rext); } else { Enumeration enumx = rext.items(); while (enumx.hasMoreElements()) { RosterItem ri = (RosterItem) enumx.nextElement(); currentRoster.put(ri.getJID(), ri); } fireUserRosterChanged(rext); } }
// ------------------------------------------------------------------------ // *****---Packet Recieved event handler---******// // this function will be called by the thread running the packetReciever // everytime a new packet is recieved // make sure it is synchronized if it modifies any of your data public synchronized void PacketReceived(PacketEvent e) { // this function defines what you do when a new packet is heard by the system (recall that the // parent class (PacketAnalyzer) already registered you to listen for new packets automatically) // if this is a long function, you should call it in a seperate thread to allow the // PacketReciever thread to continue recieving packets Packet packet = e.GetPacket(); Vector node_list = packet.CreateRoutePathArray(); for (int i = 0; i < node_list.size() - 1; i++) { Integer currentNodeNumber = (Integer) node_list.elementAt(i); NodeInfo currentNodeInfo; if ((currentNodeInfo = (NodeInfo) proprietaryNodeInfo.get(currentNodeNumber)) != null) { currentNodeInfo.SetValue(packet.getValue()); } } }