lttng.ust: Add the build-ID to the key of cache of addr2line calls
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.analysis.xml.core / src / org / eclipse / tracecompass / tmf / analysis / xml / core / model / TmfXmlBasicTransition.java
CommitLineData
3a5f73a1
JCK
1/*******************************************************************************
2 * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
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 ******************************************************************************/
9package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
10
11import java.util.ArrayList;
12import java.util.Arrays;
13import java.util.List;
14import java.util.Map;
15import java.util.regex.Pattern;
16
17import org.eclipse.jdt.annotation.NonNull;
18import org.eclipse.jdt.annotation.Nullable;
19import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
20import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
21import org.w3c.dom.Element;
22
23/**
24 * Implementation of a basic transition in the XML file
25 *
26 * @author Jean-Christian Kouame
27 * @since 2.0
28 */
29public class TmfXmlBasicTransition {
30
31 private static final Pattern WILDCARD_PATTERN = Pattern.compile("\\*"); //$NON-NLS-1$
32
33 private final List<String> fCond;
34 private final List<Pattern> fAcceptedEvents;
35
36
37 /**
38 * Constructor
39 *
40 * @param element
41 * the XML basic transition element
42 */
43 public TmfXmlBasicTransition(Element element) {
44 final @NonNull String events = element.getAttribute(TmfXmlStrings.EVENT);
45 fAcceptedEvents = new ArrayList<>();
46 for (String eventName : Arrays.asList(events.split(TmfXmlStrings.OR_SEPARATOR))) {
47 String name = WILDCARD_PATTERN.matcher(eventName).replaceAll(".*"); //$NON-NLS-1$
48 fAcceptedEvents.add(Pattern.compile(name));
49 }
50 final @NonNull String conditions = element.getAttribute(TmfXmlStrings.COND);
51 fCond = conditions.isEmpty() ? new ArrayList<>() : Arrays.asList(conditions.split(TmfXmlStrings.AND_SEPARATOR));
52 }
53
54 /**
55 * Validate the transition with the current event
56 *
57 * @param event
58 * The active event
59 * @param scenarioInfo
60 * The active scenario details.
61 * @param tests
62 * The map of test in the XML file
63 * @return true if the transition is validate false if not
64 */
65 public boolean test(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo, Map<String, TmfXmlTransitionValidator> tests) {
66 if (!validateEvent(event)) {
67 return false;
68 }
69
70 for (String cond : fCond) {
71 TmfXmlTransitionValidator test = tests.get(cond);
72 if (test == null) {
73 throw new IllegalStateException("Failed to find cond " + cond); //$NON-NLS-1$
74 }
75 if (!test.test(event, scenarioInfo)) {
76 return false;
77 }
78 }
79 return true;
80 }
81
82 private boolean validateEvent(ITmfEvent event) {
83 String eventName = event.getName();
84
85 /*
86 * This validates the event name with the accepted regular expressions
87 */
88 for (Pattern nameRegex : fAcceptedEvents) {
89 if (nameRegex.matcher(eventName).matches()) {
90 return true;
91 }
92 }
93 return false;
94 }
95}
This page took 0.032678 seconds and 5 git commands to generate.