tmf : Introduce the modules for the XML pattern analysis
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.analysis.xml.core / src / org / eclipse / tracecompass / internal / tmf / analysis / xml / core / pattern / stateprovider / XmlPatternStateProvider.java
CommitLineData
38e2a2e9
JCK
1/*******************************************************************************
2 * Copyright (c) 2016 Ericsson
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 ******************************************************************************/
9package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider;
10
11import java.util.HashSet;
12import java.util.Set;
13
14import org.eclipse.core.runtime.IPath;
15import org.eclipse.jdt.annotation.NonNull;
16import org.eclipse.jdt.annotation.Nullable;
17import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
18import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
19import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlLocation;
20import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
21import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
22import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
23import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
24import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider;
25import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
26import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
27import org.w3c.dom.Element;
28
29/**
30 * State provider for the pattern analysis
31 *
32 * @author Jean-Christian Kouame
33 */
34public class XmlPatternStateProvider extends AbstractTmfStateProvider implements IXmlStateSystemContainer {
35
36 private final IPath fFilePath;
37
38 private final @NonNull String fStateId;
39
40 /** List of all Locations */
41 private final @NonNull Set<@NonNull TmfXmlLocation> fLocations;
42
43 private final ISegmentListener fListener;
44
45 /**
46 * @param trace
47 * The active trace
48 * @param stateid
49 * The state id, which corresponds to the id of the analysis
50 * defined in the XML file
51 * @param file
52 * The XML file
53 * @param listener
54 * Listener for segment creation
55 */
56 public XmlPatternStateProvider(@NonNull ITmfTrace trace, @NonNull String stateid, @Nullable IPath file, ISegmentListener listener) {
57 super(trace, stateid);
58 fStateId = stateid;
59 fFilePath = file;
60 fListener = listener;
61 final String pathString = fFilePath.makeAbsolute().toOSString();
62 Element doc = XmlUtils.getElementInFile(pathString, TmfXmlStrings.PATTERN, fStateId);
63 fLocations = new HashSet<>();
64 if (doc == null) {
65 Activator.logError("Failed to find a pattern in " + pathString); //$NON-NLS-1$
66 return;
67 }
68 }
69
70 @Override
71 public String getAttributeValue(String name) {
72 return null;
73 }
74
75 @Override
76 public int getVersion() {
77 return 0;
78 }
79
80 @Override
81 public @NonNull ITmfStateProvider getNewInstance() {
82 return new XmlPatternStateProvider(getTrace(), getStateId(), fFilePath, fListener);
83 }
84
85 /**
86 * Get the state ID of the provider. It corresponds to the analysis ID.
87 *
88 * @return the state Id
89 */
90 public @NonNull String getStateId() {
91 return fStateId;
92 }
93
94 @Override
95 public ITmfStateSystem getStateSystem() {
96 return getStateSystemBuilder();
97 }
98
99 @Override
100 public @NonNull Iterable<@NonNull TmfXmlLocation> getLocations() {
101 return fLocations;
102 }
103
104 @Override
105 protected void eventHandle(@NonNull ITmfEvent event) {
106 }
107
108 /**
109 * Get the listerner for segments creation
110 *
111 * @return The segment listener
112 */
113 public ISegmentListener getListener() {
114 return fListener;
115 }
116
117 @Override
118 public void dispose() {
119 fListener.onNewSegment(XmlPatternSegmentStoreModule.END_SEGMENT);
120 super.dispose();
121 }
122}
This page took 0.031172 seconds and 5 git commands to generate.