/* * This file is part of the Remote Sensor Actuator Interface (ReSAI). * * Copyright(c) Andreas Kipp, Frederic Siepmann * http://opensource.cit-ec.de/projects/resai * * This file may be licensed under the terms of of the * GNU Lesser General Public License Version 3 (the ``LGPL''), * or (at your option) any later version. * * Software distributed under the License is distributed * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either * express or implied. See the LGPL for the specific language * governing rights and limitations. * * You should have received a copy of the LGPL along with this * program. If not, go to http://www.gnu.org/licenses/lgpl.html * or write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * The development of this software was supported by the * Excellence Cluster EXC 277 Cognitive Interaction Technology. * The Excellence Cluster EXC 277 is a grant of the Deutsche * Forschungsgemeinschaft (DFG) in the context of the German * Excellence Initiative. * */ /** * Packetlistener for XMPP messages. * * @author akipp */ package de.unibi.airobots.resaijavaclient.communicaton; import java.util.HashMap; import java.util.Observable; import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Packet; public class XMPPPacketListener extends Observable implements PacketListener{ private String sender = ""; private String body = ""; private HashMap receivedProperties = new HashMap(); private String recipientTAG = ""; @Override public void processPacket(Packet packet) { if (packet instanceof Message) { Message mIn = (Message) packet; setSender(mIn.getFrom()); setBody(mIn.getBody()); if (mIn.getPropertyNames().contains("TAG")) { setRecipientTAG(mIn.getProperty("TAG").toString()); } receivedProperties.clear(); for (String prop : mIn.getPropertyNames()) { receivedProperties.put(prop, mIn.getProperty(prop) .toString()); } setChanged(); notifyObservers(); } } public void setBody(String body) { this.body = body; } public String getBody() { return body; } public void setSender(String sender) { this.sender = sender; } public String getSender() { return sender; } public void setRecipientTAG(String recipientTAG) { this.recipientTAG = recipientTAG; } public String getRecipientTAG() { return recipientTAG; } public HashMap getReceivedProperties() { return receivedProperties; } public void setReceivedProperties(HashMap receivedProperties) { this.receivedProperties = receivedProperties; } }