Commit | Line | Data |
---|---|---|
048bde85 | 1 | /******************************************************************************* |
38fad53e | 2 | * Copyright (c) 2016 École Polytechnique de Montréal and others |
048bde85 GB |
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 | 13 | package org.eclipse.tracecompass.tmf.analysis.xml.ui.module; |
048bde85 GB |
14 | |
15 | import java.io.File; | |
16 | import java.io.IOException; | |
1a23419e | 17 | import java.util.List; |
537572cd | 18 | import java.util.Map; |
048bde85 GB |
19 | |
20 | import javax.xml.parsers.DocumentBuilder; | |
21 | import javax.xml.parsers.DocumentBuilderFactory; | |
22 | import javax.xml.parsers.ParserConfigurationException; | |
23 | ||
44b06bb9 | 24 | import org.eclipse.jdt.annotation.NonNull; |
38fad53e | 25 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternAnalysis; |
2bdf0193 AM |
26 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.Activator; |
27 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings; | |
38fad53e | 28 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module.Messages; |
3b5dc745 | 29 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternDensityView; |
38fad53e | 30 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternLatencyTableView; |
c8e5d00e | 31 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternScatterGraphView; |
2bdf0193 AM |
32 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.xychart.XmlXYView; |
33 | import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils; | |
34 | import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings; | |
35 | import org.eclipse.tracecompass.tmf.analysis.xml.ui.views.timegraph.XmlTimeGraphView; | |
36 | import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule; | |
37 | import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisOutput; | |
38 | import org.eclipse.tracecompass.tmf.core.analysis.ITmfNewAnalysisModuleListener; | |
38fad53e | 39 | import org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems; |
048bde85 | 40 | import org.w3c.dom.Document; |
1a23419e FW |
41 | import org.w3c.dom.Element; |
42 | import org.w3c.dom.NodeList; | |
048bde85 GB |
43 | import org.xml.sax.SAXException; |
44 | ||
45 | /** | |
46 | * This class searches all XML files to find outputs applicable to the newly | |
47 | * created analysis | |
48 | * | |
49 | * @author Geneviève Bastien | |
50 | */ | |
51 | public class TmfXmlAnalysisOutputSource implements ITmfNewAnalysisModuleListener { | |
52 | ||
53 | /** String separating data elements for the output properties */ | |
8ecd89fa | 54 | public static final @NonNull String DATA_SEPARATOR = ";;;"; //$NON-NLS-1$ |
048bde85 | 55 | |
2e9d15a9 GB |
56 | /** |
57 | * Enum to match the name of a view's XML element to its view ID. | |
58 | */ | |
44b06bb9 GB |
59 | public static enum ViewType { |
60 | /** | |
61 | * Time graph view element | |
62 | */ | |
87c5447c | 63 | TIME_GRAPH_VIEW(TmfXmlUiStrings.TIME_GRAPH_VIEW, XmlTimeGraphView.ID), |
44b06bb9 GB |
64 | /** |
65 | * XY chart view element | |
66 | */ | |
87c5447c | 67 | XY_VIEW(TmfXmlUiStrings.XY_VIEW, XmlXYView.ID); |
2e9d15a9 | 68 | |
44b06bb9 | 69 | private final @NonNull String fXmlElem; |
2e9d15a9 GB |
70 | private final String fViewId; |
71 | ||
44b06bb9 | 72 | private ViewType(@NonNull String xmlElem, String viewId) { |
2e9d15a9 GB |
73 | fXmlElem = xmlElem; |
74 | fViewId = viewId; | |
75 | } | |
76 | ||
44b06bb9 GB |
77 | /** |
78 | * Get the XML element corresponding to this view type | |
79 | * | |
80 | * @return The XML element corresponding to this type | |
81 | */ | |
82 | public @NonNull String getXmlElem() { | |
2e9d15a9 GB |
83 | return fXmlElem; |
84 | } | |
85 | ||
44b06bb9 | 86 | private String getViewId() { |
2e9d15a9 GB |
87 | return fViewId; |
88 | } | |
89 | } | |
90 | ||
38fad53e JCK |
91 | /** |
92 | * Enum for latency view type. | |
93 | * | |
94 | * @author Jean-Christian Kouame | |
95 | * @since 2.0 | |
96 | * | |
97 | */ | |
98 | public static enum LatencyViewType { | |
99 | ||
100 | /** | |
101 | * Latency Table View type | |
102 | */ | |
c8e5d00e JCK |
103 | LATENCY_TABLE(PatternLatencyTableView.ID, Messages.TmfXmlAnalysisOutputSource_LatencyTable), |
104 | ||
105 | /** | |
106 | * Latency Scatter View type | |
107 | */ | |
3b5dc745 JCK |
108 | SCATTER_GRAPH(PatternScatterGraphView.ID, Messages.TmfXmlAnalysisOutputSource_ScatterGraphTitle), |
109 | ||
110 | /** | |
111 | * Latency Density View type | |
112 | */ | |
113 | DENSITY_VIEW(PatternDensityView.ID, Messages.TmfXmlAnalysisOutputSource_DensityChartTitle); | |
38fad53e JCK |
114 | |
115 | private @NonNull String fLatencyViewId; | |
116 | private String fLatencyViewLabel; | |
117 | ||
118 | private LatencyViewType(@NonNull String viewId, String label) { | |
119 | fLatencyViewId = viewId; | |
120 | fLatencyViewLabel = label; | |
121 | } | |
122 | ||
123 | /** | |
124 | * Get the ID of the latency view | |
125 | * | |
126 | * @return The ID | |
127 | */ | |
128 | public String getViewId() { | |
129 | return fLatencyViewId; | |
130 | } | |
131 | ||
132 | /** | |
133 | * Get the label of the view | |
134 | * | |
135 | * @return The label | |
136 | */ | |
137 | public String getLabel() { | |
138 | return fLatencyViewLabel; | |
139 | } | |
140 | } | |
87c5447c | 141 | |
048bde85 GB |
142 | @Override |
143 | public void moduleCreated(IAnalysisModule module) { | |
537572cd BH |
144 | Map<String, File> files = XmlUtils.listFiles(); |
145 | for (File xmlFile : files.values()) { | |
048bde85 GB |
146 | if (!XmlUtils.xmlValidate(xmlFile).isOK()) { |
147 | continue; | |
148 | } | |
149 | ||
150 | try { | |
151 | /* Load the XML File */ | |
152 | DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); | |
153 | DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); | |
154 | Document doc = dBuilder.parse(xmlFile); | |
155 | doc.getDocumentElement().normalize(); | |
156 | ||
157 | /* get state provider views if the analysis has state systems */ | |
38fad53e | 158 | if (module instanceof ITmfAnalysisModuleWithStateSystems) { |
2e9d15a9 GB |
159 | for (ViewType viewType : ViewType.values()) { |
160 | NodeList ssViewNodes = doc.getElementsByTagName(viewType.getXmlElem()); | |
161 | for (int i = 0; i < ssViewNodes.getLength(); i++) { | |
162 | Element node = (Element) ssViewNodes.item(i); | |
163 | ||
164 | /* Check if analysis is the right one */ | |
165 | List<Element> headNodes = XmlUtils.getChildElements(node, TmfXmlStrings.HEAD); | |
166 | if (headNodes.size() != 1) { | |
167 | continue; | |
168 | } | |
1a23419e | 169 | |
2e9d15a9 GB |
170 | List<Element> analysisNodes = XmlUtils.getChildElements(headNodes.get(0), TmfXmlStrings.ANALYSIS); |
171 | for (Element analysis : analysisNodes) { | |
172 | String analysisId = analysis.getAttribute(TmfXmlStrings.ID); | |
173 | if (analysisId.equals(module.getId())) { | |
174 | String viewId = viewType.getViewId(); | |
44b06bb9 | 175 | IAnalysisOutput output = new TmfXmlViewOutput(viewId, viewType); |
2e9d15a9 GB |
176 | output.setOutputProperty(TmfXmlUiStrings.XML_OUTPUT_DATA, node.getAttribute(TmfXmlStrings.ID) + DATA_SEPARATOR + xmlFile.getAbsolutePath(), false); |
177 | module.registerOutput(output); | |
178 | } | |
1a23419e FW |
179 | } |
180 | } | |
181 | } | |
182 | } | |
38fad53e | 183 | |
c8e5d00e | 184 | // Add the latency views for pattern analysis |
38fad53e JCK |
185 | if (module instanceof XmlPatternAnalysis) { |
186 | for (LatencyViewType viewType : LatencyViewType.values()) { | |
187 | IAnalysisOutput output = new TmfXmlLatencyViewOutput(viewType.getViewId(), viewType.getLabel()); | |
188 | output.setOutputProperty(TmfXmlUiStrings.XML_LATENCY_OUTPUT_DATA, module.getId() + DATA_SEPARATOR + viewType.getLabel(), false); | |
189 | module.registerOutput(output); | |
190 | } | |
191 | } | |
192 | ||
048bde85 GB |
193 | } catch (ParserConfigurationException | SAXException | IOException e) { |
194 | Activator.logError("Error opening XML file", e); //$NON-NLS-1$ | |
195 | } | |
196 | } | |
197 | } | |
198 | ||
199 | } |