| 1 | package de.uka.ipd.sdq.simulation.abstractsimengine.util; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.List; |
| 5 | |
| 6 | import org.eclipse.core.runtime.CoreException; |
| 7 | import org.eclipse.core.runtime.IConfigurationElement; |
| 8 | import org.eclipse.core.runtime.IExtension; |
| 9 | |
| 10 | import de.uka.ipd.sdq.simulation.abstractsimengine.ISimEngineFactory; |
| 11 | |
| 12 | /** |
| 13 | * Helper class for the extension point {@code de.uka.ipd.sdq.simulation.abstractsimengine.engine} |
| 14 | * ("Abstract Simulation Engine"). |
| 15 | * |
| 16 | * @author Philipp Merkle |
| 17 | * |
| 18 | */ |
| 19 | public class AbstractSimEngineExtensionHelper { |
| 20 | |
| 21 | /** the id for the "Palladio Simulator" extension point */ |
| 22 | public static final String EXTENSION_POINT_ID = "de.uka.ipd.sdq.simulation.abstractsimengine.engine"; |
| 23 | |
| 24 | public static String[] getEngineNames() throws CoreException { |
| 25 | List<String> names = new ArrayList<String>(); |
| 26 | for (IExtension extension : ExtensionPointHelper.findExtensions(EXTENSION_POINT_ID)) { |
| 27 | for (IConfigurationElement e : ExtensionPointHelper.findConfigurationElements(extension, "engine")) { |
| 28 | if (e != null) { |
| 29 | names.add(e.getAttribute("name")); |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | return names.toArray(new String[names.size()]); |
| 34 | } |
| 35 | |
| 36 | public static String[][] getEngineNamesAndIds() throws CoreException { |
| 37 | List<String[]> names = new ArrayList<String[]>(); |
| 38 | for (IExtension extension : ExtensionPointHelper.findExtensions(EXTENSION_POINT_ID)) { |
| 39 | for (IConfigurationElement e : ExtensionPointHelper.findConfigurationElements(extension, "engine")) { |
| 40 | if (e != null) { |
| 41 | names.add(new String[] { e.getAttribute("name"), e.getAttribute("id") }); |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | return names.toArray(new String[names.size()][2]); |
| 46 | } |
| 47 | |
| 48 | public static String getEngineNameForId(String engineId) throws CoreException { |
| 49 | for (IExtension extension : ExtensionPointHelper.findExtensions(EXTENSION_POINT_ID)) { |
| 50 | for (IConfigurationElement e : ExtensionPointHelper.findConfigurationElements(extension, "engine")) { |
| 51 | if (e != null && e.getAttribute("id").equals(engineId)) { |
| 52 | return e.getAttribute("name"); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // could not find an extension for the specified id |
| 58 | return ""; |
| 59 | } |
| 60 | |
| 61 | public static String getEngineIdForName(String engineName) throws CoreException { |
| 62 | for (IExtension extension : ExtensionPointHelper.findExtensions(EXTENSION_POINT_ID)) { |
| 63 | for (IConfigurationElement e : ExtensionPointHelper.findConfigurationElements(extension, "engine")) { |
| 64 | if (e != null && e.getAttribute("name").equals(engineName)) { |
| 65 | return e.getAttribute("id"); |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // could not find an extension for the specified name |
| 71 | return ""; |
| 72 | } |
| 73 | |
| 74 | public static ISimEngineFactory getEngineFactory(String engineId) throws CoreException { |
| 75 | for (IExtension extension : ExtensionPointHelper.findExtensions(EXTENSION_POINT_ID)) { |
| 76 | for (IConfigurationElement e : ExtensionPointHelper.findConfigurationElements(extension, "engine")) { |
| 77 | if (e != null && e.getAttribute("id").equals(engineId)) { |
| 78 | return (ISimEngineFactory) e.createExecutableExtension("class"); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | // could not find an extension for the specified id |
| 84 | return null; |
| 85 | } |
| 86 | |
| 87 | } |