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
.linuxtools
.internal
.tmf
.analysis
.xml
.ui
.Activator
;
21 import org
.eclipse
.linuxtools
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
22 import org
.eclipse
.linuxtools
.tmf
.analysis
.xml
.core
.stateprovider
.TmfXmlStrings
;
23 import org
.eclipse
.linuxtools
.tmf
.analysis
.xml
.core
.stateprovider
.XmlStateSystemModule
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisModule
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisModuleHelper
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.TmfAnalysisManager
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.TmfAnalysisRequirement
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfAnalysisException
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.project
.model
.TmfTraceType
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.project
.model
.TraceTypeHelper
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
32 import org
.osgi
.framework
.Bundle
;
33 import org
.w3c
.dom
.Element
;
36 * Analysis module helpers for modules provided by XML files
38 * @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() {
72 return fSourceElement
.getAttribute(TmfXmlStrings
.ID
);
76 public String
getName() {
78 /* Label may be available in XML header */
79 List
<Element
> head
= XmlUtils
.getChildElements(fSourceElement
, TmfXmlStrings
.HEAD
);
80 if (head
.size() == 1) {
81 List
<Element
> labels
= XmlUtils
.getChildElements(head
.get(0), TmfXmlStrings
.LABEL
);
82 if (!labels
.isEmpty()) {
83 name
= labels
.get(0).getAttribute(TmfXmlStrings
.VALUE
);
94 public boolean isAutomatic() {
99 public String
getHelpText() {
104 public String
getIcon() {
109 public Bundle
getBundle() {
110 return Activator
.getDefault().getBundle();
114 public boolean appliesToTraceType(Class
<?
extends ITmfTrace
> traceClass
) {
115 /* Trace types may be available in XML header */
116 List
<Element
> head
= XmlUtils
.getChildElements(fSourceElement
, TmfXmlStrings
.HEAD
);
117 if (head
.size() != 1) {
121 * TODO: Test with custom trace types
123 List
<Element
> elements
= XmlUtils
.getChildElements(head
.get(0), TmfXmlStrings
.TRACETYPE
);
124 if (elements
.isEmpty()) {
128 for (Element element
: elements
) {
129 String traceTypeId
= element
.getAttribute(TmfXmlStrings
.ID
);
130 TraceTypeHelper helper
= TmfTraceType
.getInstance().getTraceType(traceTypeId
);
131 if ((helper
!= null) && helper
.getTrace().getClass().isAssignableFrom(traceClass
)) {
139 public Iterable
<Class
<?
extends ITmfTrace
>> getValidTraceTypes() {
140 return Collections
.EMPTY_SET
;
144 public Iterable
<TmfAnalysisRequirement
> getAnalysisRequirements() {
145 return Collections
.EMPTY_SET
;
149 public IAnalysisModule
newModule(ITmfTrace trace
) throws TmfAnalysisException
{
150 String analysisid
= getId();
151 IAnalysisModule module
= null;
154 module
= new XmlStateSystemModule();
155 XmlStateSystemModule ssModule
= (XmlStateSystemModule
) module
;
156 module
.setId(analysisid
);
157 ssModule
.setXmlFile(new Path(fSourceFile
.getAbsolutePath()));
160 * FIXME: There is no way to know if a module is automatic, so we
163 ssModule
.setAutomatic(true);
170 if (module
!= null) {
171 module
.setTrace(trace
);
172 TmfAnalysisManager
.analysisModuleCreated(module
);