analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.analysis.xml.core / src / org / eclipse / tracecompass / 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
2bdf0193 13package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
0f7276b6 14
1d7e62f9 15import java.util.LinkedList;
0f7276b6
GB
16import java.util.List;
17
12685851 18import org.eclipse.jdt.annotation.Nullable;
2bdf0193
AM
19import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
20import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
21import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
22import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
0f7276b6
GB
23import org.w3c.dom.Element;
24
25/**
1d7e62f9 26 * This Class implements a Location in the XML-defined state system, ie a named
0f7276b6
GB
27 * shortcut to reach a given attribute, used in state attributes
28 *
29 * <pre>
30 * example:
31 * <location id="CurrentCPU">
32 * <stateAttribute type="constant" value="CPUs" />
33 * <stateAttribute type="eventField" name="cpu" />
34 * ...
35 * </location>
36 * </pre>
37 *
38 * @author Florian Wininger
39 */
40public class TmfXmlLocation {
41
42 /** Path in the State System */
1d7e62f9 43 private final List<ITmfXmlStateAttribute> fPath = new LinkedList<>();
0f7276b6
GB
44
45 /** ID : name of the location */
46 private final String fId;
1d7e62f9 47 private final IXmlStateSystemContainer fContainer;
0f7276b6
GB
48
49 /**
50 * Constructor
51 *
1d7e62f9
GB
52 * @param modelFactory
53 * The factory used to create XML model elements
0f7276b6
GB
54 * @param location
55 * XML node element
1d7e62f9
GB
56 * @param container
57 * The state system container this location belongs to
0f7276b6 58 */
1d7e62f9 59 public TmfXmlLocation(ITmfXmlModelFactory modelFactory, Element location, IXmlStateSystemContainer container) {
12685851
GB
60 String id = location.getAttribute(TmfXmlStrings.ID);
61 if (id == null) {
62 throw new IllegalArgumentException();
63 }
64 fId = id;
1d7e62f9 65 fContainer = container;
0f7276b6
GB
66
67 List<Element> childElements = XmlUtils.getChildElements(location);
68 for (Element attribute : childElements) {
12685851
GB
69 if (attribute == null) {
70 continue;
71 }
1d7e62f9 72 ITmfXmlStateAttribute xAttribute = modelFactory.createStateAttribute(attribute, fContainer);
0f7276b6
GB
73 fPath.add(xAttribute);
74 }
75 }
76
77 /**
78 * Get the id of the location
79 *
80 * @return The id of a location
81 */
82 public String getId() {
83 return fId;
84 }
85
86 /**
87 * Get the quark for the path represented by this location
88 *
89 * @param event
90 * The event being handled
91 * @param startQuark
92 * The starting quark for relative search, use
1d7e62f9
GB
93 * {@link IXmlStateSystemContainer#ROOT_QUARK} for the root of
94 * the attribute tree
0f7276b6
GB
95 * @return The quark at the leaf of the path
96 */
12685851 97 public int getLocationQuark(@Nullable ITmfEvent event, int startQuark) {
0f7276b6 98 int quark = startQuark;
1d7e62f9 99 for (ITmfXmlStateAttribute attrib : fPath) {
0f7276b6 100 quark = attrib.getAttributeQuark(event, quark);
1d7e62f9
GB
101 if (quark == IXmlStateSystemContainer.ERROR_QUARK) {
102 break;
103 }
104 }
105 return quark;
106 }
107
108 /**
109 * Get the quark for the path represented by this location
110 *
111 * @param startQuark
112 * The starting quark for relative search, use
113 * {@link IXmlStateSystemContainer#ROOT_QUARK} for the root of
114 * the attribute tree
115 * @return The quark at the leaf of the path
116 */
117 public int getLocationQuark(int startQuark) {
118 int quark = startQuark;
119 for (ITmfXmlStateAttribute attrib : fPath) {
120 quark = attrib.getAttributeQuark(quark);
121 if (quark == IXmlStateSystemContainer.ERROR_QUARK) {
0f7276b6
GB
122 break;
123 }
124 }
125 return quark;
126 }
127
446598f9
GB
128 @Override
129 public String toString() {
130 return "TmfXmlLocation " + fId + ": " + fPath; //$NON-NLS-1$ //$NON-NLS-2$
131 }
132
0f7276b6 133}
This page took 0.065236 seconds and 5 git commands to generate.