// Path: AutoSIM-Environments/src/com/automatski/autosim/environments/IConnection.java
// public interface IConnection {
// 
// 	public void setConfig(Object object);
// 	
// 	
// 	public void connect() throws Exception;
// 	public void disconnect() throws Exception;
// 	
// 	public void setListener(IConnectionListener listener);
// 	public Object send(Object object) throws Exception;
// 	
// }
// 
// Path: AutoSIM-Environments/src/com/automatski/autosim/environments/IConnectionListener.java
// public interface IConnectionListener {
// 
// 	public void receive(Object object) throws Exception;
// }
// 
// Path: AutoSIM-XMPP/src/com/automatski/autosim/xmpp/config/AutoSIMConnectionConfig.java
// public class AutoSIMConnectionConfig {
// 
// 	public String name;
// 	public String host;
// 	public int port;
// 	public String username;
// 	public String password;
// 	public String servicename;
// 	
// 	public String connectorClassName;
// }


import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.chat.Chat;
import org.jivesoftware.smack.chat.ChatManager;
import org.jivesoftware.smack.chat.ChatMessageListener;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
import com.automatski.autosim.environments.IConnection;
import com.automatski.autosim.environments.IConnectionListener;
import com.automatski.autosim.xmpp.config.AutoSIMConnectionConfig;
/*
 *  AutoSIM - Internet of Things Simulator
 *  Copyright (C) 2014, Aditya Yadav <aditya@automatski.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.automatski.autosim.xmpp;



public class SampleXMPPConnection implements IConnection {

	private AutoSIMConnectionConfig config = null;
	private IConnectionListener listener = null;
	private XMPPTCPConnectionConfiguration connConfig = null;
	private AbstractXMPPConnection connection = null;
	private ChatManager chatmanager = null;
	private Chat chat = null;
	
	@Override
	public void connect() throws Exception {
		// Create a connection to the jabber.org server on a specific port.
		connConfig = XMPPTCPConnectionConfiguration.builder()
		  .setUsernameAndPassword(config.username, config.password)
		  .setServiceName(config.servicename)
		  .setHost(config.host)
		  .setPort(config.port)
		  .build();
		
		connection = new XMPPTCPConnection(connConfig);
		// Connect to the server
		connection.connect();
		// Log into the server
		connection.login();

		String receiver = config.username;
		// Assume we've created an XMPPConnection name "connection"._
		chatmanager = ChatManager.getInstanceFor(connection);
		chat = chatmanager.createChat(config.username, new ChatMessageListener() {
			public void processMessage(Chat chat, Message message) {
// Path: AutoSIM-Environments/src/com/automatski/autosim/environments/IConnection.java
// public interface IConnection {
// 
// 	public void setConfig(Object object);
// 	
// 	
// 	public void connect() throws Exception;
// 	public void disconnect() throws Exception;
// 	
// 	public void setListener(IConnectionListener listener);
// 	public Object send(Object object) throws Exception;
// 	
// }
// 
// Path: AutoSIM-Environments/src/com/automatski/autosim/environments/IConnectionListener.java
// public interface IConnectionListener {
// 
// 	public void receive(Object object) throws Exception;
// }
// 
// Path: AutoSIM-XMPP/src/com/automatski/autosim/xmpp/config/AutoSIMConnectionConfig.java
// public class AutoSIMConnectionConfig {
// 
// 	public String name;
// 	public String host;
// 	public int port;
// 	public String username;
// 	public String password;
// 	public String servicename;
// 	
// 	public String connectorClassName;
// }


// Path: AutoSIM-XMPP/src/com/automatski/autosim/xmpp/SampleXMPPConnection.java
import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.chat.Chat;
import org.jivesoftware.smack.chat.ChatManager;
import org.jivesoftware.smack.chat.ChatMessageListener;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
import com.automatski.autosim.environments.IConnection;
import com.automatski.autosim.environments.IConnectionListener;
import com.automatski.autosim.xmpp.config.AutoSIMConnectionConfig;

/*
 *  AutoSIM - Internet of Things Simulator
 *  Copyright (C) 2014, Aditya Yadav <aditya@automatski.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.automatski.autosim.xmpp;



public class SampleXMPPConnection implements IConnection {

	private AutoSIMConnectionConfig config = null;
	private IConnectionListener listener = null;
	private XMPPTCPConnectionConfiguration connConfig = null;
	private AbstractXMPPConnection connection = null;
	private ChatManager chatmanager = null;
	private Chat chat = null;
	
	@Override
	public void connect() throws Exception {
		// Create a connection to the jabber.org server on a specific port.
		connConfig = XMPPTCPConnectionConfiguration.builder()
		  .setUsernameAndPassword(config.username, config.password)
		  .setServiceName(config.servicename)
		  .setHost(config.host)
		  .setPort(config.port)
		  .build();
		
		connection = new XMPPTCPConnection(connConfig);
		// Connect to the server
		connection.connect();
		// Log into the server
		connection.login();

		String receiver = config.username;
		// Assume we've created an XMPPConnection name "connection"._
		chatmanager = ChatManager.getInstanceFor(connection);
		chat = chatmanager.createChat(config.username, new ChatMessageListener() {
			public void processMessage(Chat chat, Message message) {
				System.out.println("Received message: " + message);