| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2013 École Polytechnique de Montréal |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are |
| 5 | * made available under the terms of the Eclipse Public License v1.0 which |
| 6 | * accompanies this distribution, and is available at |
| 7 | * http://www.eclipse.org/legal/epl-v10.html |
| 8 | * |
| 9 | * Contributors: |
| 10 | * Geneviève Bastien - Initial API and implementation |
| 11 | *******************************************************************************/ |
| 12 | |
| 13 | package org.eclipse.linuxtools.internal.tmf.core.analysis; |
| 14 | |
| 15 | import java.util.HashMap; |
| 16 | import java.util.LinkedList; |
| 17 | import java.util.List; |
| 18 | import java.util.Map; |
| 19 | |
| 20 | import org.eclipse.core.runtime.IConfigurationElement; |
| 21 | import org.eclipse.core.runtime.Platform; |
| 22 | import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModuleHelper; |
| 23 | import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisModuleHelperCE; |
| 24 | |
| 25 | /** |
| 26 | * Utility class for accessing TMF analysis type extensions from the platform's |
| 27 | * extensions registry. |
| 28 | * |
| 29 | * @author Geneviève Bastien |
| 30 | * @since 3.0 |
| 31 | */ |
| 32 | public final class TmfAnalysisType { |
| 33 | |
| 34 | /** Extension point ID */ |
| 35 | public static final String TMF_ANALYSIS_TYPE_ID = "org.eclipse.linuxtools.tmf.core.analysis"; //$NON-NLS-1$ |
| 36 | |
| 37 | /** Extension point element 'module' */ |
| 38 | public static final String MODULE_ELEM = "module"; //$NON-NLS-1$ |
| 39 | |
| 40 | /** Extension point element 'parameter' */ |
| 41 | public static final String PARAMETER_ELEM = "parameter"; //$NON-NLS-1$ |
| 42 | |
| 43 | /** Extension point attribute 'ID' */ |
| 44 | public static final String ID_ATTR = "id"; //$NON-NLS-1$ |
| 45 | |
| 46 | /** Extension point attribute 'name' */ |
| 47 | public static final String NAME_ATTR = "name"; //$NON-NLS-1$ |
| 48 | |
| 49 | /** Extension point attribute 'analysis_module' */ |
| 50 | public static final String ANALYSIS_MODULE_ATTR = "analysis_module"; //$NON-NLS-1$ |
| 51 | |
| 52 | /** Extension point attribute 'automatic' */ |
| 53 | public static final String AUTOMATIC_ATTR = "automatic"; //$NON-NLS-1$ |
| 54 | |
| 55 | /** Extension point attribute 'icon' */ |
| 56 | public static final String ICON_ATTR = "icon"; //$NON-NLS-1$ |
| 57 | |
| 58 | /** Extension point attribute 'default_value' */ |
| 59 | public static final String DEFAULT_VALUE_ATTR = "default_value"; //$NON-NLS-1$ |
| 60 | |
| 61 | /** Extension point element 'tracetype' */ |
| 62 | public static final String TRACETYPE_ELEM = "tracetype"; //$NON-NLS-1$ |
| 63 | |
| 64 | /** Extension point attribute 'class' */ |
| 65 | public static final String CLASS_ATTR = "class"; //$NON-NLS-1$ |
| 66 | |
| 67 | /** Extension point attribute 'applies' */ |
| 68 | public static final String APPLIES_ATTR = "applies"; //$NON-NLS-1$ |
| 69 | |
| 70 | /** |
| 71 | * The mapping of available trace type IDs to their corresponding |
| 72 | * configuration element |
| 73 | */ |
| 74 | private final Map<String, IAnalysisModuleHelper> fAnalysisTypeAttributes = new HashMap<>(); |
| 75 | |
| 76 | private static TmfAnalysisType fInstance = null; |
| 77 | |
| 78 | /** |
| 79 | * Retrieves all configuration elements from the platform extension registry |
| 80 | * for the trace type extension. |
| 81 | * |
| 82 | * @return an array of trace type configuration elements |
| 83 | */ |
| 84 | public static IConfigurationElement[] getTypeElements() { |
| 85 | IConfigurationElement[] elements = |
| 86 | Platform.getExtensionRegistry().getConfigurationElementsFor(TMF_ANALYSIS_TYPE_ID); |
| 87 | List<IConfigurationElement> typeElements = new LinkedList<>(); |
| 88 | for (IConfigurationElement element : elements) { |
| 89 | if (element.getName().equals(MODULE_ELEM)) { |
| 90 | typeElements.add(element); |
| 91 | } |
| 92 | } |
| 93 | return typeElements.toArray(new IConfigurationElement[typeElements.size()]); |
| 94 | } |
| 95 | |
| 96 | private TmfAnalysisType() { |
| 97 | populateAnalysisTypes(); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * The analysis type instance |
| 102 | * |
| 103 | * @return the analysis type instance |
| 104 | */ |
| 105 | public static synchronized TmfAnalysisType getInstance() { |
| 106 | if (fInstance == null) { |
| 107 | fInstance = new TmfAnalysisType(); |
| 108 | } |
| 109 | return fInstance; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Get the list of analysis modules |
| 114 | * |
| 115 | * @return list of analysis modules |
| 116 | */ |
| 117 | public Map<String, IAnalysisModuleHelper> getAnalysisModules() { |
| 118 | return fAnalysisTypeAttributes; |
| 119 | } |
| 120 | |
| 121 | private void populateAnalysisTypes() { |
| 122 | if (fAnalysisTypeAttributes.isEmpty()) { |
| 123 | // Populate the Categories and Trace Types |
| 124 | IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TMF_ANALYSIS_TYPE_ID); |
| 125 | for (IConfigurationElement ce : config) { |
| 126 | String elementName = ce.getName(); |
| 127 | if (elementName.equals(TmfAnalysisType.MODULE_ELEM)) { |
| 128 | String analysisTypeId = ce.getAttribute(TmfAnalysisType.ID_ATTR); |
| 129 | fAnalysisTypeAttributes.put(analysisTypeId, new TmfAnalysisModuleHelperCE(ce)); |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | } |