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
.ParserConfigurationException
;
22 import org
.eclipse
.jdt
.annotation
.NonNull
;
23 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
24 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.core
.pattern
.stateprovider
.XmlPatternAnalysis
;
25 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.core
.stateprovider
.TmfXmlStrings
;
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
.views
.latency
.PatternDensityView
;
29 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.views
.latency
.PatternLatencyTableView
;
30 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.views
.latency
.PatternScatterGraphView
;
31 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.views
.latency
.PatternStatisticsView
;
32 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.views
.timegraph
.XmlTimeGraphView
;
33 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.views
.xychart
.XmlXYView
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModule
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisOutput
;
36 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.ITmfNewAnalysisModuleListener
;
37 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.ITmfAnalysisModuleWithStateSystems
;
38 import org
.w3c
.dom
.Document
;
39 import org
.w3c
.dom
.Element
;
40 import org
.w3c
.dom
.NodeList
;
41 import org
.xml
.sax
.SAXException
;
44 * This class searches all XML files to find outputs applicable to the newly
47 * @author Geneviève Bastien
49 public class TmfXmlAnalysisOutputSource
implements ITmfNewAnalysisModuleListener
{
51 /** String separating data elements for the output properties */
52 public static final @NonNull String DATA_SEPARATOR
= ";;;"; //$NON-NLS-1$
55 * Enum to match the name of a view's XML element to its view ID.
57 public static enum ViewType
{
59 * Time graph view element
61 TIME_GRAPH_VIEW(TmfXmlUiStrings
.TIME_GRAPH_VIEW
, XmlTimeGraphView
.ID
),
63 * XY chart view element
65 XY_VIEW(TmfXmlUiStrings
.XY_VIEW
, XmlXYView
.ID
);
67 private final @NonNull String fXmlElem
;
68 private final String fViewId
;
70 private ViewType(@NonNull String xmlElem
, String viewId
) {
76 * Get the XML element corresponding to this view type
78 * @return The XML element corresponding to this type
80 public @NonNull String
getXmlElem() {
84 private String
getViewId() {
90 * Enum for latency view type.
92 * @author Jean-Christian Kouame
94 public static enum LatencyViewType
{
97 * Latency Table View type
99 LATENCY_TABLE(PatternLatencyTableView
.ID
, Messages
.TmfXmlAnalysisOutputSource_LatencyTable
),
102 * Latency Scatter View type
104 SCATTER_GRAPH(PatternScatterGraphView
.ID
, Messages
.TmfXmlAnalysisOutputSource_ScatterGraphTitle
),
107 * Latency Density View type
109 DENSITY_VIEW(PatternDensityView
.ID
, Messages
.TmfXmlAnalysisOutputSource_DensityChartTitle
),
112 * Latency Statistic View type
114 STATISTIC_VIEW(PatternStatisticsView
.ID
, Messages
.TmfXmlAnalysisOutputSource_LatencyStatisticsTitle
);
116 private @NonNull String fLatencyViewId
;
117 private String fLatencyViewLabel
;
119 private LatencyViewType(@NonNull String viewId
, String label
) {
120 fLatencyViewId
= viewId
;
121 fLatencyViewLabel
= label
;
125 * Get the ID of the latency view
129 public String
getViewId() {
130 return fLatencyViewId
;
134 * Get the label of the view
138 public String
getLabel() {
139 return fLatencyViewLabel
;
144 public void moduleCreated(IAnalysisModule module
) {
145 Map
<String
, File
> files
= XmlUtils
.listFiles();
146 for (File xmlFile
: files
.values()) {
147 if (!XmlUtils
.xmlValidate(xmlFile
).isOK()) {
152 Document doc
= XmlUtils
.getDocumentFromFile(xmlFile
);
154 /* get state provider views if the analysis has state systems */
155 if (module
instanceof ITmfAnalysisModuleWithStateSystems
) {
156 for (ViewType viewType
: ViewType
.values()) {
157 NodeList ssViewNodes
= doc
.getElementsByTagName(viewType
.getXmlElem());
158 for (int i
= 0; i
< ssViewNodes
.getLength(); i
++) {
159 Element node
= (Element
) ssViewNodes
.item(i
);
161 /* Check if analysis is the right one */
162 List
<Element
> headNodes
= XmlUtils
.getChildElements(node
, TmfXmlStrings
.HEAD
);
163 if (headNodes
.size() != 1) {
167 List
<Element
> analysisNodes
= XmlUtils
.getChildElements(headNodes
.get(0), TmfXmlStrings
.ANALYSIS
);
168 for (Element analysis
: analysisNodes
) {
169 String analysisId
= analysis
.getAttribute(TmfXmlStrings
.ID
);
170 if (analysisId
.equals(module
.getId())) {
171 String viewId
= viewType
.getViewId();
172 IAnalysisOutput output
= new TmfXmlViewOutput(viewId
, viewType
);
173 output
.setOutputProperty(TmfXmlUiStrings
.XML_OUTPUT_DATA
, node
.getAttribute(TmfXmlStrings
.ID
) + DATA_SEPARATOR
+ xmlFile
.getAbsolutePath(), false);
174 module
.registerOutput(output
);
181 // Add the latency views for pattern analysis
182 if (module
instanceof XmlPatternAnalysis
) {
183 for (LatencyViewType viewType
: LatencyViewType
.values()) {
184 IAnalysisOutput output
= new TmfXmlLatencyViewOutput(viewType
.getViewId(), viewType
.getLabel());
185 output
.setOutputProperty(TmfXmlUiStrings
.XML_LATENCY_OUTPUT_DATA
, module
.getId() + DATA_SEPARATOR
+ viewType
.getLabel(), false);
186 module
.registerOutput(output
);
190 } catch (ParserConfigurationException
| SAXException
| IOException e
) {
191 Activator
.logError("Error opening XML file", e
); //$NON-NLS-1$