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
;
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
.module
.XmlUtils
;
26 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.core
.pattern
.stateprovider
.XmlPatternAnalysis
;
27 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.core
.stateprovider
.TmfXmlStrings
;
28 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.Activator
;
29 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.TmfXmlUiStrings
;
30 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.views
.latency
.PatternDensityView
;
31 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.views
.latency
.PatternLatencyTableView
;
32 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.views
.latency
.PatternScatterGraphView
;
33 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.views
.latency
.PatternStatisticsView
;
34 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.views
.timegraph
.XmlTimeGraphView
;
35 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.views
.xychart
.XmlXYView
;
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
;
39 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.ITmfAnalysisModuleWithStateSystems
;
40 import org
.w3c
.dom
.Document
;
41 import org
.w3c
.dom
.Element
;
42 import org
.w3c
.dom
.NodeList
;
43 import org
.xml
.sax
.SAXException
;
46 * This class searches all XML files to find outputs applicable to the newly
49 * @author Geneviève Bastien
51 public class TmfXmlAnalysisOutputSource
implements ITmfNewAnalysisModuleListener
{
53 /** String separating data elements for the output properties */
54 public static final @NonNull String DATA_SEPARATOR
= ";;;"; //$NON-NLS-1$
57 * Enum to match the name of a view's XML element to its view ID.
59 public static enum ViewType
{
61 * Time graph view element
63 TIME_GRAPH_VIEW(TmfXmlUiStrings
.TIME_GRAPH_VIEW
, XmlTimeGraphView
.ID
),
65 * XY chart view element
67 XY_VIEW(TmfXmlUiStrings
.XY_VIEW
, XmlXYView
.ID
);
69 private final @NonNull String fXmlElem
;
70 private final String fViewId
;
72 private ViewType(@NonNull String xmlElem
, String viewId
) {
78 * Get the XML element corresponding to this view type
80 * @return The XML element corresponding to this type
82 public @NonNull String
getXmlElem() {
86 private String
getViewId() {
92 * Enum for latency view type.
94 * @author Jean-Christian Kouame
96 public static enum LatencyViewType
{
99 * Latency Table View type
101 LATENCY_TABLE(PatternLatencyTableView
.ID
, Messages
.TmfXmlAnalysisOutputSource_LatencyTable
),
104 * Latency Scatter View type
106 SCATTER_GRAPH(PatternScatterGraphView
.ID
, Messages
.TmfXmlAnalysisOutputSource_ScatterGraphTitle
),
109 * Latency Density View type
111 DENSITY_VIEW(PatternDensityView
.ID
, Messages
.TmfXmlAnalysisOutputSource_DensityChartTitle
),
114 * Latency Statistic View type
116 STATISTIC_VIEW(PatternStatisticsView
.ID
, Messages
.TmfXmlAnalysisOutputSource_LatencyStatisticsTitle
);
118 private @NonNull String fLatencyViewId
;
119 private String fLatencyViewLabel
;
121 private LatencyViewType(@NonNull String viewId
, String label
) {
122 fLatencyViewId
= viewId
;
123 fLatencyViewLabel
= label
;
127 * Get the ID of the latency view
131 public String
getViewId() {
132 return fLatencyViewId
;
136 * Get the label of the view
140 public String
getLabel() {
141 return fLatencyViewLabel
;
146 public void moduleCreated(IAnalysisModule module
) {
147 Map
<String
, File
> files
= XmlUtils
.listFiles();
148 for (File xmlFile
: files
.values()) {
149 if (!XmlUtils
.xmlValidate(xmlFile
).isOK()) {
154 /* Load the XML File */
155 DocumentBuilderFactory dbFactory
= DocumentBuilderFactory
.newInstance();
156 DocumentBuilder dBuilder
= dbFactory
.newDocumentBuilder();
157 Document doc
= dBuilder
.parse(xmlFile
);
158 doc
.getDocumentElement().normalize();
160 /* get state provider views if the analysis has state systems */
161 if (module
instanceof ITmfAnalysisModuleWithStateSystems
) {
162 for (ViewType viewType
: ViewType
.values()) {
163 NodeList ssViewNodes
= doc
.getElementsByTagName(viewType
.getXmlElem());
164 for (int i
= 0; i
< ssViewNodes
.getLength(); i
++) {
165 Element node
= (Element
) ssViewNodes
.item(i
);
167 /* Check if analysis is the right one */
168 List
<Element
> headNodes
= XmlUtils
.getChildElements(node
, TmfXmlStrings
.HEAD
);
169 if (headNodes
.size() != 1) {
173 List
<Element
> analysisNodes
= XmlUtils
.getChildElements(headNodes
.get(0), TmfXmlStrings
.ANALYSIS
);
174 for (Element analysis
: analysisNodes
) {
175 String analysisId
= analysis
.getAttribute(TmfXmlStrings
.ID
);
176 if (analysisId
.equals(module
.getId())) {
177 String viewId
= viewType
.getViewId();
178 IAnalysisOutput output
= new TmfXmlViewOutput(viewId
, viewType
);
179 output
.setOutputProperty(TmfXmlUiStrings
.XML_OUTPUT_DATA
, node
.getAttribute(TmfXmlStrings
.ID
) + DATA_SEPARATOR
+ xmlFile
.getAbsolutePath(), false);
180 module
.registerOutput(output
);
187 // Add the latency views for pattern analysis
188 if (module
instanceof XmlPatternAnalysis
) {
189 for (LatencyViewType viewType
: LatencyViewType
.values()) {
190 IAnalysisOutput output
= new TmfXmlLatencyViewOutput(viewType
.getViewId(), viewType
.getLabel());
191 output
.setOutputProperty(TmfXmlUiStrings
.XML_LATENCY_OUTPUT_DATA
, module
.getId() + DATA_SEPARATOR
+ viewType
.getLabel(), false);
192 module
.registerOutput(output
);
196 } catch (ParserConfigurationException
| SAXException
| IOException e
) {
197 Activator
.logError("Error opening XML file", e
); //$NON-NLS-1$