tmf.core: null type safety (added type annotation)
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.analysis.xml.core / src / org / eclipse / tracecompass / tmf / analysis / xml / core / stateprovider / XmlStateSystemModule.java
CommitLineData
e11e382c 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2014, 2015 École Polytechnique de Montréal
e11e382c
FW
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
e11e382c 31 */
aa89118c 32public class XmlStateSystemModule extends TmfStateSystemAnalysisModule {
e11e382c 33
63f55fc0 34 private @Nullable IPath fXmlFile;
e11e382c
FW
35
36 @Override
37 protected StateSystemBackendType getBackendType() {
38 return StateSystemBackendType.FULL;
39 }
40
41 @Override
42 @NonNull
43 protected ITmfStateProvider createStateProvider() {
d0c7e4ba 44 return new XmlStateProvider(checkNotNull(getTrace()), getId(), fXmlFile);
e11e382c
FW
45 }
46
47 @Override
48 public String getName() {
d40ddf8a 49 String id = getId();
63f55fc0
GB
50 IPath xmlFile = fXmlFile;
51 if (xmlFile == null) {
d40ddf8a 52 return id;
63f55fc0 53 }
d40ddf8a 54 Element doc = XmlUtils.getElementInFile(xmlFile.makeAbsolute().toString(), TmfXmlStrings.STATE_PROVIDER, id);
aa89118c
GB
55 /* Label may be available in XML header */
56 List<Element> head = XmlUtils.getChildElements(doc, TmfXmlStrings.HEAD);
d40ddf8a 57 String name = null;
aa89118c
GB
58 if (head.size() == 1) {
59 List<Element> labels = XmlUtils.getChildElements(head.get(0), TmfXmlStrings.LABEL);
60 if (!labels.isEmpty()) {
61 name = labels.get(0).getAttribute(TmfXmlStrings.VALUE);
62 }
e11e382c 63 }
d40ddf8a 64 return (name == null) ? id : name;
e11e382c
FW
65 }
66
67 /**
68 * Sets the file path of the XML file containing the state provider
69 *
70 * @param file
9a0aa59e 71 * The absolute path to the XML file
e11e382c
FW
72 */
73 public void setXmlFile(IPath file) {
74 fXmlFile = file;
75 }
76
e11e382c
FW
77 /**
78 * Get the path to the XML file containing this state provider definition.
79 *
80 * @return XML file path
81 */
82 public IPath getXmlFile() {
83 return fXmlFile;
84 }
85
86}
This page took 0.069665 seconds and 5 git commands to generate.