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