// Path: AutoSIM-Environments/src/com/automatski/autosim/environments/IEnvironments.java
// public interface IEnvironments {
// 
// 	public void setup(String environment) throws Exception;
// 	public void start(String environment) throws Exception;
// 	public void stop(String environment) throws Exception;
// 	public void teardown(String environment) throws Exception;
// 	
// 	
// 	public void registerConnectionFactory(String name, IConnectionFactory factory); 
// 	public void deregisterConnectionFactory(String name);
// 	public IConnection getConnection(String name) throws Exception;
// 	
// 	public void registerDeviceFactory(String name, IDeviceFactory factory); 
// 	public void deregisterDeviceFactory(String name);
// 	public IDevice getDevice(String name) throws Exception;
// 	
// 	
// 	
// }
// 
// Path: AutoSIM-MQTT/src/com/automatski/autosim/mqtt/config/AutoSIMConnectionConfig.java
// public class AutoSIMConnectionConfig {
// 
// 	public String name;
// 	public String url;
// 	public String username;
// 	public String password;
// 	
// 	public String connectorClassName;
// }
// 
// Path: AutoSIM-MQTT/src/com/automatski/autosim/mqtt/config/AutoSIMMQTTConfig.java
// public class AutoSIMMQTTConfig {
// 
// 	public List<AutoSIMConnectionConfig> connections = new ArrayList<AutoSIMConnectionConfig>();
// 	
// }
// 
// Path: AutoSIM-MQTT/src/com/automatski/autosim/mqtt/utils/GsonUtils.java
// public class GsonUtils {
// 
// 	private static GsonBuilder builder = null;
// 	
// 	static {
//         builder = new GsonBuilder();
//         builder.setPrettyPrinting().serializeNulls();
// 	}
// 	
// 	public static String objectToJson(Object obj) throws Exception {
//         Gson gson = builder.create();
//         return gson.toJson(obj);
// 	}
// 	
// 	public static Object jsonToObject(String path, Class clas) throws Exception {
//         Gson gson = builder.create();
// 		String json = new String(Files.readAllBytes(Paths.get(path)));//"./albums.json")));
//         return gson.fromJson(json, clas);
// 	}
// 	
// 	
// }


import java.util.HashMap;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import com.automatski.autosim.environments.IEnvironments;
import com.automatski.autosim.mqtt.config.AutoSIMConnectionConfig;
import com.automatski.autosim.mqtt.config.AutoSIMMQTTConfig;
import com.automatski.autosim.mqtt.utils.GsonUtils;
package com.automatski.autosim.mqtt;






/**
 * This class implements a simple bundle that uses the bundle
 * context to register an English language dictionary service
 * with the OSGi framework. The dictionary service interface is
 * defined in a separate class file and is implemented by an
 * inner class.
**/



public class MQTTServiceActivator implements BundleActivator
{
	private IEnvironments environments = null;
	private AutoSIMMQTTConfig config = null;
	private HashMap<String,MQTTConnectionFactory> factories = new HashMap<String,MQTTConnectionFactory>();
	
    /**
     * Implements BundleActivator.start(). Registers an
     * instance of a dictionary service using the bundle context;
     * attaches properties to the service that can be queried
     * when performing a service look-up.
     * @param context the framework context for the bundle.
    **/
    public void start(BundleContext context) throws Exception 
    {
    	
    	//System.out.println(new File(".").getAbsolutePath());
    	
    	// read the config
    	config = (AutoSIMMQTTConfig) GsonUtils.jsonToObject("./conf/autosim-mqtt.json", AutoSIMMQTTConfig.class);

    	
    	ServiceReference[] refs = context.getServiceReferences(IEnvironments.class.getName(), "(Language=*)");
    	environments = (IEnvironments) context.getService(refs[0]);

// Path: AutoSIM-Environments/src/com/automatski/autosim/environments/IEnvironments.java
// public interface IEnvironments {
// 
// 	public void setup(String environment) throws Exception;
// 	public void start(String environment) throws Exception;
// 	public void stop(String environment) throws Exception;
// 	public void teardown(String environment) throws Exception;
// 	
// 	
// 	public void registerConnectionFactory(String name, IConnectionFactory factory); 
// 	public void deregisterConnectionFactory(String name);
// 	public IConnection getConnection(String name) throws Exception;
// 	
// 	public void registerDeviceFactory(String name, IDeviceFactory factory); 
// 	public void deregisterDeviceFactory(String name);
// 	public IDevice getDevice(String name) throws Exception;
// 	
// 	
// 	
// }
// 
// Path: AutoSIM-MQTT/src/com/automatski/autosim/mqtt/config/AutoSIMConnectionConfig.java
// public class AutoSIMConnectionConfig {
// 
// 	public String name;
// 	public String url;
// 	public String username;
// 	public String password;
// 	
// 	public String connectorClassName;
// }
// 
// Path: AutoSIM-MQTT/src/com/automatski/autosim/mqtt/config/AutoSIMMQTTConfig.java
// public class AutoSIMMQTTConfig {
// 
// 	public List<AutoSIMConnectionConfig> connections = new ArrayList<AutoSIMConnectionConfig>();
// 	
// }
// 
// Path: AutoSIM-MQTT/src/com/automatski/autosim/mqtt/utils/GsonUtils.java
// public class GsonUtils {
// 
// 	private static GsonBuilder builder = null;
// 	
// 	static {
//         builder = new GsonBuilder();
//         builder.setPrettyPrinting().serializeNulls();
// 	}
// 	
// 	public static String objectToJson(Object obj) throws Exception {
//         Gson gson = builder.create();
//         return gson.toJson(obj);
// 	}
// 	
// 	public static Object jsonToObject(String path, Class clas) throws Exception {
//         Gson gson = builder.create();
// 		String json = new String(Files.readAllBytes(Paths.get(path)));//"./albums.json")));
//         return gson.fromJson(json, clas);
// 	}
// 	
// 	
// }


// Path: AutoSIM-MQTT/src/com/automatski/autosim/mqtt/MQTTServiceActivator.java
import java.util.HashMap;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import com.automatski.autosim.environments.IEnvironments;
import com.automatski.autosim.mqtt.config.AutoSIMConnectionConfig;
import com.automatski.autosim.mqtt.config.AutoSIMMQTTConfig;
import com.automatski.autosim.mqtt.utils.GsonUtils;

package com.automatski.autosim.mqtt;






/**
 * This class implements a simple bundle that uses the bundle
 * context to register an English language dictionary service
 * with the OSGi framework. The dictionary service interface is
 * defined in a separate class file and is implemented by an
 * inner class.
**/



public class MQTTServiceActivator implements BundleActivator
{
	private IEnvironments environments = null;
	private AutoSIMMQTTConfig config = null;
	private HashMap<String,MQTTConnectionFactory> factories = new HashMap<String,MQTTConnectionFactory>();
	
    /**
     * Implements BundleActivator.start(). Registers an
     * instance of a dictionary service using the bundle context;
     * attaches properties to the service that can be queried
     * when performing a service look-up.
     * @param context the framework context for the bundle.
    **/
    public void start(BundleContext context) throws Exception 
    {
    	
    	//System.out.println(new File(".").getAbsolutePath());
    	
    	// read the config
    	config = (AutoSIMMQTTConfig) GsonUtils.jsonToObject("./conf/autosim-mqtt.json", AutoSIMMQTTConfig.class);

    	
    	ServiceReference[] refs = context.getServiceReferences(IEnvironments.class.getName(), "(Language=*)");
    	environments = (IEnvironments) context.getService(refs[0]);

    	for (AutoSIMConnectionConfig connectionConfig : config.connections){