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
.linuxtools
.internal
.tmf
.analysis
.xml
.core
.stateprovider
.model
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
18 import org
.eclipse
.linuxtools
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
19 import org
.eclipse
.linuxtools
.tmf
.analysis
.xml
.core
.stateprovider
.TmfXmlStrings
;
20 import org
.eclipse
.linuxtools
.tmf
.analysis
.xml
.core
.stateprovider
.XmlStateProvider
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
22 import org
.w3c
.dom
.Element
;
25 * This Class implements a Location in the XML state provider, ie a named
26 * shortcut to reach a given attribute, used in state attributes
30 * <location id="CurrentCPU">
31 * <stateAttribute type="constant" value="CPUs" />
32 * <stateAttribute type="eventField" name="cpu" />
37 * @author Florian Wininger
39 public class TmfXmlLocation
{
41 /** Path in the State System */
42 private final List
<TmfXmlStateAttribute
> fPath
= new ArrayList
<>();
44 /** ID : name of the location */
45 private final String fId
;
46 private final XmlStateProvider fProvider
;
54 * The state provider this location belongs to
56 public TmfXmlLocation(Element location
, XmlStateProvider provider
) {
57 fId
= location
.getAttribute(TmfXmlStrings
.ID
);
60 List
<Element
> childElements
= XmlUtils
.getChildElements(location
);
61 for (Element attribute
: childElements
) {
62 TmfXmlStateAttribute xAttribute
= new TmfXmlStateAttribute(attribute
, fProvider
);
63 fPath
.add(xAttribute
);
68 * Get the id of the location
70 * @return The id of a location
72 public String
getId() {
77 * Get the quark for the path represented by this location
80 * The event being handled
82 * The starting quark for relative search, use
83 * {@link XmlStateProvider#ROOT_QUARK} for the root of the
85 * @return The quark at the leaf of the path
87 public int getLocationQuark(ITmfEvent event
, int startQuark
) {
88 int quark
= startQuark
;
89 for (TmfXmlStateAttribute attrib
: fPath
) {
90 quark
= attrib
.getAttributeQuark(event
, quark
);
91 if (quark
== XmlStateProvider
.ERROR_QUARK
) {