// 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;

	private void processStateChange(
			final org.dyamand.service.StateChange stateChange) {
		
		final String device = stateChange.getService().getOriginalDevice().getName().toString();
		final String service = stateChange.getService().getName().toString();
		final UUID thingId = UUID.nameUUIDFromBytes((device+service).getBytes());
		
		final String stateVariable = stateChange.getStateVariable().toString();
		final Object value = stateChange.getValue();

		synchronized(adapters){
			for (final ServiceAdapter adapter : this.adapters) {
				try {
					final StateVariable translated = adapter
							.translateStateVariable(stateVariable, value);
					this.notifiyStateChange(thingId, translated.getName(), translated.getValue());
					
				} catch (final Exception e) {
				}
			}
		}
	}
	
	private void notifyOnline(
			final UUID thingId,
			final String device,
			final String service,
			final String type){
		try {
// 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;


	private void processStateChange(
			final org.dyamand.service.StateChange stateChange) {
		
		final String device = stateChange.getService().getOriginalDevice().getName().toString();
		final String service = stateChange.getService().getName().toString();
		final UUID thingId = UUID.nameUUIDFromBytes((device+service).getBytes());
		
		final String stateVariable = stateChange.getStateVariable().toString();
		final Object value = stateChange.getValue();

		synchronized(adapters){
			for (final ServiceAdapter adapter : this.adapters) {
				try {
					final StateVariable translated = adapter
							.translateStateVariable(stateVariable, value);
					this.notifiyStateChange(thingId, translated.getName(), translated.getValue());
					
				} catch (final Exception e) {
				}
			}
		}
	}
	
	private void notifyOnline(
			final UUID thingId,
			final String device,
			final String service,
			final String type){
		try {
			OnlineEvent e = new OnlineEvent();