If you think the Android project smsgateway-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
*/*fromwww.java2s.com*/
* ((e)) emite: A pure gwt (Google Web Toolkit) xmpp (jabber) library
*
* (c) 2008-2009 The emite development team (see CREDITS for details)
* This file is part of emite.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/package com.calclab.emite.im.client.chat;
import java.util.HashMap;
import com.calclab.emite.core.client.xmpp.session.Session;
import com.calclab.emite.core.client.xmpp.stanzas.Message;
import com.calclab.emite.core.client.xmpp.stanzas.XmppURI;
import com.calclab.suco.client.events.Event;
import com.calclab.suco.client.events.Listener;
publicabstractclass AbstractChat implements Chat {
protectedfinal XmppURI uri;
protected State state;
protectedfinal Event<State> onStateChanged;
protectedfinal Event<Message> onBeforeReceive;
protectedfinal Session session;
privatefinal HashMap<Class<?>, Object> data;
privatefinal Event<Message> onMessageSent;
privatefinal Event<Message> onMessageReceived;
privatefinal Event<Message> onBeforeSend;
privatefinal XmppURI starter;
public AbstractChat(final Session session, final XmppURI uri, final XmppURI starter) {
this.session = session;
this.uri = uri;
this.starter = starter;
this.data = new HashMap<Class<?>, Object>();
this.state = Chat.State.locked;
this.onStateChanged = new Event<State>("chat:onStateChanged");
this.onMessageSent = new Event<Message>("chat:onMessageSent");
this.onMessageReceived = new Event<Message>("chat:onMessageReceived");
this.onBeforeSend = new Event<Message>("chat:onBeforeSend");
this.onBeforeReceive = new Event<Message>("chat:onBeforeReceive");
}
@SuppressWarnings("unchecked")
public <T> T getData(final Class<T> type) {
return (T) data.get(type);
}
public State getState() {
return state;
}
public XmppURI getURI() {
return uri;
}
publicboolean isInitiatedByMe() {
return starter.equals(session.getCurrentUser());
}
publicvoid onBeforeReceive(final Listener<Message> listener) {
onBeforeReceive.add(listener);
}
publicvoid onBeforeSend(final Listener<Message> listener) {
onBeforeSend.add(listener);
}
publicvoid onMessageReceived(final Listener<Message> listener) {
onMessageReceived.add(listener);
}
publicvoid onMessageSent(final Listener<Message> listener) {
onMessageSent.add(listener);
}
publicvoid onStateChanged(final Listener<State> listener) {
onStateChanged.add(listener);
}
publicvoid send(final Message message) {
message.setFrom(session.getCurrentUser());
onBeforeSend.fire(message);
session.send(message);
onMessageSent.fire(message);
}
@SuppressWarnings("unchecked")
public <T> T setData(final Class<T> type, final T value) {
return (T) data.put(type, value);
}
protectedvoid receive(final Message message) {
onBeforeReceive.fire(message);
onMessageReceived.fire(message);
}
protectedvoid setState(final State state) {
if (this.state != state) {
this.state = state;
onStateChanged.fire(state);
}
}
}