bea8ab5896737493b695cfe4fb290a0df1b5abe1
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.analysis.xml.core / src / org / eclipse / tracecompass / tmf / analysis / xml / core / model / UpdateStoredFieldsAction.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.tmf.analysis.xml.core.model;
10
11 import java.util.Map.Entry;
12
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;
19
20 /**
21 * This action will update the value of the stored fields in the state system
22 * based on the current event data.
23 *
24 * @author Jean-Christian Kouame
25 * @since 2.0
26 */
27 public class UpdateStoredFieldsAction implements ITmfXmlAction {
28
29 private final IXmlStateSystemContainer fParent;
30
31 /**
32 * Constructor
33 *
34 * @param parent
35 * The state system container this action belongs to
36 */
37 public UpdateStoredFieldsAction(IXmlStateSystemContainer parent) {
38 fParent = parent;
39 }
40
41 @Override
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());
58 }
59 if (stateValue == null) {
60 throw new IllegalStateException("State value is null. Invalid type."); //$NON-NLS-1$
61 }
62 ((XmlPatternStateProvider) fParent).getHistoryBuilder().updateStoredFields(fParent, alias, stateValue, scenarioInfo, event);
63 }
64 }
65 }
66 }
67 }
This page took 0.033075 seconds and 4 git commands to generate.