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
.tmf
.analysis
.xml
.core
.model
;
11 import java
.util
.Map
.Entry
;
13 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.core
.pattern
.stateprovider
.XmlPatternStateProvider
;
14 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
15 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.TmfStateValue
;
16 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.module
.IXmlStateSystemContainer
;
17 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
18 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
21 * This action will update the value of the stored fields in the state system
22 * based on the current event data.
24 * @author Jean-Christian Kouame
27 public class UpdateStoredFieldsAction
implements ITmfXmlAction
{
29 private final IXmlStateSystemContainer fParent
;
35 * The state system container this action belongs to
37 public UpdateStoredFieldsAction(IXmlStateSystemContainer parent
) {
42 public void execute(ITmfEvent event
, TmfXmlScenarioInfo scenarioInfo
) {
43 if (fParent
instanceof XmlPatternStateProvider
) {
44 for (Entry
<String
, String
> entry
: ((XmlPatternStateProvider
) fParent
).getStoredFields().entrySet()) {
45 ITmfEventField eventField
= event
.getContent().getField(entry
.getKey());
46 ITmfStateValue stateValue
= null;
47 if (eventField
!= null) {
48 final String alias
= entry
.getValue();
49 Object field
= eventField
.getValue();
50 if (field
instanceof String
) {
51 stateValue
= TmfStateValue
.newValueString((String
) field
);
52 } else if (field
instanceof Long
) {
53 stateValue
= TmfStateValue
.newValueLong(((Long
) field
).longValue());
54 } else if (field
instanceof Integer
) {
55 stateValue
= TmfStateValue
.newValueInt(((Integer
) field
).intValue());
56 } else if (field
instanceof Double
) {
57 stateValue
= TmfStateValue
.newValueDouble(((Double
) field
).doubleValue());
59 if (stateValue
== null) {
60 throw new IllegalStateException("State value is null. Invalid type."); //$NON-NLS-1$
62 ((XmlPatternStateProvider
) fParent
).getHistoryBuilder().updateStoredFields(fParent
, alias
, stateValue
, scenarioInfo
, event
);