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
.tmf
.analysis
.xml
.core
.model
;
15 import java
.util
.LinkedList
;
16 import java
.util
.List
;
18 import org
.eclipse
.linuxtools
.tmf
.analysis
.xml
.core
.module
.IXmlStateSystemContainer
;
19 import org
.eclipse
.linuxtools
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
20 import org
.eclipse
.linuxtools
.tmf
.analysis
.xml
.core
.stateprovider
.TmfXmlStrings
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
22 import org
.w3c
.dom
.Element
;
25 * This Class implements a Location in the XML-defined state system, 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
<ITmfXmlStateAttribute
> fPath
= new LinkedList
<>();
44 /** ID : name of the location */
45 private final String fId
;
46 private final IXmlStateSystemContainer fContainer
;
52 * The factory used to create XML model elements
56 * The state system container this location belongs to
58 public TmfXmlLocation(ITmfXmlModelFactory modelFactory
, Element location
, IXmlStateSystemContainer container
) {
59 fId
= location
.getAttribute(TmfXmlStrings
.ID
);
60 fContainer
= container
;
62 List
<Element
> childElements
= XmlUtils
.getChildElements(location
);
63 for (Element attribute
: childElements
) {
64 ITmfXmlStateAttribute xAttribute
= modelFactory
.createStateAttribute(attribute
, fContainer
);
65 fPath
.add(xAttribute
);
70 * Get the id of the location
72 * @return The id of a location
74 public String
getId() {
79 * Get the quark for the path represented by this location
82 * The event being handled
84 * The starting quark for relative search, use
85 * {@link IXmlStateSystemContainer#ROOT_QUARK} for the root of
87 * @return The quark at the leaf of the path
89 public int getLocationQuark(ITmfEvent event
, int startQuark
) {
90 int quark
= startQuark
;
91 for (ITmfXmlStateAttribute attrib
: fPath
) {
92 quark
= attrib
.getAttributeQuark(event
, quark
);
93 if (quark
== IXmlStateSystemContainer
.ERROR_QUARK
) {
101 * Get the quark for the path represented by this location
104 * The starting quark for relative search, use
105 * {@link IXmlStateSystemContainer#ROOT_QUARK} for the root of
107 * @return The quark at the leaf of the path
109 public int getLocationQuark(int startQuark
) {
110 int quark
= startQuark
;
111 for (ITmfXmlStateAttribute attrib
: fPath
) {
112 quark
= attrib
.getAttributeQuark(quark
);
113 if (quark
== IXmlStateSystemContainer
.ERROR_QUARK
) {
121 public String
toString() {
122 return "TmfXmlLocation " + fId
+ ": " + fPath
; //$NON-NLS-1$ //$NON-NLS-2$