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
.HashMap
;
17 import java
.util
.List
;
20 import org
.eclipse
.core
.runtime
.Path
;
21 import org
.eclipse
.jdt
.annotation
.NonNull
;
22 import org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
;
23 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.core
.Activator
;
24 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.stateprovider
.TmfXmlStrings
;
25 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.stateprovider
.XmlStateSystemModule
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModule
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModuleHelper
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAnalysisManager
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAnalysisRequirement
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.ITmfPropertiesProvider
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.TmfTraceType
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.project
.model
.TraceTypeHelper
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
35 import org
.osgi
.framework
.Bundle
;
36 import org
.w3c
.dom
.Element
;
39 * Analysis module helpers for modules provided by XML files
41 * @author Geneviève Bastien
44 public class TmfAnalysisModuleHelperXml
implements IAnalysisModuleHelper
, ITmfPropertiesProvider
{
47 * The types of analysis that can be XML-defined
49 public enum XmlAnalysisModuleType
{
50 /** Analysis will be of type XmlStateSystemModule */
54 private final File fSourceFile
;
55 private final Element fSourceElement
;
56 private final XmlAnalysisModuleType fType
;
62 * The XML file containing the details of this analysis
64 * The XML node element
66 * The type of analysis
68 public TmfAnalysisModuleHelperXml(File xmlFile
, Element node
, XmlAnalysisModuleType type
) {
69 fSourceFile
= xmlFile
;
70 fSourceElement
= node
;
75 public String
getId() {
77 * The attribute ID cannot be null because the XML has been validated
80 return checkNotNull(fSourceElement
.getAttribute(TmfXmlStrings
.ID
));
84 public String
getName() {
86 /* Label may be available in XML header */
87 List
<Element
> head
= XmlUtils
.getChildElements(fSourceElement
, TmfXmlStrings
.HEAD
);
88 if (head
.size() == 1) {
89 List
<Element
> labels
= XmlUtils
.getChildElements(head
.get(0), TmfXmlStrings
.LABEL
);
90 if (!labels
.isEmpty()) {
91 name
= labels
.get(0).getAttribute(TmfXmlStrings
.VALUE
);
102 public boolean isAutomatic() {
110 public boolean appliesToExperiment() {
115 public String
getHelpText() {
116 return ""; //$NON-NLS-1$
120 public String
getHelpText(@NonNull ITmfTrace trace
) {
121 return ""; //$NON-NLS-1$
125 public String
getIcon() {
130 public Bundle
getBundle() {
131 return Activator
.getDefault().getBundle();
135 public boolean appliesToTraceType(Class
<?
extends ITmfTrace
> traceClass
) {
136 /* Trace types may be available in XML header */
137 List
<Element
> head
= XmlUtils
.getChildElements(fSourceElement
, TmfXmlStrings
.HEAD
);
138 if (head
.size() != 1) {
142 * TODO: Test with custom trace types
144 List
<Element
> elements
= XmlUtils
.getChildElements(head
.get(0), TmfXmlStrings
.TRACETYPE
);
145 if (elements
.isEmpty()) {
149 for (Element element
: elements
) {
150 String traceTypeId
= element
.getAttribute(TmfXmlStrings
.ID
);
151 traceTypeId
= TmfTraceType
.buildCompatibilityTraceTypeId(traceTypeId
);
152 TraceTypeHelper helper
= TmfTraceType
.getTraceType(traceTypeId
);
153 if ((helper
!= null) && helper
.getTrace().getClass().isAssignableFrom(traceClass
)) {
161 public Iterable
<Class
<?
extends ITmfTrace
>> getValidTraceTypes() {
162 return Collections
.EMPTY_SET
;
166 public Iterable
<TmfAnalysisRequirement
> getAnalysisRequirements() {
167 return Collections
.EMPTY_SET
;
171 public IAnalysisModule
newModule(ITmfTrace trace
) throws TmfAnalysisException
{
172 String analysisid
= getId();
173 IAnalysisModule module
= null;
176 module
= new XmlStateSystemModule();
177 XmlStateSystemModule ssModule
= (XmlStateSystemModule
) module
;
178 module
.setId(analysisid
);
179 ssModule
.setXmlFile(new Path(fSourceFile
.getAbsolutePath()));
182 * FIXME: There is no way to know if a module is automatic, so we
185 ssModule
.setAutomatic(true);
192 if (module
!= null) {
193 if (module
.setTrace(trace
)) {
194 TmfAnalysisManager
.analysisModuleCreated(module
);
196 /* The analysis does not apply to the trace, dispose of the module */
205 // ------------------------------------------------------------------------
206 // ITmfPropertiesProvider
207 // ------------------------------------------------------------------------
210 public @NonNull Map
<@NonNull String
, @NonNull String
> getProperties() {
211 Map
<@NonNull String
, @NonNull String
> properties
= new HashMap
<>();
212 properties
.put(NonNullUtils
.checkNotNull(Messages
.XmlModuleHelper_PropertyFile
), fSourceFile
.getName());
213 properties
.put(NonNullUtils
.checkNotNull(Messages
.XmlModuleHelper_PropertyType
), fType
.name());