tmf: Remove redundant CtfTmfEvent.getEventName() method
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / analysis / TmfAnalysisModuleHelperConfigElement.java
CommitLineData
c068a752
GB
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
13package org.eclipse.linuxtools.tmf.core.analysis;
14
15import org.eclipse.core.runtime.ContributorFactoryOSGi;
16import org.eclipse.core.runtime.CoreException;
17import org.eclipse.core.runtime.IConfigurationElement;
18import org.eclipse.core.runtime.InvalidRegistryObjectException;
19import org.eclipse.linuxtools.internal.tmf.core.Activator;
b3b03da0 20import org.eclipse.linuxtools.internal.tmf.core.analysis.TmfAnalysisModuleSourceConfigElement;
c068a752
GB
21import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
22import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
23import org.eclipse.osgi.util.NLS;
24import org.osgi.framework.Bundle;
25
26/**
27 * Analysis module helper for modules provided by a plugin's configuration
28 * elements.
29 *
30 * @author Geneviève Bastien
c4767854 31 * @since 3.0
c068a752 32 */
b3b03da0 33public class TmfAnalysisModuleHelperConfigElement implements IAnalysisModuleHelper {
c068a752
GB
34
35 private final IConfigurationElement fCe;
36
37 /**
38 * Constructor
39 *
40 * @param ce
41 * The source {@link IConfigurationElement} of this module helper
42 */
b3b03da0 43 public TmfAnalysisModuleHelperConfigElement(IConfigurationElement ce) {
c068a752
GB
44 fCe = ce;
45 }
46
47 // ----------------------------------------
48 // Wrappers to {@link IAnalysisModule} methods
49 // ----------------------------------------
50
51 @Override
52 public String getId() {
b3b03da0 53 return fCe.getAttribute(TmfAnalysisModuleSourceConfigElement.ID_ATTR);
c068a752
GB
54 }
55
56 @Override
57 public String getName() {
b3b03da0 58 return fCe.getAttribute(TmfAnalysisModuleSourceConfigElement.NAME_ATTR);
c068a752
GB
59 }
60
61 @Override
62 public boolean isAutomatic() {
b3b03da0 63 return Boolean.valueOf(fCe.getAttribute(TmfAnalysisModuleSourceConfigElement.AUTOMATIC_ATTR));
c068a752
GB
64 }
65
66 @Override
67 public String getHelpText() {
68 return new String();
69 }
70
71 @Override
72 public String getIcon() {
b3b03da0 73 return fCe.getAttribute(TmfAnalysisModuleSourceConfigElement.ICON_ATTR);
c068a752
GB
74 }
75
76 @Override
77 public Bundle getBundle() {
78 return ContributorFactoryOSGi.resolve(fCe.getContributor());
79 }
80
81 @Override
82 public boolean appliesToTraceType(Class<? extends ITmfTrace> traceclass) {
83 boolean applies = false;
84
85 /* Get the module's applying tracetypes */
b3b03da0 86 final IConfigurationElement[] tracetypeCE = fCe.getChildren(TmfAnalysisModuleSourceConfigElement.TRACETYPE_ELEM);
c068a752
GB
87 for (IConfigurationElement element : tracetypeCE) {
88 Class<?> applyclass;
89 try {
b3b03da0
GB
90 applyclass = getBundle().loadClass(element.getAttribute(TmfAnalysisModuleSourceConfigElement.CLASS_ATTR));
91 String classAppliesVal = element.getAttribute(TmfAnalysisModuleSourceConfigElement.APPLIES_ATTR);
c068a752
GB
92 boolean classApplies = true;
93 if (classAppliesVal != null) {
94 classApplies = Boolean.valueOf(classAppliesVal);
95 }
96 if (classApplies) {
97 applies = applyclass.isAssignableFrom(traceclass);
98 } else {
99 applies = !applyclass.isAssignableFrom(traceclass);
100 }
101 } catch (ClassNotFoundException e) {
102 Activator.logError("Error in applies to trace", e); //$NON-NLS-1$
103 } catch (InvalidRegistryObjectException e) {
104 Activator.logError("Error in applies to trace", e); //$NON-NLS-1$
105 }
106 }
107 return applies;
108 }
109
110 // ---------------------------------------
111 // Functionalities
112 // ---------------------------------------
113
114 @Override
115 public IAnalysisModule newModule(ITmfTrace trace) throws TmfAnalysisException {
116
117 /* Check that analysis can be executed */
118 if (!appliesToTraceType(trace.getClass())) {
119 throw new TmfAnalysisException(NLS.bind(Messages.TmfAnalysisModuleHelper_AnalysisDoesNotApply, getName()));
120 }
121
122 IAnalysisModule module = null;
123 try {
b3b03da0 124 module = (IAnalysisModule) fCe.createExecutableExtension(TmfAnalysisModuleSourceConfigElement.ANALYSIS_MODULE_ATTR);
c068a752
GB
125 module.setName(getName());
126 module.setId(getId());
127 module.setAutomatic(isAutomatic());
128
129 /* Get the module's parameters */
b3b03da0 130 final IConfigurationElement[] parametersCE = fCe.getChildren(TmfAnalysisModuleSourceConfigElement.PARAMETER_ELEM);
c068a752 131 for (IConfigurationElement element : parametersCE) {
b3b03da0
GB
132 module.addParameter(element.getAttribute(TmfAnalysisModuleSourceConfigElement.NAME_ATTR));
133 String defaultValue = element.getAttribute(TmfAnalysisModuleSourceConfigElement.DEFAULT_VALUE_ATTR);
c068a752 134 if (defaultValue != null) {
b3b03da0 135 module.setParameter(element.getAttribute(TmfAnalysisModuleSourceConfigElement.NAME_ATTR), defaultValue);
c068a752
GB
136 }
137 }
138 module.setTrace(trace);
139 } catch (CoreException e) {
140 Activator.logError("Error getting analysis modules from configuration files", e); //$NON-NLS-1$
141 }
142 return module;
143
144 }
145
146}
This page took 0.032515 seconds and 5 git commands to generate.