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
.tmf
.analysis
.xml
.ui
.module
;
16 import java
.io
.IOException
;
17 import java
.util
.List
;
20 import javax
.xml
.parsers
.DocumentBuilder
;
21 import javax
.xml
.parsers
.DocumentBuilderFactory
;
22 import javax
.xml
.parsers
.ParserConfigurationException
;
24 import org
.eclipse
.jdt
.annotation
.NonNull
;
25 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.core
.pattern
.stateprovider
.XmlPatternAnalysis
;
26 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.Activator
;
27 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.TmfXmlUiStrings
;
28 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.module
.Messages
;
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
.xychart
.XmlXYView
;
34 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
35 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.stateprovider
.TmfXmlStrings
;
36 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.ui
.views
.timegraph
.XmlTimeGraphView
;
37 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModule
;
38 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisOutput
;
39 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.ITmfNewAnalysisModuleListener
;
40 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.ITmfAnalysisModuleWithStateSystems
;
41 import org
.w3c
.dom
.Document
;
42 import org
.w3c
.dom
.Element
;
43 import org
.w3c
.dom
.NodeList
;
44 import org
.xml
.sax
.SAXException
;
47 * This class searches all XML files to find outputs applicable to the newly
50 * @author Geneviève Bastien
52 public class TmfXmlAnalysisOutputSource
implements ITmfNewAnalysisModuleListener
{
54 /** String separating data elements for the output properties */
55 public static final @NonNull String DATA_SEPARATOR
= ";;;"; //$NON-NLS-1$
58 * Enum to match the name of a view's XML element to its view ID.
60 public static enum ViewType
{
62 * Time graph view element
64 TIME_GRAPH_VIEW(TmfXmlUiStrings
.TIME_GRAPH_VIEW
, XmlTimeGraphView
.ID
),
66 * XY chart view element
68 XY_VIEW(TmfXmlUiStrings
.XY_VIEW
, XmlXYView
.ID
);
70 private final @NonNull String fXmlElem
;
71 private final String fViewId
;
73 private ViewType(@NonNull String xmlElem
, String viewId
) {
79 * Get the XML element corresponding to this view type
81 * @return The XML element corresponding to this type
83 public @NonNull String
getXmlElem() {
87 private String
getViewId() {
93 * Enum for latency view type.
95 * @author Jean-Christian Kouame
99 public static enum LatencyViewType
{
102 * Latency Table View type
104 LATENCY_TABLE(PatternLatencyTableView
.ID
, Messages
.TmfXmlAnalysisOutputSource_LatencyTable
),
107 * Latency Scatter View type
109 SCATTER_GRAPH(PatternScatterGraphView
.ID
, Messages
.TmfXmlAnalysisOutputSource_ScatterGraphTitle
),
112 * Latency Density View type
114 DENSITY_VIEW(PatternDensityView
.ID
, Messages
.TmfXmlAnalysisOutputSource_DensityChartTitle
),
117 * Latency Statistic View type
119 STATISTIC_VIEW(PatternStatisticsView
.ID
, Messages
.TmfXmlAnalysisOutputSource_LatencyStatisticsTitle
);
121 private @NonNull String fLatencyViewId
;
122 private String fLatencyViewLabel
;
124 private LatencyViewType(@NonNull String viewId
, String label
) {
125 fLatencyViewId
= viewId
;
126 fLatencyViewLabel
= label
;
130 * Get the ID of the latency view
134 public String
getViewId() {
135 return fLatencyViewId
;
139 * Get the label of the view
143 public String
getLabel() {
144 return fLatencyViewLabel
;
149 public void moduleCreated(IAnalysisModule module
) {
150 Map
<String
, File
> files
= XmlUtils
.listFiles();
151 for (File xmlFile
: files
.values()) {
152 if (!XmlUtils
.xmlValidate(xmlFile
).isOK()) {
157 /* Load the XML File */
158 DocumentBuilderFactory dbFactory
= DocumentBuilderFactory
.newInstance();
159 DocumentBuilder dBuilder
= dbFactory
.newDocumentBuilder();
160 Document doc
= dBuilder
.parse(xmlFile
);
161 doc
.getDocumentElement().normalize();
163 /* get state provider views if the analysis has state systems */
164 if (module
instanceof ITmfAnalysisModuleWithStateSystems
) {
165 for (ViewType viewType
: ViewType
.values()) {
166 NodeList ssViewNodes
= doc
.getElementsByTagName(viewType
.getXmlElem());
167 for (int i
= 0; i
< ssViewNodes
.getLength(); i
++) {
168 Element node
= (Element
) ssViewNodes
.item(i
);
170 /* Check if analysis is the right one */
171 List
<Element
> headNodes
= XmlUtils
.getChildElements(node
, TmfXmlStrings
.HEAD
);
172 if (headNodes
.size() != 1) {
176 List
<Element
> analysisNodes
= XmlUtils
.getChildElements(headNodes
.get(0), TmfXmlStrings
.ANALYSIS
);
177 for (Element analysis
: analysisNodes
) {
178 String analysisId
= analysis
.getAttribute(TmfXmlStrings
.ID
);
179 if (analysisId
.equals(module
.getId())) {
180 String viewId
= viewType
.getViewId();
181 IAnalysisOutput output
= new TmfXmlViewOutput(viewId
, viewType
);
182 output
.setOutputProperty(TmfXmlUiStrings
.XML_OUTPUT_DATA
, node
.getAttribute(TmfXmlStrings
.ID
) + DATA_SEPARATOR
+ xmlFile
.getAbsolutePath(), false);
183 module
.registerOutput(output
);
190 // Add the latency views for pattern analysis
191 if (module
instanceof XmlPatternAnalysis
) {
192 for (LatencyViewType viewType
: LatencyViewType
.values()) {
193 IAnalysisOutput output
= new TmfXmlLatencyViewOutput(viewType
.getViewId(), viewType
.getLabel());
194 output
.setOutputProperty(TmfXmlUiStrings
.XML_LATENCY_OUTPUT_DATA
, module
.getId() + DATA_SEPARATOR
+ viewType
.getLabel(), false);
195 module
.registerOutput(output
);
199 } catch (ParserConfigurationException
| SAXException
| IOException e
) {
200 Activator
.logError("Error opening XML file", e
); //$NON-NLS-1$