1 /*******************************************************************************
2 * Copyright (c) 2014 É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
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.ui
.module
;
15 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
18 import java
.util
.Collections
;
19 import java
.util
.List
;
21 import org
.eclipse
.core
.runtime
.Path
;
22 import org
.eclipse
.jdt
.annotation
.NonNull
;
23 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.ui
.Activator
;
24 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
25 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.stateprovider
.TmfXmlStrings
;
26 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.stateprovider
.XmlStateSystemModule
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModule
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModuleHelper
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAnalysisManager
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAnalysisRequirement
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
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
43 public class TmfAnalysisModuleHelperXml
implements IAnalysisModuleHelper
{
46 * The types of analysis that can be XML-defined
48 public enum XmlAnalysisModuleType
{
49 /** Analysis will be of type XmlStateSystemModule */
53 private final File fSourceFile
;
54 private final Element fSourceElement
;
55 private final XmlAnalysisModuleType fType
;
61 * The XML file containing the details of this analysis
63 * The XML node element
65 * The type of analysis
67 public TmfAnalysisModuleHelperXml(File xmlFile
, Element node
, XmlAnalysisModuleType type
) {
68 fSourceFile
= xmlFile
;
69 fSourceElement
= node
;
74 public String
getId() {
76 * The attribute ID cannot be null because the XML has been validated
79 return checkNotNull(fSourceElement
.getAttribute(TmfXmlStrings
.ID
));
83 public String
getName() {
85 /* Label may be available in XML header */
86 List
<Element
> head
= XmlUtils
.getChildElements(fSourceElement
, TmfXmlStrings
.HEAD
);
87 if (head
.size() == 1) {
88 List
<Element
> labels
= XmlUtils
.getChildElements(head
.get(0), TmfXmlStrings
.LABEL
);
89 if (!labels
.isEmpty()) {
90 name
= labels
.get(0).getAttribute(TmfXmlStrings
.VALUE
);
101 public boolean isAutomatic() {
106 public String
getHelpText() {
111 public String
getHelpText(@NonNull ITmfTrace trace
) {
112 return ""; //$NON-NLS-1$
116 public String
getIcon() {
121 public Bundle
getBundle() {
122 return Activator
.getDefault().getBundle();
126 public boolean appliesToTraceType(Class
<?
extends ITmfTrace
> traceClass
) {
127 /* Trace types may be available in XML header */
128 List
<Element
> head
= XmlUtils
.getChildElements(fSourceElement
, TmfXmlStrings
.HEAD
);
129 if (head
.size() != 1) {
133 * TODO: Test with custom trace types
135 List
<Element
> elements
= XmlUtils
.getChildElements(head
.get(0), TmfXmlStrings
.TRACETYPE
);
136 if (elements
.isEmpty()) {
140 for (Element element
: elements
) {
141 String traceTypeId
= element
.getAttribute(TmfXmlStrings
.ID
);
142 traceTypeId
= TmfTraceType
.buildCompatibilityTraceTypeId(traceTypeId
);
143 TraceTypeHelper helper
= TmfTraceType
.getTraceType(traceTypeId
);
144 if ((helper
!= null) && helper
.getTrace().getClass().isAssignableFrom(traceClass
)) {
152 public Iterable
<Class
<?
extends ITmfTrace
>> getValidTraceTypes() {
153 return Collections
.EMPTY_SET
;
157 public Iterable
<TmfAnalysisRequirement
> getAnalysisRequirements() {
158 return Collections
.EMPTY_SET
;
162 public IAnalysisModule
newModule(ITmfTrace trace
) throws TmfAnalysisException
{
163 String analysisid
= getId();
164 IAnalysisModule module
= null;
167 module
= new XmlStateSystemModule();
168 XmlStateSystemModule ssModule
= (XmlStateSystemModule
) module
;
169 module
.setId(analysisid
);
170 ssModule
.setXmlFile(new Path(fSourceFile
.getAbsolutePath()));
173 * FIXME: There is no way to know if a module is automatic, so we
176 ssModule
.setAutomatic(true);
183 if (module
!= null) {
184 module
.setTrace(trace
);
185 TmfAnalysisManager
.analysisModuleCreated(module
);