1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
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 package org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.core
.pattern
.stateprovider
;
11 import java
.util
.HashSet
;
14 import org
.eclipse
.core
.runtime
.IPath
;
15 import org
.eclipse
.jdt
.annotation
.NonNull
;
16 import org
.eclipse
.jdt
.annotation
.Nullable
;
17 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.core
.Activator
;
18 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
19 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.model
.TmfXmlLocation
;
20 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.module
.IXmlStateSystemContainer
;
21 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
22 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.stateprovider
.TmfXmlStrings
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.AbstractTmfStateProvider
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.ITmfStateProvider
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
27 import org
.w3c
.dom
.Element
;
30 * State provider for the pattern analysis
32 * @author Jean-Christian Kouame
34 public class XmlPatternStateProvider
extends AbstractTmfStateProvider
implements IXmlStateSystemContainer
{
36 private final IPath fFilePath
;
38 private final @NonNull String fStateId
;
40 /** List of all Locations */
41 private final @NonNull Set
<@NonNull TmfXmlLocation
> fLocations
;
43 private final ISegmentListener fListener
;
49 * The state id, which corresponds to the id of the analysis
50 * defined in the XML file
54 * Listener for segment creation
56 public XmlPatternStateProvider(@NonNull ITmfTrace trace
, @NonNull String stateid
, @Nullable IPath file
, ISegmentListener listener
) {
57 super(trace
, stateid
);
61 final String pathString
= fFilePath
.makeAbsolute().toOSString();
62 Element doc
= XmlUtils
.getElementInFile(pathString
, TmfXmlStrings
.PATTERN
, fStateId
);
63 fLocations
= new HashSet
<>();
65 Activator
.logError("Failed to find a pattern in " + pathString
); //$NON-NLS-1$
71 public String
getAttributeValue(String name
) {
76 public int getVersion() {
81 public @NonNull ITmfStateProvider
getNewInstance() {
82 return new XmlPatternStateProvider(getTrace(), getStateId(), fFilePath
, fListener
);
86 * Get the state ID of the provider. It corresponds to the analysis ID.
88 * @return the state Id
90 public @NonNull String
getStateId() {
95 public ITmfStateSystem
getStateSystem() {
96 return getStateSystemBuilder();
100 public @NonNull Iterable
<@NonNull TmfXmlLocation
> getLocations() {
105 protected void eventHandle(@NonNull ITmfEvent event
) {
109 * Get the listerner for segments creation
111 * @return The segment listener
113 public ISegmentListener
getListener() {
118 public void dispose() {
119 fListener
.onNewSegment(XmlPatternSegmentStoreModule
.END_SEGMENT
);