TMF: Rework some test code for XML analysis to make it easier to add test cases
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.analysis.xml.core / src / org / eclipse / tracecompass / tmf / analysis / xml / core / stateprovider / XmlStateSystemModule.java
CommitLineData
e11e382c
FW
1/*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
3 *
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
8 *
9 * Contributors:
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
2bdf0193 13package org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider;
e11e382c 14
aa89118c
GB
15import java.util.List;
16
e11e382c
FW
17import org.eclipse.core.runtime.IPath;
18import org.eclipse.jdt.annotation.NonNull;
63f55fc0 19import org.eclipse.jdt.annotation.Nullable;
2bdf0193
AM
20import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
21import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
22import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
aa89118c 23import org.w3c.dom.Element;
e11e382c
FW
24
25/**
26 * Analysis module for the data-driven state systems, defined in XML.
27 *
28 * @author Geneviève Bastien
29 * @since 3.0
30 */
aa89118c 31public class XmlStateSystemModule extends TmfStateSystemAnalysisModule {
e11e382c 32
63f55fc0 33 private @Nullable IPath fXmlFile;
e11e382c
FW
34
35 @Override
36 protected StateSystemBackendType getBackendType() {
37 return StateSystemBackendType.FULL;
38 }
39
40 @Override
41 @NonNull
42 protected ITmfStateProvider createStateProvider() {
43 return new XmlStateProvider(getTrace(), getId(), fXmlFile);
44 }
45
46 @Override
47 public String getName() {
d40ddf8a 48 String id = getId();
63f55fc0
GB
49 IPath xmlFile = fXmlFile;
50 if (xmlFile == null) {
d40ddf8a 51 return id;
63f55fc0 52 }
d40ddf8a 53 Element doc = XmlUtils.getElementInFile(xmlFile.makeAbsolute().toString(), TmfXmlStrings.STATE_PROVIDER, id);
aa89118c
GB
54 /* Label may be available in XML header */
55 List<Element> head = XmlUtils.getChildElements(doc, TmfXmlStrings.HEAD);
d40ddf8a 56 String name = null;
aa89118c
GB
57 if (head.size() == 1) {
58 List<Element> labels = XmlUtils.getChildElements(head.get(0), TmfXmlStrings.LABEL);
59 if (!labels.isEmpty()) {
60 name = labels.get(0).getAttribute(TmfXmlStrings.VALUE);
61 }
e11e382c 62 }
d40ddf8a 63 return (name == null) ? id : name;
e11e382c
FW
64 }
65
66 /**
67 * Sets the file path of the XML file containing the state provider
68 *
69 * @param file
9a0aa59e 70 * The absolute path to the XML file
e11e382c
FW
71 */
72 public void setXmlFile(IPath file) {
73 fXmlFile = file;
74 }
75
e11e382c
FW
76 /**
77 * Get the path to the XML file containing this state provider definition.
78 *
79 * @return XML file path
80 */
81 public IPath getXmlFile() {
82 return fXmlFile;
83 }
84
85}
This page took 0.042722 seconds and 5 git commands to generate.