ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.analysis.xml.core / src / org / eclipse / linuxtools / tmf / analysis / xml / core / 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.tmf.analysis.xml.core.model;
14
15 import java.util.LinkedList;
16 import java.util.List;
17
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;
23
24 /**
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
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<ITmfXmlStateAttribute> fPath = new LinkedList<>();
43
44 /** ID : name of the location */
45 private final String fId;
46 private final IXmlStateSystemContainer fContainer;
47
48 /**
49 * Constructor
50 *
51 * @param modelFactory
52 * The factory used to create XML model elements
53 * @param location
54 * XML node element
55 * @param container
56 * The state system container this location belongs to
57 */
58 public TmfXmlLocation(ITmfXmlModelFactory modelFactory, Element location, IXmlStateSystemContainer container) {
59 fId = location.getAttribute(TmfXmlStrings.ID);
60 fContainer = container;
61
62 List<Element> childElements = XmlUtils.getChildElements(location);
63 for (Element attribute : childElements) {
64 ITmfXmlStateAttribute xAttribute = modelFactory.createStateAttribute(attribute, fContainer);
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
85 * {@link IXmlStateSystemContainer#ROOT_QUARK} for the root of
86 * the attribute tree
87 * @return The quark at the leaf of the path
88 */
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) {
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) {
114 break;
115 }
116 }
117 return quark;
118 }
119
120 @Override
121 public String toString() {
122 return "TmfXmlLocation " + fId + ": " + fPath; //$NON-NLS-1$ //$NON-NLS-2$
123 }
124
125 }
This page took 0.034525 seconds and 5 git commands to generate.