0bb33274818377d5e9b7f8cc7e6b7ff57a6e8c7e
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.analysis.xml.core / src / org / eclipse / tracecompass / tmf / analysis / xml / core / stateprovider / XmlStateSystemModule.java
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
13 package org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider;
14
15 import java.util.List;
16
17 import org.eclipse.core.runtime.IPath;
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
21 import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
22 import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
23 import org.w3c.dom.Element;
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 */
31 public class XmlStateSystemModule extends TmfStateSystemAnalysisModule {
32
33 private @Nullable IPath fXmlFile;
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() {
48 String id = getId();
49 IPath xmlFile = fXmlFile;
50 if (xmlFile == null) {
51 return id;
52 }
53 Element doc = XmlUtils.getElementInFile(xmlFile.makeAbsolute().toString(), TmfXmlStrings.STATE_PROVIDER, id);
54 /* Label may be available in XML header */
55 List<Element> head = XmlUtils.getChildElements(doc, TmfXmlStrings.HEAD);
56 String name = null;
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 }
62 }
63 return (name == null) ? id : name;
64 }
65
66 /**
67 * Sets the file path of the XML file containing the state provider
68 *
69 * @param file
70 * The absolute path to the XML file
71 */
72 public void setXmlFile(IPath file) {
73 fXmlFile = file;
74 }
75
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.033336 seconds and 5 git commands to generate.