1 /*******************************************************************************
2 * Copyright (c) 2014 Ecole Polytechnique de Montreal
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 * Florian Wininger - Initial API and implementation
11 ******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.model
;
15 import java
.util
.LinkedList
;
16 import java
.util
.List
;
18 import org
.eclipse
.jdt
.annotation
.Nullable
;
19 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.module
.IXmlStateSystemContainer
;
20 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
21 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.stateprovider
.TmfXmlStrings
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
23 import org
.w3c
.dom
.Element
;
26 * This Class implements a Location in the XML-defined state system, ie a named
27 * shortcut to reach a given attribute, used in state attributes
31 * <location id="CurrentCPU">
32 * <stateAttribute type="constant" value="CPUs" />
33 * <stateAttribute type="eventField" name="cpu" />
38 * @author Florian Wininger
40 public class TmfXmlLocation
{
42 /** Path in the State System */
43 private final List
<ITmfXmlStateAttribute
> fPath
= new LinkedList
<>();
45 /** ID : name of the location */
46 private final String fId
;
47 private final IXmlStateSystemContainer fContainer
;
53 * The factory used to create XML model elements
57 * The state system container this location belongs to
59 public TmfXmlLocation(ITmfXmlModelFactory modelFactory
, Element location
, IXmlStateSystemContainer container
) {
60 String id
= location
.getAttribute(TmfXmlStrings
.ID
);
62 fContainer
= container
;
64 List
<@Nullable Element
> childElements
= XmlUtils
.getChildElements(location
);
65 for (Element attribute
: childElements
) {
66 if (attribute
== null) {
69 ITmfXmlStateAttribute xAttribute
= modelFactory
.createStateAttribute(attribute
, fContainer
);
70 fPath
.add(xAttribute
);
75 * Get the id of the location
77 * @return The id of a location
79 public String
getId() {
84 * Get the quark for the path represented by this location
87 * The event being handled
89 * The starting quark for relative search, use
90 * {@link IXmlStateSystemContainer#ROOT_QUARK} for the root of
92 * @return The quark at the leaf of the path
94 public int getLocationQuark(@Nullable ITmfEvent event
, int startQuark
) {
95 int quark
= startQuark
;
96 for (ITmfXmlStateAttribute attrib
: fPath
) {
97 quark
= attrib
.getAttributeQuark(event
, quark
);
98 if (quark
== IXmlStateSystemContainer
.ERROR_QUARK
) {
106 * Get the quark for the path represented by this location
109 * The starting quark for relative search, use
110 * {@link IXmlStateSystemContainer#ROOT_QUARK} for the root of
112 * @return The quark at the leaf of the path
114 public int getLocationQuark(int startQuark
) {
115 int quark
= startQuark
;
116 for (ITmfXmlStateAttribute attrib
: fPath
) {
117 quark
= attrib
.getAttributeQuark(quark
);
118 if (quark
== IXmlStateSystemContainer
.ERROR_QUARK
) {
126 public String
toString() {
127 return "TmfXmlLocation " + fId
+ ": " + fPath
; //$NON-NLS-1$ //$NON-NLS-2$