// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
// 
//     public final static String ID = "thing.id";
//     public final static String DEVICE = "thing.device";
//     public final static String SERVICE = "thing.service";
//     public final static String GATEWAY = "thing.gateway";
//     public final static String TYPE = "thing.type";
//     
// }
// 
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/ChangeEvent.java
// public class ChangeEvent {
// 	
// 	public UUID thingId; /* id of the thing */
// 	public UUID gatewayId; /* gateway that published the event */
// 	public String stateVariable; /* state variable that changed */
// 	public Object stateValue; /* new value of the state variable */
// 	public long timestamp; /* timestamp the event was generated */
// 	
// }
// 
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/OfflineEvent.java
// public class OfflineEvent {
// 	
// 	public UUID thingId; /* id of the thing */
// 	public UUID gatewayId; /* gateway that published the event */
// 	public long timestamp; /* timestamp the event was generated */
// 	
// }
// 
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/OnlineEvent.java
// public class OnlineEvent {
// 	
// 	public UUID thingId; /* id of the thing */
// 	public UUID gatewayId; /* gateway that published the event */
// 	public String service; /* service of the thing */
// 	public String device; /* device name of the thing */
// 	public String type; /* thing type */
// 	public long timestamp; /* timestamp the event was generated */
// 	
// }


import java.util.ArrayList;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.dyamand.event.Event;
import org.dyamand.event.EventListener;
import org.dyamand.event.ServicePOJOOfflineEvent;
import org.dyamand.event.ServicePOJOOnlineEvent;
import org.dyamand.event.StateChangedEvent;
import org.dyamand.service.ServicePOJO;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.event.EventAdmin;
import org.osgi.service.event.EventProperties;
import osgi.enroute.dto.api.DTOs;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.event.ChangeEvent;
import be.iminds.iot.things.api.event.OfflineEvent;
import be.iminds.iot.things.api.event.OnlineEvent;
			this.servicePojoOnline(servicePOJO);
		} else if (event instanceof ServicePOJOOfflineEvent) {
			final ServicePOJO servicePOJO = ((ServicePOJOOfflineEvent) event)
					.getServicePOJO();
			this.servicePojoOffline(servicePOJO);
		} else if (event instanceof StateChangedEvent) {
			final org.dyamand.service.StateChange stateChange = ((StateChangedEvent) event)
					.getStateChange();
			this.processStateChange(stateChange);
		} 
	}

    private void servicePojoOnline(final ServicePOJO servicePOJO) {
    	if(this.services.get(servicePOJO)!=null){
    		System.err.println("ServicePOJO "+servicePOJO+" already online?!");
    		return;
    	}
    	
    	// translate sensor to IoT types
    	synchronized(adapters){
			for(ServiceAdapter adapter : adapters){
				try {
				    // ADAPT!
				    final Object so = adapter.getServiceObject(servicePOJO);
	
					final String device = servicePOJO.getService().getOriginalDevice().getName().toString();
					final String service = servicePOJO.getService().getName().toString();
					final UUID thingId = UUID.nameUUIDFromBytes((device+service).getBytes());
					
					final Dictionary<String, Object> properties = new Hashtable<String, Object>();
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/Thing.java
// public interface Thing {
// 
//     public final static String ID = "thing.id";
//     public final static String DEVICE = "thing.device";
//     public final static String SERVICE = "thing.service";
//     public final static String GATEWAY = "thing.gateway";
//     public final static String TYPE = "thing.type";
//     
// }
// 
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/ChangeEvent.java
// public class ChangeEvent {
// 	
// 	public UUID thingId; /* id of the thing */
// 	public UUID gatewayId; /* gateway that published the event */
// 	public String stateVariable; /* state variable that changed */
// 	public Object stateValue; /* new value of the state variable */
// 	public long timestamp; /* timestamp the event was generated */
// 	
// }
// 
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/OfflineEvent.java
// public class OfflineEvent {
// 	
// 	public UUID thingId; /* id of the thing */
// 	public UUID gatewayId; /* gateway that published the event */
// 	public long timestamp; /* timestamp the event was generated */
// 	
// }
// 
// Path: be.iminds.iot.things.api/src/be/iminds/iot/things/api/event/OnlineEvent.java
// public class OnlineEvent {
// 	
// 	public UUID thingId; /* id of the thing */
// 	public UUID gatewayId; /* gateway that published the event */
// 	public String service; /* service of the thing */
// 	public String device; /* device name of the thing */
// 	public String type; /* thing type */
// 	public long timestamp; /* timestamp the event was generated */
// 	
// }


// Path: be.iminds.iot.things.dyamand.adapter/src/be/iminds/iot/things/dyamand/adapter/DyamandAdapter.java
import java.util.ArrayList;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.dyamand.event.Event;
import org.dyamand.event.EventListener;
import org.dyamand.event.ServicePOJOOfflineEvent;
import org.dyamand.event.ServicePOJOOnlineEvent;
import org.dyamand.event.StateChangedEvent;
import org.dyamand.service.ServicePOJO;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.event.EventAdmin;
import org.osgi.service.event.EventProperties;
import osgi.enroute.dto.api.DTOs;
import be.iminds.iot.things.api.Thing;
import be.iminds.iot.things.api.event.ChangeEvent;
import be.iminds.iot.things.api.event.OfflineEvent;
import be.iminds.iot.things.api.event.OnlineEvent;

			this.servicePojoOnline(servicePOJO);
		} else if (event instanceof ServicePOJOOfflineEvent) {
			final ServicePOJO servicePOJO = ((ServicePOJOOfflineEvent) event)
					.getServicePOJO();
			this.servicePojoOffline(servicePOJO);
		} else if (event instanceof StateChangedEvent) {
			final org.dyamand.service.StateChange stateChange = ((StateChangedEvent) event)
					.getStateChange();
			this.processStateChange(stateChange);
		} 
	}

    private void servicePojoOnline(final ServicePOJO servicePOJO) {
    	if(this.services.get(servicePOJO)!=null){
    		System.err.println("ServicePOJO "+servicePOJO+" already online?!");
    		return;
    	}
    	
    	// translate sensor to IoT types
    	synchronized(adapters){
			for(ServiceAdapter adapter : adapters){
				try {
				    // ADAPT!
				    final Object so = adapter.getServiceObject(servicePOJO);
	
					final String device = servicePOJO.getService().getOriginalDevice().getName().toString();
					final String service = servicePOJO.getService().getName().toString();
					final UUID thingId = UUID.nameUUIDFromBytes((device+service).getBytes());
					
					final Dictionary<String, Object> properties = new Hashtable<String, Object>();
					properties.put(Thing.ID, thingId.toString());