1 /*******************************************************************************
2 * Copyright (c) 2013 É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
.linuxtools
.tmf
.core
.analysis
;
15 import org
.eclipse
.core
.runtime
.ContributorFactoryOSGi
;
16 import org
.eclipse
.core
.runtime
.CoreException
;
17 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
18 import org
.eclipse
.core
.runtime
.InvalidRegistryObjectException
;
19 import org
.eclipse
.linuxtools
.internal
.tmf
.core
.Activator
;
20 import org
.eclipse
.linuxtools
.internal
.tmf
.core
.analysis
.TmfAnalysisModuleSourceConfigElement
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfAnalysisException
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
23 import org
.eclipse
.osgi
.util
.NLS
;
24 import org
.osgi
.framework
.Bundle
;
27 * Analysis module helper for modules provided by a plugin's configuration
30 * @author Geneviève Bastien
33 public class TmfAnalysisModuleHelperConfigElement
implements IAnalysisModuleHelper
{
35 private final IConfigurationElement fCe
;
41 * The source {@link IConfigurationElement} of this module helper
43 public TmfAnalysisModuleHelperConfigElement(IConfigurationElement ce
) {
47 // ----------------------------------------
48 // Wrappers to {@link IAnalysisModule} methods
49 // ----------------------------------------
52 public String
getId() {
53 return fCe
.getAttribute(TmfAnalysisModuleSourceConfigElement
.ID_ATTR
);
57 public String
getName() {
58 return fCe
.getAttribute(TmfAnalysisModuleSourceConfigElement
.NAME_ATTR
);
62 public boolean isAutomatic() {
63 return Boolean
.parseBoolean(fCe
.getAttribute(TmfAnalysisModuleSourceConfigElement
.AUTOMATIC_ATTR
));
67 public String
getHelpText() {
69 * FIXME: No need to externalize this. A better solution will be found
70 * soon and this string is just temporary
72 return new String("The trace must be opened to get the help message"); //$NON-NLS-1$
76 public String
getIcon() {
77 return fCe
.getAttribute(TmfAnalysisModuleSourceConfigElement
.ICON_ATTR
);
81 public Bundle
getBundle() {
82 return ContributorFactoryOSGi
.resolve(fCe
.getContributor());
86 public boolean appliesToTraceType(Class
<?
extends ITmfTrace
> traceclass
) {
87 boolean applies
= false;
89 /* Get the module's applying tracetypes */
90 final IConfigurationElement
[] tracetypeCE
= fCe
.getChildren(TmfAnalysisModuleSourceConfigElement
.TRACETYPE_ELEM
);
91 for (IConfigurationElement element
: tracetypeCE
) {
94 applyclass
= getBundle().loadClass(element
.getAttribute(TmfAnalysisModuleSourceConfigElement
.CLASS_ATTR
));
95 String classAppliesVal
= element
.getAttribute(TmfAnalysisModuleSourceConfigElement
.APPLIES_ATTR
);
96 boolean classApplies
= true;
97 if (classAppliesVal
!= null) {
98 classApplies
= Boolean
.parseBoolean(classAppliesVal
);
101 applies
= applyclass
.isAssignableFrom(traceclass
);
103 applies
= !applyclass
.isAssignableFrom(traceclass
);
105 } catch (ClassNotFoundException e
) {
106 Activator
.logError("Error in applies to trace", e
); //$NON-NLS-1$
107 } catch (InvalidRegistryObjectException e
) {
108 Activator
.logError("Error in applies to trace", e
); //$NON-NLS-1$
114 // ---------------------------------------
116 // ---------------------------------------
119 public IAnalysisModule
newModule(ITmfTrace trace
) throws TmfAnalysisException
{
121 /* Check that analysis can be executed */
122 if (!appliesToTraceType(trace
.getClass())) {
123 throw new TmfAnalysisException(NLS
.bind(Messages
.TmfAnalysisModuleHelper_AnalysisDoesNotApply
, getName()));
126 IAnalysisModule module
= null;
128 module
= (IAnalysisModule
) fCe
.createExecutableExtension(TmfAnalysisModuleSourceConfigElement
.ANALYSIS_MODULE_ATTR
);
129 module
.setName(getName());
130 module
.setId(getId());
131 module
.setAutomatic(isAutomatic());
133 /* Get the module's parameters */
134 final IConfigurationElement
[] parametersCE
= fCe
.getChildren(TmfAnalysisModuleSourceConfigElement
.PARAMETER_ELEM
);
135 for (IConfigurationElement element
: parametersCE
) {
136 module
.addParameter(element
.getAttribute(TmfAnalysisModuleSourceConfigElement
.NAME_ATTR
));
137 String defaultValue
= element
.getAttribute(TmfAnalysisModuleSourceConfigElement
.DEFAULT_VALUE_ATTR
);
138 if (defaultValue
!= null) {
139 module
.setParameter(element
.getAttribute(TmfAnalysisModuleSourceConfigElement
.NAME_ATTR
), defaultValue
);
142 module
.setTrace(trace
);
143 TmfAnalysisManager
.analysisModuleCreated(module
);
144 } catch (CoreException e
) {
145 Activator
.logError("Error getting analysis modules from configuration files", e
); //$NON-NLS-1$