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
.linuxtools
.tmf
.analysis
.xml
.ui
.module
;
16 import java
.util
.Collections
;
17 import java
.util
.List
;
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
;
37 * Analysis module helpers for modules provided by XML files
39 * @author Geneviève Bastien
41 public class TmfAnalysisModuleHelperXml
implements IAnalysisModuleHelper
{
44 * The types of analysis that can be XML-defined
46 public enum XmlAnalysisModuleType
{
47 /** Analysis will be of type XmlStateSystemModule */
51 private final File fSourceFile
;
52 private final Element fSourceElement
;
53 private final XmlAnalysisModuleType fType
;
59 * The XML file containing the details of this analysis
61 * The XML node element
63 * The type of analysis
65 public TmfAnalysisModuleHelperXml(File xmlFile
, Element node
, XmlAnalysisModuleType type
) {
66 fSourceFile
= xmlFile
;
67 fSourceElement
= node
;
72 public String
getId() {
73 return fSourceElement
.getAttribute(TmfXmlStrings
.ID
);
77 public String
getName() {
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
);
95 public boolean isAutomatic() {
100 public String
getHelpText() {
105 public String
getHelpText(@NonNull ITmfTrace trace
) {
106 return ""; //$NON-NLS-1$
110 public String
getIcon() {
115 public Bundle
getBundle() {
116 return Activator
.getDefault().getBundle();
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) {
127 * TODO: Test with custom trace types
129 List
<Element
> elements
= XmlUtils
.getChildElements(head
.get(0), TmfXmlStrings
.TRACETYPE
);
130 if (elements
.isEmpty()) {
134 for (Element element
: elements
) {
135 String traceTypeId
= element
.getAttribute(TmfXmlStrings
.ID
);
136 TraceTypeHelper helper
= TmfTraceType
.getInstance().getTraceType(traceTypeId
);
137 if ((helper
!= null) && helper
.getTrace().getClass().isAssignableFrom(traceClass
)) {
145 public Iterable
<Class
<?
extends ITmfTrace
>> getValidTraceTypes() {
146 return Collections
.EMPTY_SET
;
150 public Iterable
<TmfAnalysisRequirement
> getAnalysisRequirements() {
151 return Collections
.EMPTY_SET
;
155 public IAnalysisModule
newModule(ITmfTrace trace
) throws TmfAnalysisException
{
156 String analysisid
= getId();
157 IAnalysisModule module
= null;
160 module
= new XmlStateSystemModule();
161 XmlStateSystemModule ssModule
= (XmlStateSystemModule
) module
;
162 module
.setId(analysisid
);
163 ssModule
.setXmlFile(new Path(fSourceFile
.getAbsolutePath()));
166 * FIXME: There is no way to know if a module is automatic, so we
169 ssModule
.setAutomatic(true);
176 if (module
!= null) {
177 module
.setTrace(trace
);
178 TmfAnalysisManager
.analysisModuleCreated(module
);