1 /*******************************************************************************
2 * Copyright (c) 2016 École Polytechnique de Montréal and others
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
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.module
;
16 import java
.io
.IOException
;
17 import java
.util
.List
;
19 import java
.util
.stream
.Collectors
;
21 import javax
.xml
.parsers
.ParserConfigurationException
;
23 import org
.eclipse
.jdt
.annotation
.NonNull
;
24 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
25 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.core
.pattern
.stateprovider
.XmlPatternAnalysis
;
26 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.core
.stateprovider
.TmfXmlStrings
;
27 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.Activator
;
28 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.TmfXmlUiStrings
;
29 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.views
.latency
.PatternDensityView
;
30 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.views
.latency
.PatternLatencyTableView
;
31 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.views
.latency
.PatternScatterGraphView
;
32 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.views
.latency
.PatternStatisticsView
;
33 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.views
.timegraph
.XmlTimeGraphView
;
34 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.views
.xychart
.XmlXYView
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModule
;
36 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisOutput
;
37 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.ITmfNewAnalysisModuleListener
;
38 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.ITmfAnalysisModuleWithStateSystems
;
39 import org
.w3c
.dom
.Document
;
40 import org
.w3c
.dom
.Element
;
41 import org
.w3c
.dom
.NodeList
;
42 import org
.xml
.sax
.SAXException
;
45 * This class searches all XML files to find outputs applicable to the newly
48 * @author Geneviève Bastien
50 public class TmfXmlAnalysisOutputSource
implements ITmfNewAnalysisModuleListener
{
52 /** String separating data elements for the output properties */
53 public static final @NonNull String DATA_SEPARATOR
= ";;;"; //$NON-NLS-1$
56 * Enum to match the name of a view's XML element to its view ID.
58 public static enum ViewType
{
60 * Time graph view element
62 TIME_GRAPH_VIEW(TmfXmlUiStrings
.TIME_GRAPH_VIEW
, XmlTimeGraphView
.ID
),
64 * XY chart view element
66 XY_VIEW(TmfXmlUiStrings
.XY_VIEW
, XmlXYView
.ID
);
68 private final @NonNull String fXmlElem
;
69 private final String fViewId
;
71 private ViewType(@NonNull String xmlElem
, String viewId
) {
77 * Get the XML element corresponding to this view type
79 * @return The XML element corresponding to this type
81 public @NonNull String
getXmlElem() {
85 private String
getViewId() {
91 * Enum for latency view type.
93 * @author Jean-Christian Kouame
95 public static enum LatencyViewType
{
98 * Latency Table View type
100 LATENCY_TABLE(PatternLatencyTableView
.ID
, Messages
.TmfXmlAnalysisOutputSource_LatencyTable
),
103 * Latency Scatter View type
105 SCATTER_GRAPH(PatternScatterGraphView
.ID
, Messages
.TmfXmlAnalysisOutputSource_ScatterGraphTitle
),
108 * Latency Density View type
110 DENSITY_VIEW(PatternDensityView
.ID
, Messages
.TmfXmlAnalysisOutputSource_DensityChartTitle
),
113 * Latency Statistic View type
115 STATISTIC_VIEW(PatternStatisticsView
.ID
, Messages
.TmfXmlAnalysisOutputSource_LatencyStatisticsTitle
);
117 private @NonNull String fLatencyViewId
;
118 private String fLatencyViewLabel
;
120 private LatencyViewType(@NonNull String viewId
, String label
) {
121 fLatencyViewId
= viewId
;
122 fLatencyViewLabel
= label
;
126 * Get the ID of the latency view
130 public String
getViewId() {
131 return fLatencyViewId
;
135 * Get the label of the view
139 public String
getLabel() {
140 return fLatencyViewLabel
;
145 public void moduleCreated(IAnalysisModule module
) {
146 // Get all the XML files, builtin and not builtin
147 Set
<File
> files
= XmlUtils
.listBuiltinFiles().values().stream()
148 .map(p
-> p
.toFile())
149 .collect(Collectors
.toSet());
150 XmlUtils
.listFiles().values().stream()
151 .forEach(f
-> files
.add(f
));
153 for (File xmlFile
: files
) {
154 if (!XmlUtils
.xmlValidate(xmlFile
).isOK()) {
159 Document doc
= XmlUtils
.getDocumentFromFile(xmlFile
);
161 /* get state provider views if the analysis has state systems */
162 if (module
instanceof ITmfAnalysisModuleWithStateSystems
) {
163 for (ViewType viewType
: ViewType
.values()) {
164 NodeList ssViewNodes
= doc
.getElementsByTagName(viewType
.getXmlElem());
165 for (int i
= 0; i
< ssViewNodes
.getLength(); i
++) {
166 Element node
= (Element
) ssViewNodes
.item(i
);
168 /* Check if analysis is the right one */
169 List
<Element
> headNodes
= XmlUtils
.getChildElements(node
, TmfXmlStrings
.HEAD
);
170 if (headNodes
.size() != 1) {
174 List
<Element
> analysisNodes
= XmlUtils
.getChildElements(headNodes
.get(0), TmfXmlStrings
.ANALYSIS
);
175 for (Element analysis
: analysisNodes
) {
176 String analysisId
= analysis
.getAttribute(TmfXmlStrings
.ID
);
177 if (analysisId
.equals(module
.getId())) {
178 String viewId
= viewType
.getViewId();
179 IAnalysisOutput output
= new TmfXmlViewOutput(viewId
, viewType
);
180 output
.setOutputProperty(TmfXmlUiStrings
.XML_OUTPUT_DATA
, node
.getAttribute(TmfXmlStrings
.ID
) + DATA_SEPARATOR
+ xmlFile
.getAbsolutePath(), false);
181 module
.registerOutput(output
);
188 // Add the latency views for pattern analysis
189 if (module
instanceof XmlPatternAnalysis
) {
190 for (LatencyViewType viewType
: LatencyViewType
.values()) {
191 IAnalysisOutput output
= new TmfXmlLatencyViewOutput(viewType
.getViewId(), viewType
.getLabel());
192 output
.setOutputProperty(TmfXmlUiStrings
.XML_LATENCY_OUTPUT_DATA
, module
.getId() + DATA_SEPARATOR
+ viewType
.getLabel(), false);
193 module
.registerOutput(output
);
197 } catch (ParserConfigurationException
| SAXException
| IOException e
) {
198 Activator
.logError("Error opening XML file", e
); //$NON-NLS-1$