tmf: Replace event matching API to use Collection
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.analysis.xml.core / src / org / eclipse / linuxtools / internal / tmf / analysis / xml / core / stateprovider / model / TmfXmlLocation.java
1 /*******************************************************************************
2 * Copyright (c) 2014 Ecole Polytechnique de Montreal
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 *
9 * Contributors:
10 * Florian Wininger - Initial API and implementation
11 ******************************************************************************/
12
13 package org.eclipse.linuxtools.internal.tmf.analysis.xml.core.stateprovider.model;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
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;
23
24 /**
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
27 *
28 * <pre>
29 * example:
30 * <location id="CurrentCPU">
31 * <stateAttribute type="constant" value="CPUs" />
32 * <stateAttribute type="eventField" name="cpu" />
33 * ...
34 * </location>
35 * </pre>
36 *
37 * @author Florian Wininger
38 */
39 public class TmfXmlLocation {
40
41 /** Path in the State System */
42 private final List<TmfXmlStateAttribute> fPath = new ArrayList<>();
43
44 /** ID : name of the location */
45 private final String fId;
46 private final XmlStateProvider fProvider;
47
48 /**
49 * Constructor
50 *
51 * @param location
52 * XML node element
53 * @param provider
54 * The state provider this location belongs to
55 */
56 public TmfXmlLocation(Element location, XmlStateProvider provider) {
57 fId = location.getAttribute(TmfXmlStrings.ID);
58 fProvider = provider;
59
60 List<Element> childElements = XmlUtils.getChildElements(location);
61 for (Element attribute : childElements) {
62 TmfXmlStateAttribute xAttribute = new TmfXmlStateAttribute(attribute, fProvider);
63 fPath.add(xAttribute);
64 }
65 }
66
67 /**
68 * Get the id of the location
69 *
70 * @return The id of a location
71 */
72 public String getId() {
73 return fId;
74 }
75
76 /**
77 * Get the quark for the path represented by this location
78 *
79 * @param event
80 * The event being handled
81 * @param startQuark
82 * The starting quark for relative search, use
83 * {@link XmlStateProvider#ROOT_QUARK} for the root of the
84 * attribute tree
85 * @return The quark at the leaf of the path
86 */
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) {
92 break;
93 }
94 }
95 return quark;
96 }
97
98 }
This page took 0.036233 seconds and 5 git commands to generate.