use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueEventName in project tracecompass by tracecompass.
the class TmfXmlStateAttributeAndLocationCuTest method testValidStateAttributeCompilation.
/**
* Test the compilation of a valid state attribute strings, except locations
*
* @throws SAXException
* Exception thrown by parser
* @throws IOException
* Exception thrown by parser
* @throws ParserConfigurationException
* Exception thrown by parser
*/
@Test
public void testValidStateAttributeCompilation() throws SAXException, IOException, ParserConfigurationException {
String[] validStrings = { "<stateAttribute type=\"null\" />", "<stateAttribute type=\"constant\" value=\"42\" />", "<stateAttribute type=\"eventField\" value=\"myfield\" />", "<stateAttribute type=\"eventName\" />", "<stateAttribute type=\"eventName\" value=\"ignored\" />", "<stateAttribute type=\"query\" ><stateAttribute type=\"constant\" value=\"queryPath\"/></stateAttribute>", "<stateAttribute type=\"self\" />", "<stateAttribute type=\"pool\" />" };
DataDrivenValue[] generated = { TmfXmlTestUtils.NULL_VALUE, new DataDrivenValueConstant(null, ITmfStateValue.Type.NULL, "42"), new DataDrivenValueEventField(null, ITmfStateValue.Type.NULL, "myfield"), new DataDrivenValueEventName(null), new DataDrivenValueEventName(null), new DataDrivenValueQuery(null, ITmfStateValue.Type.NULL, new DataDrivenStateSystemPath(ImmutableList.of(new DataDrivenValueConstant(null, ITmfStateValue.Type.NULL, "queryPath")), IBaseQuarkProvider.IDENTITY_BASE_QUARK)), new DataDrivenValueSelf(ITmfStateValue.Type.NULL), DataDrivenValuePool.getInstance() };
for (int i = 0; i < validStrings.length; i++) {
String validString = validStrings[i];
DataDrivenValue runtimeObj = generated[i];
Element xmlElement = TmfXmlTestUtils.getXmlElement(TmfXmlStrings.STATE_ATTRIBUTE, validString);
assertNotNull(xmlElement);
List<@NonNull TmfXmlStateValueCu> compileAttribute = TmfXmlStateValueCu.compileAttribute(ANALYSIS_DATA, xmlElement);
assertNotNull(validString, compileAttribute);
assertEquals("Number of attributes", 1, compileAttribute.size());
TmfXmlStateValueCu value = compileAttribute.get(0);
assertEquals("Expected attribute", runtimeObj, value.generate());
}
}
use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueEventName in project tracecompass by tracecompass.
the class TmfXmlStateValueCu method compileAttribute.
/**
* Compile a stateAttribute XML element. It returns a list since some
* attributes may link to location values that are replaced by the
* corresponding attribute values.
*
* @param analysisData
* The analysis data already compiled
* @param valueEl
* The XML element to compile
* @return A list of value compilation units this element compiles to, or
* <code>null</code> if there was a compilation error
*/
@Nullable
public static List<TmfXmlStateValueCu> compileAttribute(AnalysisCompilationData analysisData, Element valueEl) {
String type = valueEl.getAttribute(TmfXmlStrings.TYPE);
Type forcedType = ITmfStateValue.Type.NULL;
switch(type) {
case TmfXmlStrings.TYPE_CONSTANT:
{
String name = getValueString(analysisData, valueEl);
if (name == null || name.isEmpty()) {
// TODO: Validation message here
// $NON-NLS-1$
Activator.logError("The value of a constant attribute should not be empty");
return null;
}
if (name.equals(CURRENT_SCENARIO)) {
return Collections.singletonList(CURRENT_SCENARIO_QUARK);
}
TmfXmlStateValueCu tmfXmlStateValueCu = new TmfXmlStateValueCu(() -> new DataDrivenValueConstant(null, forcedType, name));
return Collections.singletonList(tmfXmlStateValueCu);
}
case TmfXmlStrings.EVENT_FIELD:
{
String name = getValueString(analysisData, valueEl);
if (name == null || name.isEmpty()) {
// TODO: Validation message here
// $NON-NLS-1$
Activator.logError("The value of an event field attribute should not be null");
return null;
}
return Collections.singletonList(new TmfXmlStateValueCu(() -> new DataDrivenValueEventField(null, forcedType, name)));
}
case TmfXmlStrings.TYPE_LOCATION:
{
String name = getValueString(analysisData, valueEl);
if (name == null || name.isEmpty()) {
// TODO: Validation message here
// $NON-NLS-1$
Activator.logError("The value of a location attribute should not be null");
return null;
}
TmfXmlLocationCu location = analysisData.getLocation(name);
if (location == null) {
// TODO: Validation message here
// $NON-NLS-1$ //$NON-NLS-2$
Activator.logError("Location " + name + " does not exist");
return null;
}
return location.getValues();
}
case TmfXmlStrings.TYPE_QUERY:
{
List<Element> childElements = TmfXmlUtils.getChildElements(valueEl, TmfXmlStrings.STATE_ATTRIBUTE);
if (childElements.isEmpty()) {
// TODO: Validation message here
// $NON-NLS-1$
Activator.logError("A query state attribute should have children attributes");
return null;
}
TmfXmlStateSystemPathCu path = TmfXmlStateSystemPathCu.compile(analysisData, childElements);
if (path == null) {
return null;
}
return Collections.singletonList(new TmfXmlStateValueCu(new StateValueQueryGenerator(path, null, forcedType)));
}
case TmfXmlStrings.TYPE_EVENT_NAME:
return Collections.singletonList(new TmfXmlStateValueCu(() -> new DataDrivenValueEventName(null)));
case TmfXmlStrings.TYPE_NULL:
return Collections.singletonList(new TmfXmlStateValueCu(() -> new DataDrivenValueConstant(null, forcedType, null)));
case TmfXmlStrings.TYPE_SELF:
return Collections.singletonList(new TmfXmlStateValueCu(() -> new DataDrivenValueSelf(forcedType)));
case TmfXmlStrings.TYPE_POOL:
return Collections.singletonList(new TmfXmlStateValueCu(() -> DataDrivenValuePool.getInstance()));
default:
// $NON-NLS-1$
Activator.logError("Compiling state value: The XML element is not of the right type " + type);
}
return null;
}
use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueEventName in project tracecompass by tracecompass.
the class TmfXmlStateValueCu method compileValue.
/**
* Compile a stateValue XML element
*
* @param analysisData
* The analysis data already compiled
* @param valueEl
* The XML element to compile
* @return The value compilation unit or <code>null</code> if there were
* compilation errors
*/
@Nullable
public static TmfXmlStateValueCu compileValue(AnalysisCompilationData analysisData, Element valueEl) {
String type = valueEl.getAttribute(TmfXmlStrings.TYPE);
/*
* Stack peek will have a separate treatment here, as the state value
* may have sub attributes
*
* FIXME: This case should not be supported this way, have a special
* type for stack peek and remove the peek stack action..
*/
String stack = valueEl.getAttribute(TmfXmlStrings.ATTRIBUTE_STACK);
StackAction stackAction = DataDrivenActionStateChange.StackAction.getTypeFromString(stack);
if (stackAction == StackAction.PEEK) {
type = TmfXmlStrings.STACK_PEEK;
}
// Verify mapping group data
String mapGroupAttrib = valueEl.getAttribute(TmfXmlStrings.MAPPING_GROUP);
TmfXmlMappingGroupCu mappingGroup = analysisData.getMappingGroup(mapGroupAttrib);
// Make sure the mapping group exists
if (!mapGroupAttrib.isEmpty() && mappingGroup == null) {
// TODO: Validation message here
// $NON-NLS-1$ //$NON-NLS-2$
Activator.logError("The mapping group " + mapGroupAttrib + " does not exist in this analysis");
return null;
}
String mappingGroupId = (mapGroupAttrib.isEmpty() ? null : mapGroupAttrib);
/*
* Forced type allows to convert the value to a certain type : For
* example, a process's TID in an event field may arrive with a LONG
* format but we want to store the data in an INT
*/
String forcedTypeName = valueEl.getAttribute(TmfXmlStrings.FORCED_TYPE);
ITmfStateValue.Type forcedType = forcedTypeName.isEmpty() ? ITmfStateValue.Type.NULL : TmfXmlUtils.getTmfStateValueByName(forcedTypeName);
if (forcedType == null) {
// TODO: Validation message here
Activator.logError(// $NON-NLS-1$
"The given type name \"" + forcedType + // $NON-NLS-1$
"\" does not correspond to any ITmfStateValue.Type");
return null;
}
switch(type) {
case TmfXmlStrings.TYPE_INT:
{
if (mappingGroup != null) {
// TODO: Validation message here
// $NON-NLS-1$
Activator.logWarning("state value is type int but a mappingGroup is specified");
}
String value = getValueString(analysisData, valueEl);
if (value == null) {
return null;
}
Object intValue = convertValueToType(value, Type.INTEGER);
if (intValue == null) {
return null;
}
return new TmfXmlStateValueCu(() -> new DataDrivenValueConstant(mappingGroupId, forcedType, intValue));
}
case TmfXmlStrings.TYPE_LONG:
{
if (mappingGroup != null) {
// TODO: Validation message here
// $NON-NLS-1$
Activator.logWarning("state value is type long but a mappingGroup is specified");
}
String value = getValueString(analysisData, valueEl);
if (value == null) {
return null;
}
Object longValue = convertValueToType(value, Type.LONG);
if (longValue == null) {
return null;
}
return new TmfXmlStateValueCu(() -> new DataDrivenValueConstant(mappingGroupId, forcedType, longValue));
}
case TmfXmlStrings.TYPE_STRING:
{
String value = getValueString(analysisData, valueEl);
return new TmfXmlStateValueCu(() -> new DataDrivenValueConstant(mappingGroupId, forcedType, value));
}
case TmfXmlStrings.TYPE_NULL:
{
if (mappingGroup != null) {
// TODO: Validation message here
// $NON-NLS-1$
Activator.logWarning("state value is type null but a mappingGroup is specified");
}
return new TmfXmlStateValueCu(() -> new DataDrivenValueConstant(mappingGroupId, forcedType, null));
}
case TmfXmlStrings.EVENT_FIELD:
{
String name = getValueString(analysisData, valueEl);
if (name == null || name.isEmpty()) {
// TODO: Validation message here
// $NON-NLS-1$
Activator.logError("The value of an event field attribute should not be null");
return null;
}
return new TmfXmlStateValueCu(() -> new DataDrivenValueEventField(mappingGroupId, forcedType, name));
}
case TmfXmlStrings.TYPE_EVENT_NAME:
return new TmfXmlStateValueCu(() -> new DataDrivenValueEventName(mappingGroupId));
case TmfXmlStrings.TYPE_DELETE:
{
if (mappingGroup != null) {
// TODO: Validation message here
// $NON-NLS-1$
Activator.logWarning("state value is type delete but a mappingGroup is specified");
}
return new TmfXmlStateValueCu(() -> new DataDrivenValueConstant(mappingGroupId, forcedType, null));
}
case TmfXmlStrings.TYPE_QUERY:
{
List<Element> childElements = TmfXmlUtils.getChildElements(valueEl, TmfXmlStrings.STATE_ATTRIBUTE);
if (childElements.isEmpty()) {
// TODO: Validation message here
// $NON-NLS-1$
Activator.logError("A query state value should have children attributes");
return null;
}
TmfXmlStateSystemPathCu path = TmfXmlStateSystemPathCu.compile(analysisData, childElements);
if (path == null) {
return null;
}
return new TmfXmlStateValueCu(new StateValueQueryGenerator(path, mappingGroupId, forcedType));
}
case TmfXmlStrings.TYPE_SCRIPT:
{
List<Element> childElements = TmfXmlUtils.getChildElements(valueEl, TmfXmlStrings.STATE_VALUE);
Map<String, TmfXmlStateValueCu> values = new HashMap<>();
for (Element subAttributeNode : childElements) {
// state values in a script should have an ID
String valueId = subAttributeNode.getAttribute(TmfXmlStrings.ID);
TmfXmlStateValueCu subAttrib = TmfXmlStateValueCu.compileValue(analysisData, subAttributeNode);
if (subAttrib == null) {
return null;
}
values.put(valueId, subAttrib);
}
String script = getValueString(analysisData, valueEl);
if (script == null) {
// TODO: Validation message here
// $NON-NLS-1$
Activator.logError("The script resolves to null");
return null;
}
String scriptEngine = valueEl.getAttribute(TmfXmlStrings.SCRIPT_ENGINE);
if (scriptEngine.isEmpty()) {
scriptEngine = DataDrivenValueScript.DEFAULT_SCRIPT_ENGINE;
}
return new TmfXmlStateValueCu(new StateValueScriptGenerator(values, script, scriptEngine, mappingGroupId, forcedType));
}
case TmfXmlStrings.STACK_PEEK:
{
// A stack peek is like a query at the top of the stack
List<Element> childElements = TmfXmlUtils.getChildElements(valueEl, TmfXmlStrings.STATE_ATTRIBUTE);
if (childElements.isEmpty()) {
// TODO: Validation message here
// $NON-NLS-1$
Activator.logWarning("Compiling state value: Stack peek should have children state attributes");
}
TmfXmlStateSystemPathCu path = TmfXmlStateSystemPathCu.compile(analysisData, childElements);
if (path == null) {
return null;
}
return new TmfXmlStateValueCu(new StateValueStackPeekGenerator(path, mappingGroupId, forcedType));
}
default:
// $NON-NLS-1$
Activator.logError("Compiling state value: The XML element is not of the right type " + type);
}
return null;
}
Aggregations