tmf: Fix most Number unboxing problems
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / analysis / TmfAnalysisModuleHelperConfigElement.java
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.tmf.core.analysis;
14
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;
25
26 /**
27 * Analysis module helper for modules provided by a plugin's configuration
28 * elements.
29 *
30 * @author Geneviève Bastien
31 * @since 3.0
32 */
33 public class TmfAnalysisModuleHelperConfigElement implements IAnalysisModuleHelper {
34
35 private final IConfigurationElement fCe;
36
37 /**
38 * Constructor
39 *
40 * @param ce
41 * The source {@link IConfigurationElement} of this module helper
42 */
43 public TmfAnalysisModuleHelperConfigElement(IConfigurationElement ce) {
44 fCe = ce;
45 }
46
47 // ----------------------------------------
48 // Wrappers to {@link IAnalysisModule} methods
49 // ----------------------------------------
50
51 @Override
52 public String getId() {
53 return fCe.getAttribute(TmfAnalysisModuleSourceConfigElement.ID_ATTR);
54 }
55
56 @Override
57 public String getName() {
58 return fCe.getAttribute(TmfAnalysisModuleSourceConfigElement.NAME_ATTR);
59 }
60
61 @Override
62 public boolean isAutomatic() {
63 return Boolean.parseBoolean(fCe.getAttribute(TmfAnalysisModuleSourceConfigElement.AUTOMATIC_ATTR));
64 }
65
66 @Override
67 public String getHelpText() {
68 /*
69 * FIXME: No need to externalize this. A better solution will be found
70 * soon and this string is just temporary
71 */
72 return new String("The trace must be opened to get the help message"); //$NON-NLS-1$
73 }
74
75 @Override
76 public String getIcon() {
77 return fCe.getAttribute(TmfAnalysisModuleSourceConfigElement.ICON_ATTR);
78 }
79
80 @Override
81 public Bundle getBundle() {
82 return ContributorFactoryOSGi.resolve(fCe.getContributor());
83 }
84
85 @Override
86 public boolean appliesToTraceType(Class<? extends ITmfTrace> traceclass) {
87 boolean applies = false;
88
89 /* Get the module's applying tracetypes */
90 final IConfigurationElement[] tracetypeCE = fCe.getChildren(TmfAnalysisModuleSourceConfigElement.TRACETYPE_ELEM);
91 for (IConfigurationElement element : tracetypeCE) {
92 Class<?> applyclass;
93 try {
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);
99 }
100 if (classApplies) {
101 applies = applyclass.isAssignableFrom(traceclass);
102 } else {
103 applies = !applyclass.isAssignableFrom(traceclass);
104 }
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$
109 }
110 }
111 return applies;
112 }
113
114 // ---------------------------------------
115 // Functionalities
116 // ---------------------------------------
117
118 @Override
119 public IAnalysisModule newModule(ITmfTrace trace) throws TmfAnalysisException {
120
121 /* Check that analysis can be executed */
122 if (!appliesToTraceType(trace.getClass())) {
123 throw new TmfAnalysisException(NLS.bind(Messages.TmfAnalysisModuleHelper_AnalysisDoesNotApply, getName()));
124 }
125
126 IAnalysisModule module = null;
127 try {
128 module = (IAnalysisModule) fCe.createExecutableExtension(TmfAnalysisModuleSourceConfigElement.ANALYSIS_MODULE_ATTR);
129 module.setName(getName());
130 module.setId(getId());
131 module.setAutomatic(isAutomatic());
132
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);
140 }
141 }
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$
146 }
147 return module;
148
149 }
150
151 }
This page took 0.033841 seconds and 5 git commands to generate.