ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.analysis.xml.ui / src / org / eclipse / linuxtools / tmf / analysis / xml / ui / module / TmfAnalysisModuleHelperXml.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.linuxtools.tmf.analysis.xml.ui.module;
14
15 import java.io.File;
16 import java.util.Collections;
17 import java.util.List;
18
19 import org.eclipse.core.runtime.Path;
20 import org.eclipse.jdt.annotation.NonNull;
21 import org.eclipse.linuxtools.internal.tmf.analysis.xml.ui.Activator;
22 import org.eclipse.linuxtools.tmf.analysis.xml.core.module.XmlUtils;
23 import org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
24 import org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
25 import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule;
26 import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModuleHelper;
27 import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisManager;
28 import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirement;
29 import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
30 import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType;
31 import org.eclipse.linuxtools.tmf.core.project.model.TraceTypeHelper;
32 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
33 import org.osgi.framework.Bundle;
34 import org.w3c.dom.Element;
35
36 /**
37 * Analysis module helpers for modules provided by XML files
38 *
39 * @author Geneviève Bastien
40 */
41 public class TmfAnalysisModuleHelperXml implements IAnalysisModuleHelper {
42
43 /**
44 * The types of analysis that can be XML-defined
45 */
46 public enum XmlAnalysisModuleType {
47 /** Analysis will be of type XmlStateSystemModule */
48 STATE_SYSTEM
49 }
50
51 private final File fSourceFile;
52 private final Element fSourceElement;
53 private final XmlAnalysisModuleType fType;
54
55 /**
56 * Constructor
57 *
58 * @param xmlFile
59 * The XML file containing the details of this analysis
60 * @param node
61 * The XML node element
62 * @param type
63 * The type of analysis
64 */
65 public TmfAnalysisModuleHelperXml(File xmlFile, Element node, XmlAnalysisModuleType type) {
66 fSourceFile = xmlFile;
67 fSourceElement = node;
68 fType = type;
69 }
70
71 @Override
72 public String getId() {
73 return fSourceElement.getAttribute(TmfXmlStrings.ID);
74 }
75
76 @Override
77 public String getName() {
78 String name = null;
79 /* Label may be available in XML header */
80 List<Element> head = XmlUtils.getChildElements(fSourceElement, TmfXmlStrings.HEAD);
81 if (head.size() == 1) {
82 List<Element> labels = XmlUtils.getChildElements(head.get(0), TmfXmlStrings.LABEL);
83 if (!labels.isEmpty()) {
84 name = labels.get(0).getAttribute(TmfXmlStrings.VALUE);
85 }
86 }
87
88 if (name == null) {
89 name = getId();
90 }
91 return name;
92 }
93
94 @Override
95 public boolean isAutomatic() {
96 return false;
97 }
98
99 @Override
100 public String getHelpText() {
101 return new String();
102 }
103
104 @Override
105 public String getHelpText(@NonNull ITmfTrace trace) {
106 return ""; //$NON-NLS-1$
107 }
108
109 @Override
110 public String getIcon() {
111 return null;
112 }
113
114 @Override
115 public Bundle getBundle() {
116 return Activator.getDefault().getBundle();
117 }
118
119 @Override
120 public boolean appliesToTraceType(Class<? extends ITmfTrace> traceClass) {
121 /* Trace types may be available in XML header */
122 List<Element> head = XmlUtils.getChildElements(fSourceElement, TmfXmlStrings.HEAD);
123 if (head.size() != 1) {
124 return true;
125 }
126 /*
127 * TODO: Test with custom trace types
128 */
129 List<Element> elements = XmlUtils.getChildElements(head.get(0), TmfXmlStrings.TRACETYPE);
130 if (elements.isEmpty()) {
131 return true;
132 }
133
134 for (Element element : elements) {
135 String traceTypeId = element.getAttribute(TmfXmlStrings.ID);
136 TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
137 if ((helper != null) && helper.getTrace().getClass().isAssignableFrom(traceClass)) {
138 return true;
139 }
140 }
141 return false;
142 }
143
144 @Override
145 public Iterable<Class<? extends ITmfTrace>> getValidTraceTypes() {
146 return Collections.EMPTY_SET;
147 }
148
149 @Override
150 public Iterable<TmfAnalysisRequirement> getAnalysisRequirements() {
151 return Collections.EMPTY_SET;
152 }
153
154 @Override
155 public IAnalysisModule newModule(ITmfTrace trace) throws TmfAnalysisException {
156 String analysisid = getId();
157 IAnalysisModule module = null;
158 switch (fType) {
159 case STATE_SYSTEM:
160 module = new XmlStateSystemModule();
161 XmlStateSystemModule ssModule = (XmlStateSystemModule) module;
162 module.setId(analysisid);
163 ssModule.setXmlFile(new Path(fSourceFile.getAbsolutePath()));
164
165 /*
166 * FIXME: There is no way to know if a module is automatic, so we
167 * default to true
168 */
169 ssModule.setAutomatic(true);
170
171 break;
172 default:
173 break;
174
175 }
176 if (module != null) {
177 module.setTrace(trace);
178 TmfAnalysisManager.analysisModuleCreated(module);
179 }
180
181 return module;
182 }
183
184 }
This page took 0.046458 seconds and 5 git commands to generate.