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 / 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.internal.tmf.analysis.xml.core.model;
10
11 import java.util.Map.Entry;
12
13 import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
14 import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternStateProvider;
15 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
16 import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
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 */
26 public class UpdateStoredFieldsAction implements ITmfXmlAction {
27
28 private final IXmlStateSystemContainer fParent;
29
30 /**
31 * Constructor
32 *
33 * @param parent
34 * The state system container this action belongs to
35 */
36 public UpdateStoredFieldsAction(IXmlStateSystemContainer parent) {
37 fParent = parent;
38 }
39
40 @Override
41 public void execute(ITmfEvent event, TmfXmlScenarioInfo scenarioInfo) {
42 if (fParent instanceof XmlPatternStateProvider) {
43 for (Entry<String, String> entry : ((XmlPatternStateProvider) fParent).getStoredFields().entrySet()) {
44 ITmfEventField eventField = event.getContent().getField(entry.getKey());
45 ITmfStateValue stateValue = null;
46 if (eventField != null) {
47 final String alias = entry.getValue();
48 Object field = eventField.getValue();
49 if (field instanceof String) {
50 stateValue = TmfStateValue.newValueString((String) field);
51 } else if (field instanceof Long) {
52 stateValue = TmfStateValue.newValueLong(((Long) field).longValue());
53 } else if (field instanceof Integer) {
54 stateValue = TmfStateValue.newValueInt(((Integer) field).intValue());
55 } else if (field instanceof Double) {
56 stateValue = TmfStateValue.newValueDouble(((Double) field).doubleValue());
57 }
58 if (stateValue == null) {
59 throw new IllegalStateException("State value is null. Invalid type."); //$NON-NLS-1$
60 }
61 ((XmlPatternStateProvider) fParent).getHistoryBuilder().updateStoredFields(fParent, alias, stateValue, scenarioInfo, event);
62 }
63 }
64 }
65 }
66 }
This page took 0.032464 seconds and 5 git commands to generate.