Move alltests plugin to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.analysis.xml.core / src / org / eclipse / linuxtools / tmf / analysis / xml / core / model / TmfXmlLocation.java
CommitLineData
0f7276b6
GB
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
1d7e62f9 13package org.eclipse.linuxtools.tmf.analysis.xml.core.model;
0f7276b6 14
1d7e62f9 15import java.util.LinkedList;
0f7276b6
GB
16import java.util.List;
17
1d7e62f9 18import org.eclipse.linuxtools.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
0f7276b6
GB
19import org.eclipse.linuxtools.tmf.analysis.xml.core.module.XmlUtils;
20import org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
0f7276b6
GB
21import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
22import org.w3c.dom.Element;
23
24/**
1d7e62f9 25 * This Class implements a Location in the XML-defined state system, ie a named
0f7276b6
GB
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 */
39public class TmfXmlLocation {
40
41 /** Path in the State System */
1d7e62f9 42 private final List<ITmfXmlStateAttribute> fPath = new LinkedList<>();
0f7276b6
GB
43
44 /** ID : name of the location */
45 private final String fId;
1d7e62f9 46 private final IXmlStateSystemContainer fContainer;
0f7276b6
GB
47
48 /**
49 * Constructor
50 *
1d7e62f9
GB
51 * @param modelFactory
52 * The factory used to create XML model elements
0f7276b6
GB
53 * @param location
54 * XML node element
1d7e62f9
GB
55 * @param container
56 * The state system container this location belongs to
0f7276b6 57 */
1d7e62f9 58 public TmfXmlLocation(ITmfXmlModelFactory modelFactory, Element location, IXmlStateSystemContainer container) {
0f7276b6 59 fId = location.getAttribute(TmfXmlStrings.ID);
1d7e62f9 60 fContainer = container;
0f7276b6
GB
61
62 List<Element> childElements = XmlUtils.getChildElements(location);
63 for (Element attribute : childElements) {
1d7e62f9 64 ITmfXmlStateAttribute xAttribute = modelFactory.createStateAttribute(attribute, fContainer);
0f7276b6
GB
65 fPath.add(xAttribute);
66 }
67 }
68
69 /**
70 * Get the id of the location
71 *
72 * @return The id of a location
73 */
74 public String getId() {
75 return fId;
76 }
77
78 /**
79 * Get the quark for the path represented by this location
80 *
81 * @param event
82 * The event being handled
83 * @param startQuark
84 * The starting quark for relative search, use
1d7e62f9
GB
85 * {@link IXmlStateSystemContainer#ROOT_QUARK} for the root of
86 * the attribute tree
0f7276b6
GB
87 * @return The quark at the leaf of the path
88 */
89 public int getLocationQuark(ITmfEvent event, int startQuark) {
90 int quark = startQuark;
1d7e62f9 91 for (ITmfXmlStateAttribute attrib : fPath) {
0f7276b6 92 quark = attrib.getAttributeQuark(event, quark);
1d7e62f9
GB
93 if (quark == IXmlStateSystemContainer.ERROR_QUARK) {
94 break;
95 }
96 }
97 return quark;
98 }
99
100 /**
101 * Get the quark for the path represented by this location
102 *
103 * @param startQuark
104 * The starting quark for relative search, use
105 * {@link IXmlStateSystemContainer#ROOT_QUARK} for the root of
106 * the attribute tree
107 * @return The quark at the leaf of the path
108 */
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) {
0f7276b6
GB
114 break;
115 }
116 }
117 return quark;
118 }
119
446598f9
GB
120 @Override
121 public String toString() {
122 return "TmfXmlLocation " + fId + ": " + fPath; //$NON-NLS-1$ //$NON-NLS-2$
123 }
124
0f7276b6 125}
This page took 0.041464 seconds and 5 git commands to generate.