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