1 /*******************************************************************************
2 * Copyright (c) 2014, 2016 École Polytechnique de Montréal
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.module
;
12 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
15 import java
.util
.Collections
;
16 import java
.util
.List
;
18 import org
.eclipse
.core
.runtime
.Path
;
19 import org
.eclipse
.jdt
.annotation
.NonNull
;
20 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.core
.Activator
;
21 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.stateprovider
.TmfXmlStrings
;
22 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.stateprovider
.XmlStateSystemModule
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModule
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModuleHelper
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAnalysisManager
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAnalysisRequirement
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.TmfTraceType
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.TraceTypeHelper
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
31 import org
.osgi
.framework
.Bundle
;
32 import org
.w3c
.dom
.Element
;
35 * Analysis module helpers for modules provided by XML files
37 * @author Geneviève Bastien
40 public class TmfAnalysisModuleHelperXml
implements IAnalysisModuleHelper
{
43 * The types of analysis that can be XML-defined
45 public enum XmlAnalysisModuleType
{
46 /** Analysis will be of type XmlStateSystemModule */
50 private final File fSourceFile
;
51 private final Element fSourceElement
;
52 private final XmlAnalysisModuleType fType
;
58 * The XML file containing the details of this analysis
60 * The XML node element
62 * The type of analysis
64 public TmfAnalysisModuleHelperXml(File xmlFile
, Element node
, XmlAnalysisModuleType type
) {
65 fSourceFile
= xmlFile
;
66 fSourceElement
= node
;
71 public String
getId() {
73 * The attribute ID cannot be null because the XML has been validated
76 return checkNotNull(fSourceElement
.getAttribute(TmfXmlStrings
.ID
));
80 public String
getName() {
82 /* Label may be available in XML header */
83 List
<Element
> head
= XmlUtils
.getChildElements(fSourceElement
, TmfXmlStrings
.HEAD
);
84 if (head
.size() == 1) {
85 List
<Element
> labels
= XmlUtils
.getChildElements(head
.get(0), TmfXmlStrings
.LABEL
);
86 if (!labels
.isEmpty()) {
87 name
= labels
.get(0).getAttribute(TmfXmlStrings
.VALUE
);
98 public boolean isAutomatic() {
106 public boolean appliesToExperiment() {
111 public String
getHelpText() {
112 return ""; //$NON-NLS-1$
116 public String
getHelpText(@NonNull ITmfTrace trace
) {
117 return ""; //$NON-NLS-1$
121 public String
getIcon() {
126 public Bundle
getBundle() {
127 return Activator
.getDefault().getBundle();
131 public boolean appliesToTraceType(Class
<?
extends ITmfTrace
> traceClass
) {
132 /* Trace types may be available in XML header */
133 List
<Element
> head
= XmlUtils
.getChildElements(fSourceElement
, TmfXmlStrings
.HEAD
);
134 if (head
.size() != 1) {
138 * TODO: Test with custom trace types
140 List
<Element
> elements
= XmlUtils
.getChildElements(head
.get(0), TmfXmlStrings
.TRACETYPE
);
141 if (elements
.isEmpty()) {
145 for (Element element
: elements
) {
146 String traceTypeId
= element
.getAttribute(TmfXmlStrings
.ID
);
147 traceTypeId
= TmfTraceType
.buildCompatibilityTraceTypeId(traceTypeId
);
148 TraceTypeHelper helper
= TmfTraceType
.getTraceType(traceTypeId
);
149 if ((helper
!= null) && helper
.getTrace().getClass().isAssignableFrom(traceClass
)) {
157 public Iterable
<Class
<?
extends ITmfTrace
>> getValidTraceTypes() {
158 return Collections
.EMPTY_SET
;
162 public Iterable
<TmfAnalysisRequirement
> getAnalysisRequirements() {
163 return Collections
.EMPTY_SET
;
167 public IAnalysisModule
newModule(ITmfTrace trace
) throws TmfAnalysisException
{
168 String analysisid
= getId();
169 IAnalysisModule module
= null;
172 module
= new XmlStateSystemModule();
173 XmlStateSystemModule ssModule
= (XmlStateSystemModule
) module
;
174 module
.setId(analysisid
);
175 ssModule
.setXmlFile(new Path(fSourceFile
.getAbsolutePath()));
178 * FIXME: There is no way to know if a module is automatic, so we
181 ssModule
.setAutomatic(true);
188 if (module
!= null) {
189 if (module
.setTrace(trace
)) {
190 TmfAnalysisManager
.analysisModuleCreated(module
);
192 /* The analysis does not apply to the trace, dispose of the module */