package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
import java.util.List;
+import java.util.Set;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternStateProvider;
import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.XmlStateProvider;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
/* Whether this state value is an increment of the previous value */
private final boolean fIncrement;
+ /* Whether to update the current attribute or create a new state */
+ private final boolean fUpdate;
/* Stack value */
private final ValueTypeStack fStackType;
/* Forced value type */
private final IXmlStateSystemContainer fContainer;
+ private final String fMappingGroup;
+
/**
* Different behaviors of an attribute that is to be stacked
*/
/* Check if there is an increment for the value */
fIncrement = Boolean.parseBoolean(node.getAttribute(TmfXmlStrings.INCREMENT));
+ /* Check if this value is an update of the ongoing state */
+ fUpdate = Boolean.parseBoolean(node.getAttribute(TmfXmlStrings.UPDATE));
+
/* Process the XML Element state value */
fStateValue = initializeStateValue(modelFactory, node);
*/
String stack = node.getAttribute(TmfXmlStrings.ATTRIBUTE_STACK);
fStackType = ValueTypeStack.getTypeFromString(stack);
+
+ fMappingGroup = node.getAttribute(TmfXmlStrings.MAPPING_GROUP);
}
/**
return fIncrement;
}
+ /**
+ * Return whether this value should replace the current value of the
+ * attribute or if a new state should be created.
+ *
+ * @return <code>true</code> if the value is to replace the current one
+ */
+ protected boolean isUpdate() {
+ return fUpdate;
+ }
+
/**
* Get the stack type of this attribute. If the attribute is to be pushed or
* popped to a stack. The behavior of the stack attribute will depend on the
@Override
public ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
- return fStateValue.getValue(event, scenarioInfo);
+ return getMappedValue(event, scenarioInfo, fStateValue.getValue(event, scenarioInfo));
+ }
+
+ private ITmfStateValue getMappedValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo, ITmfStateValue value) {
+ try {
+ Set<TmfXmlMapEntry> group = null;
+ if (fContainer instanceof XmlPatternStateProvider) {
+ group = ((XmlPatternStateProvider) fContainer).getMappingGroup(fMappingGroup);
+ } else if (fContainer instanceof XmlStateProvider) {
+ group = ((XmlStateProvider) fContainer).getMappingGroup(fMappingGroup);
+ }
+ if (group != null) {
+ for (TmfXmlMapEntry entry : group) {
+ if (entry.getKey().getValue(event, scenarioInfo).equals(value)) {
+ return entry.getValue().getValue(event, scenarioInfo);
+ }
+ }
+ }
+ return value;
+ } catch (AttributeNotFoundException e) {
+ Activator.logError("Unable to map the state value"); //$NON-NLS-1$
+ // FIXME maybe we should return the raw state value instead of a
+ // null state value
+ return TmfStateValue.nullValue();
+ }
}
/**
quark = attribute.getAttributeQuark(event, quark, scenarioInfo);
/* the query is not valid, we stop the state change */
if (quark == IXmlStateSystemContainer.ERROR_QUARK) {
- throw new AttributeNotFoundException("Not found XML attribute " + attribute); //$NON-NLS-1$
+ Activator.logError("Not found XML attribute " + attribute); //$NON-NLS-1$
+ return;
}
}