1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
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
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.core
.analysis
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
18 import org
.eclipse
.core
.runtime
.CoreException
;
19 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
20 import org
.eclipse
.core
.runtime
.InvalidRegistryObjectException
;
21 import org
.eclipse
.core
.runtime
.Platform
;
22 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.Activator
;
25 * Utility class for accessing TMF analysis module extensions from the
26 * platform's extensions registry and returning the modules' outputs, wrapped as
27 * new module listeners.
29 * @author Geneviève Bastien
31 public class TmfAnalysisModuleOutputs
{
33 /** Extension point ID */
34 public static final String TMF_ANALYSIS_TYPE_ID
= "org.eclipse.linuxtools.tmf.core.analysis"; //$NON-NLS-1$
36 /** Extension point element 'output' */
37 public static final String OUTPUT_ELEM
= "output"; //$NON-NLS-1$
39 /** Extension point attribute 'outputClass' */
40 public static final String CLASS_ATTR
= "class"; //$NON-NLS-1$
42 /** Extension point attribute 'id' */
43 public static final String ID_ATTR
= "id"; //$NON-NLS-1$
46 * Extension point element 'analysisId' to associate the output to a single
49 public static final String ANALYSIS_ID_ELEM
= "analysisId"; //$NON-NLS-1$
52 * Extension point element 'analysisModuleClass' to associate the output
53 * with an analysis module class
55 public static final String MODULE_CLASS_ELEM
= "analysisModuleClass"; //$NON-NLS-1$
57 private TmfAnalysisModuleOutputs() {
62 * Return the analysis module outputs, wrapped as new module listeners,
63 * advertised in the extension point, in iterable format.
65 * @return List of {@link ITmfNewAnalysisModuleListener}
67 public static Iterable
<ITmfNewAnalysisModuleListener
> getOutputListeners() {
68 List
<ITmfNewAnalysisModuleListener
> newModuleListeners
= new ArrayList
<>();
69 // Get the sources element from the extension point
70 IConfigurationElement
[] config
= Platform
.getExtensionRegistry().getConfigurationElementsFor(TMF_ANALYSIS_TYPE_ID
);
71 for (IConfigurationElement ce
: config
) {
72 String elementName
= ce
.getName();
73 if (elementName
.equals(OUTPUT_ELEM
)) {
75 IAnalysisOutput output
= (IAnalysisOutput
) ce
.createExecutableExtension(CLASS_ATTR
);
77 Activator
.logWarning("An output could not be created"); //$NON-NLS-1$
80 ITmfNewAnalysisModuleListener listener
= null;
81 for (IConfigurationElement childCe
: ce
.getChildren()) {
82 if (childCe
.getName().equals(ANALYSIS_ID_ELEM
)) {
83 listener
= new TmfNewAnalysisOutputListener(output
, childCe
.getAttribute(ID_ATTR
), null);
84 } else if (childCe
.getName().equals(MODULE_CLASS_ELEM
)) {
85 listener
= new TmfNewAnalysisOutputListener(output
, null, childCe
.createExecutableExtension(CLASS_ATTR
).getClass().asSubclass(IAnalysisModule
.class));
88 if (listener
!= null) {
89 newModuleListeners
.add(listener
);
91 } catch (InvalidRegistryObjectException
| CoreException e
) {
92 Activator
.logError("Error creating module output listener", e
); //$NON-NLS-1$
96 return newModuleListeners
;