Commit | Line | Data |
---|---|---|
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 | ******************************************************************************/ | |
9 | package org.eclipse.tracecompass.tmf.analysis.xml.core.model; | |
10 | ||
11 | import java.util.ArrayList; | |
12 | import java.util.Arrays; | |
13 | import java.util.Collections; | |
14 | import java.util.List; | |
15 | ||
16 | import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer; | |
17 | import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings; | |
18 | import org.w3c.dom.Element; | |
19 | ||
20 | /** | |
21 | * This Class implements a state transition tree in the XML-defined state | |
22 | * system. | |
23 | * | |
24 | * @author Jean-Christian Kouame | |
25 | * @since 2.0 | |
26 | */ | |
27 | public class TmfXmlStateTransition extends TmfXmlBasicTransition { | |
28 | ||
29 | private static final String SAVED_STORED_FIELDS_ACTION_STRING = TmfXmlStrings.CONSTANT_PREFIX + ITmfXmlAction.SAVE_STORED_FIELDS_STRING; | |
30 | private static final String CLEAR_STORED_FIELDS_ACTION_STRINGS = TmfXmlStrings.CONSTANT_PREFIX + ITmfXmlAction.CLEAR_STORED_FIELDS_STRING; | |
31 | ||
32 | private final String fTarget; | |
33 | private final List<String> fAction; | |
34 | private final boolean fStoredFieldsToBeSaved; | |
35 | private final boolean fStoredFieldsToBeCleared; | |
36 | ||
37 | /** | |
38 | * Constructor | |
39 | * | |
40 | * @param modelFactory | |
41 | * The factory used to create XML model elements | |
42 | * @param node | |
43 | * The XML root of this state transition | |
44 | * @param container | |
45 | * The state system container this state transition belongs to | |
46 | */ | |
47 | public TmfXmlStateTransition(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container) { | |
48 | super(node); | |
49 | String target = node.getAttribute(TmfXmlStrings.TARGET); | |
50 | if (target.isEmpty()) { | |
51 | throw new IllegalStateException("No target state has been specified."); //$NON-NLS-1$ | |
52 | } | |
53 | fTarget = target; | |
54 | String action = node.getAttribute(TmfXmlStrings.ACTION); | |
55 | List<String> actions = action.equals(TmfXmlStrings.NULL) ? Collections.EMPTY_LIST : Arrays.asList(action.split(TmfXmlStrings.AND_SEPARATOR)); | |
56 | fStoredFieldsToBeSaved = (node.getAttribute(TmfXmlStrings.SAVE_STORED_FIELDS).equals(TmfXmlStrings.EMPTY_STRING) ? false : Boolean.parseBoolean(node.getAttribute(TmfXmlStrings.SAVE_STORED_FIELDS))); | |
57 | fStoredFieldsToBeCleared = (node.getAttribute(TmfXmlStrings.CLEAR_STORED_FIELDS).equals(TmfXmlStrings.EMPTY_STRING) ? false : Boolean.parseBoolean(node.getAttribute(TmfXmlStrings.CLEAR_STORED_FIELDS))); | |
58 | fAction = new ArrayList<>(); | |
59 | if (fStoredFieldsToBeSaved) { | |
60 | fAction.add(SAVED_STORED_FIELDS_ACTION_STRING); | |
61 | } | |
62 | fAction.addAll(actions); | |
63 | if (fStoredFieldsToBeCleared) { | |
64 | fAction.add(CLEAR_STORED_FIELDS_ACTION_STRINGS); | |
65 | } | |
66 | } | |
67 | ||
68 | /** | |
69 | * The next state of the state machine this state transition belongs to. | |
70 | * | |
71 | * @return the next state this transition try to reach | |
72 | */ | |
73 | public String getTarget() { | |
74 | return fTarget; | |
75 | } | |
76 | ||
77 | /** | |
78 | * The action to be executed when the input of this state transition is | |
79 | * validated | |
80 | * | |
81 | * @return the action to execute if the input is validate | |
82 | */ | |
83 | public List<String> getAction() { | |
84 | return fAction; | |
85 | } | |
86 | ||
87 | /** | |
88 | * Tell if the stored fields have to be saved at this step of the scenario | |
89 | * | |
90 | * @return If the stored fields have to be saved or not | |
91 | */ | |
92 | public boolean isStoredFieldsToBeSaved() { | |
93 | return fStoredFieldsToBeSaved; | |
94 | } | |
95 | ||
96 | /** | |
97 | * Tell if the stored fields have to be cleared at this moment of this scenario | |
98 | * | |
99 | * @return If the stored fields have to cleared or not | |
100 | */ | |
101 | public boolean isStoredFieldsToBeCleared() { | |
102 | return fStoredFieldsToBeCleared; | |
103 | } | |
104 | } |