ctf: Rename Stream* classes to CTFStream*
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.analysis.xml.ui / src / org / eclipse / linuxtools / tmf / analysis / xml / ui / module / TmfAnalysisModuleHelperXml.java
CommitLineData
97ed0cf0
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
13package org.eclipse.linuxtools.tmf.analysis.xml.ui.module;
14
15import java.io.File;
63c43609 16import java.util.Collections;
97ed0cf0
FW
17
18import org.eclipse.core.runtime.Path;
19import org.eclipse.linuxtools.internal.tmf.analysis.xml.ui.Activator;
20import org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
21import org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
22import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule;
23import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModuleHelper;
048bde85 24import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisManager;
63c43609 25import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirement;
97ed0cf0
FW
26import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
27import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
97ed0cf0
FW
28import org.osgi.framework.Bundle;
29import org.w3c.dom.Element;
30import org.w3c.dom.NodeList;
31
32/**
33 * Analysis module helpers for modules provided by XML files
34 *
35 * @author Geneviève Bastien
36 */
37public class TmfAnalysisModuleHelperXml implements IAnalysisModuleHelper {
38
39 /**
40 * The types of analysis that can be XML-defined
41 */
42 public enum XmlAnalysisModuleType {
43 /** Analysis will be of type XmlStateSystemModule */
44 STATE_SYSTEM
45 }
46
47 private final File fSourceFile;
48 private final Element fSourceElement;
49 private final XmlAnalysisModuleType fType;
50 private final XmlHeadInfoUi fHeadInfo;
51
52 /**
53 * Constructor
54 *
55 * @param xmlFile
56 * The XML file containing the details of this analysis
57 * @param node
58 * The XML node element
59 * @param type
60 * The type of analysis
61 */
62 public TmfAnalysisModuleHelperXml(File xmlFile, Element node, XmlAnalysisModuleType type) {
63 fSourceFile = xmlFile;
64 fSourceElement = node;
65 fType = type;
66
67 NodeList head = fSourceElement.getElementsByTagName(TmfXmlStrings.HEAD);
68 if (head.getLength() == 1) {
69 fHeadInfo = new XmlHeadInfoUi(head.item(0));
70 } else {
71 fHeadInfo = null;
72 }
73 }
74
75 @Override
76 public String getId() {
f47f1bbe 77 return fSourceElement.getAttribute(TmfXmlStrings.ID);
97ed0cf0
FW
78 }
79
80 @Override
81 public String getName() {
82 String name = fHeadInfo.getName();
83 if (name == null) {
84 name = getId();
85 }
86 return name;
87 }
88
89 @Override
90 public boolean isAutomatic() {
91 return false;
92 }
93
94 @Override
95 public String getHelpText() {
96 return new String();
97 }
98
99 @Override
100 public String getIcon() {
101 return null;
102 }
103
104 @Override
105 public Bundle getBundle() {
106 return Activator.getDefault().getBundle();
107 }
108
109 @Override
110 public boolean appliesToTraceType(Class<? extends ITmfTrace> traceclass) {
111 /* Trace types may be available in XML header */
112 if (fHeadInfo == null) {
113 return true;
114 }
115
116 return fHeadInfo.checkTraceType(traceclass);
117 }
118
63c43609
MR
119 @Override
120 public Iterable<Class<? extends ITmfTrace>> getValidTraceTypes() {
121 return Collections.EMPTY_SET;
122 }
123
124 @Override
125 public Iterable<TmfAnalysisRequirement> getAnalysisRequirements() {
126 return Collections.EMPTY_SET;
127 }
128
97ed0cf0
FW
129 @Override
130 public IAnalysisModule newModule(ITmfTrace trace) throws TmfAnalysisException {
131 String analysisid = getId();
132 IAnalysisModule module = null;
133 switch (fType) {
134 case STATE_SYSTEM:
135 module = new XmlStateSystemModule();
136 XmlStateSystemModule ssModule = (XmlStateSystemModule) module;
137 module.setId(analysisid);
138 ssModule.setXmlFile(new Path(fSourceFile.getAbsolutePath()));
139
140 /* Set header information if available */
141 ssModule.setHeadInfo(fHeadInfo);
048bde85
GB
142 /*
143 * FIXME: There is no way to know if a module is automatic, so we
144 * default to true
145 */
146 ssModule.setAutomatic(true);
97ed0cf0 147
97ed0cf0
FW
148 break;
149 default:
150 break;
151
152 }
153 if (module != null) {
154 module.setTrace(trace);
048bde85 155 TmfAnalysisManager.analysisModuleCreated(module);
97ed0cf0
FW
156 }
157
158 return module;
159 }
160
161}
This page took 0.033799 seconds and 5 git commands to generate.