// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/cloud/api/Observation.java
// public class Observation extends DTO {
// 	public final static String TOPIC = "osgi/trains/observation";
// 
// 	public enum Type {
// 		CHANGE, //
// 		/**
// 		 * Detected an RFID
// 		 */
// 		LOCATED, 
// 		/**
// 		 * Assignment changed
// 		 */
// 		ASSIGNMENT, 
// 		/**
// 		 * Assignment reached
// 		 */
// 		ASSIGNMENT_REACHED,
// 		/**
// 		 * Signal changed color
// 		 */
// 		SIGNAL,
// 		/**
// 		 * Switched changed alternate state
// 		 */
// 		SWITCH,
// 		/**
// 		 * A segment is blocked 
// 		 */
// 		BLOCKED,
// 		/**
// 		 * A segment is dark
// 		 */
// 		DARK,
// 		/**
// 		 * A train emergency occurs
// 		 */
// 		EMERGENCY
// 		
// 	}
// 
// 	public Type type;
// 	public String segment;
// 	public String train;
// 	public Color signal;
// 	public String assignment;
// 	public long time;
// 	public long id;
// 	public String message;
// 	public boolean alternate;
// 	public boolean blocked;
// 	public boolean dark;
// 	public boolean emergency;
// }
// 
// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/sensor/api/SensorEvent.java
// public class SensorEvent extends DTO{
// 
// 	public final static String TOPIC = "osgi/trains/sensor";
// 
// 	public enum Type {
// 		WATER, 
// 		LIGHT,
// 		MOTION,
// 		DOOR,
// 		PASSENGER
// 	}
// 	
// 	public Type type;
// 	public String segment;
// 	public String train;
// 	
// 	public boolean water;
// 	public boolean dark;
// 	public boolean motion;
// 	public boolean open;
// 	public boolean passenger;  // Passenger emergency brake
// }


import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import org.osgi.service.event.Event;
import osgi.enroute.dto.api.DTOs;
import osgi.enroute.trains.cloud.api.Observation;
import osgi.enroute.trains.sensor.api.SensorEvent;
package osgi.enroute.trains.event.util;




public class EventConvertor {

		public static Observation eventToObservation(Event event, DTOs dtos) throws Exception {
			Observation o = new Observation();
			for ( Field f : o.getClass().getFields() ) {
				if ( Modifier.isStatic(f.getModifiers()))
					continue;
				
				Object rawValue = event.getProperty(f.getName());
				Object value = dtos.convert(rawValue).to(f.getGenericType());
				f.set(o, value);
			}
			return o;
		}
		
		
// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/cloud/api/Observation.java
// public class Observation extends DTO {
// 	public final static String TOPIC = "osgi/trains/observation";
// 
// 	public enum Type {
// 		CHANGE, //
// 		/**
// 		 * Detected an RFID
// 		 */
// 		LOCATED, 
// 		/**
// 		 * Assignment changed
// 		 */
// 		ASSIGNMENT, 
// 		/**
// 		 * Assignment reached
// 		 */
// 		ASSIGNMENT_REACHED,
// 		/**
// 		 * Signal changed color
// 		 */
// 		SIGNAL,
// 		/**
// 		 * Switched changed alternate state
// 		 */
// 		SWITCH,
// 		/**
// 		 * A segment is blocked 
// 		 */
// 		BLOCKED,
// 		/**
// 		 * A segment is dark
// 		 */
// 		DARK,
// 		/**
// 		 * A train emergency occurs
// 		 */
// 		EMERGENCY
// 		
// 	}
// 
// 	public Type type;
// 	public String segment;
// 	public String train;
// 	public Color signal;
// 	public String assignment;
// 	public long time;
// 	public long id;
// 	public String message;
// 	public boolean alternate;
// 	public boolean blocked;
// 	public boolean dark;
// 	public boolean emergency;
// }
// 
// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/sensor/api/SensorEvent.java
// public class SensorEvent extends DTO{
// 
// 	public final static String TOPIC = "osgi/trains/sensor";
// 
// 	public enum Type {
// 		WATER, 
// 		LIGHT,
// 		MOTION,
// 		DOOR,
// 		PASSENGER
// 	}
// 	
// 	public Type type;
// 	public String segment;
// 	public String train;
// 	
// 	public boolean water;
// 	public boolean dark;
// 	public boolean motion;
// 	public boolean open;
// 	public boolean passenger;  // Passenger emergency brake
// }


// Path: osgi.enroute.trains.util/src/osgi/enroute/trains/event/util/EventConvertor.java
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import org.osgi.service.event.Event;
import osgi.enroute.dto.api.DTOs;
import osgi.enroute.trains.cloud.api.Observation;
import osgi.enroute.trains.sensor.api.SensorEvent;

package osgi.enroute.trains.event.util;




public class EventConvertor {

		public static Observation eventToObservation(Event event, DTOs dtos) throws Exception {
			Observation o = new Observation();
			for ( Field f : o.getClass().getFields() ) {
				if ( Modifier.isStatic(f.getModifiers()))
					continue;
				
				Object rawValue = event.getProperty(f.getName());
				Object value = dtos.convert(rawValue).to(f.getGenericType());
				f.set(o, value);
			}
			return o;
		}
		
		
		public static SensorEvent eventToSensorEvent(Event event, DTOs dtos) throws Exception {