Commit | Line | Data |
---|---|---|
97ed0cf0 FW |
1 | /******************************************************************************* |
2 | * Copyright (c) 2014 École Polytechnique de Montréal | |
3 | * | |
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 | * | |
9 | * Contributors: | |
10 | * Geneviève Bastien - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.analysis.xml.ui.module; | |
14 | ||
15 | import java.io.File; | |
16 | ||
17 | import org.eclipse.core.runtime.Path; | |
18 | import org.eclipse.linuxtools.internal.tmf.analysis.xml.ui.Activator; | |
19 | import org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider.TmfXmlStrings; | |
20 | import org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule; | |
21 | import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule; | |
22 | import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModuleHelper; | |
048bde85 | 23 | import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisManager; |
97ed0cf0 FW |
24 | import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException; |
25 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; | |
97ed0cf0 FW |
26 | import org.osgi.framework.Bundle; |
27 | import org.w3c.dom.Element; | |
28 | import org.w3c.dom.NodeList; | |
29 | ||
30 | /** | |
31 | * Analysis module helpers for modules provided by XML files | |
32 | * | |
33 | * @author Geneviève Bastien | |
34 | */ | |
35 | public class TmfAnalysisModuleHelperXml implements IAnalysisModuleHelper { | |
36 | ||
37 | /** | |
38 | * The types of analysis that can be XML-defined | |
39 | */ | |
40 | public enum XmlAnalysisModuleType { | |
41 | /** Analysis will be of type XmlStateSystemModule */ | |
42 | STATE_SYSTEM | |
43 | } | |
44 | ||
45 | private final File fSourceFile; | |
46 | private final Element fSourceElement; | |
47 | private final XmlAnalysisModuleType fType; | |
48 | private final XmlHeadInfoUi fHeadInfo; | |
49 | ||
50 | /** | |
51 | * Constructor | |
52 | * | |
53 | * @param xmlFile | |
54 | * The XML file containing the details of this analysis | |
55 | * @param node | |
56 | * The XML node element | |
57 | * @param type | |
58 | * The type of analysis | |
59 | */ | |
60 | public TmfAnalysisModuleHelperXml(File xmlFile, Element node, XmlAnalysisModuleType type) { | |
61 | fSourceFile = xmlFile; | |
62 | fSourceElement = node; | |
63 | fType = type; | |
64 | ||
65 | NodeList head = fSourceElement.getElementsByTagName(TmfXmlStrings.HEAD); | |
66 | if (head.getLength() == 1) { | |
67 | fHeadInfo = new XmlHeadInfoUi(head.item(0)); | |
68 | } else { | |
69 | fHeadInfo = null; | |
70 | } | |
71 | } | |
72 | ||
73 | @Override | |
74 | public String getId() { | |
f47f1bbe | 75 | return fSourceElement.getAttribute(TmfXmlStrings.ID); |
97ed0cf0 FW |
76 | } |
77 | ||
78 | @Override | |
79 | public String getName() { | |
80 | String name = fHeadInfo.getName(); | |
81 | if (name == null) { | |
82 | name = getId(); | |
83 | } | |
84 | return name; | |
85 | } | |
86 | ||
87 | @Override | |
88 | public boolean isAutomatic() { | |
89 | return false; | |
90 | } | |
91 | ||
92 | @Override | |
93 | public String getHelpText() { | |
94 | return new String(); | |
95 | } | |
96 | ||
97 | @Override | |
98 | public String getIcon() { | |
99 | return null; | |
100 | } | |
101 | ||
102 | @Override | |
103 | public Bundle getBundle() { | |
104 | return Activator.getDefault().getBundle(); | |
105 | } | |
106 | ||
107 | @Override | |
108 | public boolean appliesToTraceType(Class<? extends ITmfTrace> traceclass) { | |
109 | /* Trace types may be available in XML header */ | |
110 | if (fHeadInfo == null) { | |
111 | return true; | |
112 | } | |
113 | ||
114 | return fHeadInfo.checkTraceType(traceclass); | |
115 | } | |
116 | ||
117 | @Override | |
118 | public IAnalysisModule newModule(ITmfTrace trace) throws TmfAnalysisException { | |
119 | String analysisid = getId(); | |
120 | IAnalysisModule module = null; | |
121 | switch (fType) { | |
122 | case STATE_SYSTEM: | |
123 | module = new XmlStateSystemModule(); | |
124 | XmlStateSystemModule ssModule = (XmlStateSystemModule) module; | |
125 | module.setId(analysisid); | |
126 | ssModule.setXmlFile(new Path(fSourceFile.getAbsolutePath())); | |
127 | ||
128 | /* Set header information if available */ | |
129 | ssModule.setHeadInfo(fHeadInfo); | |
048bde85 GB |
130 | /* |
131 | * FIXME: There is no way to know if a module is automatic, so we | |
132 | * default to true | |
133 | */ | |
134 | ssModule.setAutomatic(true); | |
97ed0cf0 | 135 | |
97ed0cf0 FW |
136 | break; |
137 | default: | |
138 | break; | |
139 | ||
140 | } | |
141 | if (module != null) { | |
142 | module.setTrace(trace); | |
048bde85 | 143 | TmfAnalysisManager.analysisModuleCreated(module); |
97ed0cf0 FW |
144 | } |
145 | ||
146 | return module; | |
147 | } | |
148 | ||
149 | } |