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
.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
;
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
98 public static enum LatencyViewType
{
101 * Latency Table View type
103 LATENCY_TABLE(PatternLatencyTableView
.ID
, Messages
.TmfXmlAnalysisOutputSource_LatencyTable
),
106 * Latency Scatter View type
108 SCATTER_GRAPH(PatternScatterGraphView
.ID
, Messages
.TmfXmlAnalysisOutputSource_ScatterGraphTitle
),
111 * Latency Density View type
113 DENSITY_VIEW(PatternDensityView
.ID
, Messages
.TmfXmlAnalysisOutputSource_DensityChartTitle
);
115 private @NonNull String fLatencyViewId
;
116 private String fLatencyViewLabel
;
118 private LatencyViewType(@NonNull String viewId
, String label
) {
119 fLatencyViewId
= viewId
;
120 fLatencyViewLabel
= label
;
124 * Get the ID of the latency view
128 public String
getViewId() {
129 return fLatencyViewId
;
133 * Get the label of the view
137 public String
getLabel() {
138 return fLatencyViewLabel
;
143 public void moduleCreated(IAnalysisModule module
) {
144 Map
<String
, File
> files
= XmlUtils
.listFiles();
145 for (File xmlFile
: files
.values()) {
146 if (!XmlUtils
.xmlValidate(xmlFile
).isOK()) {
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();
157 /* get state provider views if the analysis has state systems */
158 if (module
instanceof ITmfAnalysisModuleWithStateSystems
) {
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
);
164 /* Check if analysis is the right one */
165 List
<Element
> headNodes
= XmlUtils
.getChildElements(node
, TmfXmlStrings
.HEAD
);
166 if (headNodes
.size() != 1) {
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();
175 IAnalysisOutput output
= new TmfXmlViewOutput(viewId
, viewType
);
176 output
.setOutputProperty(TmfXmlUiStrings
.XML_OUTPUT_DATA
, node
.getAttribute(TmfXmlStrings
.ID
) + DATA_SEPARATOR
+ xmlFile
.getAbsolutePath(), false);
177 module
.registerOutput(output
);
184 // Add the latency views for pattern analysis
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
);
193 } catch (ParserConfigurationException
| SAXException
| IOException e
) {
194 Activator
.logError("Error opening XML file", e
); //$NON-NLS-1$