| 1 | package de.uka.ipd.sdq.simucomframework; |
| 2 | |
| 3 | import org.apache.log4j.Logger; |
| 4 | import org.eclipse.core.runtime.CoreException; |
| 5 | import org.eclipse.core.runtime.IConfigurationElement; |
| 6 | import org.eclipse.core.runtime.Platform; |
| 7 | |
| 8 | import de.uka.ipd.sdq.simucomframework.model.SimuComModel; |
| 9 | import de.uka.ipd.sdq.simucomframework.simucomstatus.SimuComStatus; |
| 10 | import de.uka.ipd.sdq.simulation.abstractsimengine.ISimEngineFactory; |
| 11 | |
| 12 | /** |
| 13 | * Factory for creating simulation objects. The created objects are already attached |
| 14 | * to a desmo-j experiment |
| 15 | * @author Steffen Becker |
| 16 | * |
| 17 | */ |
| 18 | public class SimuComFactory { |
| 19 | /** Logger for this class. */ |
| 20 | private static final Logger logger = Logger.getLogger(SimuComFactory.class); |
| 21 | |
| 22 | /** |
| 23 | * Create a new simulation model as needed by desmo-j |
| 24 | * @param name The name of the simulation model |
| 25 | * @param showInReport Should desmoj report on our experiment |
| 26 | * @param showInTrance Should desmoj trace our experiment |
| 27 | * @return The created simulation model |
| 28 | */ |
| 29 | public static SimuComModel getSimuComModel(SimuComConfig config, SimuComStatus simuComStatus, boolean isRemote) { |
| 30 | ISimEngineFactory factory = null; |
| 31 | |
| 32 | for(IConfigurationElement configurationElement : Platform.getExtensionRegistry(). |
| 33 | getConfigurationElementsFor("de.uka.ipd.sdq.simulation.abstractsimengine.engine")){ |
| 34 | |
| 35 | try { |
| 36 | if (configurationElement.getAttribute("id").equals(config.getEngine())) |
| 37 | factory = (ISimEngineFactory)configurationElement.createExecutableExtension("class"); |
| 38 | } catch (CoreException e) { |
| 39 | logger.warn("Could not get factory for registered simulation engine.", e); |
| 40 | factory = null; |
| 41 | } |
| 42 | } |
| 43 | if (factory == null) |
| 44 | throw new RuntimeException("No Simulation Engine available. Please install at least one engine."); |
| 45 | else { |
| 46 | SimuComModel model = new SimuComModel( |
| 47 | config, simuComStatus, factory, isRemote); |
| 48 | |
| 49 | return model; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | } |