package pt.uminho.ceb.biosystems.mew.core.simulation.components;

import java.lang.reflect.ParameterizedType;
import java.util.HashMap;
import java.util.Map;

import pt.uminho.ceb.biosystems.mew.solvers.lp.LPProblem;

public class SimulationMethodsFactory extends AbstractSimulationMethodsFactory{

	protected Map<String, Class<? extends LPProblem>> mapTypeMethods;

	public SimulationMethodsFactory(Map<String,Class<?>> mapMethods)
	{
		super(mapMethods);
		this.mapTypeMethods = new HashMap<String, Class<? extends LPProblem>>();
		for(String id : mapMethods.keySet())
			mapTypeMethods.put(id, getProblemClass(mapMethods.get(id)));
	}
	
	@Override
	public void registerMethod(String id, Class<?> method){
		super.registerMethod(id, method);
		mapTypeMethods.put(id, getProblemClass(method));
	}
	
	public Class<? extends LPProblem> getProblemTypeFromMethod(String method){
		return mapTypeMethods.get(method);
	}
	
//	public void addProperty(String key, Object value){
//		methodProperties.put(key, value);
//	}
//	
//	public void removeProperty(String key){
//		
//		methodProperties.remove(key);
//	}
//	
//	public Object getProperty(String key){
//		return methodProperties.get(key);
//	}
	
	
	@SuppressWarnings({"unchecked"})
	private static <T extends LPProblem> Class<T> getProblemClass(final Class<?> klass){
		
		Class<T> ret = null;
		
		ParameterizedType parameterizedType =
			       (ParameterizedType) klass.getGenericSuperclass();
		ret = (Class<T>) parameterizedType.getActualTypeArguments()[0];
		
		return ret;
	}

}

@@ -1341,16 +1341,24 @@
 ull;%0A%09%09%0A
+%09%09try%7B%0A%09
 %09%09Parame
@@ -1392,16 +1392,17 @@
 pe =%0A%09%09%09
+%09
        (
@@ -1450,16 +1450,17 @@
 lass();%0A
+%09
 %09%09ret = 
@@ -1517,16 +1517,69 @@
 s()%5B0%5D;%0A
+%09%09%7Dcatch (Exception e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A
 %09%09%0A%09%09ret

rollback and put try again but for unknown reasons, must be check in future