1 /*******************************************************************************
2 * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
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
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Arrays
;
13 import java
.util
.Collections
;
14 import java
.util
.List
;
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
;
21 * This Class implements a state transition tree in the XML-defined state
24 * @author Jean-Christian Kouame
26 public class TmfXmlStateTransition
extends TmfXmlBasicTransition
{
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
;
31 private final String fTarget
;
32 private final List
<String
> fAction
;
33 private final boolean fStoredFieldsToBeSaved
;
34 private final boolean fStoredFieldsToBeCleared
;
40 * The factory used to create XML model elements
42 * The XML root of this state transition
44 * The state system container this state transition belongs to
46 public TmfXmlStateTransition(ITmfXmlModelFactory modelFactory
, Element node
, IXmlStateSystemContainer container
) {
48 String target
= node
.getAttribute(TmfXmlStrings
.TARGET
);
49 if (target
.isEmpty()) {
50 throw new IllegalStateException("No target state has been specified."); //$NON-NLS-1$
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
);
61 fAction
.addAll(actions
);
62 if (fStoredFieldsToBeCleared
) {
63 fAction
.add(CLEAR_STORED_FIELDS_ACTION_STRINGS
);
68 * The next state of the state machine this state transition belongs to.
70 * @return the next state this transition try to reach
72 public String
getTarget() {
77 * The action to be executed when the input of this state transition is
80 * @return the action to execute if the input is validate
82 public List
<String
> getAction() {
87 * Tell if the stored fields have to be saved at this step of the scenario
89 * @return If the stored fields have to be saved or not
91 public boolean isStoredFieldsToBeSaved() {
92 return fStoredFieldsToBeSaved
;
96 * Tell if the stored fields have to be cleared at this moment of this scenario
98 * @return If the stored fields have to cleared or not
100 public boolean isStoredFieldsToBeCleared() {
101 return fStoredFieldsToBeCleared
;