TMF: Cache average char width to speed up control flow drawing.
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.analysis.xml.ui / src / org / eclipse / tracecompass / tmf / analysis / xml / ui / module / TmfAnalysisModuleHelperXml.java
CommitLineData
97ed0cf0
FW
1/*******************************************************************************
2 * Copyright (c) 2014 É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
2bdf0193 13package org.eclipse.tracecompass.tmf.analysis.xml.ui.module;
97ed0cf0 14
5db5a3a4
AM
15import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
16
97ed0cf0 17import java.io.File;
63c43609 18import java.util.Collections;
aa89118c 19import java.util.List;
97ed0cf0
FW
20
21import org.eclipse.core.runtime.Path;
54eae41f 22import org.eclipse.jdt.annotation.NonNull;
2bdf0193
AM
23import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.Activator;
24import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
25import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
26import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
27import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
28import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper;
29import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisManager;
30import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisRequirement;
31import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
32import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
33import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper;
34import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
97ed0cf0
FW
35import org.osgi.framework.Bundle;
36import org.w3c.dom.Element;
97ed0cf0
FW
37
38/**
39 * Analysis module helpers for modules provided by XML files
40 *
41 * @author Geneviève Bastien
42 */
43public class TmfAnalysisModuleHelperXml implements IAnalysisModuleHelper {
44
45 /**
46 * The types of analysis that can be XML-defined
47 */
48 public enum XmlAnalysisModuleType {
49 /** Analysis will be of type XmlStateSystemModule */
50 STATE_SYSTEM
51 }
52
53 private final File fSourceFile;
54 private final Element fSourceElement;
55 private final XmlAnalysisModuleType fType;
97ed0cf0
FW
56
57 /**
58 * Constructor
59 *
60 * @param xmlFile
61 * The XML file containing the details of this analysis
62 * @param node
63 * The XML node element
64 * @param type
65 * The type of analysis
66 */
67 public TmfAnalysisModuleHelperXml(File xmlFile, Element node, XmlAnalysisModuleType type) {
68 fSourceFile = xmlFile;
69 fSourceElement = node;
70 fType = type;
97ed0cf0
FW
71 }
72
73 @Override
74 public String getId() {
ba27dd38
GB
75 /*
76 * The attribute ID cannot be null because the XML has been validated
77 * and it is mandatory
78 */
5db5a3a4 79 return checkNotNull(fSourceElement.getAttribute(TmfXmlStrings.ID));
97ed0cf0
FW
80 }
81
82 @Override
83 public String getName() {
aa89118c
GB
84 String name = null;
85 /* Label may be available in XML header */
86 List<Element> head = XmlUtils.getChildElements(fSourceElement, TmfXmlStrings.HEAD);
87 if (head.size() == 1) {
88 List<Element> labels = XmlUtils.getChildElements(head.get(0), TmfXmlStrings.LABEL);
89 if (!labels.isEmpty()) {
90 name = labels.get(0).getAttribute(TmfXmlStrings.VALUE);
91 }
92 }
93
97ed0cf0
FW
94 if (name == null) {
95 name = getId();
96 }
97 return name;
98 }
99
100 @Override
101 public boolean isAutomatic() {
102 return false;
103 }
104
105 @Override
106 public String getHelpText() {
107 return new String();
108 }
109
54eae41f
GB
110 @Override
111 public String getHelpText(@NonNull ITmfTrace trace) {
112 return ""; //$NON-NLS-1$
113 }
114
97ed0cf0
FW
115 @Override
116 public String getIcon() {
117 return null;
118 }
119
120 @Override
121 public Bundle getBundle() {
122 return Activator.getDefault().getBundle();
123 }
124
125 @Override
aa89118c 126 public boolean appliesToTraceType(Class<? extends ITmfTrace> traceClass) {
97ed0cf0 127 /* Trace types may be available in XML header */
aa89118c
GB
128 List<Element> head = XmlUtils.getChildElements(fSourceElement, TmfXmlStrings.HEAD);
129 if (head.size() != 1) {
130 return true;
131 }
132 /*
133 * TODO: Test with custom trace types
134 */
135 List<Element> elements = XmlUtils.getChildElements(head.get(0), TmfXmlStrings.TRACETYPE);
136 if (elements.isEmpty()) {
97ed0cf0
FW
137 return true;
138 }
139
aa89118c
GB
140 for (Element element : elements) {
141 String traceTypeId = element.getAttribute(TmfXmlStrings.ID);
e86f7ac4 142 traceTypeId = TmfTraceType.buildCompatibilityTraceTypeId(traceTypeId);
a4a116c3 143 TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
aa89118c
GB
144 if ((helper != null) && helper.getTrace().getClass().isAssignableFrom(traceClass)) {
145 return true;
146 }
147 }
148 return false;
97ed0cf0
FW
149 }
150
63c43609
MR
151 @Override
152 public Iterable<Class<? extends ITmfTrace>> getValidTraceTypes() {
153 return Collections.EMPTY_SET;
154 }
155
156 @Override
157 public Iterable<TmfAnalysisRequirement> getAnalysisRequirements() {
158 return Collections.EMPTY_SET;
159 }
160
97ed0cf0
FW
161 @Override
162 public IAnalysisModule newModule(ITmfTrace trace) throws TmfAnalysisException {
163 String analysisid = getId();
164 IAnalysisModule module = null;
165 switch (fType) {
166 case STATE_SYSTEM:
167 module = new XmlStateSystemModule();
168 XmlStateSystemModule ssModule = (XmlStateSystemModule) module;
169 module.setId(analysisid);
170 ssModule.setXmlFile(new Path(fSourceFile.getAbsolutePath()));
171
048bde85
GB
172 /*
173 * FIXME: There is no way to know if a module is automatic, so we
174 * default to true
175 */
176 ssModule.setAutomatic(true);
97ed0cf0 177
97ed0cf0
FW
178 break;
179 default:
180 break;
181
182 }
183 if (module != null) {
184 module.setTrace(trace);
048bde85 185 TmfAnalysisManager.analysisModuleCreated(module);
97ed0cf0
FW
186 }
187
188 return module;
189 }
190
191}
This page took 0.063302 seconds and 5 git commands to generate.