tmf.xml: Move all .core and .ui packages to internal
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Wed, 20 Apr 2016 00:51:44 +0000 (20:51 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Tue, 3 May 2016 13:54:04 +0000 (09:54 -0400)
and remove the @since tags from the files.

Change-Id: I087db7e4f275e042ce6fa36809aeb1b4a9a8a712
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/71022
Reviewed-by: Hudson CI
138 files changed:
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/module/XmlAnalysisModuleSourceTest.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/module/XmlUtilsTest.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/StateProviderModelTest.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/StateProviderModuleTest.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/StateProviderTest.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/TmfXmlConditionTest.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/TmfXmlDoubleTest.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/src/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stateprovider/TmfXmlPatternSegmentBuilderTest.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/stubs/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stubs/PatternSegmentFactoryStub.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core.tests/stubs/org/eclipse/tracecompass/tmf/analysis/xml/core/tests/stubs/StateSystemContainerStub.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/META-INF/MANIFEST.MF
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/plugin.xml
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/ITmfXmlAction.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/ITmfXmlCondition.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/ITmfXmlModelFactory.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/ITmfXmlStateAttribute.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/ITmfXmlStateValue.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/ResetStoredFieldsAction.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlAction.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlBasicTransition.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlCondition.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlEventHandler.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlFsm.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlLocation.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlPatternEventHandler.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlPatternSegmentBuilder.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlScenario.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlScenarioHistoryBuilder.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlScenarioInfo.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlState.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateAttribute.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateChange.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateTransition.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateValue.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlTimestampCondition.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlTransitionValidator.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/UpdateStoredFieldsAction.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/package-info.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyModelFactory.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateAttribute.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateValue.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readonly/package-info.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteModelFactory.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateAttribute.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateValue.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readwrite/package-info.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/ITmfXmlTopLevelElement.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/IXmlStateSystemContainer.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/Messages.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/TmfAnalysisModuleHelperXml.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/XmlAnalysisModuleSource.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/XmlUtils.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/messages.properties [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlCommon.xsd [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlDefinition.xsd [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlPatternStateProvider.xsd [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlStateProvider.xsd [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlView.xsd [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/pattern/stateprovider/XmlPatternAnalysis.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/pattern/stateprovider/XmlPatternLatencyStatisticsAnalysis.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/pattern/stateprovider/XmlPatternStateProvider.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/segment/TmfXmlPatternSegment.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/stateprovider/TmfXmlStrings.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/stateprovider/XmlStateProvider.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/stateprovider/XmlStateSystemModule.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/ITmfXmlAction.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/ITmfXmlCondition.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/ITmfXmlModelFactory.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/ITmfXmlStateAttribute.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/ITmfXmlStateValue.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/ResetStoredFieldsAction.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlAction.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlBasicTransition.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlCondition.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlEventHandler.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlFsm.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlLocation.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlPatternEventHandler.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlPatternSegmentBuilder.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlScenario.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlScenarioHistoryBuilder.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlScenarioInfo.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlState.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlStateAttribute.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlStateChange.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlStateTransition.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlStateValue.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlTimestampCondition.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlTransitionValidator.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/UpdateStoredFieldsAction.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/package-info.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyModelFactory.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateAttribute.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateValue.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readonly/package-info.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteModelFactory.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateAttribute.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateValue.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readwrite/package-info.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/ITmfXmlTopLevelElement.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/IXmlStateSystemContainer.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/Messages.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/TmfAnalysisModuleHelperXml.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/XmlAnalysisModuleSource.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/XmlUtils.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/messages.properties [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/xmlCommon.xsd [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/xmlDefinition.xsd [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/xmlPatternStateProvider.xsd [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/xmlStateProvider.xsd [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/xmlView.xsd [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/segment/TmfXmlPatternSegment.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/stateprovider/TmfXmlStrings.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/stateprovider/XmlStateProvider.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/stateprovider/XmlStateSystemModule.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/META-INF/MANIFEST.MF
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/plugin.xml
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/handler/ManageXMLAnalysisDialog.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/module/TmfXmlAnalysisOutputSource.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/module/TmfXmlLatencyViewOutput.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/module/TmfXmlViewOutput.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/AbstractXmlViewInfo.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/XmlLatencyViewInfo.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/XmlViewInfo.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/timegraph/Messages.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/timegraph/XmlEntry.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/timegraph/XmlPresentationProvider.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/timegraph/messages.properties [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/xychart/XmlXYViewer.java
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/module/TmfXmlAnalysisOutputSource.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/module/TmfXmlLatencyViewOutput.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/module/TmfXmlViewOutput.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/Messages.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlEntry.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlPresentationProvider.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java [deleted file]
tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/messages.properties [deleted file]

index 6f2e9ad0178b57f45fde1cd6662e5854a68647da..d7d0c5bdada398b8555f1ec462910e94cc456c66 100644 (file)
@@ -22,9 +22,9 @@ import java.io.File;
 import java.util.Map;
 import java.util.stream.StreamSupport;
 
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.TmfAnalysisModuleHelperXml.XmlAnalysisModuleType;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlAnalysisModuleSource;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlAnalysisModuleSource;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.TmfAnalysisModuleHelperXml.XmlAnalysisModuleType;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
 import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper;
 import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisManager;
index ffbbe7cd190dac3995045d197fb3fdedd0ab3a02..1d1fb801c92f09254e300efb963cb3681ec74ef3 100644 (file)
@@ -29,16 +29,16 @@ import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.segment.TmfXmlPatternSegment;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
 import org.eclipse.tracecompass.statesystem.core.StateSystemUtils;
 import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
 import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
 import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.segment.TmfXmlPatternSegment;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.Activator;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
 import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
index 14943a302d50f541a9503df8f4fa507d4f45e43c..ecad5858c3d95c3b4dcb74d848ecad65a0485098 100644 (file)
@@ -19,12 +19,12 @@ import static org.junit.Assert.fail;
 import java.util.List;
 
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
 import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
 import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
 import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
index b9415eacad5f9b7d36ef28df9ccf3987d668c5d2..31ee3244ceb803a777dc00756e0c8223e91866f5 100644 (file)
@@ -18,9 +18,9 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
index 9f5619ec52a5f4dee286b4c76feb3d282f0e1586..f823087cd145b51b36a118d091d5575ccc20a1ee 100644 (file)
@@ -21,10 +21,10 @@ import java.util.List;
 
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Path;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
index 762afcc3b38bcbae28b3580d9dad42814a2d9823..06b97cfa2484f27b0cbd882efd2d05b5e499073c 100644 (file)
@@ -18,12 +18,12 @@ import static org.junit.Assert.fail;
 import java.util.List;
 
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
 import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
 import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
 import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
index 579ee90d6023ac9b095c2b04beeb68b34ffde2d0..797a74d59a017990b81c54eb0f1f3bb48d06b61e 100644 (file)
@@ -15,10 +15,10 @@ import static org.junit.Assert.assertNotNull;
 import java.util.List;
 
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
 import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
 import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
index 6d4d804742288413423f611f15808853c9072377..462c7287a0d327d23832da451fb0b28b62bf6975 100644 (file)
@@ -16,12 +16,12 @@ import java.io.File;
 
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlPatternSegmentBuilder;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.readwrite.TmfXmlReadWriteModelFactory;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.segment.TmfXmlPatternSegment;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlPatternSegmentBuilder;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readwrite.TmfXmlReadWriteModelFactory;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.segment.TmfXmlPatternSegment;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.stubs.PatternSegmentFactoryStub;
index e38b28caafd9928dc2624a97f6f766cd806d4158..d7cc8e39d66dbae2bae312a96ab60cf293cfe17f 100644 (file)
@@ -11,9 +11,9 @@ package org.eclipse.tracecompass.tmf.analysis.xml.core.tests.stubs;
 import java.util.Map;
 
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.segment.TmfXmlPatternSegment;
 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
 import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.segment.TmfXmlPatternSegment;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
index b9f0555e775b058ef3055fa639009c351579285d..dc5d4c00c84b8539894337d18868e461feb03eff 100644 (file)
@@ -11,9 +11,9 @@ package org.eclipse.tracecompass.tmf.analysis.xml.core.tests.stubs;
 import java.util.HashSet;
 
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlLocation;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlLocation;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
 
 /**
  * This class is a stub for State system Container.
index 92c7ad7f3487231485f6bc974274c4f358483e46..9f826b95699379351d905c0c03d37adcf6507873 100644 (file)
@@ -14,11 +14,11 @@ Require-Bundle: org.eclipse.core.runtime,
  org.eclipse.tracecompass.segmentstore.core,
  org.eclipse.tracecompass.analysis.timing.core
 Export-Package: org.eclipse.tracecompass.internal.tmf.analysis.xml.core;x-friends:="org.eclipse.tracecompass.tmf.analysis.xml.core.tests",
+ org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;x-friends:="org.eclipse.tracecompass.tmf.analysis.xml.core.tests,org.eclipse.tracecompass.tmf.analysis.xml.ui",
+ org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readonly;x-friends:="org.eclipse.tracecompass.tmf.analysis.xml.core.tests,org.eclipse.tracecompass.tmf.analysis.xml.ui",
+ org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readwrite;x-friends:="org.eclipse.tracecompass.tmf.analysis.xml.core.tests,org.eclipse.tracecompass.tmf.analysis.xml.ui",
+ org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module;x-friends:="org.eclipse.tracecompass.tmf.analysis.xml.core.tests,org.eclipse.tracecompass.tmf.analysis.xml.ui",
  org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider;x-friends:="org.eclipse.tracecompass.tmf.analysis.xml.ui",
- org.eclipse.tracecompass.tmf.analysis.xml.core.model,
- org.eclipse.tracecompass.tmf.analysis.xml.core.model.readonly,
- org.eclipse.tracecompass.tmf.analysis.xml.core.model.readwrite,
- org.eclipse.tracecompass.tmf.analysis.xml.core.module,
- org.eclipse.tracecompass.tmf.analysis.xml.core.segment,
- org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider
+ org.eclipse.tracecompass.internal.tmf.analysis.xml.core.segment;x-friends:="org.eclipse.tracecompass.tmf.analysis.xml.core.tests",
+ org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider;x-friends:="org.eclipse.tracecompass.tmf.analysis.xml.core.tests,org.eclipse.tracecompass.tmf.analysis.xml.ui"
 Import-Package: com.google.common.collect
index 16af43baad12c4fae3298a26856770a1de40bd3c..faf28f395460e79e893fb8e8966b820cc8ea8016 100644 (file)
@@ -5,7 +5,7 @@
    <extension
          point="org.eclipse.linuxtools.tmf.core.analysis">
       <source
-            class="org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlAnalysisModuleSource">
+            class="org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlAnalysisModuleSource">
       </source>
    </extension>
 </plugin>
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/ITmfXmlAction.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/ITmfXmlAction.java
new file mode 100644 (file)
index 0000000..69d4b54
--- /dev/null
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ ******************************************************************************/
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+
+/**
+ * Interface for an action behavior. An action is an output of the pattern.
+ * Basically something that the pattern needs to do if it reaches a given state.
+ *
+ * @author Jean-Christian Kouame
+ */
+public interface ITmfXmlAction {
+
+    /** The save stored fields action label */
+    String SAVE_STORED_FIELDS_STRING = "saveStoredFields"; //$NON-NLS-1$
+
+    /** The clear stored fields action label */
+    String CLEAR_STORED_FIELDS_STRING = "clearStoredFields"; //$NON-NLS-1$
+
+    /**
+     * Execute the action
+     *
+     * @param event
+     *            The active event
+     * @param scenarioInfo
+     *            The active scenario details. Or <code>null</code> if there is
+     *            no scenario.
+     */
+    void execute(ITmfEvent event, TmfXmlScenarioInfo scenarioInfo);
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/ITmfXmlCondition.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/ITmfXmlCondition.java
new file mode 100644 (file)
index 0000000..a2a4e5f
--- /dev/null
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ ******************************************************************************/
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+
+/**
+ * Determines a true or false value for a given input. The input is an event and
+ * an optional scenarioInfo.
+ *
+ * @author Matthew Khouzam
+ */
+public interface ITmfXmlCondition {
+
+    /**
+     * Test the result of the condition for an event
+     *
+     * @param event
+     *            The event on which to test the condition
+     * @param scenarioInfo
+     *            The active scenario details. Or <code>null</code> if there is
+     *            no scenario.
+     * @return Whether the condition is true or not
+     */
+    boolean test(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo);
+
+}
\ No newline at end of file
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/ITmfXmlModelFactory.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/ITmfXmlModelFactory.java
new file mode 100644 (file)
index 0000000..09d1e1a
--- /dev/null
@@ -0,0 +1,202 @@
+/*******************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.w3c.dom.Element;
+
+/**
+ * Interface to create XML model elements in different contexts. This allows to
+ * reuse the same XML syntax and parsers, but use the elements differently
+ * depending on the what is intended to be done with them.
+ *
+ * @author Geneviève Bastien
+ */
+public interface ITmfXmlModelFactory {
+
+    /**
+     * Create a new XML state attribute
+     *
+     * @param attribute
+     *            XML element of the attribute
+     * @param container
+     *            The state system container this state attribute belongs to
+     * @return The new state attribute
+     */
+    ITmfXmlStateAttribute createStateAttribute(Element attribute, IXmlStateSystemContainer container);
+
+    /**
+     * Create a new state value where the value corresponds to a path of
+     * {@link ITmfXmlStateAttribute}
+     *
+     * @param node
+     *            The state value XML element
+     * @param container
+     *            The state system container this state value belongs to
+     * @param attributes
+     *            The attributes representing the path to this value
+     * @return The new state value
+     */
+    ITmfXmlStateValue createStateValue(Element node, IXmlStateSystemContainer container, List<ITmfXmlStateAttribute> attributes);
+
+    /**
+     * Create a new state value where the value corresponds to a field in an
+     * event
+     *
+     * @param node
+     *            The state value XML element
+     * @param container
+     *            The state system container this state value belongs to
+     * @param eventField
+     *            The event field where to get the value
+     * @return The new state value
+     */
+    ITmfXmlStateValue createStateValue(Element node, IXmlStateSystemContainer container, String eventField);
+
+    /**
+     * Create a new XML condition
+     *
+     * @param node
+     *            The XML root of this condition
+     * @param container
+     *            The state system container this condition belongs to
+     * @return The new XML condition
+     */
+    TmfXmlCondition createCondition(Element node, IXmlStateSystemContainer container);
+
+    /**
+     * Create a new XML event handler
+     *
+     * @param node
+     *            The XML event handler element
+     * @param container
+     *            The state system container this state value belongs to
+     * @return The new XML event handler
+     */
+    TmfXmlEventHandler createEventHandler(Element node, IXmlStateSystemContainer container);
+
+    /**
+     * Create a new XML state change
+     *
+     * @param node
+     *            The XML state change element
+     * @param container
+     *            The state system container this state change belongs to
+     * @return The new XML state change
+     */
+    TmfXmlStateChange createStateChange(Element node, IXmlStateSystemContainer container);
+
+    /**
+     * Create a new XML location
+     *
+     * @param node
+     *            The XML location element
+     * @param container
+     *            The state system container this location belongs to
+     * @return The new XML location
+     */
+    TmfXmlLocation createLocation(Element node, IXmlStateSystemContainer container);
+
+    /**
+     * Create a new XML pattern event handler
+     *
+     * @param node
+     *            The XML pattern event handler element
+     * @param container
+     *            The state system container this pattern event handler belongs to
+     * @return The new XML pattern event handler
+     */
+    TmfXmlPatternEventHandler createPatternEventHandler(Element node, IXmlStateSystemContainer container);
+
+    /**
+     * Create a new XML transition validator
+     *
+     * @param node
+     *            The XML test element
+     * @param container
+     *            The state system container this test belongs to
+     * @return The new {@link TmfXmlTransitionValidator}
+     */
+    TmfXmlTransitionValidator createTransitionValidator(Element node, IXmlStateSystemContainer container);
+
+    /**
+     * Create a new XML action
+     *
+     * @param node
+     *            The XML action element
+     * @param container
+     *            The state system container this action belongs to
+     * @return The new {@link TmfXmlAction}
+     */
+    TmfXmlAction createAction(Element node, IXmlStateSystemContainer container);
+
+    /**
+     * Create a new XML FSM
+     *
+     * @param node
+     *            The XML FSM element
+     * @param container
+     *            The state system container this FSM belongs to
+     * @return The new {@link TmfXmlFsm}
+     */
+    TmfXmlFsm createFsm(Element node, IXmlStateSystemContainer container);
+
+    /**
+     * Create a new XML state
+     *
+     * @param node
+     *            The XML state element
+     * @param container
+     *            The state system container this state belongs to
+     * @param parent
+     *            The parent state
+     * @return The new {@link TmfXmlState}
+     */
+    TmfXmlState createState(Element node, IXmlStateSystemContainer container, @Nullable TmfXmlState parent);
+
+    /**
+     * Create a new XML state transition
+     *
+     * @param node
+     *            The XML state transition element
+     * @param container
+     *            The state system container this state transition belongs to
+     * @return The new XML {@link TmfXmlStateTransition}
+     */
+    TmfXmlStateTransition createStateTransition(Element node, IXmlStateSystemContainer container);
+
+    /**
+     * Create a new XML timestamp condition
+     *
+     * @param node
+     *            The XML timestamp condition element
+     * @param container
+     *            The state system container this timestamp condition belongs to
+     * @return The new {@link TmfXmlTimestampCondition}
+     */
+    TmfXmlTimestampCondition createTimestampsCondition(Element node, IXmlStateSystemContainer container);
+
+    /**
+     * Create a new pattern segment builder
+     *
+     * @param node
+     *            The XML pattern segment builder
+     * @param container
+     *            The state system container this pattern segment builder belongs to
+     * @return The new {@link TmfXmlPatternSegmentBuilder}
+     */
+    TmfXmlPatternSegmentBuilder createPatternSegmentBuilder(Element node, IXmlStateSystemContainer container);
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/ITmfXmlStateAttribute.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/ITmfXmlStateAttribute.java
new file mode 100644 (file)
index 0000000..4087bc7
--- /dev/null
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+
+/**
+ * Interface that describe a state attribute defined in an XML element
+ *
+ * @author Geneviève Bastien
+ */
+public interface ITmfXmlStateAttribute {
+
+    /**
+     * This method gets the quark for this state attribute in the State System.
+     *
+     * Unless this attribute is a location, in which case the quark must exist,
+     * the quark will be added to the state system if the state system is in
+     * builder mode.
+     *
+     * @param startQuark
+     *            root quark, use {@link IXmlStateSystemContainer#ROOT_QUARK} to
+     *            search the full attribute tree
+     * @param scenarioInfo
+     *            The active scenario details. Or <code>null</code> if there is
+     *            no scenario.
+     * @return the quark described by attribute or
+     *         {@link IXmlStateSystemContainer#ERROR_QUARK} if quark cannot be
+     *         found
+     */
+    int getAttributeQuark(int startQuark, @Nullable TmfXmlScenarioInfo scenarioInfo);
+
+    /**
+     * This method gets the quark for this state attribute in the State System.
+     *
+     * Unless this attribute is a location, in which case the quark must exist,
+     * the quark will be added to the state system if the state system is in
+     * builder mode. This state attribute path uses runtime data queried using
+     * the current event.
+     *
+     * @param event
+     *            The current event being handled
+     * @param startQuark
+     *            root quark, use {@link IXmlStateSystemContainer#ROOT_QUARK} to
+     *            search the full attribute tree
+     * @param scenarioInfo
+     *            The active scenario details. Or <code>null</code> if there is
+     *            no scenario.
+     * @return the quark described by attribute or
+     *         {@link IXmlStateSystemContainer#ERROR_QUARK} if quark cannot be
+     *         found
+     */
+    int getAttributeQuark(@Nullable ITmfEvent event, int startQuark, @Nullable TmfXmlScenarioInfo scenarioInfo);
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/ITmfXmlStateValue.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/ITmfXmlStateValue.java
new file mode 100644 (file)
index 0000000..eb4a74f
--- /dev/null
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+
+/**
+ * Interface that describe operations on a state value described in an XML
+ * element
+ *
+ * @author Geneviève Bastien
+ */
+public interface ITmfXmlStateValue {
+
+    /**
+     * Get the current {@link ITmfStateValue} of this state value for an event.
+     * It does not increment the value and does not any other processing of the
+     * value.
+     *
+     * @param event
+     *            The current event or <code>null</code> if no event is
+     *            available.
+     * @param scenarioInfo
+     *            The active scenario details. Or <code>null</code> if there is
+     *            no scenario.
+     * @return the {@link ITmfStateValue}
+     * @throws AttributeNotFoundException
+     *             May be thrown by the state system during the query
+     */
+    ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException;
+
+    /**
+     * Get the value of the event field that is the path of this state value
+     *
+     * @param event
+     *            The current event
+     * @return the value of the event field
+     */
+    ITmfStateValue getEventFieldValue(ITmfEvent event);
+
+    /**
+     * Get the list of state attributes, the path to the state value
+     *
+     * @return the list of Attribute to have the path in the State System
+     */
+    List<ITmfXmlStateAttribute> getAttributes();
+
+    /**
+     * Handles an event, by setting the value of the attribute described by the
+     * state attribute path in the state system.
+     *
+     * @param event
+     *            The event to process
+     * @param scenarioInfo
+     *            The active scenario details. Or <code>null</code> if there is
+     *            no scenario.
+     * @throws AttributeNotFoundException
+     *             Pass through the exception it received
+     * @throws TimeRangeException
+     *             Pass through the exception it received
+     * @throws StateValueTypeException
+     *             Pass through the exception it received
+     */
+    void handleEvent(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException;
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/ResetStoredFieldsAction.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/ResetStoredFieldsAction.java
new file mode 100644 (file)
index 0000000..06ab863
--- /dev/null
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ ******************************************************************************/
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.Map.Entry;
+
+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.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+
+/**
+ * This action will reset the value of each stored values to a null
+ * {@link ITmfStateValue} in the state system
+ */
+public class ResetStoredFieldsAction implements ITmfXmlAction {
+
+    private final IXmlStateSystemContainer fParent;
+
+    /**
+     * Constructor
+     *
+     * @param parent
+     *            The state system container this action belongs to
+     */
+    public ResetStoredFieldsAction(IXmlStateSystemContainer parent) {
+        fParent = parent;
+    }
+
+    @Override
+    public void execute(ITmfEvent event, TmfXmlScenarioInfo scenarioInfo) {
+        if (fParent instanceof XmlPatternStateProvider) {
+            for (Entry<String, String> entry : ((XmlPatternStateProvider) fParent).getStoredFields().entrySet()) {
+                ((XmlPatternStateProvider) fParent).getHistoryBuilder().resetStoredFields(fParent, entry.getValue(), scenarioInfo, event);
+            }
+        }
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlAction.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlAction.java
new file mode 100644 (file)
index 0000000..7714e2b
--- /dev/null
@@ -0,0 +1,164 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ ******************************************************************************/
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
+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.module.XmlUtils;
+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.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
+import org.w3c.dom.Element;
+
+/**
+ * This Class implements an action tree in the XML-defined state system.
+ * An action is a collection of {@link ITmfXmlAction} that are executed when necessary.
+ *
+ * @author Jean-Christian Kouame
+ */
+public class TmfXmlAction implements ITmfXmlAction {
+
+    private final IXmlStateSystemContainer fParent;
+    private final String fId;
+    private final List<ITmfXmlAction> fActionList = new ArrayList<>();
+
+    /**
+     * Constructor
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param node
+     *            The XML root of this action
+     * @param container
+     *            The state system container this action belongs to
+     */
+    public TmfXmlAction(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container) {
+        fParent = container;
+        fId = NonNullUtils.checkNotNull(node.getAttribute(TmfXmlStrings.ID));
+        List<@Nullable Element> childElements = XmlUtils.getChildElements(node);
+        for (Element child : childElements) {
+            final @NonNull Element nonNullChild = NonNullUtils.checkNotNull(child);
+            switch (nonNullChild.getNodeName()) {
+            case TmfXmlStrings.STATE_CHANGE:
+                fActionList.add(new StateChange(modelFactory, nonNullChild, fParent));
+                break;
+            case TmfXmlStrings.FSM_SCHEDULE_ACTION:
+                fActionList.add(new ScheduleNewScenario(modelFactory, nonNullChild, fParent));
+                break;
+            case TmfXmlStrings.SEGMENT:
+                fActionList.add(new GeneratePatternSegment(modelFactory, nonNullChild, fParent));
+                break;
+            case TmfXmlStrings.ACTION:
+                fActionList.add(new TmfXmlAction(modelFactory, nonNullChild, fParent));
+                break;
+            default:
+                Activator.logError("Invalid action type : " + nonNullChild.getNodeName()); //$NON-NLS-1$
+            }
+        }
+
+    }
+
+    /**
+     * Get the ID of this action
+     *
+     * @return The id of this action
+     */
+    public String getId() {
+        return fId;
+    }
+
+    @Override
+    public void execute(@NonNull ITmfEvent event, TmfXmlScenarioInfo scenarioInfo) {
+        // the order of the actions is important, do not parallelize.
+        for (ITmfXmlAction action : fActionList) {
+            action.execute(event, scenarioInfo);
+        }
+    }
+
+    /**
+     * Private class for an action that will create a state change in the state
+     * system
+     */
+    private class StateChange implements ITmfXmlAction {
+
+        private final TmfXmlStateChange fStateChange;
+
+        public StateChange(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer parent) {
+            fStateChange = modelFactory.createStateChange(node, parent);
+        }
+
+        @Override
+        public void execute(@NonNull ITmfEvent event, TmfXmlScenarioInfo scenarioInfo) {
+            try {
+                fStateChange.handleEvent(event, scenarioInfo);
+            } catch (StateValueTypeException | AttributeNotFoundException e) {
+                Activator.logError("Exception when executing action state change", e); //$NON-NLS-1$
+            }
+        }
+    }
+
+    /**
+     * Private class for an action that will instantiate and schedule a new instance of
+     * an fsm
+     */
+    private static class ScheduleNewScenario implements ITmfXmlAction {
+
+        /**
+         * Constructor
+         *
+         * @param modelFactory
+         *            The factory used to create XML model elements
+         * @param node
+         *            The XML root of this action
+         * @param container
+         *            The state system container this action belongs to
+         */
+        public ScheduleNewScenario(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container) {
+        }
+
+        @Override
+        public void execute(ITmfEvent event, TmfXmlScenarioInfo scenarioInfo) {
+            // TODO This action needs to be implemented
+            throw new UnsupportedOperationException("Schedule an FSM is not yet supported"); //$NON-NLS-1$
+        }
+    }
+
+    /**
+     * Private class for an action that will generate pattern segment
+     */
+    private static class GeneratePatternSegment implements ITmfXmlAction {
+
+        private final TmfXmlPatternSegmentBuilder fSegmentBuilder;
+        private final XmlPatternStateProvider fProvider;
+
+        public GeneratePatternSegment(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer parent) {
+            fProvider = ((XmlPatternStateProvider) parent);
+            fSegmentBuilder = modelFactory.createPatternSegmentBuilder(node, parent);
+        }
+
+        @Override
+        public void execute(ITmfEvent event, TmfXmlScenarioInfo scenarioInfo) {
+            long ts = fProvider.getHistoryBuilder().getStartTime(fProvider, scenarioInfo, event);
+            // FIXME Should the scale always be nanoseconds?
+            ITmfTimestamp start = TmfTimestamp.fromNanos(ts);
+            ITmfTimestamp end = event.getTimestamp();
+            fSegmentBuilder.generatePatternSegment(event, start, end, scenarioInfo);
+        }
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlBasicTransition.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlBasicTransition.java
new file mode 100644 (file)
index 0000000..70d1b36
--- /dev/null
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ ******************************************************************************/
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.w3c.dom.Element;
+
+/**
+ * Implementation of a basic transition in the XML file
+ *
+ * @author Jean-Christian Kouame
+ */
+public class TmfXmlBasicTransition {
+
+    private static final Pattern WILDCARD_PATTERN = Pattern.compile("\\*"); //$NON-NLS-1$
+
+    private final List<String> fCond;
+    private final List<Pattern> fAcceptedEvents;
+
+
+    /**
+     * Constructor
+     *
+     * @param element
+     *            the XML basic transition element
+     */
+    public TmfXmlBasicTransition(Element element) {
+        final @NonNull String events = element.getAttribute(TmfXmlStrings.EVENT);
+        fAcceptedEvents = new ArrayList<>();
+        for (String eventName : Arrays.asList(events.split(TmfXmlStrings.OR_SEPARATOR))) {
+            String name = WILDCARD_PATTERN.matcher(eventName).replaceAll(".*"); //$NON-NLS-1$
+            fAcceptedEvents.add(Pattern.compile(name));
+        }
+        final @NonNull String conditions = element.getAttribute(TmfXmlStrings.COND);
+        fCond = conditions.isEmpty() ? new ArrayList<>() : Arrays.asList(conditions.split(TmfXmlStrings.AND_SEPARATOR));
+    }
+
+    /**
+     * Validate the transition with the current event
+     *
+     * @param event
+     *            The active event
+     * @param scenarioInfo
+     *            The active scenario details.
+     * @param tests
+     *            The map of test in the XML file
+     * @return true if the transition is validate false if not
+     */
+    public boolean test(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo, Map<String, TmfXmlTransitionValidator> tests) {
+        if (!validateEvent(event)) {
+            return false;
+        }
+
+        for (String cond : fCond) {
+            TmfXmlTransitionValidator test = tests.get(cond);
+            if (test == null) {
+                throw new IllegalStateException("Failed to find cond " + cond); //$NON-NLS-1$
+            }
+            if (!test.test(event, scenarioInfo)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    private boolean validateEvent(ITmfEvent event) {
+        String eventName = event.getName();
+
+        /*
+         * This validates the event name with the accepted regular expressions
+         */
+        for (Pattern nameRegex : fAcceptedEvents) {
+            if (nameRegex.matcher(eventName).matches()) {
+                return true;
+            }
+        }
+        return false;
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlCondition.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlCondition.java
new file mode 100644 (file)
index 0000000..6e68f92
--- /dev/null
@@ -0,0 +1,353 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2015 Ecole Polytechnique de Montreal and others
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Florian Wininger - Initial API and implementation
+ *   Naser Ezzati - Add the comparison operators
+ *   Patrick Tasse - Add message to exceptions
+ *   Jean-Christian Kouame - Add comparison between two state values
+ ******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
+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.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
+import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.w3c.dom.Element;
+
+/**
+ * This Class implement a condition tree in the XML-defined state system.
+ *
+ * <pre>
+ * example:
+ * <and>
+ *   <condition>
+ *       <stateAttribute type="location" value="CurrentThread" />
+ *       <stateAttribute type="constant" value="System_call" />
+ *       <stateValue type="null" />
+ *   </condition>
+ *   <condition>
+ *      <stateValue type="long" value="2" />
+ *      <stateValue type="long" value="5" />
+ *   </condition>
+ * </and>
+ * </pre>
+ *
+ * @author Florian Wininger
+ */
+public class TmfXmlCondition implements ITmfXmlCondition {
+
+    private final List<TmfXmlCondition> fConditions = new ArrayList<>();
+    private final List<ITmfXmlStateValue> fStateValues;
+    private final LogicalOperator fOperator;
+    private final IXmlStateSystemContainer fContainer;
+    private final ConditionOperator fConditionOperator;
+    private ConditionType fType;
+    private @Nullable TmfXmlTimestampCondition fTimeCondition;
+
+    private enum LogicalOperator {
+        NONE,
+        NOT,
+        AND,
+        OR
+    }
+
+    private enum ConditionOperator {
+        NONE,
+        EQ,
+        NE,
+        GE,
+        GT,
+        LE,
+        LT
+    }
+
+    // TODO The XmlCondition needs to be split into several classes of condition
+    // instead of using an enum
+    private enum ConditionType {
+        DATA,
+        TIME,
+        NONE
+    }
+
+    /**
+     * Factory to create {@link TmfXmlCondition}
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param node
+     *            The XML root of this condition
+     * @param container
+     *            The state system container this condition belongs to
+     * @return The new {@link TmfXmlCondition}
+     */
+    public static TmfXmlCondition create(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container) {
+        Element rootNode = node;
+        /* Process the conditions: in each case, only process Element nodes */
+        List<@Nullable Element> childElements = XmlUtils.getChildElements(rootNode);
+
+        /*
+         * If the node is an if, take the child as the root condition
+         *
+         * FIXME: Maybe the caller should do this instead.
+         */
+        if (node.getNodeName().equals(TmfXmlStrings.IF)) {
+            if (childElements.isEmpty()) {
+                throw new IllegalArgumentException("TmfXmlCondition constructor: IF node with no child element"); //$NON-NLS-1$
+            }
+            rootNode = NonNullUtils.checkNotNull(childElements.get(0));
+            childElements = XmlUtils.getChildElements(rootNode);
+        }
+
+        List<@NonNull TmfXmlCondition> conditions = new ArrayList<>();
+        switch (rootNode.getNodeName()) {
+        case TmfXmlStrings.CONDITION:
+            return createPatternCondition(modelFactory, container, rootNode, childElements);
+        case TmfXmlStrings.NOT:
+            return createMultipleCondition(modelFactory, container, childElements, LogicalOperator.NOT, conditions);
+        case TmfXmlStrings.AND:
+            return createMultipleCondition(modelFactory, container, childElements, LogicalOperator.AND, conditions);
+        case TmfXmlStrings.OR:
+            return createMultipleCondition(modelFactory, container, childElements, LogicalOperator.OR, conditions);
+        default:
+            throw new IllegalArgumentException("TmfXmlCondition constructor: XML node " + rootNode.getNodeName() + " is of the wrong type"); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+    }
+
+    private static TmfXmlCondition createPatternCondition(ITmfXmlModelFactory modelFactory, IXmlStateSystemContainer container, Element rootNode, List<@Nullable Element> childElements) {
+        ArrayList<ITmfXmlStateValue> stateValues;
+        ConditionOperator conditionOperator;
+        TmfXmlTimestampCondition timeCondition = null;
+        int size = rootNode.getElementsByTagName(TmfXmlStrings.STATE_VALUE).getLength();
+        if (size != 0) {
+            stateValues = new ArrayList<>(size);
+            if (size == 1) {
+                conditionOperator = getConditionOperator(rootNode);
+                getStateValuesForXmlCondition(modelFactory, NonNullUtils.checkNotNull(childElements), stateValues, container);
+            } else {
+                // No need to test if the childElements size is actually 2.
+                // The XSD validation do this check already.
+                conditionOperator = ConditionOperator.EQ;
+                stateValues.add(modelFactory.createStateValue(NonNullUtils.checkNotNull(childElements.get(0)), container, new ArrayList<ITmfXmlStateAttribute>()));
+                stateValues.add(modelFactory.createStateValue(NonNullUtils.checkNotNull(childElements.get(1)), container, new ArrayList<ITmfXmlStateAttribute>()));
+            }
+            return new TmfXmlCondition(ConditionType.DATA, stateValues, LogicalOperator.NONE, conditionOperator, null, new ArrayList<>(), container);
+        }
+        final Element firstElement = NonNullUtils.checkNotNull(childElements.get(0));
+        timeCondition = modelFactory.createTimestampsCondition(firstElement, container);
+        return new TmfXmlCondition(ConditionType.TIME, new ArrayList<>(), LogicalOperator.NONE, ConditionOperator.EQ, timeCondition, new ArrayList<>(), container);
+    }
+
+    private static TmfXmlCondition createMultipleCondition(ITmfXmlModelFactory modelFactory, IXmlStateSystemContainer container, List<@Nullable Element> childElements, LogicalOperator op,
+            List<@NonNull TmfXmlCondition> conditions) {
+        for (Element condition : childElements) {
+            if (condition == null) {
+                continue;
+            }
+            conditions.add(modelFactory.createCondition(condition, container));
+        }
+        return new TmfXmlCondition(ConditionType.NONE, new ArrayList<>(), op, ConditionOperator.NONE, null, conditions, container);
+    }
+
+    private TmfXmlCondition(ConditionType type, ArrayList<@NonNull ITmfXmlStateValue> stateValues, LogicalOperator operator, ConditionOperator conditionOperator, @Nullable TmfXmlTimestampCondition timeCondition, List<@NonNull TmfXmlCondition> conditions,
+            IXmlStateSystemContainer container) {
+        fType = type;
+        fStateValues = stateValues;
+        fOperator = operator;
+        fTimeCondition = timeCondition;
+        fContainer = container;
+        fConditions.addAll(conditions);
+        fConditionOperator = conditionOperator;
+    }
+
+    private static void getStateValuesForXmlCondition(ITmfXmlModelFactory modelFactory, List<@Nullable Element> childElements, List<ITmfXmlStateValue> stateValues, IXmlStateSystemContainer container) {
+        Element stateValueElement = NonNullUtils.checkNotNull(childElements.remove(childElements.size() - 1));
+        /*
+         * A state value is either preceded by an eventField or a number of
+         * state attributes
+         */
+        final Element firstElement = NonNullUtils.checkNotNull(childElements.get(0));
+        if (childElements.size() == 1 && firstElement.getNodeName().equals(TmfXmlStrings.ELEMENT_FIELD)) {
+            String attribute = firstElement.getAttribute(TmfXmlStrings.NAME);
+            stateValues.add(modelFactory.createStateValue(stateValueElement, container, attribute));
+        } else {
+            List<ITmfXmlStateAttribute> attributes = new ArrayList<>();
+            for (Element element : childElements) {
+                if (element == null) {
+                    throw new NullPointerException("There should be at list one element"); //$NON-NLS-1$
+                }
+                if (!element.getNodeName().equals(TmfXmlStrings.STATE_ATTRIBUTE)) {
+                    throw new IllegalArgumentException("TmfXmlCondition: a condition either has a eventField element or a number of TmfXmlStateAttribute elements before the state value"); //$NON-NLS-1$
+                }
+                ITmfXmlStateAttribute attribute = modelFactory.createStateAttribute(element, container);
+                attributes.add(attribute);
+            }
+            stateValues.add(modelFactory.createStateValue(stateValueElement, container, attributes));
+        }
+    }
+
+    private static ConditionOperator getConditionOperator(Element rootNode) {
+        String equationType = rootNode.getAttribute(TmfXmlStrings.OPERATOR);
+        switch (equationType) {
+        case TmfXmlStrings.EQ:
+            return ConditionOperator.EQ;
+        case TmfXmlStrings.NE:
+            return ConditionOperator.NE;
+        case TmfXmlStrings.GE:
+            return ConditionOperator.GE;
+        case TmfXmlStrings.GT:
+            return ConditionOperator.GT;
+        case TmfXmlStrings.LE:
+            return ConditionOperator.LE;
+        case TmfXmlStrings.LT:
+            return ConditionOperator.LT;
+        case TmfXmlStrings.NULL:
+            return ConditionOperator.EQ;
+        default:
+            throw new IllegalArgumentException("TmfXmlCondition: invalid comparison operator."); //$NON-NLS-1$
+        }
+    }
+
+    @Override
+    public boolean test(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
+        ITmfStateSystem ss = fContainer.getStateSystem();
+        if (fType == ConditionType.DATA) {
+            try {
+                return testForEvent(event, NonNullUtils.checkNotNull(ss), scenarioInfo);
+            } catch (AttributeNotFoundException e) {
+                Activator.logError("Attribute not found", e); //$NON-NLS-1$
+                return false;
+            }
+        } else if (fType == ConditionType.TIME) {
+            if (fTimeCondition != null) {
+                return fTimeCondition.test(event, scenarioInfo);
+            }
+        } else if (!fConditions.isEmpty()) {
+            /* Verify a condition tree */
+            switch (fOperator) {
+            case AND:
+                for (ITmfXmlCondition childCondition : fConditions) {
+                    if (!childCondition.test(event, scenarioInfo)) {
+                        return false;
+                    }
+                }
+                return true;
+            case NONE:
+                break;
+            case NOT:
+                return !fConditions.get(0).test(event, scenarioInfo);
+            case OR:
+                for (ITmfXmlCondition childCondition : fConditions) {
+                    if (childCondition.test(event, scenarioInfo)) {
+                        return true;
+                    }
+                }
+                return false;
+            default:
+                break;
+
+            }
+        }
+        return true;
+    }
+
+    private boolean testForEvent(ITmfEvent event, ITmfStateSystem ss, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
+        /*
+         * The condition is either the equality check of a state value or a
+         * boolean operation on other conditions
+         */
+        if (fStateValues.size() == 1) {
+            ITmfXmlStateValue filter = fStateValues.get(0);
+            int quark = IXmlStateSystemContainer.ROOT_QUARK;
+            for (ITmfXmlStateAttribute attribute : filter.getAttributes()) {
+                quark = attribute.getAttributeQuark(event, quark, scenarioInfo);
+                /*
+                 * When verifying a condition, the state attribute must exist,
+                 * if it does not, the query is not valid, we stop the condition
+                 * check
+                 */
+                if (quark == IXmlStateSystemContainer.ERROR_QUARK) {
+                    throw new AttributeNotFoundException(ss.getSSID() + " Attribute:" + attribute); //$NON-NLS-1$
+                }
+            }
+
+            /*
+             * The actual value: it can be either queried in the state system or
+             * found in the event
+             */
+            ITmfStateValue valueState = (quark != IXmlStateSystemContainer.ROOT_QUARK) ? ss.queryOngoingState(quark) : filter.getEventFieldValue(event);
+
+            /* Get the value to compare to from the XML file */
+            ITmfStateValue valueXML;
+            valueXML = filter.getValue(event, scenarioInfo);
+            return compare(valueState, valueXML, fConditionOperator);
+        }
+        /* Get the two values needed for the comparison */
+        ITmfStateValue valuesXML1 = fStateValues.get(0).getValue(event, scenarioInfo);
+        ITmfStateValue valuesXML2 = fStateValues.get(1).getValue(event, scenarioInfo);
+        return valuesXML1.equals(valuesXML2);
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder output = new StringBuilder("TmfXmlCondition: "); //$NON-NLS-1$
+        if (fOperator != LogicalOperator.NONE) {
+            output.append(fOperator).append(" on ").append(fConditions); //$NON-NLS-1$
+        } else {
+            output.append(fConditionOperator).append(" {").append(fStateValues.get(0)); //$NON-NLS-1$
+            if (fStateValues.size() == 2) {
+                output.append(", ").append(fStateValues.get(1)); //$NON-NLS-1$
+            }
+            output.append("}"); //$NON-NLS-1$
+        }
+        return output.toString();
+    }
+
+    /**
+     * Compare two ITmfStateValues based on the given comparison operator
+     *
+     * @param source
+     *            the state value to compare to
+     * @param dest
+     *            the state value to be compared with
+     * @param comparisonOperator
+     *            the operator to compare the inputs
+     * @return the boolean result of the comparison
+     */
+    public boolean compare(ITmfStateValue source, ITmfStateValue dest, ConditionOperator comparisonOperator) {
+        switch (comparisonOperator) {
+        // TODO The comparison operator should have a compareHelper that calls compare
+        case EQ:
+            return (source.compareTo(dest) == 0);
+        case NE:
+            return (source.compareTo(dest) != 0);
+        case GE:
+            return (source.compareTo(dest) >= 0);
+        case GT:
+            return (source.compareTo(dest) > 0);
+        case LE:
+            return (source.compareTo(dest) <= 0);
+        case LT:
+            return (source.compareTo(dest) < 0);
+        case NONE:
+        default:
+            throw new IllegalArgumentException("TmfXmlCondition: invalid comparison operator."); //$NON-NLS-1$
+        }
+    }
+}
\ No newline at end of file
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlEventHandler.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlEventHandler.java
new file mode 100644 (file)
index 0000000..2dd0513
--- /dev/null
@@ -0,0 +1,136 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ecole Polytechnique de Montreal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Florian Wininger - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+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.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.w3c.dom.Element;
+
+/**
+ * This Class implements an EventHandler in the XML-defined state system
+ *
+ * <pre>
+ * example:
+ * <eventHandler eventName="eventName">
+ *  <stateChange>
+ *      ...
+ *  </stateChange>
+ *  <stateChange>
+ *      ...
+ *  </stateChange>
+ * </eventHandler>
+ * </pre>
+ *
+ * @author Florian Wininger
+ */
+public class TmfXmlEventHandler {
+
+    /* list of states changes */
+    private final List<TmfXmlStateChange> fStateChangeList = new ArrayList<>();
+    private final String fName;
+    private final IXmlStateSystemContainer fParent;
+
+    /**
+     * Constructor
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param node
+     *            XML event handler element
+     * @param parent
+     *            The state system container this event handler belongs to
+     */
+    public TmfXmlEventHandler(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer parent) {
+        fParent = parent;
+        String name = node.getAttribute(TmfXmlStrings.HANDLER_EVENT_NAME);
+        fName = name;
+
+        List<@NonNull Element> childElements = XmlUtils.getChildElements(node, TmfXmlStrings.STATE_CHANGE);
+        /* load state changes */
+        for (Element childElem : childElements) {
+            TmfXmlStateChange stateChange = modelFactory.createStateChange(childElem, fParent);
+            fStateChangeList.add(stateChange);
+        }
+    }
+
+    private boolean appliesToEvent(ITmfEvent event) {
+        String eventName = event.getName();
+
+        /* test for full name */
+        if (eventName.equals(fName)) {
+            return true;
+        }
+
+        /* test for the wildcard at the end */
+        if ((fName.endsWith(TmfXmlStrings.WILDCARD) && eventName.startsWith(fName.replace(TmfXmlStrings.WILDCARD, TmfXmlStrings.NULL)))) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * If the event handler can handle the event, it applies all state changes
+     * to modify the state system accordingly
+     *
+     * @param event
+     *            The trace event to handle
+     */
+    public void handleEvent(ITmfEvent event) {
+        if (!appliesToEvent(event)) {
+            return;
+        }
+
+        /* Process all state changes */
+        for (TmfXmlStateChange stateChange : fStateChangeList) {
+            try {
+                stateChange.handleEvent(event, null);
+            } catch (AttributeNotFoundException ae) {
+                /*
+                 * This would indicate a problem with the logic of the manager
+                 * here, so it shouldn't happen.
+                 */
+                Activator.logError("Attribute not found", ae); //$NON-NLS-1$
+            } catch (TimeRangeException tre) {
+                /*
+                 * This would happen if the events in the trace aren't ordered
+                 * chronologically, which should never be the case ...
+                 */
+                Activator.logError("TimeRangeException caught in the state system's event manager.  Are the events in the trace correctly ordered?", tre); //$NON-NLS-1$
+            } catch (StateValueTypeException sve) {
+                /*
+                 * This would happen if we were trying to push/pop attributes
+                 * not of type integer. Which, once again, should never happen.
+                 */
+                Activator.logError("State value type error", sve); //$NON-NLS-1$
+            }
+
+        }
+
+    }
+
+    @Override
+    public String toString() {
+        return "TmfXmlEventHandler: " + fName; //$NON-NLS-1$
+    }
+
+}
\ No newline at end of file
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlFsm.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlFsm.java
new file mode 100644 (file)
index 0000000..bef9400
--- /dev/null
@@ -0,0 +1,308 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ ******************************************************************************/
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlScenarioHistoryBuilder.ScenarioStatusType;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * This Class implements a state machine (FSM) tree in the XML-defined state
+ * system.
+ *
+ * @author Jean-Christian Kouame
+ */
+public class TmfXmlFsm {
+
+    private final Map<String, TmfXmlState> fStatesMap;
+    private final List<TmfXmlScenario> fActiveScenariosList;
+    private final List<TmfXmlBasicTransition> fPreconditions;
+    private final String fId;
+    private final ITmfXmlModelFactory fModelFactory;
+    private final IXmlStateSystemContainer fContainer;
+    private final String fFinalStateId;
+    private final String fAbandonStateId;
+    private final boolean fInstanceMultipleEnabled;
+    private final String fInitialStateId;
+    private int fTotalScenarios;
+
+    /**
+     * Factory to create a {@link TmfXmlFsm}
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param node
+     *            The XML root of this fsm
+     * @param container
+     *            The state system container this fsm belongs to
+     * @return The new {@link TmfXmlFsm}
+     */
+    public static TmfXmlFsm create(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container) {
+        String id = node.getAttribute(TmfXmlStrings.ID);
+        boolean instanceMultipleEnabled = node.getAttribute(TmfXmlStrings.MULTIPLE).isEmpty() ? true : Boolean.parseBoolean(node.getAttribute(TmfXmlStrings.MULTIPLE));
+        final List<@NonNull TmfXmlBasicTransition> preconditions = new ArrayList<>();
+
+        // Get the preconditions
+        NodeList nodesPreconditions = node.getElementsByTagName(TmfXmlStrings.PRECONDITION);
+        for (int i = 0; i < nodesPreconditions.getLength(); i++) {
+            preconditions.add(new TmfXmlBasicTransition(((Element) NonNullUtils.checkNotNull(nodesPreconditions.item(i)))));
+        }
+
+        // Get the initial state and the preconditions
+        String initialState = node.getAttribute(TmfXmlStrings.INITIAL);
+        if (initialState.isEmpty()) {
+            NodeList nodesInitialState = node.getElementsByTagName(TmfXmlStrings.INITIAL);
+            if (nodesInitialState.getLength() == 1) {
+                NodeList nodesTransition = ((Element) nodesInitialState.item(0)).getElementsByTagName(TmfXmlStrings.TRANSITION);
+                if (nodesInitialState.getLength() != 1) {
+                    throw new IllegalArgumentException("initial state : there should be one and only one initial state."); //$NON-NLS-1$
+                }
+                initialState = ((Element) nodesTransition.item(0)).getAttribute(TmfXmlStrings.TARGET);
+            }
+        }
+
+        Map<@NonNull String, @NonNull TmfXmlState> statesMap = new HashMap<>();
+        // Get the FSM states
+        NodeList nodesState = node.getElementsByTagName(TmfXmlStrings.STATE);
+        for (int i = 0; i < nodesState.getLength(); i++) {
+            Element element = (Element) NonNullUtils.checkNotNull(nodesState.item(i));
+            TmfXmlState state = modelFactory.createState(element, container, null);
+            statesMap.put(state.getId(), state);
+
+            // If the initial state was not already set, we use the first state
+            // declared in the fsm description as initial state
+            if (initialState.isEmpty()) {
+                initialState = state.getId();
+            }
+        }
+
+        if (initialState.isEmpty()) {
+            throw new IllegalStateException("No initial state has been declared in fsm " + id); //$NON-NLS-1$
+        }
+
+        // Get the FSM final state
+        String finalStateId = TmfXmlStrings.NULL;
+        NodeList nodesFinalState = node.getElementsByTagName(TmfXmlStrings.FINAL);
+        if (nodesFinalState.getLength() == 1) {
+            final Element finalElement = NonNullUtils.checkNotNull((Element) nodesFinalState.item(0));
+            finalStateId = finalElement.getAttribute(TmfXmlStrings.ID);
+            if (!finalStateId.isEmpty()) {
+                TmfXmlState finalState = modelFactory.createState(finalElement, container, null);
+                statesMap.put(finalState.getId(), finalState);
+            }
+        }
+
+        // Get the FSM abandon state
+        String abandonStateId = TmfXmlStrings.NULL;
+        NodeList nodesAbandonState = node.getElementsByTagName(TmfXmlStrings.ABANDON_STATE);
+        if (nodesAbandonState.getLength() == 1) {
+            final Element abandonElement = NonNullUtils.checkNotNull((Element) nodesAbandonState.item(0));
+            abandonStateId = abandonElement.getAttribute(TmfXmlStrings.ID);
+            if (!abandonStateId.isEmpty()) {
+                TmfXmlState abandonState = modelFactory.createState(abandonElement, container, null);
+                statesMap.put(abandonState.getId(), abandonState);
+            }
+        }
+        return new TmfXmlFsm(modelFactory, container, id, instanceMultipleEnabled, initialState, finalStateId, abandonStateId, preconditions, statesMap);
+    }
+
+    private TmfXmlFsm(ITmfXmlModelFactory modelFactory, IXmlStateSystemContainer container, String id, boolean multiple,
+            String initialState, String finalState, String abandonState, List<TmfXmlBasicTransition> preconditions,
+            Map<String, TmfXmlState> states) {
+        fModelFactory = modelFactory;
+        fTotalScenarios = 0;
+        fContainer = container;
+        fId = id;
+        fInstanceMultipleEnabled = multiple;
+        fInitialStateId = initialState;
+        fFinalStateId = finalState;
+        fAbandonStateId = abandonState;
+        fPreconditions = ImmutableList.copyOf(preconditions);
+        fStatesMap = ImmutableMap.copyOf(states);
+        fActiveScenariosList = new ArrayList<>();
+    }
+
+    /**
+     * Get the fsm ID
+     *
+     * @return the id of this fsm
+     */
+    public String getId() {
+        return fId;
+    }
+
+    /**
+     * Get the initial state ID of this fsm
+     *
+     * @return the id of the initial state of this finite state machine
+     */
+    public String getInitialStateId() {
+        return fInitialStateId;
+    }
+
+    /**
+     * Get the final state ID of this fsm
+     *
+     * @return the id of the final state of this finite state machine
+     */
+    public String getFinalStateId() {
+        return fFinalStateId;
+    }
+
+    /**
+     * Get the abandon state ID fo this fsm
+     *
+     * @return the id of the abandon state of this finite state machine
+     */
+    public String getAbandonStateId() {
+        return fAbandonStateId;
+    }
+
+    /**
+     * Get the states table of this fsm in map
+     *
+     * @return The map containing all state definition for this fsm
+     */
+    public Map<String, TmfXmlState> getStatesMap() {
+        return Collections.unmodifiableMap(fStatesMap);
+    }
+
+    /**
+     * Process the active event and determine the next step of this fsm
+     *
+     * @param event
+     *            The event to process
+     * @param tests
+     *            The list of possible transitions of the state machine
+     * @param scenarioInfo
+     *            The active scenario details.
+     * @return A pair containing the next state of the state machine and the
+     *         actions to execute
+     */
+    public @Nullable TmfXmlStateTransition next(ITmfEvent event, Map<String, TmfXmlTransitionValidator> tests, TmfXmlScenarioInfo scenarioInfo) {
+        boolean matched = false;
+        TmfXmlStateTransition stateTransition = null;
+        TmfXmlState state = NonNullUtils.checkNotNull(fStatesMap.get(scenarioInfo.getActiveState()));
+        for (int i = 0; i < state.getTransitionList().size() && !matched; i++) {
+            stateTransition = state.getTransitionList().get(i);
+            matched = stateTransition.test(event, scenarioInfo, tests);
+        }
+        return matched ? stateTransition : null;
+    }
+
+
+
+    /**
+     * Validate the preconditions of this fsm. If not validate, the fsm will
+     * skip the active event.
+     *
+     * @param event
+     *            The current event
+     * @param tests
+     *            The transition inputs
+     * @return True if one of the precondition is validated, false otherwise
+     */
+    private boolean validatePreconditions(ITmfEvent event, Map<String, TmfXmlTransitionValidator> tests) {
+        if (fPreconditions.isEmpty()) {
+            return true;
+        }
+        for (TmfXmlBasicTransition precondition : fPreconditions) {
+            if (precondition.test(event, null, tests)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Handle the current event
+     *
+     * @param event
+     *            The current event
+     * @param transitionMap
+     *            The transitions of the pattern
+     */
+    public void handleEvent(ITmfEvent event, Map<String, TmfXmlTransitionValidator> transitionMap) {
+        if (!validatePreconditions(event, transitionMap)) {
+            return;
+        }
+        for (Iterator<TmfXmlScenario> currentItr = fActiveScenariosList.iterator(); currentItr.hasNext();) {
+            TmfXmlScenario scenario = currentItr.next();
+            // Remove inactive scenarios or handle the active ones.
+            if (!scenario.isActive()) {
+                currentItr.remove();
+            } else {
+                handleScenario(scenario, event);
+            }
+        }
+    }
+
+    /**
+     * Abandon all ongoing scenarios
+     */
+    public void dispose() {
+        for (TmfXmlScenario scenario : fActiveScenariosList) {
+            if (scenario.isActive()) {
+                scenario.cancel();
+            }
+        }
+    }
+
+    private static void handleScenario(TmfXmlScenario scenario, ITmfEvent event) {
+        if (scenario.isActive()) {
+            scenario.handleEvent(event);
+        }
+    }
+
+    /**
+     * Create a new scenario of this fsm
+     *
+     * @param event
+     *            The current event, null if not
+     * @param eventHandler
+     *            The event handler this fsm belongs
+     * @param force
+     *            True to force the creation of the scenario, false otherwise
+     */
+    public synchronized void createScenario(@Nullable ITmfEvent event, TmfXmlPatternEventHandler eventHandler, boolean force) {
+        if (force || isNewScenarioAllowed()) {
+            TmfXmlScenario scenario = new TmfXmlScenario(event, eventHandler, fId, fContainer, fModelFactory);
+            fTotalScenarios++;
+            fActiveScenariosList.add(scenario);
+        }
+    }
+
+    /**
+     * Check if we have the right to create a new scenario. A new scenario could
+     * be created if it is not the first scenario of an FSM and the FSM is not a
+     * singleton and the status of the last created scenario is not PENDING.
+     *
+     * @return True if the start of a new scenario is allowed, false otherwise
+     */
+    public synchronized boolean isNewScenarioAllowed() {
+        return !fActiveScenariosList.get(fActiveScenariosList.size() - 1).getScenarioInfos().getStatus().equals(ScenarioStatusType.PENDING)
+                && fInstanceMultipleEnabled && fTotalScenarios > 0;
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlLocation.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlLocation.java
new file mode 100644 (file)
index 0000000..be94b2e
--- /dev/null
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ecole Polytechnique de Montreal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Florian Wininger - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.w3c.dom.Element;
+
+/**
+ * This Class implements a Location in the XML-defined state system, ie a named
+ * shortcut to reach a given attribute, used in state attributes
+ *
+ * <pre>
+ * example:
+ *  <location id="CurrentCPU">
+ *    <stateAttribute type="constant" value="CPUs" />
+ *    <stateAttribute type="eventField" name="cpu" />
+ *    ...
+ *  </location>
+ * </pre>
+ *
+ * @author Florian Wininger
+ */
+public class TmfXmlLocation {
+
+    /** Path in the State System */
+    private final List<ITmfXmlStateAttribute> fPath = new LinkedList<>();
+
+    /** ID : name of the location */
+    private final String fId;
+    private final IXmlStateSystemContainer fContainer;
+
+    /**
+     * Constructor
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param location
+     *            XML node element
+     * @param container
+     *            The state system container this location belongs to
+     */
+    public TmfXmlLocation(ITmfXmlModelFactory modelFactory, Element location, IXmlStateSystemContainer container) {
+        String id = location.getAttribute(TmfXmlStrings.ID);
+        fId = id;
+        fContainer = container;
+
+        List<@Nullable Element> childElements = XmlUtils.getChildElements(location);
+        for (Element attribute : childElements) {
+            if (attribute == null) {
+                continue;
+            }
+            ITmfXmlStateAttribute xAttribute = modelFactory.createStateAttribute(attribute, fContainer);
+            fPath.add(xAttribute);
+        }
+    }
+
+    /**
+     * Get the id of the location
+     *
+     * @return The id of a location
+     */
+    public String getId() {
+        return fId;
+    }
+
+    /**
+     * Get the quark for the path represented by this location
+     *
+     * @param event
+     *            The event being handled
+     *
+     * @param startQuark
+     *            The starting quark for relative search, use
+     *            {@link IXmlStateSystemContainer#ROOT_QUARK} for the root of
+     *            the attribute tree
+     * @param scenarioInfo
+     *            The active scenario details. Or <code>null</code> if there is
+     *            no scenario.
+     * @return The quark at the leaf of the path
+     */
+    public int getLocationQuark(@Nullable ITmfEvent event, int startQuark, @Nullable TmfXmlScenarioInfo scenarioInfo) {
+        int quark = startQuark;
+        for (ITmfXmlStateAttribute attrib : fPath) {
+            quark = attrib.getAttributeQuark(event, quark, scenarioInfo);
+            if (quark == IXmlStateSystemContainer.ERROR_QUARK) {
+                break;
+            }
+        }
+        return quark;
+    }
+
+    /**
+     * Get the quark for the path represented by this location
+     *
+     * @param startQuark
+     *            The starting quark for relative search, use
+     *            {@link IXmlStateSystemContainer#ROOT_QUARK} for the root of
+     *            the attribute tree
+     * @param scenarioInfo
+     *            The active scenario details. Or <code>null</code> if there is
+     *            no scenario.
+     * @return The quark at the leaf of the path
+     */
+    public int getLocationQuark(int startQuark, @Nullable TmfXmlScenarioInfo scenarioInfo) {
+        int quark = startQuark;
+        for (ITmfXmlStateAttribute attrib : fPath) {
+            quark = attrib.getAttributeQuark(quark, scenarioInfo);
+            if (quark == IXmlStateSystemContainer.ERROR_QUARK) {
+                break;
+            }
+        }
+        return quark;
+    }
+
+    @Override
+    public String toString() {
+        return "TmfXmlLocation " + fId + ": " + fPath; //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+}
\ No newline at end of file
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlPatternEventHandler.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlPatternEventHandler.java
new file mode 100644 (file)
index 0000000..47806b7
--- /dev/null
@@ -0,0 +1,197 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ ******************************************************************************/
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
+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.tmf.core.event.ITmfEvent;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * This Class implements a pattern handler tree in the XML-defined state system.
+ * It receives events and dispatches it to Active finite state machines.
+ *
+ * @author Jean-Christian Kouame
+ */
+public class TmfXmlPatternEventHandler {
+
+    /* list of states changes */
+    private final XmlPatternStateProvider fParent;
+
+    private final List<String> fInitialFsm;
+    private final Map<String, TmfXmlTransitionValidator> fTestMap = new HashMap<>();
+    private final Map<String, ITmfXmlAction> fActionMap = new HashMap<>();
+    private final Map<String, TmfXmlFsm> fFsmMap = new HashMap<>();
+    private final List<TmfXmlFsm> fActiveFsmList = new ArrayList<>();
+
+    /**
+     * Constructor
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param node
+     *            The XML root of this event handler
+     * @param parent
+     *            The state system container this event handler belongs to
+     */
+    public TmfXmlPatternEventHandler(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer parent) {
+        fParent = (XmlPatternStateProvider) parent;
+        String initialFsm = node.getAttribute(TmfXmlStrings.INITIAL);
+        fInitialFsm = initialFsm.isEmpty() ? Collections.EMPTY_LIST : Arrays.asList(initialFsm.split(TmfXmlStrings.AND_SEPARATOR));
+
+        NodeList nodesTest = node.getElementsByTagName(TmfXmlStrings.TEST);
+        /* load transition input */
+        for (int i = 0; i < nodesTest.getLength(); i++) {
+            Element element = (Element) nodesTest.item(i);
+            if (element == null) {
+                throw new IllegalArgumentException();
+            }
+            TmfXmlTransitionValidator test = modelFactory.createTransitionValidator(element, fParent);
+            fTestMap.put(test.getId(), test);
+        }
+
+        NodeList nodesAction = node.getElementsByTagName(TmfXmlStrings.ACTION);
+        /* load actions */
+        for (int i = 0; i < nodesAction.getLength(); i++) {
+            Element element = (Element) nodesAction.item(i);
+            if (element == null) {
+                throw new IllegalArgumentException();
+            }
+            ITmfXmlAction action = modelFactory.createAction(element, fParent);
+            fActionMap.put(((TmfXmlAction) action).getId(), action);
+        }
+        fActionMap.put(TmfXmlStrings.CONSTANT_PREFIX + ITmfXmlAction.CLEAR_STORED_FIELDS_STRING, new ResetStoredFieldsAction(fParent));
+        fActionMap.put(TmfXmlStrings.CONSTANT_PREFIX + ITmfXmlAction.SAVE_STORED_FIELDS_STRING, new UpdateStoredFieldsAction(fParent));
+
+        NodeList nodesFsm = node.getElementsByTagName(TmfXmlStrings.FSM);
+        /* load fsm */
+        for (int i = 0; i < nodesFsm.getLength(); i++) {
+            Element element = (Element) nodesFsm.item(i);
+            if (element == null) {
+                throw new IllegalArgumentException();
+            }
+            TmfXmlFsm fsm = modelFactory.createFsm(element, fParent);
+            fFsmMap.put(fsm.getId(), fsm);
+        }
+    }
+
+    /**
+     * Start a new scenario for this specific fsm id. If the fsm support only a
+     * single instance and this instance already exist, no new scenario is then
+     * started. If the scenario is created we handle the current event directly.
+     *
+     * @param fsmIds
+     *            The IDs of the fsm to start
+     * @param event
+     *            The current event
+     * @param force
+     *            True to force the creation of the scenario, false otherwise
+     */
+    public void startScenario(List<String> fsmIds, @Nullable ITmfEvent event, boolean force) {
+        for (String fsmId : fsmIds) {
+            TmfXmlFsm fsm = NonNullUtils.checkNotNull(fFsmMap.get(fsmId));
+            if (!fActiveFsmList.contains(fsm)) {
+                fActiveFsmList.add(fsm);
+            }
+            fsm.createScenario(event, this, force);
+        }
+    }
+
+    /**
+     * Get all the defined transition tests
+     *
+     * @return The tests in a map
+     */
+    public Map<String, TmfXmlTransitionValidator> getTestMap() {
+        return ImmutableMap.copyOf(fTestMap);
+    }
+
+    /**
+     * Get all the defined actions
+     *
+     * @return The actions
+     */
+    public Map<String, ITmfXmlAction> getActionMap() {
+        return ImmutableMap.copyOf(fActionMap);
+    }
+
+    /**
+     * If the pattern handler can handle the event, it send the event to all
+     * finite state machines with ongoing scenarios
+     *
+     * @param event
+     *            The trace event to handle
+     */
+    public void handleEvent(ITmfEvent event) {
+        /*
+         * Order is important so cannot be parallelized
+         */
+        final @NonNull List<@NonNull TmfXmlFsm> activeFsmList = fActiveFsmList;
+        final @NonNull Map<@NonNull String, @NonNull TmfXmlFsm> fsmMap = fFsmMap;
+        if (activeFsmList.isEmpty()) {
+            List<String> fsmIds = fInitialFsm;
+            if (fsmIds.isEmpty()) {
+                fsmIds = new ArrayList<>();
+                for (TmfXmlFsm fsm : fsmMap.values()) {
+                    fsmIds.add(fsm.getId());
+                }
+            }
+            if (!fsmIds.isEmpty()) {
+                startScenario(fsmIds, null, true);
+            }
+        } else {
+            List<String> fsmToStart = new ArrayList<>();
+            for (Map.Entry<String, TmfXmlFsm> entry : fsmMap.entrySet()) {
+                if (entry.getValue().isNewScenarioAllowed()) {
+                    fsmToStart.add(entry.getKey());
+                }
+            }
+            if (!fsmToStart.isEmpty()) {
+                startScenario(fsmToStart, null, false);
+            }
+        }
+        for (TmfXmlFsm fsm : activeFsmList) {
+            fsm.handleEvent(event, fTestMap);
+        }
+    }
+
+    /**
+     * Abandon all the ongoing scenarios
+     */
+    public void dispose() {
+        for (TmfXmlFsm fsm : fActiveFsmList) {
+            fsm.dispose();
+        }
+    }
+
+    /**
+     * Get the fsm corresponding to the specified id
+     *
+     * @param fsmId
+     *            The id of the fsm
+     * @return The fsm found, null if nothing found
+     */
+    public @Nullable TmfXmlFsm getFsm(String fsmId) {
+        return fFsmMap.get(fsmId);
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlPatternSegmentBuilder.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlPatternSegmentBuilder.java
new file mode 100644 (file)
index 0000000..19bb1af
--- /dev/null
@@ -0,0 +1,342 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ ******************************************************************************/
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+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.segment.TmfXmlPatternSegment;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * This class defines a pattern segment builder. It will use the XML description
+ * of the pattern segment to generate it at runtime.
+ *
+ * @author Jean-Christian Kouame
+ */
+public class TmfXmlPatternSegmentBuilder {
+
+    /**
+     * The string unknown
+     */
+    public static final String UNKNOWN_STRING = "unknown"; //$NON-NLS-1$
+    /**
+     * Prefix for the pattern segment name
+     */
+    public static final String PATTERN_SEGMENT_NAME_PREFIX = "seg_"; //$NON-NLS-1$
+    private final ITmfXmlModelFactory fModelFactory;
+    private final IXmlStateSystemContainer fContainer;
+    private final List<TmfXmlPatternSegmentField> fFields = new ArrayList<>();
+    private final TmfXmlPatternSegmentType fSegmentType;
+
+    /**
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param node
+     *            XML element of the pattern segment builder
+     * @param parent
+     *            The state system container this pattern segment builder
+     *            belongs to
+     */
+    public TmfXmlPatternSegmentBuilder(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer parent) {
+        fModelFactory = modelFactory;
+        fContainer = parent;
+
+        //Set the XML type of the segment
+        NodeList nodesSegmentType = node.getElementsByTagName(TmfXmlStrings.SEGMENT_TYPE);
+        Element element = (Element) nodesSegmentType.item(0);
+        if (element == null) {
+            throw new IllegalArgumentException();
+        }
+        fSegmentType = new TmfXmlPatternSegmentType(element);
+
+        //Set the XML content of the segment
+        NodeList nodesSegmentContent = node.getElementsByTagName(TmfXmlStrings.SEGMENT_CONTENT);
+        Element fContentElement = (Element) nodesSegmentContent.item(0);
+        if (fContentElement != null) {
+            NodeList nodesSegmentField = fContentElement.getElementsByTagName(TmfXmlStrings.SEGMENT_FIELD);
+            for (int i = 0; i < nodesSegmentField.getLength(); i++) {
+                fFields.add(new TmfXmlPatternSegmentField(checkNotNull((Element) nodesSegmentField.item(i))));
+            }
+        }
+    }
+
+    /**
+     * Generate a pattern segment
+     *
+     * @param event
+     *            The active event
+     * @param start
+     *            Start time of the pattern segment to generate
+     * @param end
+     *            End time of the pattern segment to generate
+     * @param scenarioInfo
+     *            The active scenario details. Or <code>null</code> if there is
+     *            no scenario.
+     * @return The pattern segment generated
+     */
+    public TmfXmlPatternSegment generatePatternSegment(ITmfEvent event, ITmfTimestamp start, ITmfTimestamp end, @Nullable TmfXmlScenarioInfo scenarioInfo) {
+        int scale = event.getTimestamp().getScale();
+        long startValue = start.toNanos();
+        long endValue = end.toNanos();
+        String segmentName = getPatternSegmentName(event, scenarioInfo);
+        Map<String, ITmfStateValue> fields = new HashMap<>();
+        setPatternSegmentContent(event, start, end, fields, scenarioInfo);
+        TmfXmlPatternSegment segment = new TmfXmlPatternSegment(startValue, endValue, scale, segmentName, fields);
+        if (fContainer instanceof XmlPatternStateProvider) {
+            ((XmlPatternStateProvider) fContainer).getListener().onNewSegment(segment);
+        }
+        return segment;
+    }
+
+    /**
+     * Get the pattern segment name
+     *
+     * @param event
+     *            The active event
+     * @param scenarioInfo
+     *            The active scenario details. Or <code>null</code> if there is
+     *            no scenario.
+     * @return The name of the segment
+     */
+    private String getPatternSegmentName(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
+        return fSegmentType.getName(event, scenarioInfo);
+    }
+
+    /**
+     * Compute all the fields and their values for this pattern segment. The
+     * fields could be constant values or values queried from the state system.
+     *
+     * @param event
+     *            The current event
+     * @param start
+     *            The start timestamp of this segment
+     * @param end
+     *            The end timestamp of this segment
+     * @param fields
+     *            The map that will contained all the fields
+     * @param scenarioInfo
+     *            The active scenario details. Or <code>null</code> if there is
+     *            no scenario.
+     */
+    private void setPatternSegmentContent(ITmfEvent event, ITmfTimestamp start, ITmfTimestamp end, Map<String, ITmfStateValue> fields, @Nullable TmfXmlScenarioInfo scenarioInfo) {
+        for (TmfXmlPatternSegmentField field : fFields) {
+            fields.put(field.getName().intern(), field.getValue(event, scenarioInfo));
+        }
+        if (scenarioInfo != null) {
+            addStoredFieldsContent(event, fields, scenarioInfo);
+        }
+    }
+
+    /**
+     * Query the stored fields path and add them to the content of the pattern
+     * segment. This is specific to pattern analysis.
+     *
+     * @param event
+     *            The active event
+     * @param fields
+     *            The segment fields
+     * @param info
+     *            The active scenario details
+     */
+    protected void addStoredFieldsContent(ITmfEvent event, Map<String, ITmfStateValue> fields, final TmfXmlScenarioInfo info) {
+        if (fContainer instanceof XmlPatternStateProvider) {
+            for (Entry<String, String> entry : ((XmlPatternStateProvider) fContainer).getStoredFields().entrySet()) {
+                ITmfStateValue value = ((XmlPatternStateProvider) fContainer).getHistoryBuilder().getStoredFieldValue(fContainer, entry.getValue(), info, event);
+                if (!value.isNull()) {
+                    fields.put(entry.getValue().intern(), value);
+                }
+            }
+        }
+    }
+
+    private static ITmfStateValue getStateValueFromConstant(String constantValue, String type) {
+        switch (type) {
+        case TmfXmlStrings.TYPE_INT:
+            return TmfStateValue.newValueInt(Integer.parseInt(constantValue));
+        case TmfXmlStrings.TYPE_LONG:
+            return TmfStateValue.newValueLong(Long.parseLong(constantValue));
+        case TmfXmlStrings.TYPE_STRING:
+            return TmfStateValue.newValueString(constantValue);
+        case TmfXmlStrings.TYPE_NULL:
+            return TmfStateValue.nullValue();
+        default:
+            throw new IllegalArgumentException("Invalid type of field : " + type); //$NON-NLS-1$
+        }
+    }
+
+    private static void getNameFromXmlStateValue(ITmfEvent event, StringBuilder builder, ITmfXmlStateValue xmlStateValue, @Nullable TmfXmlScenarioInfo scenarioInfo) {
+        try {
+            ITmfStateValue value = xmlStateValue.getValue(event, scenarioInfo);
+            switch (value.getType()) {
+            case DOUBLE:
+                builder.append(value.unboxDouble());
+                break;
+            case INTEGER:
+                builder.append(value.unboxInt());
+                break;
+            case LONG:
+                builder.append(value.unboxLong());
+                break;
+            case NULL:
+                builder.append(UNKNOWN_STRING);
+                break;
+            case STRING:
+                builder.append(value.unboxStr());
+                break;
+            default:
+                throw new StateValueTypeException("Invalid type of state value"); //$NON-NLS-1$
+            }
+        } catch (AttributeNotFoundException e) {
+            Activator.logInfo("Impossible to get the state value", e); //$NON-NLS-1$
+        }
+    }
+
+    /**
+     * This class represents the segment fields described in the XML. The real
+     * value of the field will be set at runtime using the active event.
+     *
+     * @author Jean-Christian Kouame
+     *
+     */
+    private class TmfXmlPatternSegmentField {
+        private final String fName;
+        private final String fType;
+        private final @Nullable ITmfStateValue fStateValue;
+        private final @Nullable ITmfXmlStateValue fXmlStateValue;
+
+        /**
+         * Constructor
+         *
+         * @param element
+         *            The pattern segment field node
+         */
+        public TmfXmlPatternSegmentField(Element element) {
+            // The name, the type and the value of each field could respectively
+            // be found from the attributes name, type and value. If the value
+            // attribute is not available, try to find it from the child state
+            // value.
+            fName = element.getAttribute(TmfXmlStrings.NAME);
+            fType = element.getAttribute(TmfXmlStrings.TYPE);
+            String constantValue = element.getAttribute(TmfXmlStrings.VALUE);
+            if (constantValue.isEmpty() && !fType.equals(TmfXmlStrings.TYPE_NULL)) {
+                fStateValue = null;
+                Element elementFieldStateValue = (Element) element.getElementsByTagName(TmfXmlStrings.STATE_VALUE).item(0);
+                if (elementFieldStateValue == null) {
+                    throw new IllegalArgumentException("The value of the field " + fName + " is missing"); //$NON-NLS-1$ //$NON-NLS-2$
+                }
+                fXmlStateValue = fModelFactory.createStateValue(elementFieldStateValue, fContainer, new ArrayList<>());
+            } else {
+                fStateValue = getStateValueFromConstant(constantValue, fType);
+                fXmlStateValue = null;
+            }
+        }
+
+        /**
+         * Get the real value of the XML pattern segment field
+         *
+         * @param event
+         *            The active event
+         * @return The state value representing the value of the XML pattern
+         *         segment field
+         * @param scenarioInfo
+         *            The active scenario details. Or <code>null</code> if there
+         *            is no scenario.
+         */
+        public ITmfStateValue getValue(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
+            if (fStateValue != null) {
+                return fStateValue;
+            }
+            try {
+                return checkNotNull(fXmlStateValue).getValue(event, scenarioInfo);
+            } catch (AttributeNotFoundException e) {
+                Activator.logError("Failed to get the state value", e); //$NON-NLS-1$
+            }
+            throw new IllegalStateException("Failed to get the value for the segment field " + fName); //$NON-NLS-1$
+        }
+
+        /**
+         * Get the name of the XML pattern segment field
+         *
+         * @return The name
+         */
+        public String getName() {
+            return fName;
+        }
+    }
+
+    /**
+     * This class represents the segment type described in XML.
+     *
+     * @author Jean-Christian Kouame
+     *
+     */
+    private class TmfXmlPatternSegmentType {
+        private final String fSegmentNameAttribute;
+        private final @Nullable ITmfXmlStateValue fNameStateValue;
+
+        /**
+         * Constructor
+         *
+         * @param element
+         *            The pattern segment type node
+         */
+        public TmfXmlPatternSegmentType(Element element) {
+            // Try to find the segment name from the name attribute. If
+            // attribute not available, try to find it from the child state value
+            fSegmentNameAttribute = element.getAttribute(TmfXmlStrings.SEGMENT_NAME);
+            if (!fSegmentNameAttribute.isEmpty()) {
+                fNameStateValue = null;
+            } else {
+                Element elementSegmentNameStateValue = (Element) element.getElementsByTagName(TmfXmlStrings.STATE_VALUE).item(0);
+                if (elementSegmentNameStateValue == null) {
+                    throw new IllegalArgumentException("Failed to get the segment name. A state value is needed."); //$NON-NLS-1$
+                }
+                fNameStateValue = fModelFactory.createStateValue(elementSegmentNameStateValue, fContainer, new ArrayList<>());
+            }
+        }
+
+        /**
+         * Get the name of the segment
+         *
+         * @param event
+         *            The active event
+         * @param scenarioInfo
+         *            The active scenario details. Or <code>null</code> if there
+         *            is no scenario.
+         * @return The segment name
+         */
+        public String getName(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
+            StringBuilder name = new StringBuilder(PATTERN_SEGMENT_NAME_PREFIX);
+            if (fNameStateValue != null) {
+                getNameFromXmlStateValue(event, name, fNameStateValue, scenarioInfo);
+            } else {
+                name.append(fSegmentNameAttribute);
+            }
+            return name.toString().intern();
+        }
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlScenario.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlScenario.java
new file mode 100644 (file)
index 0000000..2e1f0cd
--- /dev/null
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ ******************************************************************************/
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlScenarioHistoryBuilder.ScenarioStatusType;
+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.tmf.core.event.ITmfEvent;
+
+/**
+ * This Class implements a Scenario in the XML-defined state system
+ */
+public class TmfXmlScenario {
+
+    private final IXmlStateSystemContainer fContainer;
+    private final TmfXmlFsm fFsm;
+    private TmfXmlPatternEventHandler fPatternHandler;
+    private TmfXmlScenarioInfo fScenarioInfo;
+    TmfXmlScenarioHistoryBuilder fHistoryBuilder;
+
+    /**
+     * Constructor
+     *
+     * @param event
+     *            The event at which this scenario is created
+     * @param patternHandler
+     *            The filter handler
+     * @param fsmId
+     *            the id of the fsm executed by this scenario
+     * @param container
+     *            The state system container this scenario belongs to
+     * @param modelFactory
+     *            The model factory
+     */
+    public TmfXmlScenario(@Nullable ITmfEvent event, TmfXmlPatternEventHandler patternHandler, String fsmId, IXmlStateSystemContainer container, ITmfXmlModelFactory modelFactory) {
+        TmfXmlFsm fsm = patternHandler.getFsm(fsmId);
+        if (fsm == null) {
+            throw new IllegalArgumentException(fsmId + "has not been declared."); //$NON-NLS-1$
+        }
+        fFsm = fsm;
+        fContainer = container;
+        fHistoryBuilder = ((XmlPatternStateProvider) container).getHistoryBuilder();
+        fPatternHandler = patternHandler;
+        int quark = fHistoryBuilder.assignScenarioQuark(fContainer, fsmId);
+        int statusQuark = fHistoryBuilder.getScenarioStatusQuark(fContainer, quark);
+        fScenarioInfo = new TmfXmlScenarioInfo(fFsm.getInitialStateId(), ScenarioStatusType.PENDING, quark, statusQuark, fFsm);
+        fHistoryBuilder.update(fContainer, fScenarioInfo, event);
+    }
+
+    /**
+     * Get this scenario infos
+     *
+     * @return The scenario info
+     */
+    public TmfXmlScenarioInfo getScenarioInfos() {
+        return fScenarioInfo;
+    }
+
+    /**
+     * Cancel the execution of this scenario
+     */
+    public void cancel() {
+        fScenarioInfo.setStatus(ScenarioStatusType.ABANDONED);
+        if (fScenarioInfo.getStatus() != ScenarioStatusType.PENDING) {
+            fHistoryBuilder.completeScenario(fContainer, fScenarioInfo, null);
+        }
+    }
+
+    /**
+     * Test if the scenario is active or not
+     *
+     * @return True if the scenario is active, false otherwise
+     */
+    public boolean isActive() {
+        return fScenarioInfo.getStatus().equals(ScenarioStatusType.PENDING) || fScenarioInfo.getStatus().equals(ScenarioStatusType.IN_PROGRESS);
+    }
+
+    /**
+     * Handle the ongoing event
+     *
+     * @param event
+     *            The ongoing event
+     */
+    public void handleEvent(ITmfEvent event) {
+
+        TmfXmlStateTransition out = fFsm.next(event, fPatternHandler.getTestMap(), fScenarioInfo);
+        if (out == null) {
+            return;
+        }
+
+        // Processing the actions in the transition
+        final List<String> actions = out.getAction();
+        for (String actionId : actions) {
+            ITmfXmlAction action = fPatternHandler.getActionMap().get(actionId);
+            if (action != null) {
+                action.execute(event, fScenarioInfo);
+            } else {
+                throw new IllegalStateException("Action " + actionId + " cannot be found."); //$NON-NLS-1$ //$NON-NLS-2$
+            }
+        }
+
+        // Change the activeState
+        final @NonNull String nextState = out.getTarget();
+        if (fScenarioInfo.getStatus().equals(ScenarioStatusType.PENDING)) {
+            fScenarioInfo.setStatus(ScenarioStatusType.IN_PROGRESS);
+            fHistoryBuilder.startScenario(fContainer, fScenarioInfo, event);
+        } else if (nextState.equals(fFsm.getAbandonStateId())) {
+            fScenarioInfo.setStatus(ScenarioStatusType.ABANDONED);
+            fHistoryBuilder.completeScenario(fContainer, fScenarioInfo, event);
+        } else if (nextState.equals(fFsm.getFinalStateId())) {
+            fScenarioInfo.setStatus(ScenarioStatusType.MATCHED);
+            fHistoryBuilder.completeScenario(fContainer, fScenarioInfo, event);
+        }
+        fScenarioInfo.setActiveState(nextState);
+        fHistoryBuilder.update(fContainer, fScenarioInfo, event);
+    }
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlScenarioHistoryBuilder.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlScenarioHistoryBuilder.java
new file mode 100644 (file)
index 0000000..026d573
--- /dev/null
@@ -0,0 +1,438 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ ******************************************************************************/
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
+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.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
+import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
+import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.statesystem.TmfAttributePool;
+
+import com.google.common.collect.BiMap;
+import com.google.common.collect.ImmutableBiMap;
+
+/**
+ * This class is responsible for creating scenarios, updating their status and
+ * data, and saving the scenario data to the state system
+ */
+public class TmfXmlScenarioHistoryBuilder {
+
+    /** The string 'status' */
+    public static final String STATUS = "status"; //$NON-NLS-1$
+    /** The string for "nbScenarios" */
+    public static final String SCENARIO_COUNT = "nbScenarios"; //$NON-NLS-1$
+
+    /** The string for start time */
+    private static final String START_TIME = "startTime"; //$NON-NLS-1$
+    /** Error message */
+    private static final String ERROR_MESSAGE = "The state system is null"; //$NON-NLS-1$
+
+    private final Map<String, TmfAttributePool> fFsmPools = new HashMap<>();
+
+    /**
+     * All possible types of status for a scenario
+     */
+    public enum ScenarioStatusType {
+        /**
+         * scenario pending for start point
+         */
+        PENDING,
+        /**
+         * scenario in progress
+         */
+        IN_PROGRESS,
+        /**
+         * scenario abandoned
+         */
+        ABANDONED,
+        /**
+         * scenario match with the pattern
+         */
+        MATCHED
+    }
+
+    /**
+     * Cache the available status in a map
+     */
+    protected static final BiMap<ScenarioStatusType, ITmfStateValue> STATUS_MAP = NonNullUtils.checkNotNull(ImmutableBiMap.of(
+            ScenarioStatusType.PENDING, TmfStateValue.newValueInt(0),
+            ScenarioStatusType.IN_PROGRESS, TmfStateValue.newValueInt(1),
+            ScenarioStatusType.MATCHED, TmfStateValue.newValueInt(2),
+            ScenarioStatusType.ABANDONED, TmfStateValue.newValueInt(3)));
+
+    /**
+     * Get the scenario matched process start time
+     *
+     * @param container
+     *            The state system container this class use
+     * @param info
+     *            The scenario details
+     * @param event
+     *            The current event
+     *
+     * @return The start time of the matching process for the specified scenario
+     */
+    public long getStartTime(final IXmlStateSystemContainer container, final TmfXmlScenarioInfo info, final ITmfEvent event) {
+        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
+        long ts = getTimestamp(event, ss);
+        try {
+            int attributeQuark = getQuarkRelativeAndAdd(ss, info.getQuark(), START_TIME);
+            ITmfStateInterval state = ss.querySingleState(ts, attributeQuark);
+            return state.getStartTime();
+        } catch (AttributeNotFoundException | StateSystemDisposedException e) {
+            Activator.logError("failed to get the start time of the scenario", e); //$NON-NLS-1$
+        }
+        return -1L;
+    }
+
+    /**
+     * Save the stored fields
+     *
+     * @param container
+     *            The state system container this class use
+     * @param attributeName
+     *            The name of the attribute to save
+     * @param value
+     *            The value of the attribute to save
+     * @param info
+     *            The scenario details
+     * @param event
+     *            The current event
+     */
+    public void updateStoredFields(final IXmlStateSystemContainer container, final String attributeName, final ITmfStateValue value, final TmfXmlScenarioInfo info, final ITmfEvent event) {
+        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
+        long ts = getTimestamp(event, ss);
+        try {
+            int attributeQuark = getQuarkRelativeAndAdd(ss, info.getQuark(), TmfXmlStrings.STORED_FIELDS, attributeName);
+            ss.modifyAttribute(ts, value, attributeQuark);
+        } catch (StateValueTypeException | AttributeNotFoundException e) {
+            Activator.logError("failed to save the stored field " + attributeName, e); //$NON-NLS-1$
+        }
+    }
+
+    /**
+     * Clear the special fields
+     *
+     * @param container
+     *            The state system container this class use
+     * @param attributeName
+     *            The name of the attribute to save
+     * @param info
+     *            The scenario details
+     * @param event
+     *            The current event
+     */
+    public void resetStoredFields(final IXmlStateSystemContainer container, final String attributeName, final TmfXmlScenarioInfo info, final ITmfEvent event) {
+        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
+        long ts = getTimestamp(event, ss);
+        ITmfStateValue value = TmfStateValue.nullValue();
+        try {
+            int attributeQuark = getQuarkRelativeAndAdd(ss, info.getQuark(), TmfXmlStrings.STORED_FIELDS, attributeName);
+            ss.modifyAttribute(ts, value, attributeQuark);
+        } catch (StateValueTypeException | AttributeNotFoundException e) {
+            Activator.logError("failed to clear the stored fields", e); //$NON-NLS-1$
+        }
+    }
+
+    /**
+     * Get the value of a special field in the state system
+     *
+     * @param container
+     *            The state system container this class use
+     * @param attributeName
+     *            The attribute name of the special field
+     * @param info
+     *            The scenario details
+     * @param event
+     *            The current event
+     *
+     * @return The value of a special field saved into the state system
+     */
+    public ITmfStateValue getStoredFieldValue(IXmlStateSystemContainer container, String attributeName, final TmfXmlScenarioInfo info, ITmfEvent event) {
+        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
+        long ts = event.getTimestamp().toNanos();
+        ITmfStateInterval state = null;
+        try {
+            int attributeQuark = getQuarkRelativeAndAdd(ss, info.getQuark(), TmfXmlStrings.STORED_FIELDS, attributeName);
+            state = ss.querySingleState(ts, attributeQuark);
+        } catch (AttributeNotFoundException | StateSystemDisposedException e) {
+            Activator.logError("failed to get the value of the stored field " + attributeName, e); //$NON-NLS-1$
+        }
+        return (state != null) ? NonNullUtils.checkNotNull(state.getStateValue()) : TmfStateValue.nullValue();
+    }
+
+    /**
+     * Get the attribute pool for this fsm
+     *
+     * @param container
+     *            The state system container
+     * @param fsmId
+     *            The ID of the FSM
+     * @return The attribute pool associated with this FSM
+     */
+    protected TmfAttributePool getPoolFor(IXmlStateSystemContainer container, String fsmId) {
+        TmfAttributePool pool = fFsmPools.get(fsmId);
+        if (pool != null) {
+            return pool;
+        }
+        ITmfStateSystemBuilder ss = NonNullUtils.checkNotNull((ITmfStateSystemBuilder) container.getStateSystem());
+        String[] fsmPath = new String[] { TmfXmlStrings.SCENARIOS, fsmId };
+        int quark = getQuarkAbsoluteAndAdd(ss, fsmPath);
+        pool = new TmfAttributePool(ss, quark);
+        fFsmPools.put(fsmId, pool);
+        return pool;
+    }
+
+    /**
+     * Get the scenario quark
+     *
+     * @param container
+     *            The state system container this class use
+     * @param fsmId
+     *            Id of the fsm this scenario is associated to
+     * @return The scenario quark
+     */
+    public int assignScenarioQuark(IXmlStateSystemContainer container, String fsmId) {
+        TmfAttributePool pool = getPoolFor(container, fsmId);
+        return pool.getAvailable();
+    }
+
+    /**
+     * Get the scenario status quark
+     *
+     * @param container
+     *            The state system container this class use
+     * @param scenarioQuark
+     *            The scenario quark
+     * @return The scenario quark
+     */
+    public int getScenarioStatusQuark(IXmlStateSystemContainer container, int scenarioQuark) {
+        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
+        return getQuarkRelativeAndAdd(ss, scenarioQuark, STATUS);
+    }
+
+    /**
+     * Get the start time of a specific state of the scenario
+     *
+     * @param container
+     *            The state system container this class use
+     * @param stateName
+     *            The name of the current state of the scenario
+     * @param info
+     *            The scenario details
+     * @param event
+     *            The current event
+     *
+     * @return The start time for the specified state
+     */
+    public long getSpecificStateStartTime(final IXmlStateSystemContainer container, final String stateName, final TmfXmlScenarioInfo info, final ITmfEvent event) {
+        long ts = event.getTimestamp().getValue();
+        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
+        try {
+            int attributeQuark = getQuarkRelativeAndAdd(ss, info.getQuark(), TmfXmlStrings.STATE, stateName, START_TIME);
+            ITmfStateInterval state = ss.querySingleState(ts, attributeQuark);
+            return state.getStartTime();
+        } catch (AttributeNotFoundException | StateSystemDisposedException e) {
+            Activator.logError("failed the start time of the state " + stateName, e); //$NON-NLS-1$
+        }
+        return -1l;
+    }
+
+    /**
+     * Basic quark-retrieving method. Pass an attribute in parameter as an array
+     * of strings, the matching quark will be returned. If the attribute does
+     * not exist, it will add the quark to the state system if the context
+     * allows it.
+     *
+     * See {@link ITmfStateSystemBuilder#getQuarkAbsoluteAndAdd(String...)}
+     *
+     * @param ss
+     *            The state system the attribute belongs to
+     * @param path
+     *            Full path to the attribute
+     * @return The quark for this attribute
+     */
+    private static int getQuarkAbsoluteAndAdd(@Nullable ITmfStateSystemBuilder ss, String... path) {
+        if (ss == null) {
+            throw new NullPointerException(ERROR_MESSAGE);
+        }
+        return ss.getQuarkAbsoluteAndAdd(path);
+    }
+
+    /**
+     * Quark-retrieving method, but the attribute is queried starting from the
+     * startNodeQuark. If the attribute does not exist, it will add it to the
+     * state system if the context allows it.
+     *
+     * See {@link ITmfStateSystemBuilder#getQuarkRelativeAndAdd(int, String...)}
+     *
+     ** @param ss
+     *            The state system the attribute belongs to
+     * @param startNodeQuark
+     *            The quark of the attribute from which 'path' originates.
+     * @param path
+     *            Relative path to the attribute
+     * @return The quark for this attribute
+     */
+    private static int getQuarkRelativeAndAdd(@Nullable ITmfStateSystemBuilder ss, int startNodeQuark, String... path) {
+        if (ss == null) {
+            throw new NullPointerException(ERROR_MESSAGE);
+        }
+        return ss.getQuarkRelativeAndAdd(startNodeQuark, path);
+    }
+
+    /**
+     * Update the scenario internal data
+     *
+     * @param container
+     *            The state system container this class use
+     * @param info
+     *            The scenario details
+     * @param event
+     *            The current event
+     */
+    public void update(final IXmlStateSystemContainer container, final TmfXmlScenarioInfo info, final @Nullable ITmfEvent event) {
+        updateScenarioSpecificStateStartTime(event, container, info);
+        updateScenarioState(event, container, info);
+        updateScenarioStatus(event, container, info);
+    }
+
+    private static void updateScenarioStatus(@Nullable ITmfEvent event, IXmlStateSystemContainer container, final TmfXmlScenarioInfo info) {
+        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
+        long ts = getTimestamp(event, ss);
+        ITmfStateValue value;
+        try {
+            // save the status
+            switch (info.getStatus()) {
+            case IN_PROGRESS:
+                value = STATUS_MAP.get(ScenarioStatusType.IN_PROGRESS);
+                break;
+            case ABANDONED:
+                value = STATUS_MAP.get(ScenarioStatusType.ABANDONED);
+                break;
+            case MATCHED:
+                value = STATUS_MAP.get(ScenarioStatusType.MATCHED);
+                break;
+            case PENDING:
+                value = STATUS_MAP.get(ScenarioStatusType.PENDING);
+                break;
+            default:
+                value = TmfStateValue.nullValue();
+                break;
+            }
+            ss.modifyAttribute(ts, value, info.getStatusQuark());
+        } catch (StateValueTypeException | AttributeNotFoundException e) {
+            Activator.logError("failed to update scenario status"); //$NON-NLS-1$
+        }
+    }
+
+    private static long getTimestamp(@Nullable ITmfEvent event, @Nullable ITmfStateSystemBuilder ss) {
+        if (event != null) {
+            return event.getTimestamp().toNanos();
+        }
+        if (ss != null) {
+            return ss.getCurrentEndTime();
+        }
+        throw new IllegalArgumentException("Event and state system cannot be null at the same time."); //$NON-NLS-1$
+    }
+
+    private static void updateScenarioState(final @Nullable ITmfEvent event, final IXmlStateSystemContainer container, final TmfXmlScenarioInfo info) {
+        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
+        long ts = getTimestamp(event, ss);
+        try {
+            // save the status
+            ITmfStateValue value = TmfStateValue.newValueString(info.getActiveState());
+            int attributeQuark = ss.getQuarkRelativeAndAdd(info.getQuark(), TmfXmlStrings.STATE);
+            ss.modifyAttribute(ts, value, attributeQuark);
+        } catch (StateValueTypeException | AttributeNotFoundException e) {
+            Activator.logError("failed to update scenario state"); //$NON-NLS-1$
+        }
+    }
+
+    /**
+     * Update the start time of specified state
+     *
+     * @param event
+     *            The current event
+     * @param container
+     *            The state system container this class use
+     * @param info
+     *            The scenario details
+     */
+    private static void updateScenarioSpecificStateStartTime(final @Nullable ITmfEvent event, final IXmlStateSystemContainer container, final TmfXmlScenarioInfo info) {
+        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
+        long ts = getTimestamp(event, ss);
+        try {
+            int stateQuark = ss.getQuarkRelativeAndAdd(info.getQuark(), TmfXmlStrings.STATE);
+            String activeState = ss.queryOngoingState(stateQuark).unboxStr();
+            if (activeState.compareTo(info.getActiveState()) != 0) {
+                int attributeQuark = ss.getQuarkRelativeAndAdd(stateQuark, info.getActiveState(), START_TIME);
+                ITmfStateValue value = TmfStateValue.newValueLong(ts);
+                ss.modifyAttribute(ts, value, attributeQuark);
+            }
+        } catch (StateValueTypeException | AttributeNotFoundException e) {
+            Activator.logError("failed to update the start time of the state"); //$NON-NLS-1$
+        }
+    }
+
+    /**
+     * Start the scenario, sets the start time for the time of the event
+     *
+     * @param container
+     *            The state system container this class use
+     * @param info
+     *            The scenario details. The value should be null if there is no
+     *            scenario
+     * @param event
+     *            The active event
+     */
+    public void startScenario(final IXmlStateSystemContainer container, final TmfXmlScenarioInfo info, final ITmfEvent event) {
+        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
+        long ts = getTimestamp(event, ss);
+        try {
+            // save the status
+            ITmfStateValue value = TmfStateValue.newValueLong(ts);
+            int attributeQuark = ss.getQuarkRelativeAndAdd(info.getQuark(), START_TIME);
+            ss.modifyAttribute(ts, value, attributeQuark);
+        } catch (StateValueTypeException | AttributeNotFoundException e) {
+            Activator.logError("failed to update the start time of the scenario"); //$NON-NLS-1$
+        }
+    }
+
+    /**
+     * Set the end time of the scenario to the time of the event, or current
+     * state system end time if null, and recycle the attribute quark
+     *
+     * @param container
+     *            The state system container this class use
+     * @param info
+     *            The scenario details. The value should be null if there is no
+     *            scenario
+     * @param event
+     *            The active event
+     */
+    public void completeScenario(final IXmlStateSystemContainer container, final TmfXmlScenarioInfo info, final @Nullable ITmfEvent event) {
+        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
+        long ts = getTimestamp(event, ss);
+        TmfAttributePool pool = getPoolFor(container, info.getFsmId());
+        pool.recycle(info.getQuark(), ts);
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlScenarioInfo.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlScenarioInfo.java
new file mode 100644 (file)
index 0000000..6f6b8fa
--- /dev/null
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ ******************************************************************************/
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlScenarioHistoryBuilder.ScenarioStatusType;
+
+/**
+ * This class gives basic details about a scenario (quark, scenarioName, ...)
+ *
+ * @author Jean-Christian Kouame
+ */
+public class TmfXmlScenarioInfo {
+
+    private final int fQuark;
+    private final TmfXmlFsm fFsm;
+    private final int fStatusQuark;
+    private String fActiveState;
+    private ScenarioStatusType fStatus;
+
+    /**
+     * Constructor
+     *
+     * @param activeState
+     *            The active state
+     * @param status
+     *            The scenario status
+     * @param quark
+     *            The scenario quark
+     * @param statusQuark
+     *            The scenario status quark
+     * @param fsm
+     *            The FSM this scenario is part of
+     */
+    public TmfXmlScenarioInfo(String activeState, ScenarioStatusType status, int quark, int statusQuark, TmfXmlFsm fsm) {
+        fActiveState = activeState;
+        fQuark = quark;
+        fStatus = status;
+        fStatusQuark = statusQuark;
+        fFsm = fsm;
+    }
+
+    /**
+     * Set the active state
+     *
+     * @param activeState
+     *            The active state
+     */
+    public void setActiveState(String activeState) {
+        fActiveState = activeState;
+    }
+
+    /**
+     * Set the status of this active scenario
+     *
+     * @param status
+     *            The scenario status
+     */
+    public void setStatus(ScenarioStatusType status) {
+        fStatus = status;
+    }
+
+    /**
+     * Get the scenario quark
+     *
+     * @return The quark
+     */
+    public int getQuark() {
+        return fQuark;
+    }
+
+    /**
+     * Get the scenario active state
+     *
+     * @return The active state
+     */
+    public String getActiveState() {
+        return fActiveState;
+    }
+
+    /**
+     * Get the active scenario status
+     *
+     * @return The status
+     */
+    public ScenarioStatusType getStatus() {
+        return fStatus;
+    }
+
+    /**
+     * Get the scenario status quark
+     *
+     * @return The quark
+     */
+    public int getStatusQuark() {
+        return fStatusQuark;
+    }
+
+    /**
+     * Get the ID of the FSM this scenario is part of
+     *
+     * @return The ID of the FSM
+     */
+    public String getFsmId() {
+        return fFsm.getId();
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlState.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlState.java
new file mode 100644 (file)
index 0000000..12807b4
--- /dev/null
@@ -0,0 +1,293 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ ******************************************************************************/
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * This class implements a state tree described in XML-defined pattern
+ *
+ * @author Jean-Christian Kouame
+ */
+public class TmfXmlState {
+
+    private final String fId;
+    private final IXmlStateSystemContainer fContainer;
+    private final List<TmfXmlStateTransition> fTransitions;
+    private @Nullable TmfXmlState fparent;
+    private List<String> fOnEntryActions;
+    private List<String> fOnExitActions;
+    //TODO Sub-state are not yet supported.
+    private Map<String, TmfXmlState> fChildren;
+    private @Nullable TmfXmlStateTransition fInitialTransition;
+    private @Nullable String fInitialStateId;
+    private @Nullable String fFinalStateId;
+    private Type fType;
+
+    /**
+     * Enum for the type of state
+     */
+    public enum Type {
+        /**
+         * Final state type
+         */
+        FINAL,
+        /**
+         * Initial state type
+         */
+        INITIAL,
+        /**
+         * Fail state type, the pattern has failed to match
+         */
+        FAIL,
+        /**
+         * This is the normal state type, for states that are not the first,
+         * final or failing state
+         */
+        DEFAULT
+    }
+
+    private TmfXmlState(IXmlStateSystemContainer container, Type type, String id, @Nullable TmfXmlState parent, List<@NonNull TmfXmlStateTransition> transitions, Map<@NonNull String, @NonNull TmfXmlState> children, List<String> onentryActions, List<String> onexitActions) {
+        fContainer = container;
+        fType = type;
+        fId = id;
+        fparent = parent;
+        fTransitions = transitions;
+        fChildren = children;
+        fOnEntryActions = onentryActions;
+        fOnExitActions = onexitActions;
+    }
+
+    /**
+     * Constructor
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param node
+     *            The XML root of this state
+     * @param container
+     *            The state system container this state definition belongs to
+     * @param parent
+     *            The parent state of this state
+     * @return The new {@link TmfXmlState}
+     */
+    public static TmfXmlState create(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container, @Nullable TmfXmlState parent) {
+        Type type = getStateType(node);
+        String id = node.getAttribute(TmfXmlStrings.ID);
+        List<TmfXmlStateTransition> transitions = getTransitions(modelFactory, container, node);
+
+        NodeList nodesOnentry = node.getElementsByTagName(TmfXmlStrings.ONENTRY);
+        List<String> onentryActions = nodesOnentry.getLength() > 0 ? Arrays.asList(((Element) nodesOnentry.item(0)).getAttribute(TmfXmlStrings.ACTION).split(TmfXmlStrings.AND_SEPARATOR)) : Collections.EMPTY_LIST;
+
+        NodeList nodesOnexit = node.getElementsByTagName(TmfXmlStrings.ONEXIT);
+        List<String> onexitActions = nodesOnexit.getLength() > 0 ? Arrays.asList(((Element) nodesOnexit.item(0)).getAttribute(TmfXmlStrings.ACTION).split(TmfXmlStrings.AND_SEPARATOR)) : Collections.EMPTY_LIST;
+
+        TmfXmlState state = new TmfXmlState(container, type, id, parent, transitions, new HashMap<>(), onentryActions, onexitActions);
+        initState(state, modelFactory, container, node);
+
+        return state;
+    }
+
+    private static void getFinalState(TmfXmlState parentState, ITmfXmlModelFactory modelFactory, IXmlStateSystemContainer container, Element node) {
+        NodeList nodesFinal = node.getElementsByTagName(TmfXmlStrings.FINAL);
+        String finalStateId = null;
+        if (nodesFinal.getLength() > 0) {
+            final Element finalElement = NonNullUtils.checkNotNull((Element) nodesFinal.item(0));
+            finalStateId = nodesFinal.getLength() > 0 ? finalElement.getAttribute(TmfXmlStrings.ID) : null;
+            TmfXmlState finalState = modelFactory.createState(finalElement, container, parentState);
+            parentState.getChildren().put(finalState.getId(), finalState);
+        }
+        parentState.fFinalStateId = finalStateId;
+    }
+
+    private static void getSubStates(TmfXmlState parentState, ITmfXmlModelFactory modelFactory, IXmlStateSystemContainer container, Element node) {
+        String initial = node.getAttribute(TmfXmlStrings.INITIAL);
+        TmfXmlStateTransition initialTransition = null;
+        if (initial.isEmpty()) {
+            NodeList nodesInitial = node.getElementsByTagName(TmfXmlStrings.INITIAL);
+            if (nodesInitial.getLength() == 1) {
+                final @NonNull Element transitionElement = NonNullUtils.checkNotNull((Element) ((Element) nodesInitial.item(0)).getElementsByTagName(TmfXmlStrings.TRANSITION).item(0));
+                initialTransition = modelFactory.createStateTransition(transitionElement, container);
+                initial = initialTransition.getTarget();
+            }
+        }
+
+        NodeList nodesState = node.getElementsByTagName(TmfXmlStrings.STATE);
+        for (int i = 0; i < nodesState.getLength(); i++) {
+            TmfXmlState child = modelFactory.createState(NonNullUtils.checkNotNull((Element) nodesState.item(i)), container, parentState);
+            parentState.getChildren().put(child.getId(), child);
+
+            if (i == 0 && initial.isEmpty()) {
+                initial = child.getId();
+            }
+        }
+        parentState.fInitialStateId = initial.isEmpty() ? null : initial;
+        parentState.fInitialTransition = initialTransition;
+    }
+
+    private static void initState(TmfXmlState state, ITmfXmlModelFactory modelFactory, IXmlStateSystemContainer container, Element node) {
+        getSubStates(state, modelFactory, container, node);
+        getFinalState(state, modelFactory, container, node);
+    }
+
+    /**
+     * Get the List of transitions for this state
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param node
+     *            The XML root of this state definition
+     * @return The list of transitions
+     */
+    private static List<@NonNull TmfXmlStateTransition> getTransitions(ITmfXmlModelFactory modelFactory, IXmlStateSystemContainer container, Element node) {
+        List<@NonNull TmfXmlStateTransition> transitions = new ArrayList<>();
+        NodeList nodesTransition = node.getElementsByTagName(TmfXmlStrings.TRANSITION);
+        for (int i = 0; i < nodesTransition.getLength(); i++) {
+            final Element element = (Element) nodesTransition.item(i);
+            if (element == null) {
+                throw new IllegalArgumentException();
+            }
+            TmfXmlStateTransition transition = modelFactory.createStateTransition(element, container);
+            transitions.add(transition);
+        }
+        return transitions;
+    }
+
+    /**
+     * Get the state type from its XML definition
+     * @param node
+     *            The XML definition of the state
+     * @return The state type
+     */
+    private static Type getStateType(Element node) {
+        switch (node.getNodeName()) {
+        case TmfXmlStrings.FINAL:
+            return Type.FINAL;
+        case TmfXmlStrings.INITIAL:
+            return Type.INITIAL;
+        case TmfXmlStrings.ABANDON:
+            return Type.FAIL;
+        case TmfXmlStrings.STATE:
+        default:
+            return Type.DEFAULT;
+        }
+    }
+
+    /**
+     * Get the state id
+     *
+     * @return The state id
+     */
+    public String getId() {
+        return fId;
+    }
+
+    /**
+     * Get the container
+     *
+     * @return The container
+     */
+    public IXmlStateSystemContainer getContainer() {
+        return fContainer;
+    }
+
+    /**
+     * The list of transitions of this state
+     *
+     * @return The list of transitions
+     */
+    public List<TmfXmlStateTransition> getTransitionList() {
+        return fTransitions;
+    }
+
+    /**
+     * Get the actions to execute when entering this state, in an array
+     *
+     * @return The array of actions
+     */
+    public List<String> getOnEntryActions() {
+        return fOnEntryActions;
+    }
+
+    /**
+     * Get the actions to execute when leaving this state, in an array
+     *
+     * @return The array of actions
+     */
+    public List<String> getOnExitActions() {
+        return fOnExitActions;
+    }
+
+    /**
+     * Get children states of this state into a map
+     *
+     * @return The map of children state
+     */
+    public Map<String, TmfXmlState> getChildren() {
+        return fChildren;
+    }
+
+    /**
+     * Get the initial transition of this state
+     *
+     * @return The initial transition
+     */
+    public @Nullable TmfXmlStateTransition getInitialTransition() {
+        return fInitialTransition;
+    }
+
+    /**
+     * Get the initial state ID
+     *
+     * @return The initial state ID
+     */
+    public @Nullable String getInitialStateId() {
+        return fInitialStateId;
+    }
+
+    /**
+     * Get the final state ID
+     *
+     * @return The final state ID
+     */
+    public @Nullable String getFinalStateId() {
+        return fFinalStateId;
+    }
+
+    /**
+     * Get the parent state
+     *
+     * @return The parent state
+     */
+    public @Nullable TmfXmlState getParent() {
+        return fparent;
+    }
+
+    /**
+     * Get the type of this state
+     *
+     * @return The type of the state
+     */
+    public Type getType() {
+        return fType;
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateAttribute.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateAttribute.java
new file mode 100644 (file)
index 0000000..cbe56f6
--- /dev/null
@@ -0,0 +1,348 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2015 Ecole Polytechnique de Montreal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Florian Wininger - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.Nullable;
+import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString;
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
+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.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
+import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
+import org.w3c.dom.Element;
+
+/**
+ * This Class implements a single attribute value in the XML-defined state
+ * system.
+ *
+ * <pre>
+ * Examples:
+ * <stateAttribute type="constant" value="Threads" />
+ * <stateAttribute type="query" />
+ *      <stateAttribute type="constant" value="CPUs" />
+ *      <stateAttribute type="eventField" value="cpu" />
+ *      <stateAttribute type="constant" value="Current_thread" />
+ * </attribute>
+ * </pre>
+ *
+ * @author Florian Wininger
+ */
+public abstract class TmfXmlStateAttribute implements ITmfXmlStateAttribute {
+
+    private enum StateAttributeType {
+        NONE,
+        CONSTANT,
+        EVENTFIELD,
+        QUERY,
+        LOCATION,
+        SELF,
+        EVENTNAME
+    }
+
+    private final String CURRENT_STATE = "#currentState"; //$NON-NLS-1$
+
+    private final String CURRENT_SCENARIO = "#CurrentScenario"; //$NON-NLS-1$
+
+    /** Type of attribute */
+    private final StateAttributeType fType;
+
+    /** Attribute's name */
+    private final @Nullable String fName;
+
+    /** List of attributes for a query */
+    private final List<ITmfXmlStateAttribute> fQueryList = new LinkedList<>();
+
+    private final IXmlStateSystemContainer fContainer;
+
+    /**
+     * Constructor
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param attribute
+     *            XML element of the attribute
+     * @param container
+     *            The state system container this state attribute belongs to
+     */
+    protected TmfXmlStateAttribute(ITmfXmlModelFactory modelFactory, Element attribute, IXmlStateSystemContainer container) {
+        fContainer = container;
+
+        switch (attribute.getAttribute(TmfXmlStrings.TYPE)) {
+        case TmfXmlStrings.TYPE_CONSTANT:
+            fType = StateAttributeType.CONSTANT;
+            fName = getAttributeName(attribute);
+            break;
+        case TmfXmlStrings.EVENT_FIELD:
+            fType = StateAttributeType.EVENTFIELD;
+            fName = getAttributeName(attribute);
+            break;
+        case TmfXmlStrings.TYPE_LOCATION:
+            fType = StateAttributeType.LOCATION;
+            fName = getAttributeName(attribute);
+            break;
+        case TmfXmlStrings.TYPE_QUERY:
+            List<@Nullable Element> childElements = XmlUtils.getChildElements(attribute);
+            for (Element subAttributeNode : childElements) {
+                if (subAttributeNode == null) {
+                    continue;
+                }
+                ITmfXmlStateAttribute subAttribute = modelFactory.createStateAttribute(subAttributeNode, fContainer);
+                fQueryList.add(subAttribute);
+            }
+            fType = StateAttributeType.QUERY;
+            fName = null;
+            break;
+        case TmfXmlStrings.TYPE_EVENT_NAME:
+            fType = StateAttributeType.EVENTNAME;
+            fName = getAttributeName(attribute);
+            break;
+        case TmfXmlStrings.NULL:
+            fType = StateAttributeType.NONE;
+            fName = null;
+            break;
+        case TmfXmlStrings.TYPE_SELF:
+            fType = StateAttributeType.SELF;
+            fName = null;
+            break;
+        default:
+            throw new IllegalArgumentException("TmfXmlStateAttribute constructor: The XML element is not of the right type"); //$NON-NLS-1$
+        }
+    }
+
+    private String getAttributeName(Element attribute) {
+        return fContainer.getAttributeValue(attribute.getAttribute(TmfXmlStrings.VALUE)).intern();
+    }
+
+    @Override
+    public int getAttributeQuark(int startQuark, @Nullable TmfXmlScenarioInfo scenarioInfo) {
+        return getAttributeQuark(null, startQuark, scenarioInfo);
+    }
+
+    /**
+     * Basic quark-retrieving method. Pass an attribute in parameter as an array
+     * of strings, the matching quark will be returned. If the attribute does
+     * not exist, it will add the quark to the state system if the context
+     * allows it.
+     *
+     * See {@link ITmfStateSystemBuilder#getQuarkAbsoluteAndAdd(String...)}
+     *
+     * @param path
+     *            Full path to the attribute
+     * @return The quark for this attribute
+     * @throws AttributeNotFoundException
+     *             The attribute does not exist and cannot be added
+     */
+    protected abstract int getQuarkAbsoluteAndAdd(String... path) throws AttributeNotFoundException;
+
+    /**
+     * Quark-retrieving method, but the attribute is queried starting from the
+     * startNodeQuark. If the attribute does not exist, it will add it to the
+     * state system if the context allows it.
+     *
+     * See {@link ITmfStateSystemBuilder#getQuarkRelativeAndAdd(int, String...)}
+     *
+     * @param startNodeQuark
+     *            The quark of the attribute from which 'path' originates.
+     * @param path
+     *            Relative path to the attribute
+     * @return The quark for this attribute
+     * @throws AttributeNotFoundException
+     *             The attribute does not exist and cannot be added
+     */
+    protected abstract int getQuarkRelativeAndAdd(int startNodeQuark, String... path) throws AttributeNotFoundException;
+
+    /**
+     * Get the state system associated with this attribute's container
+     *
+     * @return The state system associated with this state attribute
+     */
+    protected @Nullable ITmfStateSystem getStateSystem() {
+        return fContainer.getStateSystem();
+    }
+
+    @Override
+    public int getAttributeQuark(@Nullable ITmfEvent event, int startQuark, @Nullable TmfXmlScenarioInfo scenarioInfo) {
+        ITmfStateSystem ss = getStateSystem();
+        if (ss == null) {
+            throw new IllegalStateException("The state system hasn't been initialized yet"); //$NON-NLS-1$
+        }
+        String name = nullToEmptyString(fName);
+        if (name.length() > 0 && name.charAt(0) == '#' && scenarioInfo == null) {
+            throw new IllegalStateException("XML Attribute needs " + fName + " but the data is not available.");  //$NON-NLS-1$//$NON-NLS-2$
+        }
+        name = name.equals(CURRENT_STATE) ? checkNotNull(scenarioInfo).getActiveState()
+                        : fName;
+
+        try {
+            switch (fType) {
+            case CONSTANT: {
+                int quark;
+                if (name == null) {
+                    throw new IllegalStateException("Invalid attribute name"); //$NON-NLS-1$
+                }
+                if (name.equals(CURRENT_SCENARIO)) {
+                    return checkNotNull(scenarioInfo).getQuark();
+                }
+                if (startQuark == IXmlStateSystemContainer.ROOT_QUARK) {
+                    quark = getQuarkAbsoluteAndAdd(name);
+                } else {
+                    quark = getQuarkRelativeAndAdd(startQuark, name);
+                }
+                return quark;
+            }
+            case EVENTFIELD: {
+                int quark = IXmlStateSystemContainer.ERROR_QUARK;
+                if (event == null) {
+                    Activator.logWarning("XML State attribute: looking for an event field, but event is null"); //$NON-NLS-1$
+                    return quark;
+                }
+                if (name == null) {
+                    throw new IllegalStateException("Invalid attribute name"); //$NON-NLS-1$
+                }
+                if (name.equals(TmfXmlStrings.CPU)) {
+                    /* See if the event advertises a CPU aspect */
+                    Integer cpu = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(
+                            event.getTrace(), TmfCpuAspect.class, event);
+                    if (cpu != null) {
+                        quark = getQuarkRelativeAndAdd(startQuark, cpu.toString());
+                    }
+                } else {
+                    final ITmfEventField content = event.getContent();
+                    /* stop if the event field doesn't exist */
+                    if (content.getField(name) == null) {
+                        return IXmlStateSystemContainer.ERROR_QUARK;
+                    }
+
+                    Object field = content.getField(name).getValue();
+
+                    if (field instanceof String) {
+                        String fieldString = (String) field;
+                        quark = getQuarkRelativeAndAdd(startQuark, fieldString);
+                    } else if (field instanceof Long) {
+                        Long fieldLong = (Long) field;
+                        quark = getQuarkRelativeAndAdd(startQuark, fieldLong.toString());
+                    } else if (field instanceof Integer) {
+                        Integer fieldInterger = (Integer) field;
+                        quark = getQuarkRelativeAndAdd(startQuark, fieldInterger.toString());
+                    }
+                }
+                return quark;
+            }
+            case QUERY: {
+                int quark;
+                ITmfStateValue value = TmfStateValue.nullValue();
+                int quarkQuery = IXmlStateSystemContainer.ROOT_QUARK;
+
+                for (ITmfXmlStateAttribute attrib : fQueryList) {
+                    quarkQuery = attrib.getAttributeQuark(event, quarkQuery, scenarioInfo);
+                    if (quarkQuery == IXmlStateSystemContainer.ERROR_QUARK) {
+                        break;
+                    }
+                }
+
+                // the query may fail: for example CurrentThread if there
+                // has not been a sched_switch event
+                if (quarkQuery != IXmlStateSystemContainer.ERROR_QUARK) {
+                    value = ss.queryOngoingState(quarkQuery);
+                }
+
+                switch (value.getType()) {
+                case INTEGER: {
+                    int result = value.unboxInt();
+                    quark = getQuarkRelativeAndAdd(startQuark, String.valueOf(result));
+                    break;
+                }
+                case LONG: {
+                    long result = value.unboxLong();
+                    quark = getQuarkRelativeAndAdd(startQuark, String.valueOf(result));
+                    break;
+                }
+                case STRING: {
+                    String result = value.unboxStr();
+                    quark = getQuarkRelativeAndAdd(startQuark, result);
+                    break;
+                }
+                case DOUBLE:
+                case NULL:
+                default:
+                    quark = IXmlStateSystemContainer.ERROR_QUARK; // error
+                    break;
+                }
+                return quark;
+            }
+            case LOCATION: {
+                int quark = startQuark;
+                String idLocation = name;
+
+                /* TODO: Add a fContainer.getLocation(id) method */
+                for (TmfXmlLocation location : fContainer.getLocations()) {
+                    if (location.getId().equals(idLocation)) {
+                        quark = location.getLocationQuark(event, quark, scenarioInfo);
+                        if (quark == IXmlStateSystemContainer.ERROR_QUARK) {
+                            break;
+                        }
+                    }
+                }
+                return quark;
+            }
+            case EVENTNAME: {
+                int quark = IXmlStateSystemContainer.ERROR_QUARK;
+                if (event == null) {
+                    Activator.logWarning("XML State attribute: looking for an eventname, but event is null"); //$NON-NLS-1$
+                    return quark;
+                }
+                quark = getQuarkRelativeAndAdd(startQuark, event.getName());
+                return quark;
+            }
+            case SELF:
+                return startQuark;
+            case NONE:
+            default:
+                return startQuark;
+            }
+        } catch (AttributeNotFoundException ae) {
+            /*
+             * This can be happen before the creation of the node for a query in
+             * the state system. Example : current thread before a sched_switch
+             */
+            return IXmlStateSystemContainer.ERROR_QUARK;
+        } catch (StateValueTypeException e) {
+            /*
+             * This would happen if we were trying to push/pop attributes not of
+             * type integer. Which, once again, should never happen.
+             */
+            Activator.logError("StateValueTypeException", e); //$NON-NLS-1$
+            return IXmlStateSystemContainer.ERROR_QUARK;
+        }
+    }
+
+    @Override
+    public String toString() {
+        return "TmfXmlStateAttribute " + fType + ": " + fName; //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateChange.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateChange.java
new file mode 100644 (file)
index 0000000..df4a08c
--- /dev/null
@@ -0,0 +1,220 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ecole Polytechnique de Montreal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Florian Wininger - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * This Class implement a State Change in the XML-defined state system
+ *
+ * <pre>
+ *  example 1: Simple state change
+ *  <stateChange>
+ *      <stateAttribute type="location" value="CurrentThread" />
+ *      <stateAttribute type="constant" value="System_call" />
+ *      <stateValue type="null" />
+ *  </stateChange>
+ *
+ *  example 2: Conditional state change
+ *  <stateChange>
+ *     <if>
+ *      <condition>
+ *        <stateAttribute type="location" value="CurrentThread" />
+ *        <stateAttribute type="constant" value="System_call" />
+ *        <stateValue type="null" />
+ *      </condition>
+ *     </if>
+ *    <then>
+ *      <stateAttribute type="location" value="CurrentThread" />
+ *      <stateAttribute type="constant" value="Status" />
+ *      <stateValue int="$PROCESS_STATUS_RUN_USERMODE"/>
+ *    </then>
+ *    <else>
+ *      <stateAttribute type="location" value="CurrentThread" />
+ *      <stateAttribute type="constant" value="Status" />
+ *      <stateValue int="$PROCESS_STATUS_RUN_SYSCALL"/>
+ *    </else>
+ *  </stateChange>
+ * </pre>
+ *
+ * @author Florian Wininger
+ */
+public class TmfXmlStateChange {
+
+    private final IXmlStateChange fChange;
+    private final IXmlStateSystemContainer fContainer;
+
+    /**
+     * Constructor
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param statechange
+     *            XML node root of this state change
+     * @param container
+     *            The state system container this state change belongs to
+     */
+    public TmfXmlStateChange(ITmfXmlModelFactory modelFactory, Element statechange, IXmlStateSystemContainer container) {
+        fContainer = container;
+
+        /*
+         * child nodes is either a list of TmfXmlStateAttributes and
+         * TmfXmlStateValues, or an if-then-else series of nodes.
+         */
+        Node ifNode = statechange.getElementsByTagName(TmfXmlStrings.IF).item(0);
+        if (ifNode != null) {
+            /* the state change has a condition */
+            fChange = new XmlConditionalChange(modelFactory, statechange);
+        } else {
+            /* the state change does not have a condition */
+            fChange = new XmlStateValueChange(modelFactory, statechange);
+        }
+    }
+
+    /**
+     * Execute the state change for an event. If necessary, it validates the
+     * condition and executes the required change.
+     *
+     * @param event
+     *            The event to process
+     * @param scenarioInfo
+     *            The active scenario details. The value should be null if there
+     *            no scenario.
+     * @throws AttributeNotFoundException
+     *             Pass through the exception it received
+     * @throws TimeRangeException
+     *             Pass through the exception it received
+     * @throws StateValueTypeException
+     *             Pass through the exception it received
+     */
+    public void handleEvent(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException {
+        fChange.handleEvent(event, scenarioInfo);
+    }
+
+    @Override
+    public String toString() {
+        return "TmfXmlStateChange: " + fChange; //$NON-NLS-1$
+    }
+
+    /* Interface for both private classes to handle the event */
+    private interface IXmlStateChange {
+        void handleEvent(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException;
+    }
+
+    /**
+     * Conditional state change with a condition to verify
+     */
+    private class XmlConditionalChange implements IXmlStateChange {
+        private final ITmfXmlCondition fCondition;
+        private final TmfXmlStateChange fThenChange;
+        private final @Nullable TmfXmlStateChange fElseChange;
+
+        public XmlConditionalChange(ITmfXmlModelFactory modelFactory, Element statechange) {
+            /*
+             * The if node exists, it has been verified before calling this
+             */
+            Node ifNode = statechange.getElementsByTagName(TmfXmlStrings.IF).item(0);
+            if (ifNode == null) {
+                throw new IllegalArgumentException();
+            }
+            fCondition = modelFactory.createCondition((Element) ifNode, fContainer);
+
+            Node thenNode = statechange.getElementsByTagName(TmfXmlStrings.THEN).item(0);
+            if (thenNode == null) {
+                throw new IllegalArgumentException("Conditional state change: there should be a then clause."); //$NON-NLS-1$
+            }
+            fThenChange = modelFactory.createStateChange((Element) thenNode, fContainer);
+
+            Node elseNode = statechange.getElementsByTagName(TmfXmlStrings.ELSE).item(0);
+            if (elseNode != null) {
+                fElseChange = modelFactory.createStateChange((Element) elseNode, fContainer);
+            } else {
+                fElseChange = null;
+            }
+        }
+
+        @Override
+        public void handleEvent(@NonNull ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException {
+            TmfXmlStateChange toExecute = fThenChange;
+            if (!fCondition.test(event, scenarioInfo)) {
+                toExecute = fElseChange;
+            }
+
+            if (toExecute == null) {
+                return;
+            }
+            toExecute.handleEvent(event, scenarioInfo);
+        }
+
+        @Override
+        public String toString() {
+            return "Condition: " + fCondition; //$NON-NLS-1$
+        }
+    }
+
+    /**
+     * State change with no condition
+     */
+    private class XmlStateValueChange implements IXmlStateChange {
+        private final ITmfXmlStateValue fValue;
+
+        public XmlStateValueChange(ITmfXmlModelFactory modelFactory, Element statechange) {
+            List<@Nullable Element> childElements = XmlUtils.getChildElements(statechange);
+
+            /*
+             * Last child element is the state value, the others are attributes
+             * to reach to value to set
+             */
+            Element stateValueElement = childElements.remove(childElements.size() - 1);
+            if (stateValueElement == null) {
+                throw new IllegalStateException();
+            }
+            List<ITmfXmlStateAttribute> attributes = new ArrayList<>();
+            for (Element element : childElements) {
+                if (element == null || !element.getNodeName().equals(TmfXmlStrings.STATE_ATTRIBUTE)) {
+                    throw new IllegalArgumentException("TmfXmlStateChange: a state change must have only TmfXmlStateAttribute elements before the state value"); //$NON-NLS-1$
+                }
+                ITmfXmlStateAttribute attribute = modelFactory.createStateAttribute(element, fContainer);
+                attributes.add(attribute);
+            }
+            if (attributes.isEmpty()) {
+                throw new IllegalArgumentException("TmfXmlStateChange: a state change must have at least one TmfXmlStateAttribute element before the state value"); //$NON-NLS-1$
+            }
+            fValue = modelFactory.createStateValue(stateValueElement, fContainer, attributes);
+        }
+
+        @Override
+        public void handleEvent(@NonNull ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException {
+            fValue.handleEvent(event, scenarioInfo);
+        }
+
+        @Override
+        public String toString() {
+            return "Value: " + fValue; //$NON-NLS-1$
+        }
+    }
+
+}
\ No newline at end of file
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateTransition.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateTransition.java
new file mode 100644 (file)
index 0000000..d458f3a
--- /dev/null
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ ******************************************************************************/
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.w3c.dom.Element;
+
+/**
+ * This Class implements a state transition tree in the XML-defined state
+ * system.
+ *
+ * @author Jean-Christian Kouame
+ */
+public class TmfXmlStateTransition extends TmfXmlBasicTransition {
+
+    private static final String SAVED_STORED_FIELDS_ACTION_STRING = TmfXmlStrings.CONSTANT_PREFIX + ITmfXmlAction.SAVE_STORED_FIELDS_STRING;
+    private static final String CLEAR_STORED_FIELDS_ACTION_STRINGS = TmfXmlStrings.CONSTANT_PREFIX + ITmfXmlAction.CLEAR_STORED_FIELDS_STRING;
+
+    private final String fTarget;
+    private final List<String> fAction;
+    private final boolean fStoredFieldsToBeSaved;
+    private final boolean fStoredFieldsToBeCleared;
+
+    /**
+     * Constructor
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param node
+     *            The XML root of this state transition
+     * @param container
+     *            The state system container this state transition belongs to
+     */
+    public TmfXmlStateTransition(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container) {
+        super(node);
+        String target = node.getAttribute(TmfXmlStrings.TARGET);
+        if (target.isEmpty()) {
+            throw new IllegalStateException("No target state has been specified."); //$NON-NLS-1$
+        }
+        fTarget = target;
+        String action = node.getAttribute(TmfXmlStrings.ACTION);
+        List<String> actions = action.equals(TmfXmlStrings.NULL) ? Collections.EMPTY_LIST : Arrays.asList(action.split(TmfXmlStrings.AND_SEPARATOR));
+        fStoredFieldsToBeSaved = (node.getAttribute(TmfXmlStrings.SAVE_STORED_FIELDS).equals(TmfXmlStrings.EMPTY_STRING) ? false : Boolean.parseBoolean(node.getAttribute(TmfXmlStrings.SAVE_STORED_FIELDS)));
+        fStoredFieldsToBeCleared = (node.getAttribute(TmfXmlStrings.CLEAR_STORED_FIELDS).equals(TmfXmlStrings.EMPTY_STRING) ? false : Boolean.parseBoolean(node.getAttribute(TmfXmlStrings.CLEAR_STORED_FIELDS)));
+        fAction = new ArrayList<>();
+        if (fStoredFieldsToBeSaved) {
+            fAction.add(SAVED_STORED_FIELDS_ACTION_STRING);
+        }
+        fAction.addAll(actions);
+        if (fStoredFieldsToBeCleared) {
+            fAction.add(CLEAR_STORED_FIELDS_ACTION_STRINGS);
+        }
+    }
+
+    /**
+     * The next state of the state machine this state transition belongs to.
+     *
+     * @return the next state this transition try to reach
+     */
+    public String getTarget() {
+        return fTarget;
+    }
+
+    /**
+     * The action to be executed when the input of this state transition is
+     * validated
+     *
+     * @return the action to execute if the input is validate
+     */
+    public List<String> getAction() {
+        return fAction;
+    }
+
+    /**
+     * Tell if the stored fields have to be saved at this step of the scenario
+     *
+     * @return If the stored fields have to be saved or not
+     */
+    public boolean isStoredFieldsToBeSaved() {
+        return fStoredFieldsToBeSaved;
+    }
+
+    /**
+     * Tell if the stored fields have to be cleared at this moment of this scenario
+     *
+     * @return If the stored fields have to cleared or not
+     */
+    public boolean isStoredFieldsToBeCleared() {
+        return fStoredFieldsToBeCleared;
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateValue.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlStateValue.java
new file mode 100644 (file)
index 0000000..b5d44ca
--- /dev/null
@@ -0,0 +1,503 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2015 Ecole Polytechnique de Montreal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Florian Wininger - Initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
+import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+import org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
+import org.w3c.dom.Element;
+
+/**
+ * This Class implements a State Value in the XML-defined state system, along
+ * with the path to get to the value (either a list of state attributes or an
+ * event field)
+ *
+ * <pre>
+ * Example:
+ *   <stateAttribute type="location" value="CurrentThread" />
+ *   <stateAttribute type="constant" value="System_call" />
+ *   <stateValue type="null" />
+ * </pre>
+ *
+ * @author Florian Wininger
+ */
+public abstract class TmfXmlStateValue implements ITmfXmlStateValue {
+
+    private final TmfXmlStateValueBase fStateValue;
+
+    /* Path in the State System */
+    private final List<ITmfXmlStateAttribute> fPath;
+    /* Event field to match with this state value */
+    private final @Nullable String fEventField;
+
+    /* Whether this state value is an increment of the previous value */
+    private final boolean fIncrement;
+    /* Stack value */
+    private final ValueTypeStack fStackType;
+    /* Forced value type */
+    private final ITmfStateValue.Type fForcedType;
+
+    private final IXmlStateSystemContainer fContainer;
+
+    /**
+     * Different behaviors of an attribute that is to be stacked
+     */
+    protected enum ValueTypeStack {
+        /** Not stacked */
+        NULL,
+        /** Peek at the value at the top of the stack */
+        PEEK,
+        /** Take the value at the top of the stack */
+        POP,
+        /** Push the value on the stack */
+        PUSH;
+
+        /**
+         * Get the type stack value corresponding to a string
+         *
+         * @param input
+         *            The string to match to a value
+         * @return The ValueTypeStack value
+         */
+        public static ValueTypeStack getTypeFromString(String input) {
+            switch (input) {
+            case TmfXmlStrings.STACK_PUSH:
+                return PUSH;
+            case TmfXmlStrings.STACK_POP:
+                return POP;
+            case TmfXmlStrings.STACK_PEEK:
+                return PEEK;
+            default:
+                return NULL;
+            }
+        }
+    }
+
+    /**
+     * Constructor
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param node
+     *            The state value XML element
+     * @param container
+     *            The state system container this state value belongs to
+     * @param eventField
+     *            The event field where to get the value
+     * @param attributes
+     *            The attributes representing the path to this value
+     */
+    protected TmfXmlStateValue(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container, List<ITmfXmlStateAttribute> attributes, @Nullable String eventField) {
+        fPath = attributes;
+        fContainer = container;
+        fEventField = eventField;
+        if (!node.getNodeName().equals(TmfXmlStrings.STATE_VALUE)) {
+            throw new IllegalArgumentException("TmfXmlStateValue constructor: Element is not a stateValue"); //$NON-NLS-1$
+        }
+
+        /* Check if there is an increment for the value */
+        fIncrement = Boolean.parseBoolean(node.getAttribute(TmfXmlStrings.INCREMENT));
+
+        /* Process the XML Element state value */
+        fStateValue = initializeStateValue(modelFactory, node);
+
+        /*
+         * 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
+         */
+        switch (node.getAttribute(TmfXmlStrings.FORCED_TYPE)) {
+        case TmfXmlStrings.TYPE_STRING:
+            fForcedType = ITmfStateValue.Type.STRING;
+            break;
+        case TmfXmlStrings.TYPE_INT:
+            fForcedType = ITmfStateValue.Type.INTEGER;
+            break;
+        case TmfXmlStrings.TYPE_LONG:
+            fForcedType = ITmfStateValue.Type.LONG;
+            break;
+        case TmfXmlStrings.TYPE_DOUBLE:
+            fForcedType = ITmfStateValue.Type.DOUBLE;
+            break;
+        default:
+            fForcedType = ITmfStateValue.Type.NULL;
+        }
+
+        /*
+         * Stack Actions : allow to define a stack with PUSH/POP/PEEK methods
+         */
+        String stack = node.getAttribute(TmfXmlStrings.ATTRIBUTE_STACK);
+        fStackType = ValueTypeStack.getTypeFromString(stack);
+    }
+
+    /**
+     * Initialize a {@link TmfXmlStateValueBase} object for the type and value
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param node
+     *            The state value XML element
+     * @return The internal state value type corresponding to this state value
+     */
+    protected TmfXmlStateValueBase initializeStateValue(ITmfXmlModelFactory modelFactory, Element node) {
+        return new TmfXmlStateValueNull();
+    }
+
+    /**
+     * Return the state system container this class is attached to
+     *
+     * @return The state system container
+     */
+    protected IXmlStateSystemContainer getSsContainer() {
+        return fContainer;
+    }
+
+    /**
+     * Get the state system associated with this value's container
+     *
+     * @return The state system associated with the state system container
+     */
+    protected @Nullable ITmfStateSystem getStateSystem() {
+        return fContainer.getStateSystem();
+    }
+
+    /**
+     * Return whether this value is an increment of the previous value
+     *
+     * @return <code>true</code> if the value is an increment
+     */
+    protected boolean isIncrement() {
+        return fIncrement;
+    }
+
+    /**
+     * 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
+     * implementation of the model.
+     *
+     * @return The stack type of the attribute
+     */
+    protected ValueTypeStack getStackType() {
+        return fStackType;
+    }
+
+    /**
+     * Get the forced type of the value. For example, if the value obtained from
+     * the attributes is not in this forced type, it will be converted to this.
+     *
+     * @return The desired type of the value
+     */
+    protected ITmfStateValue.Type getForcedType() {
+        return fForcedType;
+    }
+
+    @Override
+    public ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
+        return fStateValue.getValue(event, scenarioInfo);
+    }
+
+    /**
+     * Get the value of the event field that is the path of this state value
+     *
+     * @param event
+     *            The current event
+     * @return the value of the event field
+     */
+    @Override
+    public ITmfStateValue getEventFieldValue(@NonNull ITmfEvent event) {
+        String eventField = fEventField;
+        if (eventField == null) {
+            throw new IllegalStateException();
+        }
+        return getEventFieldValue(event, eventField);
+    }
+
+    /**
+     * Get the value of an event field
+     *
+     * @param event
+     *            The current event
+     * @param fieldName
+     *            The name of the field of which to get the value
+     * @return The value of the event field
+     */
+    protected ITmfStateValue getEventFieldValue(ITmfEvent event, String fieldName) {
+
+        ITmfStateValue value = TmfStateValue.nullValue();
+
+        final ITmfEventField content = event.getContent();
+
+        /* Exception for "CPU", returns the source of this event */
+        /* FIXME : Nameclash if a eventfield have "cpu" for name. */
+        if (fieldName.equals(TmfXmlStrings.CPU)) {
+            Integer cpu = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(event.getTrace(), TmfCpuAspect.class, event);
+            if (cpu != null) {
+                return TmfStateValue.newValueInt(cpu.intValue());
+            }
+        }
+        /* Exception also for "TIMESTAMP", returns the timestamp of this event */
+        if (fieldName.equals(TmfXmlStrings.TIMESTAMP)) {
+            return TmfStateValue.newValueLong(event.getTimestamp().getValue());
+        }
+        if (content.getField(fieldName) == null) {
+            return value;
+        }
+
+        Object field = content.getField(fieldName).getValue();
+
+        /*
+         * Try to find the right type. The type can be forced by
+         * "forcedType" argument.
+         */
+
+        if (field instanceof String) {
+            String fieldString = (String) field;
+
+            switch (fForcedType) {
+            case INTEGER:
+                value = TmfStateValue.newValueInt(Integer.parseInt(fieldString));
+                break;
+            case LONG:
+                value = TmfStateValue.newValueLong(Long.parseLong(fieldString));
+                break;
+            case DOUBLE:
+                value = TmfStateValue.newValueDouble(Double.parseDouble(fieldString));
+                break;
+            case NULL:
+            case STRING:
+            default:
+                value = TmfStateValue.newValueString(fieldString);
+                break;
+            }
+        } else if (field instanceof Long) {
+            Long fieldLong = (Long) field;
+
+            switch (fForcedType) {
+            case INTEGER:
+                value = TmfStateValue.newValueInt(fieldLong.intValue());
+                break;
+            case STRING:
+                value = TmfStateValue.newValueString(fieldLong.toString());
+                break;
+            case DOUBLE:
+                value = TmfStateValue.newValueDouble(fieldLong.doubleValue());
+                break;
+            case LONG:
+            case NULL:
+            default:
+                value = TmfStateValue.newValueLong(fieldLong);
+                break;
+            }
+        } else if (field instanceof Integer) {
+            Integer fieldInteger = (Integer) field;
+
+            switch (fForcedType) {
+            case LONG:
+                value = TmfStateValue.newValueLong(fieldInteger.longValue());
+                break;
+            case STRING:
+                value = TmfStateValue.newValueString(fieldInteger.toString());
+                break;
+            case DOUBLE:
+                value = TmfStateValue.newValueDouble(fieldInteger.doubleValue());
+                break;
+            case INTEGER:
+            case NULL:
+            default:
+                value = TmfStateValue.newValueInt(fieldInteger);
+                break;
+            }
+        } else if (field instanceof Double) {
+            Double fieldDouble = (Double) field;
+
+            switch (fForcedType) {
+            case LONG:
+                value = TmfStateValue.newValueLong(fieldDouble.longValue());
+                break;
+            case STRING:
+                value = TmfStateValue.newValueString(fieldDouble.toString());
+                break;
+            case INTEGER:
+                value = TmfStateValue.newValueInt(fieldDouble.intValue());
+                break;
+            case DOUBLE:
+            case NULL:
+            default:
+                value = TmfStateValue.newValueDouble(fieldDouble);
+                break;
+            }
+        }
+        return value;
+    }
+
+    /**
+     * Get the list of state attributes, the path to the state value
+     *
+     * @return the list of Attribute to have the path in the State System
+     */
+    @Override
+    public List<ITmfXmlStateAttribute> getAttributes() {
+        return fPath;
+    }
+
+    @Override
+    public void handleEvent(@NonNull ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException {
+        int quark = IXmlStateSystemContainer.ROOT_QUARK;
+
+        for (ITmfXmlStateAttribute attribute : fPath) {
+            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$
+            }
+        }
+
+        long ts = event.getTimestamp().getValue();
+        fStateValue.handleEvent(event, quark, ts, scenarioInfo);
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder("TmfXmlStateValue: "); //$NON-NLS-1$
+        if (fEventField != null) {
+            builder.append("Field=").append(fEventField).append("; "); //$NON-NLS-1$ //$NON-NLS-2$
+        } else if (!fPath.isEmpty()) {
+            builder.append("Path=").append(fPath).append("; "); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+        builder.append(fStateValue);
+        return builder.toString();
+    }
+
+    /**
+     * Base class for all state values. Contain default methods to handle event,
+     * process or increment the value
+     */
+    protected abstract class TmfXmlStateValueBase {
+
+        /**
+         * Get the value associated with this state value.
+         *
+         * @param event
+         *            The event which can be used to retrieve the value if
+         *            necessary. The event can be <code>null</code> if no event
+         *            is required.
+         * @param scenarioInfo
+         *            The active scenario details. The value should be null if
+         *            there no scenario.
+         * @return The state value corresponding to this XML state value
+         * @throws AttributeNotFoundException
+         *             Pass through the exception it received
+         */
+        public abstract ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException;
+
+        /**
+         * Do something with the state value, possibly using an event
+         *
+         * @param event
+         *            The event being handled. If there is no event is
+         *            available, use <code>null</code>.
+         * @param quark
+         *            The quark for this value
+         * @param timestamp
+         *            The timestamp of the event
+         * @param scenarioInfo
+         *            The active scenario details. The value should be null if
+         *            there no scenario.
+         * @throws StateValueTypeException
+         *             Pass through the exception it received
+         * @throws TimeRangeException
+         *             Pass through the exception it received
+         * @throws AttributeNotFoundException
+         *             Pass through the exception it received
+         */
+        public void handleEvent(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
+            if (fIncrement) {
+                incrementValue(event, quark, timestamp, scenarioInfo);
+            } else {
+                ITmfStateValue value = getValue(event, scenarioInfo);
+                processValue(quark, timestamp, value);
+            }
+        }
+
+        /**
+         * Set the value of a quark at a given timestamp.
+         *
+         * @param quark
+         *            The quark for this value
+         * @param timestamp
+         *            The timestamp
+         * @param value
+         *            The value of this state value
+         * @throws TimeRangeException
+         *             Pass through the exception it received
+         * @throws StateValueTypeException
+         *             Pass through the exception it received
+         * @throws AttributeNotFoundException
+         *             Pass through the exception it received
+         */
+        @SuppressWarnings("unused")
+        protected void processValue(int quark, long timestamp, ITmfStateValue value) throws TimeRangeException, StateValueTypeException, AttributeNotFoundException {
+        }
+
+        /**
+         * Increments the value of the parameter
+         *
+         * @param event
+         *            The event being handled
+         * @param quark
+         *            The quark for this value
+         * @param timestamp
+         *            The timestamp of the event
+         * @param scenarioInfo
+         *            The active scenario details. The value should be null if
+         *            there no scenario.
+         * @throws StateValueTypeException
+         *             Pass through the exception it received
+         * @throws TimeRangeException
+         *             Pass through the exception it received
+         * @throws AttributeNotFoundException
+         *             Pass through the exception it received
+         */
+        @SuppressWarnings("unused")
+        protected void incrementValue(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
+        }
+    }
+
+    /* This state value uses a constant value, defined in the XML */
+    private class TmfXmlStateValueNull extends TmfXmlStateValueBase {
+
+        @Override
+        public ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
+            return TmfStateValue.nullValue();
+        }
+
+        @Override
+        public String toString() {
+            return "NULL"; //$NON-NLS-1$
+        }
+    }
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlTimestampCondition.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlTimestampCondition.java
new file mode 100644 (file)
index 0000000..b79d6e2
--- /dev/null
@@ -0,0 +1,282 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ ******************************************************************************/
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
+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.module.XmlUtils;
+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.statesystem.core.ITmfStateSystem;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.w3c.dom.Element;
+
+/**
+ * This Class implements a timestamp condition tree in the XML-defined state
+ * system.
+ *
+ * @author Jean-Christian Kouame
+ */
+public class TmfXmlTimestampCondition implements ITmfXmlCondition {
+
+    private enum TimeRangeOperator {
+        IN,
+        OUT,
+        OTHER
+    }
+
+    private enum ElapsedTimeOperator {
+        LESS,
+        EQUAL,
+        MORE,
+        NONE
+    }
+
+    private static final long US = 1000l;
+    private final IXmlTimestampsCondition fTimestampsCondition;
+    private final IXmlStateSystemContainer fParent;
+
+    /**
+     * Constructor
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param node
+     *            The XML root of this timestamp condition
+     * @param container
+     *            The state system container this timestamp condition belongs to
+     */
+    public TmfXmlTimestampCondition(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container) {
+        fParent = container;
+        String type = node.getNodeName();
+        switch (type) {
+        case TmfXmlStrings.TIME_RANGE:
+            fTimestampsCondition = new TmfXmlTimeRangeCondition(modelFactory, node, fParent);
+            break;
+        case TmfXmlStrings.ELAPSED_TIME:
+            fTimestampsCondition = new TmfXmlElapsedTimeCondition(modelFactory, node, fParent);
+            break;
+        default:
+            throw new IllegalArgumentException("Invalid timestampsChecker declaration in XML : Type should be timeRange or elapsedTime"); //$NON-NLS-1$
+        }
+    }
+
+    /**
+     * Normalize the value into a nanosecond time value
+     *
+     * @param timestamp
+     *            The timestamp value
+     * @param unit
+     *            The initial unit of the timestamp
+     * @return The value of the timestamp in nanoseconds
+     */
+    public static long valueToNanoseconds(long timestamp, String unit) {
+        switch (unit) {
+        case TmfXmlStrings.NS:
+            return timestamp;
+        case TmfXmlStrings.US:
+            return timestamp * US;
+        case TmfXmlStrings.MS:
+            return timestamp * US * US;
+        case TmfXmlStrings.S:
+            return timestamp * US * US * US;
+        default:
+            throw new IllegalArgumentException("The time unit is not yet supporting."); //$NON-NLS-1$
+        }
+    }
+
+    /**
+     * Validate the event
+     *
+     * @param event
+     *            The current event
+     * @param scenarioInfo
+     *            The active scenario details. The value should be null if there
+     *            is no scenario
+     * @return True if the test succeed, false otherwise
+     */
+    @Override
+    public boolean test(ITmfEvent event,@Nullable TmfXmlScenarioInfo scenarioInfo) {
+        return fTimestampsCondition.test(event, scenarioInfo);
+    }
+
+    private interface IXmlTimestampsCondition extends ITmfXmlCondition {
+    }
+
+    private class TmfXmlTimeRangeCondition implements IXmlTimestampsCondition {
+
+        private final TimeRangeOperator fType;
+        private final String fUnit;
+        private final String fBegin;
+        private final String fEnd;
+        private final IXmlStateSystemContainer fContainer;
+
+        /**
+         * Constructor
+         *
+         * @param modelFactory
+         *            The factory used to create XML model elements
+         * @param node
+         *            The XML root of this time range condition transition
+         * @param container
+         *            The state system container this time range condition
+         *            belongs to
+         */
+        public TmfXmlTimeRangeCondition(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container) {
+            fContainer = container;
+            String unit = node.getAttribute(TmfXmlStrings.UNIT);
+            fUnit = unit;
+            List<@Nullable Element> childElements = NonNullUtils.checkNotNull(XmlUtils.getChildElements(node));
+            if (childElements.size() != 1) {
+                throw new IllegalArgumentException("Invalid timestampsChecker declaration in XML : Only one timing condition is allowed"); //$NON-NLS-1$
+            }
+            final Element firstElement = NonNullUtils.checkNotNull(childElements.get(0));
+            String type = firstElement.getNodeName();
+            switch (type) {
+            case TmfXmlStrings.IN:
+                fType = TimeRangeOperator.IN;
+                break;
+            case TmfXmlStrings.OUT:
+                fType = TimeRangeOperator.OUT;
+                break;
+            default:
+                fType = TimeRangeOperator.OTHER;
+                break;
+            }
+
+            final String begin = firstElement.getAttribute(TmfXmlStrings.BEGIN);
+            final String end = firstElement.getAttribute(TmfXmlStrings.END);
+            fBegin = begin;
+            fEnd = end;
+        }
+
+        @Override
+        public boolean test(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
+            ITmfStateSystem ss = fContainer.getStateSystem();
+
+            long begin;
+            begin = valueToNanoseconds(Long.parseLong(fBegin), fUnit);
+
+            long end;
+            end = valueToNanoseconds(Long.parseLong(fEnd), fUnit);
+
+            // swap the value if begin > end
+            if (begin > end) {
+                begin = begin ^ end;
+                end = begin ^ end;
+                begin = begin ^ end;
+            }
+
+            begin = Math.max(ss.getStartTime(), begin);
+            end = Math.min(ss.getCurrentEndTime(), end);
+            begin = Math.min(begin, end);
+
+            long ts = event.getTimestamp().toNanos();
+            switch (fType) {
+            case IN:
+                return intersects(begin, end, ts);
+            case OUT:
+                return !intersects(begin, end, ts);
+            case OTHER:
+            default:
+                return false;
+            }
+        }
+
+        private boolean intersects(long begin, long end, long ts) {
+            return ts >= begin && ts <= end;
+        }
+
+    }
+
+    private class TmfXmlElapsedTimeCondition implements IXmlTimestampsCondition {
+
+        private final IXmlStateSystemContainer fContainer;
+        private final ElapsedTimeOperator fType;
+        private final String fUnit;
+        private final String fValue;
+        private final String fReferenceState;
+
+        /**
+         * Constructor
+         *
+         * @param modelFactory
+         *            The factory used to create XML model elements
+         * @param node
+         *            The XML root of this elapsed time condition
+         * @param container
+         *            The state system container this elapsed time condition
+         *            belongs to
+         */
+        public TmfXmlElapsedTimeCondition(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container) {
+            fContainer = container;
+            String unit = node.getAttribute(TmfXmlStrings.UNIT);
+            fUnit = unit;
+            List<@Nullable Element> childElements = XmlUtils.getChildElements(node);
+            if (childElements.size() != 1) {
+                throw new IllegalArgumentException("Invalid timestampsChecker declaration in XML : Only one timing condition is allowed"); //$NON-NLS-1$
+            }
+            final Element firstElement = NonNullUtils.checkNotNull(childElements.get(0));
+            String type = firstElement.getNodeName();
+            switch (type) {
+            case TmfXmlStrings.LESS:
+                fType = ElapsedTimeOperator.LESS;
+                break;
+            case TmfXmlStrings.EQUAL:
+                fType = ElapsedTimeOperator.EQUAL;
+                break;
+            case TmfXmlStrings.MORE:
+                fType = ElapsedTimeOperator.MORE;
+                break;
+            default:
+                fType = ElapsedTimeOperator.NONE;
+                break;
+            }
+            final String reference = firstElement.getAttribute(TmfXmlStrings.SINCE);
+            final String value = firstElement.getAttribute(TmfXmlStrings.VALUE);
+            fReferenceState = reference;
+            fValue = value;
+        }
+
+        @Override
+        public boolean test(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
+            if (scenarioInfo == null) {
+                Activator.logError("Elapse time conditions require scenarioInfos and scenarioInfos is null"); //$NON-NLS-1$
+                return false;
+            }
+            boolean success;
+            long ts = event.getTimestamp().toNanos();
+            long referenceTimestamps = ((XmlPatternStateProvider) fContainer).getHistoryBuilder().getSpecificStateStartTime(fContainer, fReferenceState, scenarioInfo, event);
+            if (ts < referenceTimestamps) {
+                throw new IllegalArgumentException("Timestamp is inferior to reference time"); //$NON-NLS-1$
+            }
+            switch (fType) {
+            case LESS:
+                success = (ts - referenceTimestamps) < valueToNanoseconds(Long.parseLong(fValue), fUnit);
+                break;
+            case EQUAL:
+                success = (ts - referenceTimestamps) == valueToNanoseconds(Long.parseLong(fValue), fUnit);
+                break;
+            case MORE:
+                success = (ts - referenceTimestamps) > valueToNanoseconds(Long.parseLong(fValue), fUnit);
+                break;
+            case NONE:
+            default:
+                success = false;
+                break;
+            }
+            return success;
+        }
+
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlTransitionValidator.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/TmfXmlTransitionValidator.java
new file mode 100644 (file)
index 0000000..5e88c38
--- /dev/null
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ ******************************************************************************/
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * This Class implements a transition input tree in the XML-defined state
+ * system.
+ *
+ * TODO We should merge this class with the current TmfXmlCondition, that should
+ * be kept as is for compatibility with current stateProvider
+ *
+ * @author Jean-Christian Kouame
+ */
+public class TmfXmlTransitionValidator implements ITmfXmlCondition {
+
+    IXmlStateSystemContainer fParent;
+    private final String fId;
+    private final ITmfXmlCondition fCondition;
+
+    /**
+     * Constructor
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param node
+     *            The XML root of this transition input
+     * @param parent
+     *            The state system container this transition input belongs to
+     */
+    public TmfXmlTransitionValidator(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer parent) {
+        fParent = parent;
+        fId = node.getAttribute(TmfXmlStrings.ID);
+
+        List<@Nullable Element> childElements = XmlUtils.getChildElements(node);
+        Node child = NonNullUtils.checkNotNull(childElements.get(0));
+        fCondition = modelFactory.createCondition((Element) child, parent);
+    }
+
+    /**
+     * Get the ID of this transition input
+     *
+     * @return The id of this transition input
+     */
+    public String getId() {
+        return fId;
+    }
+
+    @Override
+    public boolean test(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
+        return fCondition.test(event, scenarioInfo);
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/UpdateStoredFieldsAction.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/UpdateStoredFieldsAction.java
new file mode 100644 (file)
index 0000000..5a4a06e
--- /dev/null
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ ******************************************************************************/
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
+
+import java.util.Map.Entry;
+
+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.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+
+/**
+ * This action will update the value of the stored fields in the state system
+ * based on the current event data.
+ *
+ * @author Jean-Christian Kouame
+ */
+public class UpdateStoredFieldsAction implements ITmfXmlAction {
+
+    private final IXmlStateSystemContainer fParent;
+
+    /**
+     * Constructor
+     *
+     * @param parent
+     *            The state system container this action belongs to
+     */
+    public UpdateStoredFieldsAction(IXmlStateSystemContainer parent) {
+        fParent = parent;
+    }
+
+    @Override
+    public void execute(ITmfEvent event, TmfXmlScenarioInfo scenarioInfo) {
+        if (fParent instanceof XmlPatternStateProvider) {
+            for (Entry<String, String> entry : ((XmlPatternStateProvider) fParent).getStoredFields().entrySet()) {
+                ITmfEventField eventField = event.getContent().getField(entry.getKey());
+                ITmfStateValue stateValue = null;
+                if (eventField != null) {
+                    final String alias = entry.getValue();
+                    Object field = eventField.getValue();
+                    if (field instanceof String) {
+                        stateValue = TmfStateValue.newValueString((String) field);
+                    } else if (field instanceof Long) {
+                        stateValue = TmfStateValue.newValueLong(((Long) field).longValue());
+                    } else if (field instanceof Integer) {
+                        stateValue = TmfStateValue.newValueInt(((Integer) field).intValue());
+                    } else if (field instanceof Double) {
+                        stateValue = TmfStateValue.newValueDouble(((Double) field).doubleValue());
+                    }
+                    if (stateValue == null) {
+                        throw new IllegalStateException("State value is null. Invalid type."); //$NON-NLS-1$
+                    }
+                    ((XmlPatternStateProvider) fParent).getHistoryBuilder().updateStoredFields(fParent, alias, stateValue, scenarioInfo, event);
+                }
+            }
+        }
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/package-info.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/package-info.java
new file mode 100644 (file)
index 0000000..0e8cafb
--- /dev/null
@@ -0,0 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Ericsson - Initial API and implementation
+ *******************************************************************************/
+
+@org.eclipse.jdt.annotation.NonNullByDefault package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model;
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyModelFactory.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyModelFactory.java
new file mode 100644 (file)
index 0000000..085d30f
--- /dev/null
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readonly;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlStateValue;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlAction;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlCondition;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlEventHandler;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlFsm;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlLocation;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlPatternEventHandler;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlPatternSegmentBuilder;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlState;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlStateChange;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlStateTransition;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlTimestampCondition;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlTransitionValidator;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.w3c.dom.Element;
+
+/**
+ * Concrete factory for XML model elements in read only mode
+ *
+ * @author Geneviève Bastien
+ */
+public class TmfXmlReadOnlyModelFactory implements ITmfXmlModelFactory {
+
+    private static @Nullable ITmfXmlModelFactory fInstance = null;
+
+    /**
+     * Get the instance of this model creator
+     *
+     * @return The {@link TmfXmlReadOnlyModelFactory} instance
+     */
+    public static synchronized ITmfXmlModelFactory getInstance() {
+        ITmfXmlModelFactory instance = fInstance;
+        if (instance == null) {
+            instance = new TmfXmlReadOnlyModelFactory();
+            fInstance = instance;
+        }
+        return instance;
+    }
+
+    @Override
+    public ITmfXmlStateAttribute createStateAttribute(Element attribute, IXmlStateSystemContainer container) {
+        return new TmfXmlReadOnlyStateAttribute(this, attribute, container);
+    }
+
+    @Override
+    public ITmfXmlStateValue createStateValue(Element node, IXmlStateSystemContainer container, List<ITmfXmlStateAttribute> attributes) {
+        return new TmfXmlReadOnlyStateValue(this, node, container, attributes);
+    }
+
+    @Override
+    public ITmfXmlStateValue createStateValue(Element node, IXmlStateSystemContainer container, String eventField) {
+        return new TmfXmlReadOnlyStateValue(this, node, container, eventField);
+    }
+
+    @Override
+    public TmfXmlCondition createCondition(Element node, IXmlStateSystemContainer container) {
+        return TmfXmlCondition.create(this, node, container);
+    }
+
+    @Override
+    public TmfXmlEventHandler createEventHandler(Element node, IXmlStateSystemContainer container) {
+        return new TmfXmlEventHandler(this, node, container);
+    }
+
+    @Override
+    public TmfXmlStateChange createStateChange(Element node, IXmlStateSystemContainer container) {
+        return new TmfXmlStateChange(this, node, container);
+    }
+
+    @Override
+    public TmfXmlLocation createLocation(Element node, IXmlStateSystemContainer container) {
+        return new TmfXmlLocation(this, node, container);
+    }
+
+    @Override
+    public TmfXmlPatternEventHandler createPatternEventHandler(Element node, IXmlStateSystemContainer container) {
+        return new TmfXmlPatternEventHandler(this, node, container);
+    }
+
+    @Override
+    public TmfXmlTransitionValidator createTransitionValidator(Element node, IXmlStateSystemContainer container) {
+        return new TmfXmlTransitionValidator(this, node, container);
+    }
+
+    @Override
+    public TmfXmlAction createAction(Element node, IXmlStateSystemContainer container) {
+        return new TmfXmlAction(this, node, container);
+    }
+
+    @Override
+    public TmfXmlFsm createFsm(Element node, IXmlStateSystemContainer container) {
+        return TmfXmlFsm.create(this, node, container);
+    }
+
+    @Override
+    public @NonNull TmfXmlState createState(Element node, IXmlStateSystemContainer container, @Nullable TmfXmlState parent) {
+        return TmfXmlState.create(this, node, container, parent);
+    }
+
+    @Override
+    public TmfXmlStateTransition createStateTransition(Element node, IXmlStateSystemContainer container) {
+        return new TmfXmlStateTransition(this, node, container);
+    }
+
+    @Override
+    public TmfXmlTimestampCondition createTimestampsCondition(Element node, IXmlStateSystemContainer container) {
+        return new TmfXmlTimestampCondition(this, node, container);
+    }
+
+    @Override
+    public TmfXmlPatternSegmentBuilder createPatternSegmentBuilder(Element node, IXmlStateSystemContainer container) {
+        return new TmfXmlPatternSegmentBuilder(this, node, container);
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateAttribute.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateAttribute.java
new file mode 100644 (file)
index 0000000..9617fb6
--- /dev/null
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readonly;
+
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlStateAttribute;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
+import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
+import org.w3c.dom.Element;
+
+/**
+ * Implements a state attribute in a read only mode. See
+ * {@link TmfXmlStateAttribute} for the syntax of this attribute.
+ *
+ * In read-only mode, attributes that are requested but do not exist in the
+ * state system will not be added.
+ *
+ * @author Geneviève Bastien
+ */
+public class TmfXmlReadOnlyStateAttribute extends TmfXmlStateAttribute {
+
+    /**
+     * Constructor
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param attribute
+     *            The XML element corresponding to this attribute
+     * @param container
+     *            The state system container this state value belongs to
+     */
+    public TmfXmlReadOnlyStateAttribute(TmfXmlReadOnlyModelFactory modelFactory, Element attribute, IXmlStateSystemContainer container) {
+        super(modelFactory, attribute, container);
+    }
+
+    @Override
+    protected int getQuarkAbsoluteAndAdd(String... path) throws AttributeNotFoundException {
+        ITmfStateSystem ss = getStateSystem();
+        if (ss == null) {
+            throw new IllegalStateException("The state system hasn't been initialized yet"); //$NON-NLS-1$
+        }
+        return ss.getQuarkAbsolute(path);
+    }
+
+    @Override
+    protected int getQuarkRelativeAndAdd(int startNodeQuark, String... path) throws AttributeNotFoundException {
+        ITmfStateSystem ss = getStateSystem();
+        if (ss == null) {
+            throw new IllegalStateException("The state system hasn't been initialized yet"); //$NON-NLS-1$
+        }
+        return ss.getQuarkRelative(startNodeQuark, path);
+    }
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateValue.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateValue.java
new file mode 100644 (file)
index 0000000..601a0b9
--- /dev/null
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readonly;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlStateValue;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.w3c.dom.Element;
+
+/**
+ * Implements a state value is a read only mode. See {@link TmfXmlStateValue}
+ * for the syntax of the state value.
+ *
+ * In read mode, a state value will typically be used to find a path to a value,
+ * so the value is known and there is a path of attributes that should lead to
+ * it.
+ *
+ * @author Geneviève Bastien
+ */
+public class TmfXmlReadOnlyStateValue extends TmfXmlStateValue {
+
+    /**
+     * Constructor where the path to the value is a list of state attributes
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param node
+     *            The state value XML element
+     * @param container
+     *            The state system container this state value belongs to
+     * @param attributes
+     *            The attributes representing the path to this value
+     */
+    public TmfXmlReadOnlyStateValue(TmfXmlReadOnlyModelFactory modelFactory, Element node,
+            IXmlStateSystemContainer container, List<ITmfXmlStateAttribute> attributes) {
+        super(modelFactory, node, container, attributes, null);
+    }
+
+    /**
+     * Constructor where the path to the value is an event field
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param node
+     *            The state value XML element
+     * @param container
+     *            The state system container this state value belongs to
+     * @param eventField
+     *            The event field where to get the value
+     */
+    public TmfXmlReadOnlyStateValue(TmfXmlReadOnlyModelFactory modelFactory, Element node,
+            IXmlStateSystemContainer container, String eventField) {
+        super(modelFactory, node, container, Collections.EMPTY_LIST, eventField);
+    }
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readonly/package-info.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readonly/package-info.java
new file mode 100644 (file)
index 0000000..f2df573
--- /dev/null
@@ -0,0 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Ericsson - Initial API and implementation
+ *******************************************************************************/
+
+@org.eclipse.jdt.annotation.NonNullByDefault package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readonly;
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteModelFactory.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteModelFactory.java
new file mode 100644 (file)
index 0000000..b1859e9
--- /dev/null
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readwrite;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlStateValue;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlAction;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlCondition;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlEventHandler;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlFsm;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlLocation;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlPatternEventHandler;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlPatternSegmentBuilder;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlState;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlStateChange;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlStateTransition;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlTimestampCondition;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlTransitionValidator;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.w3c.dom.Element;
+
+/**
+ * Concrete factory for XML model elements in read write mode
+ *
+ * @author Geneviève Bastien
+ */
+public class TmfXmlReadWriteModelFactory implements ITmfXmlModelFactory {
+
+    private static @Nullable ITmfXmlModelFactory fInstance = null;
+
+    /**
+     * Get the instance of this model creator
+     *
+     * @return The {@link TmfXmlReadWriteModelFactory} instance
+     */
+    public static synchronized ITmfXmlModelFactory getInstance() {
+        ITmfXmlModelFactory instance = fInstance;
+        if (instance == null) {
+            instance = new TmfXmlReadWriteModelFactory();
+            fInstance = instance;
+        }
+        return instance;
+    }
+
+    @Override
+    public ITmfXmlStateAttribute createStateAttribute(Element attribute, IXmlStateSystemContainer container) {
+        return new TmfXmlReadWriteStateAttribute(this, attribute, container);
+    }
+
+    @Override
+    public ITmfXmlStateValue createStateValue(Element node, IXmlStateSystemContainer container, List<ITmfXmlStateAttribute> attributes) {
+        return new TmfXmlReadWriteStateValue(this, node, container, attributes);
+    }
+
+    @Override
+    public ITmfXmlStateValue createStateValue(Element node, IXmlStateSystemContainer container, String eventField) {
+        return new TmfXmlReadWriteStateValue(this, node, container, eventField);
+    }
+
+    @Override
+    public TmfXmlCondition createCondition(Element node, IXmlStateSystemContainer container) {
+        return TmfXmlCondition.create(this, node, container);
+    }
+
+    @Override
+    public TmfXmlEventHandler createEventHandler(Element node, IXmlStateSystemContainer container) {
+        return new TmfXmlEventHandler(this, node, container);
+    }
+
+    @Override
+    public TmfXmlStateChange createStateChange(Element node, IXmlStateSystemContainer container) {
+        return new TmfXmlStateChange(this, node, container);
+    }
+
+    @Override
+    public TmfXmlLocation createLocation(Element node, IXmlStateSystemContainer container) {
+        return new TmfXmlLocation(this, node, container);
+    }
+
+    @Override
+    public TmfXmlPatternEventHandler createPatternEventHandler(Element node, IXmlStateSystemContainer container) {
+        return new TmfXmlPatternEventHandler(this, node, container);
+    }
+
+    @Override
+    public TmfXmlTransitionValidator createTransitionValidator(Element node, IXmlStateSystemContainer container) {
+        return new TmfXmlTransitionValidator(this, node, container);
+    }
+
+    @Override
+    public TmfXmlAction createAction(Element node, IXmlStateSystemContainer container) {
+        return new TmfXmlAction(this, node, container);
+    }
+
+    @Override
+    public TmfXmlFsm createFsm(Element node, IXmlStateSystemContainer container) {
+        return TmfXmlFsm.create(this, node, container);
+    }
+
+    @Override
+    public @NonNull TmfXmlState createState(Element node, IXmlStateSystemContainer container, @Nullable TmfXmlState parent) {
+        return TmfXmlState.create(this, node, container, parent);
+    }
+
+    @Override
+    public TmfXmlStateTransition createStateTransition(Element node, IXmlStateSystemContainer container) {
+        return new TmfXmlStateTransition(this, node, container);
+    }
+
+    @Override
+    public TmfXmlTimestampCondition createTimestampsCondition(Element node, IXmlStateSystemContainer container) {
+        return new TmfXmlTimestampCondition(this, node, container);
+    }
+
+    @Override
+    public TmfXmlPatternSegmentBuilder createPatternSegmentBuilder(Element node, IXmlStateSystemContainer container) {
+        return new TmfXmlPatternSegmentBuilder(this, node, container);
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateAttribute.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateAttribute.java
new file mode 100644 (file)
index 0000000..4b9aac3
--- /dev/null
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readwrite;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlStateAttribute;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
+import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
+import org.w3c.dom.Element;
+
+/**
+ * Implements a state attribute in a read write mode. See
+ * {@link TmfXmlStateAttribute} for the syntax of this attribute.
+ *
+ * In read-write mode, attributes that are requested but do not exist are added
+ * to the state system.
+ *
+ * @author Geneviève Bastien
+ */
+public class TmfXmlReadWriteStateAttribute extends TmfXmlStateAttribute {
+
+    /**
+     * Constructor
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param attribute
+     *            The XML element corresponding to this attribute
+     * @param container
+     *            The state system container this state value belongs to
+     */
+    public TmfXmlReadWriteStateAttribute(TmfXmlReadWriteModelFactory modelFactory, Element attribute, IXmlStateSystemContainer container) {
+        super(modelFactory, attribute, container);
+    }
+
+    @Override
+    protected @Nullable ITmfStateSystemBuilder getStateSystem() {
+        return (ITmfStateSystemBuilder) super.getStateSystem();
+    }
+
+    @Override
+    protected int getQuarkAbsoluteAndAdd(String... path) throws AttributeNotFoundException {
+        ITmfStateSystemBuilder ss = getStateSystem();
+        if (ss == null) {
+            throw new IllegalStateException("The state system hasn't been initialized yet"); //$NON-NLS-1$
+        }
+        return ss.getQuarkAbsoluteAndAdd(path);
+    }
+
+    @Override
+    protected int getQuarkRelativeAndAdd(int startNodeQuark, String... path) throws AttributeNotFoundException {
+        ITmfStateSystemBuilder ss = getStateSystem();
+        if (ss == null) {
+            throw new IllegalStateException("The state system hasn't been initialized yet"); //$NON-NLS-1$
+        }
+        return ss.getQuarkRelativeAndAdd(startNodeQuark, path);
+    }
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateValue.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateValue.java
new file mode 100644 (file)
index 0000000..db51183
--- /dev/null
@@ -0,0 +1,409 @@
+/*******************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readwrite;
+
+import java.util.ArrayList;
+import java.util.List;
+
+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.model.ITmfXmlModelFactory;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlScenarioInfo;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlStateValue;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
+import org.eclipse.tracecompass.statesystem.core.StateSystemBuilderUtils;
+import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.w3c.dom.Element;
+
+/**
+ * Implements a state value in a read write mode. See {@link TmfXmlStateValue}
+ * for the syntax of the state value.
+ *
+ * In read/write mode, a state value can be considered as an assignation where
+ * the state value is assigned to the quark represented by the state attributes
+ *
+ * @author Geneviève Bastien
+ */
+public class TmfXmlReadWriteStateValue extends TmfXmlStateValue {
+
+    private static final String ILLEGAL_STATE_EXCEPTION_MESSAGE = "The state system hasn't been initialized yet"; //$NON-NLS-1$
+
+    /**
+     * Constructor where the path to the value is a list of state attributes
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param node
+     *            The state value XML element
+     * @param container
+     *            The state system container this state value belongs to
+     * @param attributes
+     *            The attributes representing the path to this value
+     */
+    public TmfXmlReadWriteStateValue(TmfXmlReadWriteModelFactory modelFactory, Element node, IXmlStateSystemContainer container, List<ITmfXmlStateAttribute> attributes) {
+        this(modelFactory, node, container, attributes, null);
+    }
+
+    /**
+     * Constructor where the path to the value is an event field
+     *
+     * @param modelFactory
+     *            The factory used to create XML model elements
+     * @param node
+     *            The state value XML element
+     * @param container
+     *            The state system container this state value belongs to
+     * @param eventField
+     *            The event field where to get the value
+     */
+    public TmfXmlReadWriteStateValue(TmfXmlReadWriteModelFactory modelFactory, Element node, IXmlStateSystemContainer container, String eventField) {
+        this(modelFactory, node, container, new ArrayList<ITmfXmlStateAttribute>(), eventField);
+    }
+
+    private TmfXmlReadWriteStateValue(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container, List<ITmfXmlStateAttribute> attributes, @Nullable String eventField) {
+        super(modelFactory, node, container, attributes, eventField);
+    }
+
+    @Override
+    protected @Nullable ITmfStateSystemBuilder getStateSystem() {
+        return (ITmfStateSystemBuilder) super.getStateSystem();
+    }
+
+    @Override
+    protected TmfXmlStateValueBase initializeStateValue(ITmfXmlModelFactory modelFactory, Element node) {
+        TmfXmlStateValueBase stateValueType = null;
+        /* Process the XML Element state value */
+        String type = node.getAttribute(TmfXmlStrings.TYPE);
+        String value = getSsContainer().getAttributeValue(node.getAttribute(TmfXmlStrings.VALUE));
+        if (value == null) {
+            throw new IllegalStateException();
+        }
+
+        switch (type) {
+        case TmfXmlStrings.TYPE_INT: {
+            /* Integer value */
+            ITmfStateValue stateValue = TmfStateValue.newValueInt(Integer.parseInt(value));
+            stateValueType = new TmfXmlStateValueTmf(stateValue);
+            break;
+        }
+        case TmfXmlStrings.TYPE_LONG: {
+            /* Long value */
+            ITmfStateValue stateValue = TmfStateValue.newValueLong(Long.parseLong(value));
+            stateValueType = new TmfXmlStateValueTmf(stateValue);
+            break;
+        }
+        case TmfXmlStrings.TYPE_STRING: {
+            /* String value */
+            ITmfStateValue stateValue = TmfStateValue.newValueString(value);
+            stateValueType = new TmfXmlStateValueTmf(stateValue);
+            break;
+        }
+        case TmfXmlStrings.TYPE_NULL: {
+            /* Null value */
+            ITmfStateValue stateValue = TmfStateValue.nullValue();
+            stateValueType = new TmfXmlStateValueTmf(stateValue);
+            break;
+        }
+        case TmfXmlStrings.EVENT_FIELD:
+            /* Event field */
+            stateValueType = new TmfXmlStateValueEventField(value);
+            break;
+        case TmfXmlStrings.TYPE_EVENT_NAME:
+            /* The value is the event name */
+            stateValueType = new TmfXmlStateValueEventName();
+            break;
+        case TmfXmlStrings.TYPE_DELETE:
+            /* Deletes the value of an attribute */
+            stateValueType = new TmfXmlStateValueDelete();
+            break;
+        case TmfXmlStrings.TYPE_QUERY:
+            /* Value is the result of a query */
+            List<@Nullable Element> children = XmlUtils.getChildElements(node);
+            List<ITmfXmlStateAttribute> childAttributes = new ArrayList<>();
+            for (Element child : children) {
+                if (child == null) {
+                    continue;
+                }
+                ITmfXmlStateAttribute queryAttribute = modelFactory.createStateAttribute(child, getSsContainer());
+                childAttributes.add(queryAttribute);
+            }
+            stateValueType = new TmfXmlStateValueQuery(childAttributes);
+            break;
+        default:
+            throw new IllegalArgumentException(String.format("TmfXmlStateValue constructor: unexpected element %s for stateValue type", type)); //$NON-NLS-1$
+        }
+        return stateValueType;
+    }
+
+    // ----------------------------------------------------------
+    // Internal state value classes for the different types
+    // ----------------------------------------------------------
+
+    /**
+     * Base class for all state value. Contain default methods to handle event,
+     * process or increment the value
+     */
+    protected abstract class TmfXmlStateValueTypeReadWrite extends TmfXmlStateValueBase {
+
+        @Override
+        public final void handleEvent(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
+            if (isIncrement()) {
+                incrementValue(event, quark, timestamp, scenarioInfo);
+            } else {
+                ITmfStateValue value = getValue(event, scenarioInfo);
+                processValue(quark, timestamp, value);
+            }
+        }
+
+        @Override
+        protected void processValue(int quark, long timestamp, ITmfStateValue value) throws AttributeNotFoundException, TimeRangeException, StateValueTypeException {
+            ITmfStateSystemBuilder ss = getStateSystem();
+            if (ss == null) {
+                throw new IllegalStateException(ILLEGAL_STATE_EXCEPTION_MESSAGE);
+            }
+            switch (getStackType()) {
+            case POP:
+                ss.popAttribute(timestamp, quark);
+                break;
+            case PUSH:
+                ss.pushAttribute(timestamp, value, quark);
+                break;
+            case NULL:
+            case PEEK:
+            default:
+                ss.modifyAttribute(timestamp, value, quark);
+                break;
+            }
+        }
+
+        @Override
+        protected void incrementValue(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
+            ITmfStateSystemBuilder ss = getStateSystem();
+            if (ss == null) {
+                throw new IllegalStateException(ILLEGAL_STATE_EXCEPTION_MESSAGE);
+            }
+            StateSystemBuilderUtils.incrementAttributeInt(ss, timestamp, quark, 1);
+        }
+    }
+
+    private static @Nullable ITmfStateValue incrementByType(int quark, ITmfStateSystem ss, ITmfStateValue stateValue) throws AttributeNotFoundException {
+        ITmfStateValue value = null;
+        switch (stateValue.getType()) {
+        case LONG: {
+            long incrementLong = stateValue.unboxLong();
+            ITmfStateValue currentState = ss.queryOngoingState(quark);
+            long currentValue = (currentState.isNull() ? 0 : currentState.unboxLong());
+            value = TmfStateValue.newValueLong(incrementLong + currentValue);
+            return value;
+        }
+        case INTEGER: {
+            int increment = stateValue.unboxInt();
+            ITmfStateValue currentState = ss.queryOngoingState(quark);
+            int currentValue = (currentState.isNull() ? 0 : currentState.unboxInt());
+            value = TmfStateValue.newValueInt(increment + currentValue);
+            return value;
+        }
+        case DOUBLE:
+        case NULL:
+        case STRING:
+        default:
+        }
+        return value;
+    }
+
+    /* This state value uses a constant value, defined in the XML */
+    private class TmfXmlStateValueTmf extends TmfXmlStateValueTypeReadWrite {
+
+        private final ITmfStateValue fValue;
+
+        public TmfXmlStateValueTmf(ITmfStateValue value) {
+            fValue = value;
+        }
+
+        @Override
+        public ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
+            return fValue;
+        }
+
+        @Override
+        public void incrementValue(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
+            ITmfStateSystem ss = getStateSystem();
+            if (ss == null) {
+                throw new IllegalStateException(ILLEGAL_STATE_EXCEPTION_MESSAGE);
+            }
+            ITmfStateValue value = incrementByType(quark, ss, fValue);
+            if (value != null) {
+                processValue(quark, timestamp, value);
+            } else {
+                Activator.logWarning("TmfXmlStateValue: The increment value is not a number type"); //$NON-NLS-1$
+            }
+        }
+
+        @Override
+        public String toString() {
+            return "Value=" + fValue; //$NON-NLS-1$
+        }
+
+    }
+
+    /* The state value uses the value of an event field */
+    private class TmfXmlStateValueEventField extends TmfXmlStateValueTypeReadWrite {
+
+        private final String fFieldName;
+
+        public TmfXmlStateValueEventField(String field) {
+            fFieldName = field;
+        }
+
+        @Override
+        public ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
+            if (event == null) {
+                Activator.logWarning("XML State value: requested an event field, but event is null"); //$NON-NLS-1$
+                return TmfStateValue.nullValue();
+            }
+            return getEventFieldValue(event, fFieldName);
+        }
+
+        @Override
+        public void incrementValue(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
+            ITmfStateSystem ss = getSsContainer().getStateSystem();
+            if (ss == null) {
+                throw new IllegalStateException(ILLEGAL_STATE_EXCEPTION_MESSAGE);
+            }
+            ITmfStateValue incrementValue = getValue(event, scenarioInfo);
+            ITmfStateValue value = incrementByType(quark, ss, incrementValue);
+            if (value != null) {
+                processValue(quark, timestamp, value);
+            } else {
+                Activator.logWarning(String.format("TmfXmlStateValue: The event field increment %s is not a number type but a %s", fFieldName, incrementValue.getType())); //$NON-NLS-1$
+            }
+        }
+
+        @Override
+        public String toString() {
+            return "Event Field=" + fFieldName; //$NON-NLS-1$
+        }
+    }
+
+    /* The state value is the event name */
+    private class TmfXmlStateValueEventName extends TmfXmlStateValueTypeReadWrite {
+
+        @Override
+        public @NonNull ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
+            if (event == null) {
+                Activator.logWarning("XML State value: request event name, but event is null"); //$NON-NLS-1$
+                return TmfStateValue.nullValue();
+            }
+            return TmfStateValue.newValueString(event.getName());
+        }
+
+        @Override
+        public String toString() {
+            return "Event name"; //$NON-NLS-1$
+        }
+    }
+
+    /* The state value deletes an attribute */
+    private class TmfXmlStateValueDelete extends TmfXmlStateValueTypeReadWrite {
+
+        @Override
+        public @NonNull ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
+            return TmfStateValue.nullValue();
+        }
+
+        @Override
+        protected void processValue(int quark, long timestamp, ITmfStateValue value) throws TimeRangeException, AttributeNotFoundException {
+            ITmfStateSystem ss = getStateSystem();
+            if (!(ss instanceof ITmfStateSystemBuilder)) {
+                throw new IllegalStateException("incrementValue should never be called when not building the state system"); //$NON-NLS-1$
+            }
+            ITmfStateSystemBuilder builder = (ITmfStateSystemBuilder) ss;
+            builder.removeAttribute(timestamp, quark);
+        }
+
+        @Override
+        public String toString() {
+            return "Delete"; //$NON-NLS-1$
+        }
+    }
+
+    /* The state value uses the result of a query */
+    private class TmfXmlStateValueQuery extends TmfXmlStateValueTypeReadWrite {
+
+        private final List<ITmfXmlStateAttribute> fQueryValue;
+
+        public TmfXmlStateValueQuery(List<ITmfXmlStateAttribute> childAttributes) {
+            fQueryValue = childAttributes;
+        }
+
+        @Override
+        public ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
+            /* Query the state system for the value */
+            ITmfStateValue value = TmfStateValue.nullValue();
+            int quarkQuery = IXmlStateSystemContainer.ROOT_QUARK;
+            ITmfStateSystem ss = getStateSystem();
+            if (ss == null) {
+                throw new IllegalStateException(ILLEGAL_STATE_EXCEPTION_MESSAGE);
+            }
+
+            for (ITmfXmlStateAttribute attribute : fQueryValue) {
+                quarkQuery = attribute.getAttributeQuark(event, quarkQuery, scenarioInfo);
+                if (quarkQuery == IXmlStateSystemContainer.ERROR_QUARK) {
+                    /* the query is not valid, we stop the state change */
+                    break;
+                }
+            }
+            /*
+             * the query can fail : for example, if a value is requested but has
+             * not been set yet
+             */
+            if (quarkQuery != IXmlStateSystemContainer.ERROR_QUARK) {
+                value = ss.queryOngoingState(quarkQuery);
+            }
+            return value;
+        }
+
+        @Override
+        public void incrementValue(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
+            ITmfStateSystem ss = getStateSystem();
+            if (ss == null) {
+                throw new IllegalStateException(ILLEGAL_STATE_EXCEPTION_MESSAGE);
+            }
+
+            ITmfStateValue incrementValue = getValue(event, scenarioInfo);
+            ITmfStateValue value = incrementByType(quark, ss, incrementValue);
+            if (value != null) {
+                processValue(quark, timestamp, value);
+            } else {
+                Activator.logWarning("TmfXmlStateValue: The query result increment is not a number type"); //$NON-NLS-1$
+            }
+        }
+
+        @Override
+        public String toString() {
+            return "Query=" + fQueryValue; //$NON-NLS-1$
+        }
+    }
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readwrite/package-info.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/model/readwrite/package-info.java
new file mode 100644 (file)
index 0000000..c4f5528
--- /dev/null
@@ -0,0 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Ericsson - Initial API and implementation
+ *******************************************************************************/
+
+@org.eclipse.jdt.annotation.NonNullByDefault package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readwrite;
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/ITmfXmlTopLevelElement.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/ITmfXmlTopLevelElement.java
new file mode 100644 (file)
index 0000000..6cdae08
--- /dev/null
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module;
+
+/**
+ * Interface implemented by all classes representing XML top-level elements, for
+ * example state providers and views
+ *
+ * @author Geneviève Bastien
+ */
+public interface ITmfXmlTopLevelElement {
+
+    /**
+     * Get the requested value for an attribute. If the value is a pre-defined
+     * value, we return the string corresponding in the defined values map in
+     * the top-level XML element.
+     *
+     * @param name
+     *            the string to get
+     * @return the actual string value
+     */
+    String getAttributeValue(String name);
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/IXmlStateSystemContainer.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/IXmlStateSystemContainer.java
new file mode 100644 (file)
index 0000000..d00d4ea
--- /dev/null
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlLocation;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
+
+/**
+ * Interface that all XML defined objects who provide, use or contain state
+ * system must implement in order to use the state provider model elements in
+ * {@link org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model} package
+ *
+ * @author Geneviève Bastien
+ */
+public interface IXmlStateSystemContainer extends ITmfXmlTopLevelElement {
+
+    /** Root quark, to get values at the root of the state system */
+    int ROOT_QUARK = -1;
+    /**
+     * Error quark, value taken when a state system quark query is in error.
+     *
+     * FIXME: Originally in the code, the -1 was used for both root quark and
+     * return errors, so it has the same value as root quark, but maybe it can
+     * be changed to something else -2? A quark can never be negative
+     */
+    int ERROR_QUARK = -1;
+
+    /**
+     * Get the state system managed by this XML object
+     *
+     * @return The state system
+     */
+    ITmfStateSystem getStateSystem();
+
+    /**
+     * Get the list of locations defined in this top level XML element
+     *
+     * @return The list of {@link TmfXmlLocation}
+     */
+    @NonNull Iterable<@NonNull TmfXmlLocation> getLocations();
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/Messages.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/Messages.java
new file mode 100644 (file)
index 0000000..e6246b2
--- /dev/null
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Externalized messages for the XML analysis module package
+ *
+ * @author Geneviève Bastien
+ */
+public class Messages extends NLS {
+    private static final String BUNDLE_NAME = "org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.messages"; //$NON-NLS-1$
+
+    /** Property name for file */
+    public static String XmlModuleHelper_PropertyFile;
+
+    /** Property name for type */
+    public static String XmlModuleHelper_PropertyType;
+
+    /** Error copying XML file to workspace folder */
+    public static String XmlUtils_ErrorCopyingFile;
+    /** XML parse error */
+    public static String XmlUtils_XmlParseError;
+    /** Error occurred while validating XML */
+    public static String XmlUtils_XmlValidateError;
+    /** XML validation error */
+    public static String XmlUtils_XmlValidationError;
+
+    static {
+        // initialize resource bundle
+        NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+    }
+
+    private Messages() {
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/TmfAnalysisModuleHelperXml.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/TmfAnalysisModuleHelperXml.java
new file mode 100644 (file)
index 0000000..84bcf32
--- /dev/null
@@ -0,0 +1,236 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2016 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternAnalysis;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
+import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
+import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper;
+import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisManager;
+import org.eclipse.tracecompass.tmf.core.analysis.requirements.TmfAnalysisRequirement;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
+import org.eclipse.tracecompass.tmf.core.project.model.ITmfPropertiesProvider;
+import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
+import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.osgi.framework.Bundle;
+import org.w3c.dom.Element;
+
+/**
+ * Analysis module helpers for modules provided by XML files
+ *
+ * @author Geneviève Bastien
+ * @since 2.0
+ */
+public class TmfAnalysisModuleHelperXml implements IAnalysisModuleHelper, ITmfPropertiesProvider {
+
+    /**
+     * The types of analysis that can be XML-defined
+     */
+    public enum XmlAnalysisModuleType {
+        /** Analysis will be of type XmlStateSystemModule */
+        STATE_SYSTEM,
+
+        /**
+         * Analysis will be of type XmlPatternAnalysisModule
+         *
+         * @since 2.0
+         */
+        PATTERN
+    }
+
+    private final File fSourceFile;
+    private final Element fSourceElement;
+    private final XmlAnalysisModuleType fType;
+
+    /**
+     * Constructor
+     *
+     * @param xmlFile
+     *            The XML file containing the details of this analysis
+     * @param node
+     *            The XML node element
+     * @param type
+     *            The type of analysis
+     */
+    public TmfAnalysisModuleHelperXml(File xmlFile, Element node, XmlAnalysisModuleType type) {
+        fSourceFile = xmlFile;
+        fSourceElement = node;
+        fType = type;
+    }
+
+    @Override
+    public String getId() {
+        /*
+         * The attribute ID cannot be null because the XML has been validated
+         * and it is mandatory
+         */
+        return fSourceElement.getAttribute(TmfXmlStrings.ID);
+    }
+
+    @Override
+    public String getName() {
+        String name = null;
+        /* Label may be available in XML header */
+        List<Element> head = XmlUtils.getChildElements(fSourceElement, TmfXmlStrings.HEAD);
+        if (head.size() == 1) {
+            List<Element> labels = XmlUtils.getChildElements(head.get(0), TmfXmlStrings.LABEL);
+            if (!labels.isEmpty()) {
+                name = labels.get(0).getAttribute(TmfXmlStrings.VALUE);
+            }
+        }
+
+        if (name == null) {
+            name = getId();
+        }
+        return name;
+    }
+
+    @Override
+    public boolean isAutomatic() {
+        return false;
+    }
+
+    /**
+     * @since 1.0
+     */
+    @Override
+    public boolean appliesToExperiment() {
+        return false;
+    }
+
+    @Override
+    public String getHelpText() {
+        return ""; //$NON-NLS-1$
+    }
+
+    @Override
+    public String getHelpText(@NonNull ITmfTrace trace) {
+        return ""; //$NON-NLS-1$
+    }
+
+    @Override
+    public String getIcon() {
+        return null;
+    }
+
+    @Override
+    public Bundle getBundle() {
+        return Activator.getDefault().getBundle();
+    }
+
+    @Override
+    public boolean appliesToTraceType(Class<? extends ITmfTrace> traceClass) {
+        /* Trace types may be available in XML header */
+        List<Element> head = XmlUtils.getChildElements(fSourceElement, TmfXmlStrings.HEAD);
+        if (head.size() != 1) {
+            return true;
+        }
+        /*
+         * TODO: Test with custom trace types
+         */
+        List<Element> elements = XmlUtils.getChildElements(head.get(0), TmfXmlStrings.TRACETYPE);
+        if (elements.isEmpty()) {
+            return true;
+        }
+
+        for (Element element : elements) {
+            String traceTypeId = element.getAttribute(TmfXmlStrings.ID);
+            traceTypeId = TmfTraceType.buildCompatibilityTraceTypeId(traceTypeId);
+            TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
+            if ((helper != null) && helper.getTrace().getClass().isAssignableFrom(traceClass)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public Iterable<Class<? extends ITmfTrace>> getValidTraceTypes() {
+        return Collections.EMPTY_SET;
+    }
+
+    @Override
+    public Iterable<TmfAnalysisRequirement> getAnalysisRequirements() {
+        return Collections.EMPTY_SET;
+    }
+
+    @Override
+    public IAnalysisModule newModule(ITmfTrace trace) throws TmfAnalysisException {
+        String analysisid = getId();
+        IAnalysisModule module = null;
+        switch (fType) {
+        case STATE_SYSTEM:
+            module = new XmlStateSystemModule();
+            XmlStateSystemModule ssModule = (XmlStateSystemModule) module;
+            module.setId(analysisid);
+            ssModule.setXmlFile(new Path(fSourceFile.getAbsolutePath()));
+
+            /*
+             * FIXME: There is no way to know if a module is automatic, so we
+             * default to true
+             */
+            ssModule.setAutomatic(true);
+
+            break;
+        case PATTERN:
+            module = new XmlPatternAnalysis();
+            module.setName(getName());
+            module.setId(analysisid);
+            XmlPatternAnalysis paModule = (XmlPatternAnalysis) module;
+            paModule.setXmlFile(new Path(fSourceFile.getAbsolutePath()));
+
+            /*
+             * FIXME: Maybe the pattern analysis should not be automatic.
+             */
+            paModule.setAutomatic(true);
+
+            break;
+        default:
+            break;
+
+        }
+        if (module != null) {
+            if (module.setTrace(trace)) {
+                TmfAnalysisManager.analysisModuleCreated(module);
+            } else {
+                /* The analysis does not apply to the trace, dispose of the module */
+                module.dispose();
+                module = null;
+            }
+        }
+
+        return module;
+    }
+
+    // ------------------------------------------------------------------------
+    // ITmfPropertiesProvider
+    // ------------------------------------------------------------------------
+
+    @Override
+    public @NonNull Map<@NonNull String, @NonNull String> getProperties() {
+        Map<@NonNull String, @NonNull String> properties = new HashMap<>();
+        properties.put(NonNullUtils.checkNotNull(Messages.XmlModuleHelper_PropertyFile), fSourceFile.getName());
+        properties.put(NonNullUtils.checkNotNull(Messages.XmlModuleHelper_PropertyType), fType.name());
+        return properties;
+    }
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/XmlAnalysisModuleSource.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/XmlAnalysisModuleSource.java
new file mode 100644 (file)
index 0000000..0e7cdff
--- /dev/null
@@ -0,0 +1,204 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2016 École Polytechnique de Montréal and others
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.nio.channels.FileChannel;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.TmfAnalysisModuleHelperXml.XmlAnalysisModuleType;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper;
+import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleSource;
+import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisManager;
+import org.osgi.framework.Bundle;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * Analysis module source who creates helpers for the analysis modules described
+ * in the imported XML files
+ *
+ * @author Geneviève Bastien
+ * @since 2.0
+ */
+public class XmlAnalysisModuleSource implements IAnalysisModuleSource {
+
+    /** Extension point ID */
+    private static final String TMF_XML_BUILTIN_ID = "org.eclipse.linuxtools.tmf.analysis.xml.core.files"; //$NON-NLS-1$
+    private static final String XML_FILE_ELEMENT = "xmlfile"; //$NON-NLS-1$
+
+    private static final String XML_FILE_ATTRIB = "file"; //$NON-NLS-1$
+
+    /*
+     * Legacy (Linux Tools) XML directory.
+     * TODO Remove once we feel the transition phase is over.
+     */
+    private static final IPath XML_DIRECTORY_LEGACY =
+            Activator.getDefault().getStateLocation().removeLastSegments(1)
+            .append("org.eclipse.linuxtools.tmf.analysis.xml.core") //$NON-NLS-1$
+            .append("xml_files"); //$NON-NLS-1$
+
+    private static List<@NonNull IAnalysisModuleHelper> fModules = null;
+
+    /**
+     * Constructor. It adds the new module listener to the analysis manager.
+     */
+    public XmlAnalysisModuleSource() {
+
+    }
+
+    @Override
+    public synchronized Iterable<IAnalysisModuleHelper> getAnalysisModules() {
+        List<@NonNull IAnalysisModuleHelper> modules = fModules;
+        if (modules == null) {
+            modules = new ArrayList<>();
+            fModules = modules;
+            populateBuiltinModules();
+            populateAnalysisModules();
+        }
+        return modules;
+    }
+
+    private static void processFile(File xmlFile) {
+        if (!XmlUtils.xmlValidate(xmlFile).isOK()) {
+            return;
+        }
+
+        try {
+            /* Load the XML File */
+            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+            Document doc = dBuilder.parse(xmlFile);
+            doc.getDocumentElement().normalize();
+
+            /* get State Providers modules */
+            NodeList stateproviderNodes = doc.getElementsByTagName(TmfXmlStrings.STATE_PROVIDER);
+            for (int i = 0; i < stateproviderNodes.getLength(); i++) {
+                Element node = (Element) stateproviderNodes.item(i);
+
+                IAnalysisModuleHelper helper = new TmfAnalysisModuleHelperXml(xmlFile, node, XmlAnalysisModuleType.STATE_SYSTEM);
+                fModules.add(helper);
+            }
+
+            /* get pattern modules */
+            NodeList patternNodes = doc.getElementsByTagName(TmfXmlStrings.PATTERN);
+            for (int i = 0; i < patternNodes.getLength(); i++) {
+                Element node = (Element) patternNodes.item(i);
+
+                IAnalysisModuleHelper helper = new TmfAnalysisModuleHelperXml(xmlFile, node, XmlAnalysisModuleType.PATTERN);
+                fModules.add(helper);
+            }
+        } catch (ParserConfigurationException | SAXException | IOException e) {
+            Activator.logError("Error opening XML file", e); //$NON-NLS-1$
+        }
+    }
+
+    private static void populateBuiltinModules() {
+        /* Get the XML files advertised through the extension point */
+        IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(TMF_XML_BUILTIN_ID);
+        for (IConfigurationElement element : elements) {
+            if (element.getName().equals(XML_FILE_ELEMENT)) {
+                final String filename = element.getAttribute(XML_FILE_ATTRIB);
+                final String name = element.getContributor().getName();
+                // Run this in a safe runner in case there is an exception
+                // (IOException, FileNotFoundException, NPE, etc).
+                // This makes sure other extensions are not prevented from
+                // working if one is faulty.
+                SafeRunner.run(new ISafeRunnable() {
+
+                    @Override
+                    public void run() throws IOException {
+                        if (name != null) {
+                            Bundle bundle = Platform.getBundle(name);
+                            if (bundle != null) {
+                                URL xmlUrl = bundle.getResource(filename);
+                                if (xmlUrl == null) {
+                                    throw new FileNotFoundException(filename);
+                                }
+                                URL locatedURL = FileLocator.toFileURL(xmlUrl);
+                                processFile(new File(locatedURL.getFile()));
+                            }
+                        }
+                    }
+
+                    @Override
+                    public void handleException(Throwable exception) {
+                        // Handled sufficiently in SafeRunner
+                    }
+                });
+            }
+        }
+    }
+
+    private static void populateAnalysisModules() {
+        IPath pathToFiles = XmlUtils.getXmlFilesPath();
+        File folder = pathToFiles.toFile();
+        if (!(folder.isDirectory() && folder.exists())) {
+            return;
+        }
+        /*
+         * Transfer files from Linux Tools directory.
+         */
+        File oldFolder = XML_DIRECTORY_LEGACY.toFile();
+        final File[] oldAnalysisFiles = oldFolder.listFiles();
+        if (oldAnalysisFiles != null) {
+            for (File fromFile : oldAnalysisFiles) {
+                File toFile = pathToFiles.append(fromFile.getName()).toFile();
+                if (!toFile.exists() && !fromFile.isDirectory()) {
+                    try (FileInputStream fis = new FileInputStream(fromFile);
+                            FileOutputStream fos = new FileOutputStream(toFile);
+                            FileChannel source = fis.getChannel();
+                            FileChannel destination = fos.getChannel();) {
+                        destination.transferFrom(source, 0, source.size());
+                    } catch (IOException e) {
+                        String error = Messages.XmlUtils_ErrorCopyingFile;
+                        Activator.logError(error, e);
+                    }
+                }
+            }
+        }
+        Map<String, File> files = XmlUtils.listFiles();
+        for (File xmlFile : files.values()) {
+            processFile(xmlFile);
+        }
+    }
+
+    /**
+     * Notifies the main XML analysis module that the executable modules list
+     * may have changed and needs to be refreshed.
+     */
+    public static void notifyModuleChange() {
+        fModules = null;
+        TmfAnalysisManager.refreshModules();
+    }
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/XmlUtils.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/XmlUtils.java
new file mode 100644 (file)
index 0000000..53619e3
--- /dev/null
@@ -0,0 +1,374 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2016 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module;
+
+import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.nio.channels.FileChannel;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Class containing some utilities for the XML plug-in packages: for example, it
+ * manages the XML files and validates them
+ *
+ * @author Geneviève Bastien
+ */
+public class XmlUtils {
+
+    /** Sub-directory of the plug-in where XML files are stored */
+    private static final String XML_DIRECTORY = "xml_files"; //$NON-NLS-1$
+
+    /** Name of the XSD schema file */
+    private static final String XSD = "xmlDefinition.xsd"; //$NON-NLS-1$
+
+    /**
+     * Extension for XML files
+     * @since 2.0
+     */
+    public static final String XML_EXTENSION = "xml"; //$NON-NLS-1$
+
+    /** Make this class non-instantiable */
+    private XmlUtils() {
+
+    }
+
+    /**
+     * Get the path where the XML files are stored. Create it if it does not
+     * exist
+     *
+     * @return path to XML files
+     */
+    public static IPath getXmlFilesPath() {
+        IPath path = Activator.getDefault().getStateLocation();
+        path = path.addTrailingSeparator().append(XML_DIRECTORY);
+
+        /* Check if directory exists, otherwise create it */
+        File dir = path.toFile();
+        if (!dir.exists() || !dir.isDirectory()) {
+            dir.mkdirs();
+        }
+
+        return path;
+    }
+
+    /**
+     * Validate the XML file input with the XSD schema
+     *
+     * @param xmlFile
+     *            XML file to validate
+     * @return True if the XML validates
+     */
+    public static IStatus xmlValidate(File xmlFile) {
+        URL url = XmlUtils.class.getResource(XSD);
+        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+        Source xmlSource = new StreamSource(xmlFile);
+        try {
+            Schema schema = schemaFactory.newSchema(url);
+            Validator validator = schema.newValidator();
+            validator.validate(xmlSource);
+        } catch (SAXParseException e) {
+            String error = NLS.bind(Messages.XmlUtils_XmlParseError, e.getLineNumber(), e.getLocalizedMessage());
+            Activator.logError(error);
+            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, error, e);
+        } catch (SAXException e) {
+            String error = NLS.bind(Messages.XmlUtils_XmlValidationError, e.getLocalizedMessage());
+            Activator.logError(error);
+            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, error, e);
+        } catch (IOException e) {
+            String error = Messages.XmlUtils_XmlValidateError;
+            Activator.logError("IO exception occurred", e); //$NON-NLS-1$
+            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, error, e);
+        }
+        return Status.OK_STATUS;
+    }
+
+    /**
+     * Adds an XML file to the plugin's path. The XML file should have been
+     * validated using the {@link XmlUtils#xmlValidate(File)} method before
+     * calling this method.
+     *
+     * @param fromFile
+     *            The XML file to add
+     * @return Whether the file was successfully added
+     */
+    public static IStatus addXmlFile(File fromFile) {
+
+        /* Copy file to path */
+        File toFile = getXmlFilesPath().addTrailingSeparator().append(fromFile.getName()).toFile();
+
+        return copyXmlFile(fromFile, toFile);
+    }
+
+    /**
+     * List all files under the XML analysis files path. It returns a map where
+     * the key is the file name.
+     *
+     * @return A map with all the XML analysis files
+     * @since 2.0
+     */
+    public static synchronized @NonNull Map<String, File> listFiles() {
+        IPath pathToFiles = XmlUtils.getXmlFilesPath();
+        File folder = pathToFiles.toFile();
+
+        Map<String, File> fileMap = new HashMap<>();
+        if ((folder.isDirectory() && folder.exists())) {
+            File[] listOfFiles = folder.listFiles();
+            if (listOfFiles != null) {
+                for (File file : listOfFiles) {
+                    IPath path = new Path(file.getName());
+                    if (path.getFileExtension().equals(XML_EXTENSION)) {
+                        fileMap.put(file.getName(), file);
+                    }
+                }
+            } else {
+                Activator.logError("I/O error occured while accessing files in folder " + folder.getPath()); //$NON-NLS-1$
+            }
+        }
+        return Collections.unmodifiableMap(fileMap);
+    }
+
+    /**
+     * Delete an XML analysis file
+     *
+     * @param name
+     *            The XML file to delete
+     * @since 2.0
+     */
+    public static void deleteFile(String name) {
+        Map<String, File> files = listFiles();
+        File file = files.get(name);
+        if (file == null) {
+            return;
+        }
+        file.delete();
+    }
+
+    /**
+     * Export an XML analysis file to an external path
+     *
+     * @param from
+     *            The name of the file to export
+     * @param to
+     *            The full path of the file to write to
+     * @return Whether the file was successfully exported
+     * @since 2.0
+     */
+    public static IStatus exportXmlFile(String from, String to) {
+
+        /* Copy file to path */
+        File fromFile = getXmlFilesPath().addTrailingSeparator().append(from).toFile();
+
+        if (!fromFile.exists()) {
+            Activator.logError("Failed to find XML analysis file " + fromFile.getName()); //$NON-NLS-1$
+            return Status.CANCEL_STATUS;
+        }
+
+        File toFile = new File(to);
+
+        return copyXmlFile(fromFile, toFile);
+    }
+
+    private static IStatus copyXmlFile(File fromFile, File toFile) {
+        try {
+            if (!toFile.exists()) {
+                toFile.createNewFile();
+            }
+        } catch (IOException e) {
+            String error = Messages.XmlUtils_ErrorCopyingFile;
+            Activator.logError(error, e);
+            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, error, e);
+        }
+
+        try (FileInputStream fis = new FileInputStream(fromFile);
+                FileOutputStream fos = new FileOutputStream(toFile);
+                FileChannel source = fis.getChannel();
+                FileChannel destination = fos.getChannel();) {
+            destination.transferFrom(source, 0, source.size());
+        } catch (IOException e) {
+            String error = Messages.XmlUtils_ErrorCopyingFile;
+            Activator.logError(error, e);
+            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, error, e);
+        }
+        return Status.OK_STATUS;
+    }
+
+    /**
+     * Get the IDs of all the analysis described in a single file
+     *
+     * @param fileName
+     *            The file name
+     * @return The list of IDs
+     * @since 2.0
+     */
+    public static List<String> getAnalysisIdsFromFile(String fileName) {
+        List<String> ids = new ArrayList<>();
+        File file = getXmlFilesPath().addTrailingSeparator().append(fileName).toFile();
+        if (file.exists()) {
+            try {
+                /* Load the XML File */
+                DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+                DocumentBuilder dBuilder;
+                dBuilder = dbFactory.newDocumentBuilder();
+                Document doc = dBuilder.parse(file);
+                doc.getDocumentElement().normalize();
+
+                /* get State Providers modules */
+                NodeList stateproviderNodes = doc.getElementsByTagName(TmfXmlStrings.STATE_PROVIDER);
+                for (int i = 0; i < stateproviderNodes.getLength(); i++) {
+                    ids.add(nullToEmptyString(((Element) stateproviderNodes.item(i)).getAttribute(TmfXmlStrings.ID)));
+                }
+
+                /* get patterns modules */
+                NodeList patternNodes = doc.getElementsByTagName(TmfXmlStrings.PATTERN);
+                for (int i = 0; i < patternNodes.getLength(); i++) {
+                    ids.add(nullToEmptyString(((Element) patternNodes.item(i)).getAttribute(TmfXmlStrings.ID)));
+                }
+            } catch (ParserConfigurationException | SAXException | IOException e) {
+                Activator.logError("Failed to get analyses IDs from " + fileName); //$NON-NLS-1$
+            }
+        }
+        return ids;
+    }
+
+    /**
+     * Get only the XML element children of an XML element.
+     *
+     * @param parent
+     *            The parent element to get children from
+     * @return The list of children Element of the parent
+     */
+    public static @NonNull List<@Nullable Element> getChildElements(Element parent) {
+        NodeList childNodes = parent.getChildNodes();
+        List<@Nullable Element> childElements = new ArrayList<>();
+        for (int index = 0; index < childNodes.getLength(); index++) {
+            if (childNodes.item(index).getNodeType() == Node.ELEMENT_NODE) {
+                childElements.add((Element) childNodes.item(index));
+            }
+        }
+        return childElements;
+    }
+
+    /**
+     * Get the XML children element of an XML element, but only those of a
+     * certain type
+     *
+     * @param parent
+     *            The parent element to get the children from
+     * @param elementTag
+     *            The tag of the elements to return
+     * @return The list of children {@link Element} of the parent
+     */
+    public static List<@NonNull Element> getChildElements(Element parent, String elementTag) {
+        /* get the state providers and find the corresponding one */
+        NodeList nodes = parent.getElementsByTagName(elementTag);
+        List<@NonNull Element> childElements = new ArrayList<>();
+
+        for (int i = 0; i < nodes.getLength(); i++) {
+            Element node = (Element) nodes.item(i);
+            if (node.getParentNode().equals(parent)) {
+                childElements.add(node);
+            }
+        }
+        return childElements;
+    }
+
+    /**
+     * Return the node element corresponding to the requested type in the file.
+     *
+     * TODO: Nothing prevents from having duplicate type -> id in a same file.
+     * That should not be allowed. If you want an element with the same ID as
+     * another one, it should be in a different file and we should check it at
+     * validation time.
+     *
+     * @param filePath
+     *            The absolute path to the XML file
+     * @param elementType
+     *            The type of top level element to search for
+     * @param elementId
+     *            The ID of the desired element
+     * @return The XML element or <code>null</code> if not found
+     */
+    public static Element getElementInFile(String filePath, @NonNull String elementType, @NonNull String elementId) {
+
+        if (filePath == null) {
+            return null;
+        }
+
+        IPath path = new Path(filePath);
+        File file = path.toFile();
+        if (file == null || !file.exists() || !file.isFile() || !xmlValidate(file).isOK()) {
+            return null;
+        }
+
+        try {
+            /* Load the XML File */
+            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+            DocumentBuilder dBuilder;
+
+            dBuilder = dbFactory.newDocumentBuilder();
+            Document doc = dBuilder.parse(file);
+            doc.getDocumentElement().normalize();
+
+            /* get the state providers and find the corresponding one */
+            NodeList nodes = doc.getElementsByTagName(elementType);
+            Element foundNode = null;
+
+            for (int i = 0; i < nodes.getLength(); i++) {
+                Element node = (Element) nodes.item(i);
+                String id = node.getAttribute(TmfXmlStrings.ID);
+                if (id.equals(elementId)) {
+                    foundNode = node;
+                }
+            }
+            return foundNode;
+        } catch (ParserConfigurationException | SAXException | IOException e) {
+            return null;
+        }
+
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/messages.properties b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/messages.properties
new file mode 100644 (file)
index 0000000..9622a76
--- /dev/null
@@ -0,0 +1,17 @@
+###############################################################################
+# Copyright (c) 2014 Ericsson
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#    Ericsson - Initial API and implementation
+###############################################################################
+XmlModuleHelper_PropertyFile=Source XML File
+XmlModuleHelper_PropertyType=Type of analysis
+XmlUtils_ErrorCopyingFile=An error occurred while copying the XML file to the TMF directory. The file was not imported.
+XmlUtils_XmlParseError=XML Parsing error at line {0}: {1}
+XmlUtils_XmlValidateError=An error occurred while validating the XML file.
+XmlUtils_XmlValidationError=Error validating XML file {0}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlCommon.xsd b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlCommon.xsd
new file mode 100644 (file)
index 0000000..453a219
--- /dev/null
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- ***************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Florian Wininger - Initial API and implementation
+ *************************************************************************** -->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+       attributeFormDefault="unqualified" elementFormDefault="qualified">
+
+       <xs:complexType name="definedValue">
+               <xs:annotation>
+                       <xs:documentation>Maps a string (usually a human-readable value used by the XML elements) to another string (a value in the system, which can be converted to an integer, long by the a stateValue element or used as-is).</xs:documentation></xs:annotation>
+               <xs:attribute name="name" type="xs:string" use="required" >
+                       <xs:annotation>
+                               <xs:documentation>The human-readable string to identify this value. This is what will be manipulated by the XML and shown to the end-user (if applicable).</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="value" type="xs:string" use="required" >
+                       <xs:annotation>
+                               <xs:documentation>A system value the 'name' maps to. It will usually not be shown to the end user.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="color" type="xs:string" use="optional" >
+                       <xs:annotation>
+                               <xs:documentation>Optional color attribute to this mapping. This attribute is used in XML-defined views to represent this mapping.</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="location">
+               <xs:annotation>
+                       <xs:documentation>Define a path in a state system, that can then be used as a shortcut in other XML elements.</xs:documentation></xs:annotation>
+               <xs:sequence>
+                       <xs:element maxOccurs="unbounded" minOccurs="0" name="stateAttribute" type="stateAttribute" >
+                               <xs:annotation>
+                                       <xs:documentation>Define each element of the path represented by this location. For instance, if location "abc" has path "a/b/c", there would be a sequence of 3 stateAttribute elements of type constant.</xs:documentation></xs:annotation></xs:element>
+               </xs:sequence>
+               <xs:attribute name="id" type="xs:string" use="required" >
+                       <xs:annotation>
+                               <xs:documentation>The identifier of this location, used inside the XML element in the scope of which it is defined.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:anyAttribute />
+       </xs:complexType>
+
+</xs:schema>
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlDefinition.xsd b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlDefinition.xsd
new file mode 100644 (file)
index 0000000..492ddc1
--- /dev/null
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- ***************************************************************************
+ * Copyright (c) 2014, 2015 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Florian Wininger - Initial API and implementation
+ *************************************************************************** -->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+       attributeFormDefault="unqualified" elementFormDefault="qualified">
+
+       <xs:include schemaLocation="xmlCommon.xsd" />
+       <xs:include schemaLocation="xmlStateProvider.xsd" />
+       <xs:include schemaLocation="xmlPatternStateProvider.xsd" />
+       <xs:include schemaLocation="xmlView.xsd" />
+       <xs:element name="tmfxml">
+               <xs:complexType>
+                       <xs:choice maxOccurs="unbounded">
+                               <xs:element maxOccurs="unbounded" minOccurs="0" name="timeGraphView" type="timeGraphView" >
+                                       <xs:annotation>
+                                               <xs:documentation>Define a new time graph view.</xs:documentation></xs:annotation></xs:element>
+                               <xs:element maxOccurs="unbounded" minOccurs="0" name="xyView" type="xyView" >
+                                       <xs:annotation>
+                                               <xs:documentation>Define a new XY chart view.</xs:documentation></xs:annotation></xs:element>
+                               <xs:element maxOccurs="unbounded" minOccurs="0" name="stateProvider" type="stateProvider" >
+                                       <xs:annotation>
+                                               <xs:documentation>Define a new state provider</xs:documentation></xs:annotation></xs:element>
+                               <xs:element maxOccurs="unbounded" minOccurs="0" name="pattern" type="pattern" >
+                                       <xs:annotation>
+                                               <xs:documentation>Define a new pattern analysis</xs:documentation></xs:annotation></xs:element>
+                       </xs:choice>
+               </xs:complexType>
+       </xs:element>
+
+</xs:schema>
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlPatternStateProvider.xsd b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlPatternStateProvider.xsd
new file mode 100644 (file)
index 0000000..042fa19
--- /dev/null
@@ -0,0 +1,460 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- ***************************************************************************
+ * Copyright (c) 2016 École Polytechnique de Montréal and others
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *************************************************************************** -->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+       attributeFormDefault="unqualified" elementFormDefault="qualified">
+       <xs:complexType name="pattern">
+               <xs:annotation>
+                       <xs:documentation>Declares a pattern provider which defines one or several sequences of trace data that one would want to locate within the trace. Each pattern provider defined in XML will become an analysis in Trace Compass.</xs:documentation></xs:annotation>
+               <xs:sequence maxOccurs="1" minOccurs="1">
+                       <xs:element maxOccurs="1" minOccurs="0" name="head" type="headPattern" >
+                               <xs:annotation>
+                                       <xs:documentation>Provides meta-information on this pattern provider, like labels and applicable trace types.</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="unbounded" minOccurs="0" name="storedField" type="storedField" >
+                               <xs:annotation>
+                                       <xs:documentation>Defines a data from the trace event that will be stored in the database with the specified name. It is a way to save and update the value of a field of the trace events each time it will be seen. For instance, it can be used to save the value of the field 'fd' each time it will be seen.</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="unbounded" minOccurs="0" name="definedValue" type="definedValue" >
+                               <xs:annotation>
+                                       <xs:documentation>Defines a value that maps a string used in the pattern state provider to a numbered value.</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="unbounded" minOccurs="0" name="location" type="location" >
+                               <xs:annotation>
+                                       <xs:documentation>Declares shortcuts to frequently used attribute/data locations. For instance, if a path to an often-used attribute is CPUs/{event.some_field}/Threads/Status, it may be a good idea to put this path in a location and then use the location name in the event handlers.</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="1" minOccurs="1" name="patternHandler" type="patternHandler" >
+                               <xs:annotation>
+                                       <xs:documentation>Describes the pattern behavior. It defines all the entities; i.e., all the transitions, actions and state machines that describe the pattern.</xs:documentation></xs:annotation></xs:element>
+               </xs:sequence>
+               <xs:attribute name="id" type="xs:string" use="required" >
+                       <xs:annotation>
+                               <xs:documentation>The unique ID of this pattern provider. It will be used to identify the analysis that will be built from this pattern provider.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="version" type="xs:integer" use="required" >
+                       <xs:annotation>
+                               <xs:documentation>The version ID of this pattern provider. Whenever the pattern provider changes so that the resulting state system is different from previous versions, this version number should be bumped.</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="headPattern">
+               <xs:annotation>
+                       <xs:documentation>Declares the meta-information that can be defined for an XML pattern provider.</xs:documentation></xs:annotation>
+               <xs:sequence>
+                       <xs:element maxOccurs="unbounded" minOccurs="0" name="traceType">
+                               <xs:annotation>
+                                       <xs:documentation>Indicates that the pattern provider applies to a given trace type.</xs:documentation></xs:annotation>
+                               <xs:complexType>
+                                       <xs:attribute name="id" use="required" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The ID of the trace type, as declared in a org.eclipse.linuxtools.tmf.core.tracetype extension point or a custom trace parser. For example: "org.eclipse.linuxtools.lttng2.kernel.tracetype" or "org.eclipse.linuxtools.lttng2.ust.tracetype" for respectively LTTng Kernel and LTTng UST traces.</xs:documentation></xs:annotation></xs:attribute>
+                               </xs:complexType>
+                       </xs:element>
+                       <xs:element maxOccurs="1" minOccurs="0" name="label">
+                               <xs:annotation>
+                                       <xs:documentation>Adds a label to the pattern provider. If provided, this text will be the name of the analysis that the user will see in Trace Compass.</xs:documentation></xs:annotation>
+                               <xs:complexType>
+                                       <xs:attribute name="value" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The text to name this pattern provider (and the analysis it will generate).</xs:documentation></xs:annotation></xs:attribute>
+                               </xs:complexType>
+                       </xs:element>
+               </xs:sequence>
+       </xs:complexType>
+
+       <xs:complexType name="storedField">
+               <xs:annotation>
+                       <xs:documentation>Declares an event data that will be saved in the database each time it will be seen. It is used to save fields that could appear often in the events stream. The data saved could be added to the pattern segment as fields when they will be generated.</xs:documentation></xs:annotation>
+               <xs:attribute name="id" type="xs:string" use="required">
+                       <xs:annotation>
+                               <xs:documentation>The id of the data in the incoming events.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="alias" type="xs:string" use="optional">
+                       <xs:annotation>
+                               <xs:documentation>The alias that the event data will have in the database.</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="patternHandler">
+               <xs:annotation>
+                       <xs:documentation>Declares the entities necessary to describe the pattern behavior.</xs:documentation></xs:annotation>
+               <xs:sequence maxOccurs="unbounded" minOccurs="1">
+                       <xs:choice maxOccurs="unbounded" minOccurs="0">
+                               <xs:element maxOccurs="unbounded" minOccurs="0" name="test" type="test" >
+                                       <xs:annotation>
+                                               <xs:documentation>Defines a condition that could be used in the FSMs as transition to trigger state changes into them.</xs:documentation></xs:annotation></xs:element>
+                               <xs:element maxOccurs="unbounded" minOccurs="0" name="action" type="action">
+                                       <xs:annotation>
+                                               <xs:documentation>Defines an action that could be executed when leaving a state of an FSM.</xs:documentation></xs:annotation></xs:element>
+                       </xs:choice>
+                       <xs:element maxOccurs="unbounded" minOccurs="1" name="fsm" type="state">
+                               <xs:annotation>
+                                       <xs:documentation>Defines a finite state machine that will describe the behavior or a part of the behavior of a pattern. The FSM uses the transitions described to modify its behavior and can execute actions. Each pattern could have one or several FSMs to describe its behavior.</xs:documentation></xs:annotation></xs:element>
+               </xs:sequence>
+               <xs:attribute name="initial" type="xs:string" use="optional">
+                       <xs:annotation>
+                                       <xs:documentation>Lists the state machines (FSMs) that will start directly at the beginning of the analysis. For instance, if the pattern need to start with both FSM A and B, the value of this attribute will be "A:B"</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="test">
+               <xs:annotation>
+                                       <xs:documentation>Defines a test condition that will be validated in a fsm.".</xs:documentation></xs:annotation>
+               <xs:sequence>
+                       <xs:element maxOccurs="1" minOccurs="0" name="if" type="patternSingleCondition">
+                               <xs:annotation>
+                                       <xs:documentation>Defines a condition element, in the form "if (some_path == value)".</xs:documentation></xs:annotation></xs:element>
+               </xs:sequence>
+               <xs:attribute name="id" type="xs:string" use="required">
+                       <xs:annotation>
+                               <xs:documentation>The id of this test. The id will be used as reference to this test.</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="patternSingleCondition">
+               <xs:choice maxOccurs="1" minOccurs="1">
+                       <xs:element name="condition" type="patternCondition">
+                               <xs:annotation>
+                                       <xs:documentation>Defines a condition element to validate.</xs:documentation></xs:annotation></xs:element>
+                       <xs:element name="not" type="patternSingleCondition" >
+                               <xs:annotation>
+                                       <xs:documentation>Negates the result of the following condition, allowing statements of the form "if (!cond)".</xs:documentation></xs:annotation></xs:element>
+                       <xs:element name="and" type="patternMultipleCondition" >
+                               <xs:annotation>
+                                       <xs:documentation>ANDs 2 conditional statements, allowing statements of the form "if (condA AND condB)"</xs:documentation></xs:annotation></xs:element>
+                       <xs:element name="or" type="patternMultipleCondition" >
+                               <xs:annotation>
+                                       <xs:documentation>ORs 2 conditional statements, allowing statements of the form "if (condA OR condB)"</xs:documentation></xs:annotation></xs:element>
+               </xs:choice>
+       </xs:complexType>
+
+       <xs:complexType name="patternMultipleCondition">
+               <xs:annotation>
+                       <xs:documentation>Allows the composition of more than one conditional statements.</xs:documentation></xs:annotation>
+               <xs:sequence maxOccurs="unbounded" minOccurs="1">
+                       <xs:element maxOccurs="1" minOccurs="0" name="condition" type="patternCondition">
+                               <xs:annotation>
+                                       <xs:documentation>Defines a condition element.</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="1" minOccurs="0" name="or" type="patternMultipleCondition" >
+                               <xs:annotation>
+                                       <xs:documentation>ORs 2 conditional statements, allowing statements of the form "if (condA OR condB)"</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="1" minOccurs="0" name="and" type="patternMultipleCondition" >
+                               <xs:annotation>
+                                       <xs:documentation>ANDs 2 conditional statements, allowing statements of the form "if (condA AND condB)"</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="1" minOccurs="0" name="not" type="patternSingleCondition" >
+                               <xs:annotation>
+                                       <xs:documentation>Negates the result of the following condition, allowing statements of the form "if (!cond)".</xs:documentation></xs:annotation></xs:element>
+               </xs:sequence>
+               <xs:anyAttribute />
+       </xs:complexType>
+
+       <xs:complexType name="patternCondition">
+               <xs:choice maxOccurs="1" minOccurs="1">
+                       <xs:sequence maxOccurs="1" minOccurs="1">
+                               <xs:choice maxOccurs="1">
+                                       <xs:sequence>
+                                               <xs:choice maxOccurs="1" minOccurs="1">
+                                                       <xs:element maxOccurs="unbounded" minOccurs="1" name="stateAttribute" type="stateAttribute" >
+                                                               <xs:annotation>
+                                                                       <xs:documentation>Compares the current value of an attribute of the state system.</xs:documentation></xs:annotation></xs:element>
+                                                       <xs:element maxOccurs="1" minOccurs="1" name="field" type="eventField" >
+                                                               <xs:annotation>
+                                                                       <xs:documentation>Compares the value of an event field.</xs:documentation></xs:annotation></xs:element>
+                                               </xs:choice>
+                                               <xs:element maxOccurs="1" minOccurs="1" name="stateValue" type="stateValue" >
+                                                       <xs:annotation>
+                                                               <xs:documentation>Defines the value to compare to.</xs:documentation></xs:annotation></xs:element>
+                                       </xs:sequence>
+                                       <xs:sequence>
+                                               <xs:element maxOccurs="2" minOccurs="2" name="stateValue" type="stateValue"/>
+                                       </xs:sequence>
+                               </xs:choice>
+                       </xs:sequence>
+
+                       <xs:sequence maxOccurs="1" minOccurs="1">
+                               <xs:element maxOccurs="1" minOccurs="1" name="timerange">
+                               <xs:annotation>
+                                       <xs:documentation>Defines a condition element, in a form like "if (x &lt; value &lt; y)".</xs:documentation></xs:annotation>
+                                       <xs:complexType>
+                                               <xs:choice>
+                                                       <xs:element name="in" type="timeRangeSingleCondition">
+                                                               <xs:annotation>
+                                                                       <xs:documentation>Defines a condition element, in the form "if (x &lt; value &lt; y)".</xs:documentation></xs:annotation></xs:element>
+                                                       <xs:element name="out" type="timeRangeSingleCondition">
+                                                               <xs:annotation>
+                                                                       <xs:documentation>Defines a condition element, in the form "if (value &lt; x || value &gt; y)".</xs:documentation></xs:annotation></xs:element>
+                                               </xs:choice>
+                                               <xs:attribute name="unit" default="ns">
+                                                       <xs:annotation>
+                                                               <xs:documentation>The unit of the timing values used for the condition.</xs:documentation></xs:annotation>
+                                                       <xs:simpleType>
+                                                               <xs:restriction base="xs:string">
+                                                                       <xs:enumeration value="ns">
+                                                                               <xs:annotation>
+                                                                                       <xs:documentation>nanosecond</xs:documentation></xs:annotation></xs:enumeration>
+                                                                       <xs:enumeration value="us">
+                                                                               <xs:annotation>
+                                                                                       <xs:documentation>microsecond</xs:documentation></xs:annotation></xs:enumeration>
+                                                                       <xs:enumeration value="ms">
+                                                                               <xs:annotation>
+                                                                                       <xs:documentation>millisecond</xs:documentation></xs:annotation></xs:enumeration>
+                                                                       <xs:enumeration value="s">
+                                                                               <xs:annotation>
+                                                                                       <xs:documentation>second</xs:documentation></xs:annotation></xs:enumeration>
+                                                               </xs:restriction>
+                                                       </xs:simpleType>
+                                               </xs:attribute>
+                                       </xs:complexType>
+                               </xs:element>
+                       </xs:sequence>
+
+                       <xs:sequence maxOccurs="1" minOccurs="1">
+                               <xs:element maxOccurs="1" minOccurs="1" name="elapsedTime">
+                                       <xs:complexType>
+                                               <xs:choice>
+                                                       <xs:element maxOccurs="1" minOccurs="1" name="less" type="elapsedTimeSingleCondition">
+                                                               <xs:annotation>
+                                                                       <xs:documentation>Defines a condition element, in the form "if (value &lt; x)".</xs:documentation></xs:annotation></xs:element>
+                                                       <xs:element maxOccurs="1" minOccurs="1" name="equal" type="elapsedTimeSingleCondition">
+                                                               <xs:annotation>
+                                                                       <xs:documentation>Defines a condition element, in the form "if (value == x)".</xs:documentation></xs:annotation></xs:element>
+                                                       <xs:element maxOccurs="1" minOccurs="1" name="more" type="elapsedTimeSingleCondition">
+                                                               <xs:annotation>
+                                                                       <xs:documentation>Defines a condition element, in the form "if (value &gt; x)".</xs:documentation></xs:annotation></xs:element>
+                                               </xs:choice>
+                                               <xs:attribute name="unit" default="ns">
+                                                       <xs:annotation>
+                                                               <xs:documentation>The unit of the timing values used for the condition.</xs:documentation></xs:annotation>
+                                                       <xs:simpleType>
+                                                               <xs:restriction base="xs:string">
+                                                                       <xs:enumeration value="ns">
+                                                                               <xs:annotation>
+                                                                                       <xs:documentation>nanosecond</xs:documentation></xs:annotation></xs:enumeration>
+                                                                       <xs:enumeration value="us">
+                                                                               <xs:annotation>
+                                                                                       <xs:documentation>microsecond</xs:documentation></xs:annotation></xs:enumeration>
+                                                                       <xs:enumeration value="ms">
+                                                                               <xs:annotation>
+                                                                                       <xs:documentation>millisecond</xs:documentation></xs:annotation></xs:enumeration>
+                                                                       <xs:enumeration value="s">
+                                                                               <xs:annotation>
+                                                                                       <xs:documentation>second</xs:documentation></xs:annotation></xs:enumeration>
+                                                               </xs:restriction>
+                                                       </xs:simpleType>
+                                               </xs:attribute>
+                                       </xs:complexType>
+                               </xs:element>
+                       </xs:sequence>
+
+               </xs:choice>
+       </xs:complexType>
+
+       <xs:complexType name="timeRangeSingleCondition">
+               <xs:annotation>
+                       <xs:documentation>Defines a timerange condition.</xs:documentation></xs:annotation>
+               <xs:attribute name="begin" type="xs:long" use="required">
+                       <xs:annotation>
+                               <xs:documentation>The timestamp of the beginning of the range.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="end" type="xs:long" use="required">
+                       <xs:annotation>
+                               <xs:documentation>The timestamp of the end of the range.</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="elapsedTimeSingleCondition">
+               <xs:annotation>
+                       <xs:documentation>Defines an elapsed time condition.</xs:documentation></xs:annotation>
+               <xs:attribute name="since" type="xs:string" use="required">
+                       <xs:annotation>
+                               <xs:documentation>The starting point from where the condition will be evaluated.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="value" type="xs:long" use="required">
+                       <xs:annotation>
+                               <xs:documentation>The value used for the comparison.</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="action">
+               <xs:annotation>
+                       <xs:documentation>Define an action that could be executed. Three kind of action are actually supported : state changes, generation of pattern segments and start of a new instance of an FSM.</xs:documentation></xs:annotation>
+               <xs:sequence maxOccurs="unbounded" minOccurs="1">
+                       <xs:choice>
+                               <xs:element maxOccurs="unbounded" minOccurs="0" name="stateChange" type="stateChange">
+                                       <xs:annotation>
+                                               <xs:documentation>Defines how the database is modified by the data provided by the event aspects and the values already stored in the database. A data may cause more than one state change.</xs:documentation></xs:annotation></xs:element>
+                               <xs:element maxOccurs="unbounded" minOccurs="0" name="segment" type="segment">
+                                       <xs:annotation>
+                                               <xs:documentation>Defines a pattern segment that will be generated. The generated segment has content.</xs:documentation></xs:annotation></xs:element>
+                               <xs:element maxOccurs="1" minOccurs="0" name="fsmScheduleAction" type="fsmScheduleAction">
+                                       <xs:annotation>
+                                               <xs:documentation>Declares an FSM that will be scheduled to start.</xs:documentation></xs:annotation></xs:element>
+                               <xs:element maxOccurs="unbounded" minOccurs="0" name="action" type="action">
+                                       <xs:annotation>
+                                               <xs:documentation>Declares an action that will be executed. With this, an action could call another one using its ID.</xs:documentation></xs:annotation></xs:element>
+                       </xs:choice>
+               </xs:sequence>
+               <xs:attribute name="id" type="xs:string" use="required">
+                       <xs:annotation>
+                               <xs:documentation>The ID of the action. This ID is used to reference to this action when needed.</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="fsmScheduleAction">
+               <xs:annotation>
+                       <xs:documentation>Defines an action to start a new instance of an FSM.</xs:documentation></xs:annotation>
+               <xs:attribute name="id" type="xs:string" use="required">
+                       <xs:annotation>
+                               <xs:documentation>The ID of the FSM to start.</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="segment">
+               <xs:annotation>
+                       <xs:documentation>Describes a pattern segment that could be generated by the pattern. A pattern segment is an output of the pattern. It is a segment that would be generated by an FSM in the pattern. Its start will be the start timestamp of the scenario and its end will be the timestamp of the current event. This type of segment has a name and it is possible to add fields.</xs:documentation></xs:annotation>
+               <xs:sequence maxOccurs="1" minOccurs="1">
+                       <xs:element name="segType" >
+                               <xs:annotation>
+                                               <xs:documentation>The XML description of the segment type.</xs:documentation></xs:annotation>
+                               <xs:complexType>
+                                       <xs:sequence maxOccurs="1" minOccurs="0">
+                                               <xs:element maxOccurs="1" name="segName">
+                                                       <xs:annotation>
+                                                               <xs:documentation>Defines the name of the segment. This name could be a value queried from the database or from the event aspects or could be a constant.</xs:documentation></xs:annotation>
+                                                       <xs:complexType>
+                                                               <xs:sequence>
+                                                                       <xs:element maxOccurs="1" minOccurs="1" name="stateValue" type="stateValue">
+                                                                               <xs:annotation>
+                                                                                       <xs:documentation>The value of the segment name.</xs:documentation></xs:annotation></xs:element>
+                                                               </xs:sequence>
+                                                       </xs:complexType>
+                                               </xs:element>
+                                       </xs:sequence>
+                                       <xs:attribute name="segName" type="xs:string" use="optional">
+                                               <xs:annotation>
+                                                       <xs:documentation>The value of the segment name.</xs:documentation></xs:annotation></xs:attribute>
+                               </xs:complexType>
+                       </xs:element>
+                       <xs:element minOccurs="0" name="segContent">
+                               <xs:annotation>
+                                       <xs:documentation>Describes the content of the segment.</xs:documentation></xs:annotation>
+                               <xs:complexType>
+                                       <xs:sequence maxOccurs="1" minOccurs="1">
+                                               <xs:element maxOccurs="unbounded" minOccurs="1" name="segField" type="segField">
+                                                       <xs:annotation>
+                                                               <xs:documentation>Defines a field for the segment.</xs:documentation></xs:annotation></xs:element>
+                                       </xs:sequence>
+                               </xs:complexType>
+                       </xs:element>
+               </xs:sequence>
+       </xs:complexType>
+
+       <xs:complexType name="segField">
+               <xs:annotation>
+                       <xs:documentation>Describes a field for a pattern segment. The value of the field could be a constant or the result of a query to the database or the value of an event aspect.</xs:documentation></xs:annotation>
+               <xs:sequence maxOccurs="1" minOccurs="0">
+                       <xs:annotation>
+                                       <xs:documentation>Defines the value of the field, if it is a data from the ongoing event or if the value is stored in the database.</xs:documentation></xs:annotation>
+                       <xs:element maxOccurs="1" minOccurs="0" name="stateValue" type="stateValue" />
+               </xs:sequence>
+               <xs:attribute name="name" type="xs:string" use="required">
+                       <xs:annotation>
+                               <xs:documentation>Declares the name of the field.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="type" use="required">
+                       <xs:annotation>
+                               <xs:documentation>The type of this field value.</xs:documentation></xs:annotation>
+                       <xs:simpleType>
+                               <xs:restriction base="xs:string">
+                                       <xs:enumeration value="null" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The value is a null value.</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="int" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The value is a constant of type integer.</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="long" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The value is a constant of type long.</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="string" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The value is a constant of type string.</xs:documentation></xs:annotation></xs:enumeration>
+                               </xs:restriction>
+                       </xs:simpleType>
+               </xs:attribute>
+               <xs:attribute name="value" type="xs:string" use="optional">
+                       <xs:annotation>
+                               <xs:documentation>Declares the value of the field, if the value is a constant.</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="initialState">
+               <xs:sequence>
+                       <xs:element maxOccurs="unbounded" minOccurs="1" name="transition" type="transition">
+                               <xs:annotation>
+                                       <xs:documentation>Declares a transition for the state.</xs:documentation></xs:annotation></xs:element>
+               </xs:sequence>
+       </xs:complexType>
+
+       <xs:complexType name="finalState">
+               <xs:attribute name="id" type="xs:string" use="required">
+                       <xs:annotation>
+                               <xs:documentation>The id of the state. This name is used to reference to this state when needed.</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="state">
+               <xs:annotation>
+                                       <xs:documentation>Declares a state. Two types of states are actually supported : atomic state and complex state. An atomic state is state without sub-state and complex state is a full state with sub-state. An atomic state is a complex state but with less capacity.</xs:documentation></xs:annotation>
+               <xs:sequence maxOccurs="1">
+                       <xs:element maxOccurs="1" minOccurs="0" name="onentry" type="handlers">
+                               <xs:annotation>
+                                       <xs:documentation>Declares a list of actions to execute when entering the complex state.</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="1" minOccurs="0" name="onexit" type="handlers">
+                               <xs:annotation>
+                                       <xs:documentation>Declares a list of actions to execute when exiting the complex state.</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="unbounded" minOccurs="0" name="precondition" type="transition">
+                               <xs:annotation>
+                                       <xs:documentation>Declares a precondition for this fsm. At least one of the preconditions needs to be validated before being able to activate process the fsm. A precondition is a special transition with no target or action. It should contains only conditions that needs to be validated. Only used for fsm.</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="1" minOccurs="0" name="initial" type="initialState">
+                               <xs:annotation>
+                                       <xs:documentation>Declares the default initial state of this complex state. Must not be specified for an atomic state</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="unbounded" minOccurs="0" name="state" type="state">
+                               <xs:annotation>
+                                       <xs:documentation>Declares an state as children of this declared state state.</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="1" minOccurs="0" name="final" type="finalState">
+                               <xs:annotation>
+                                       <xs:documentation>Declares the default final state of this complex state.</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="unbounded" minOccurs="0" name="transition" type="transition">
+                               <xs:annotation>
+                                       <xs:documentation>Declares a transition for the state.</xs:documentation></xs:annotation></xs:element>
+               </xs:sequence>
+               <xs:attribute name="id" type="xs:string" use="required">
+                       <xs:annotation>
+                               <xs:documentation>The id of the state. This name is used to reference to this state when needed.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="initial" type="xs:string" use="optional">
+                       <xs:annotation>
+                               <xs:documentation>The id of the initial state of the complex state. MUST NOT be specified in conjunction with the 'initial' element.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="automatic" type="xs:string" use="optional">
+                       <xs:annotation>
+                               <xs:documentation>When reaching this state, this attribute specifies whether or not the state will use the ongoing event or will wait for the next event before starting to analyze its transitions. MUST NOT be specified if the complex state is an fsm.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="multiple" type="xs:boolean" use="optional" default="true">
+                       <xs:annotation>
+                               <xs:documentation>ONLY USE for fsm. Specifies if this FSM allows multiple instance or only one instance. If not specified, this attribute will be set to 'true' by default.</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="transition">
+               <xs:annotation>
+                       <xs:documentation>Describes a transition of this state. The transition describes how the event data can change the state of the FSM and trigger an action.</xs:documentation></xs:annotation>
+               <xs:attribute name="event" type="xs:string" use="optional">
+                       <xs:annotation>
+                               <xs:documentation>The event name to be validated.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="cond" type="xs:string" use="optional">
+                       <xs:annotation>
+                               <xs:documentation>The ID of the test to be validated.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="target" type="xs:string" use="optional">
+                       <xs:annotation>
+                               <xs:documentation>The name of the state that the FSM will reach if the 'cond' condition is validated.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="action" type="xs:string" use="optional">
+                       <xs:annotation>
+                               <xs:documentation>The list of IDs of the actions that would be executed if the conditions are validated. If action A and B need to be executed, the value will be 'A:B'.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="saveStoredFields" type="xs:string" use="optional">
+                       <xs:annotation>
+                               <xs:documentation>The action that specifies that the defined fields need to be checked and saved into the database if they are found in the event data. If not specify, the value will be false by default. This action let the user decide when he wants to save the special fields.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="clearStoredFields" type="xs:string" use="optional">
+                       <xs:annotation>
+                               <xs:documentation>The action that specifies that the defined fields need to be all cleared from the database. If not specify, the value will be false by default. This action let the user decide when he wants to clear the special fields.</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="handlers">
+               <xs:attribute name="action" type="xs:string" use="required">
+                       <xs:annotation>
+                               <xs:documentation>The list of IDs of the actions that would be executed. If action A and B need to be executed, the value should be 'A:B'.</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+</xs:schema>
\ No newline at end of file
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlStateProvider.xsd b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlStateProvider.xsd
new file mode 100644 (file)
index 0000000..8703857
--- /dev/null
@@ -0,0 +1,337 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- ***************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal and others
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Florian Wininger - Initial API and implementation
+ *************************************************************************** -->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+       attributeFormDefault="unqualified" elementFormDefault="qualified">
+
+       <xs:complexType name="stateProvider">
+               <xs:annotation>
+                       <xs:documentation>Declares a data-driven state provider which defines how events change the state of attributes of the system. Each state provider defined in XML will become an analysis in TMF.</xs:documentation></xs:annotation>
+               <xs:sequence maxOccurs="1" minOccurs="1">
+                       <xs:element maxOccurs="1" minOccurs="0" name="head" type="headProvider" >
+                               <xs:annotation>
+                                       <xs:documentation>Provide meta-information on this state provider, like labels and applicable trace types.</xs:documentation></xs:annotation></xs:element>
+                       <xs:sequence maxOccurs="unbounded" minOccurs="1">
+                               <xs:choice maxOccurs="unbounded" minOccurs="0">
+                                       <xs:element maxOccurs="unbounded" minOccurs="0" name="definedValue" type="definedValue" >
+                                               <xs:annotation>
+                                                       <xs:documentation>Define a value that maps a string used in the state provider to a numbered value.</xs:documentation></xs:annotation></xs:element>
+                                       <xs:element maxOccurs="unbounded" minOccurs="0" name="location" type="location" >
+                                               <xs:annotation>
+                                                       <xs:documentation>Declare shortcuts to frequently used attribute/data locations. For instance, if a path to an often-used attribute is CPUs/{event.some_field}/Threads/Status, it may be a good idea to put this path in a location and then use the location name in the event handlers.</xs:documentation></xs:annotation></xs:element>
+                               </xs:choice>
+                               <xs:element maxOccurs="unbounded" minOccurs="1" name="eventHandler" type="eventHandler" >
+                                       <xs:annotation>
+                                               <xs:documentation>Define how a given event will modify the state system being built. For each event in the trace that causes a state change, a event handler should be defined.</xs:documentation></xs:annotation></xs:element>
+                       </xs:sequence>
+               </xs:sequence>
+               <xs:attribute name="id" type="xs:string" use="required" >
+                       <xs:annotation>
+                               <xs:documentation>The unique ID of this state provider. It will be used to identify the analysis that will be built from this state provider.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="version" type="xs:integer" use="required" >
+                       <xs:annotation>
+                               <xs:documentation>The version ID of this state provider. Whenever the state provider changes so that the resulting state system is different from previous versions, this version number should be bumped.</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="headProvider">
+               <xs:annotation>
+                       <xs:documentation>Declares the meta-information that can be defined for an XML state provider.</xs:documentation></xs:annotation>
+               <xs:sequence>
+                       <xs:element maxOccurs="unbounded" minOccurs="0" name="traceType">
+                               <xs:annotation>
+                                       <xs:documentation>Indicate that the state provider applies to a given trace type.</xs:documentation></xs:annotation>
+                               <xs:complexType>
+                                       <xs:attribute name="id" use="required" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The ID of the trace type, as declared in a org.eclipse.linuxtools.tmf.core.tracetype extension point or a custom trace parser. For example: "org.eclipse.linuxtools.lttng2.kernel.tracetype" or "org.eclipse.linuxtools.lttng2.ust.tracetype" for respectively LTTng Kernel and LTTng UST traces.</xs:documentation></xs:annotation></xs:attribute>
+                               </xs:complexType>
+                       </xs:element>
+                       <xs:element maxOccurs="1" minOccurs="0" name="label">
+                               <xs:annotation>
+                                       <xs:documentation>Add a label to the state provider. If provided, this text will be the name of the analysis that the user will see in TMF.</xs:documentation></xs:annotation>
+                               <xs:complexType>
+                                       <xs:attribute name="value" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The text to name this state provider (and the analysis it will generate).</xs:documentation></xs:annotation></xs:attribute>
+                               </xs:complexType>
+                       </xs:element>
+               </xs:sequence>
+       </xs:complexType>
+
+       <xs:complexType name="eventHandler">
+               <xs:annotation>
+                       <xs:documentation>Define how an event modifies the state of the system. There should be one event handler for each event causing a state change.</xs:documentation></xs:annotation>
+               <xs:sequence>
+                       <xs:element maxOccurs="unbounded" minOccurs="1" name="stateChange" type="stateChange" >
+                               <xs:annotation>
+                                       <xs:documentation>Define how the state system is modified by the event. An event may cause more than one state change.</xs:documentation></xs:annotation></xs:element>
+               </xs:sequence>
+               <xs:attribute name="eventName" type="xs:string" use="required" >
+                       <xs:annotation>
+                               <xs:documentation>Name of the event that causes a state change.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:anyAttribute />
+       </xs:complexType>
+
+       <xs:complexType name="stateChange">
+               <xs:annotation>
+                       <xs:documentation>Define a change of state in the state system being built.</xs:documentation></xs:annotation>
+               <xs:choice maxOccurs="1" minOccurs="1">
+                       <xs:sequence maxOccurs="1" minOccurs="1">
+                               <xs:annotation>
+                                       <xs:documentation>Describe a single attribute assignation. Simply put: a state change where path/to/attribute=value.</xs:documentation></xs:annotation>
+                               <xs:element maxOccurs="unbounded" minOccurs="1" name="stateAttribute" type="stateAttribute" >
+                                       <xs:annotation>
+                                               <xs:documentation>Explain how to reach an attribute in the state system. It describes the path/to/attribute.</xs:documentation></xs:annotation></xs:element>
+                               <xs:element maxOccurs="1" minOccurs="1" name="stateValue" type="stateValue" >
+                                       <xs:annotation>
+                                               <xs:documentation>Explain how to obtain the value of the state attribute to modify.</xs:documentation></xs:annotation></xs:element>
+                       </xs:sequence>
+                       <xs:sequence maxOccurs="1" minOccurs="1">
+                               <xs:annotation>
+                                       <xs:documentation>Describe a conditional state change, where different path conditions may lead to different state changes.</xs:documentation></xs:annotation>
+                               <xs:element maxOccurs="1" minOccurs="1" name="if" type="conditionSingle" >
+                                       <xs:annotation>
+                                               <xs:documentation>Define the condition to verify.</xs:documentation></xs:annotation></xs:element>
+                               <xs:element maxOccurs="1" minOccurs="1" name="then" type="stateChange" >
+                                       <xs:annotation>
+                                               <xs:documentation>Define the state change to use if the previous condition is true.</xs:documentation></xs:annotation></xs:element>
+                               <xs:element maxOccurs="1" minOccurs="0" name="else" type="stateChange" >
+                                       <xs:annotation>
+                                               <xs:documentation>Optionally define the state change to use if the condition is false.</xs:documentation></xs:annotation></xs:element>
+                       </xs:sequence>
+               </xs:choice>
+       </xs:complexType>
+
+       <xs:complexType name="condition">
+               <xs:annotation>
+                       <xs:documentation>Define a conditional statement. Conditions may use values of the state system or from the event being handled. This element defines a statement in the form of "if (some_path == value)".</xs:documentation></xs:annotation>
+               <xs:choice>
+                       <xs:sequence>
+                               <xs:choice maxOccurs="1" minOccurs="1">
+                                       <xs:element maxOccurs="unbounded" minOccurs="1" name="stateAttribute" type="stateAttribute" >
+                                               <xs:annotation>
+                                                       <xs:documentation>Compare the current value of an attribute of the state system.</xs:documentation></xs:annotation></xs:element>
+                                       <xs:element maxOccurs="1" minOccurs="1" name="field" type="eventField" >
+                                               <xs:annotation>
+                                                       <xs:documentation>Compare the value of an event field.</xs:documentation></xs:annotation></xs:element>
+                               </xs:choice>
+                               <xs:element maxOccurs="1" minOccurs="1" name="stateValue" type="stateValue" >
+                                       <xs:annotation>
+                                               <xs:documentation>Define the value to compare to.</xs:documentation></xs:annotation></xs:element>
+                       </xs:sequence>
+                       <xs:sequence>
+                               <xs:element maxOccurs="2" minOccurs="2" name="stateValue" type="stateValue"/>
+                       </xs:sequence>
+               </xs:choice>
+
+               <xs:attribute name="operator" default="eq">
+                       <xs:annotation>
+                               <xs:documentation>Indicate that a comparison operation will be performed with the value</xs:documentation></xs:annotation>
+                       <xs:simpleType>
+                               <xs:restriction base="xs:string">
+                                       <xs:enumeration value="eq">
+                                               <xs:annotation>
+                                                       <xs:documentation>The operation type is to check if two values are equal</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="ne">
+                                               <xs:annotation>
+                                                       <xs:documentation>The operation type is to check if two values are not equal</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="ge">
+                                               <xs:annotation>
+                                                       <xs:documentation>The operation type is to check if the first value is greater than or equal the second one</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="gt">
+                                               <xs:annotation>
+                                                       <xs:documentation>The operation type is to check if the first value is greater than the second one</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="le">
+                                               <xs:annotation>
+                                                       <xs:documentation>The operation type is to check if the first value is smaller than or equal the second one</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="lt">
+                                               <xs:annotation>
+                                                       <xs:documentation>The operation type is to check if the first value is smaller than the second one</xs:documentation></xs:annotation></xs:enumeration>
+                               </xs:restriction>
+                       </xs:simpleType>
+               </xs:attribute>
+
+       </xs:complexType>
+
+       <xs:complexType name="conditionSingle">
+               <xs:annotation>
+                       <xs:documentation>Define a conditional statement with only one child. From this element, a condition may be composed of other conditional elements to create more complex conditional statements.</xs:documentation></xs:annotation>
+               <xs:choice maxOccurs="1" minOccurs="1">
+                       <xs:element name="condition" type="condition" >
+                               <xs:annotation>
+                                       <xs:documentation>Define a condition element, in the form "if (some_path == value)".</xs:documentation></xs:annotation></xs:element>
+                       <xs:element name="not" type="conditionSingle" >
+                               <xs:annotation>
+                                       <xs:documentation>Negate the result of the following condition, allowing statements of the form "if (!cond)".</xs:documentation></xs:annotation></xs:element>
+                       <xs:element name="and" type="conditionMultiple" >
+                               <xs:annotation>
+                                       <xs:documentation>ANDs 2 conditional statements, allowing statements of the form "if (condA AND condB)"</xs:documentation></xs:annotation></xs:element>
+                       <xs:element name="or" type="conditionMultiple" >
+                               <xs:annotation>
+                                       <xs:documentation>ORs 2 conditional statements, allowing statements of the form "if (condA OR condB)"</xs:documentation></xs:annotation></xs:element>
+               </xs:choice>
+               <xs:anyAttribute />
+       </xs:complexType>
+
+       <xs:complexType name="conditionMultiple">
+               <xs:annotation>
+                       <xs:documentation>Allows the composition of more than one conditional statements.</xs:documentation></xs:annotation>
+               <xs:sequence maxOccurs="unbounded" minOccurs="1">
+                       <xs:element maxOccurs="1" minOccurs="0" name="condition" type="condition" >
+                               <xs:annotation>
+                                       <xs:documentation>Define a condition element, in the form "if (some_path == value)".</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="1" minOccurs="0" name="or" type="conditionMultiple" >
+                               <xs:annotation>
+                                       <xs:documentation>ORs 2 conditional statements, allowing statements of the form "if (condA OR condB)"</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="1" minOccurs="0" name="and" type="conditionMultiple" >
+                               <xs:annotation>
+                                       <xs:documentation>ANDs 2 conditional statements, allowing statements of the form "if (condA AND condB)"</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="1" minOccurs="0" name="not" type="conditionSingle" >
+                               <xs:annotation>
+                                       <xs:documentation>Negate the result of the following condition, allowing statements of the form "if (!cond)".</xs:documentation></xs:annotation></xs:element>
+               </xs:sequence>
+               <xs:anyAttribute />
+       </xs:complexType>
+
+       <xs:complexType name="stateAttribute">
+               <xs:annotation>
+                       <xs:documentation>Define a path to an attribute of the state system.</xs:documentation></xs:annotation>
+               <xs:sequence>
+                       <xs:element maxOccurs="unbounded" minOccurs="0" name="stateAttribute" type="stateAttribute" >
+                               <xs:annotation>
+                                       <xs:documentation>If the type is a "query", those stateAttribute elements describe the elements of the query.</xs:documentation></xs:annotation></xs:element>
+               </xs:sequence>
+               <xs:attribute name="type" use="required">
+                       <xs:annotation>
+                               <xs:documentation>The type of path to this attribute. The meaning of those paths type will depend on the context where the stateAttribute is being used. Not all types will make sense everywhere.</xs:documentation></xs:annotation>
+                       <xs:simpleType>
+                               <xs:restriction base="xs:string">
+                                       <xs:enumeration value="null" >
+                                               <xs:annotation>
+                                                       <xs:documentation>This type does not change the current attribute. Whatever attribute was the reference attribute at a given time, it will be returned as is.</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="constant" >
+                                               <xs:annotation>
+                                                       <xs:documentation>This type identifies the state system attribute by a constant string. For instance, if the first level attribute of the state system is "Threads", then a constant type with "Threads" value should be used.</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="eventField" >
+                                               <xs:annotation>
+                                                       <xs:documentation>This type identifies the attribute by the value of an event field. Note that the event field corresponds to the attribute name, not its value. For example, if the event has a field called "current_cpu" with a value of "2", "2" would be the attribute name we want.</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="eventName" >
+                                               <xs:annotation>
+                                                       <xs:documentation>This type identifies the attribute as the name of an event.</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="location" >
+                                               <xs:annotation>
+                                                       <xs:documentation>This type indicates that the path to the attribute is at the specified location. Location simply avoids having to write full path to an attribute each time it is being used, but the location itself is a sequence of stateAttribute elements. For example, if we previously defined a location named "CurrentThead" for path "CPUs/{current_cpu}/CurrentThread", we can use a stateAttribute of type location with "CurrentThread" value.</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="query" >
+                                               <xs:annotation>
+                                                       <xs:documentation>This type indicates that the path to the attribute is the result of a query. If this type is selected, a sequence of stateAttribute elements needs to be specified for this state attribute. The result of the query is the attribute name of the current element. For example, if the attribute we want is the PID of the current process on CPU 0, that PID can be found through the query "CPUs/0/CurrentThread". The value of this attribute would be, for example, 1234, the attribute we are looking for.</xs:documentation></xs:annotation></xs:enumeration>
+                               </xs:restriction>
+                       </xs:simpleType>
+               </xs:attribute>
+               <xs:attribute name="value" type="xs:string" >
+                       <xs:annotation>
+                               <xs:documentation>The value of this state attribute. A value should be specified only if the type is "constant", "eventField" or "location".</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="stateValue">
+               <xs:annotation>
+                       <xs:documentation>Define a value, that can be assigned to an attribute of the state system.</xs:documentation></xs:annotation>
+               <xs:sequence>
+                       <xs:annotation>
+                               <xs:documentation>For a "query" value type, a sequence of stateAttributes will define the query whose result is the value.</xs:documentation></xs:annotation>
+                       <xs:element maxOccurs="unbounded" minOccurs="0" name="stateAttribute" type="stateAttribute" ></xs:element>
+               </xs:sequence>
+               <xs:attribute name="type" use="required">
+                       <xs:annotation>
+                               <xs:documentation>The type of this state value. It will describe how to obtain to value and/or what to do with it.</xs:documentation></xs:annotation>
+                       <xs:simpleType>
+                               <xs:restriction base="xs:string">
+                                       <xs:enumeration value="null" >
+                                               <xs:annotation>
+                                                       <xs:documentation>Indicate that the value is a null value.</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="int" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The value is a constant of type integer.</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="long" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The value is a constant of type long</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="string" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The value is a constant of type string</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="eventField" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The value is the content of an event field. The "value" attribute is the field name. To convert this field to a certain type, attribute "forcedType" may be used.</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="eventName" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The value is the name of the event.</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="delete" >
+                                               <xs:annotation>
+                                                       <xs:documentation>Indicate that the attribute the value is to be applied to should be deleted.</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="query" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The value is the result of a query to the state system. If this type is selected, a sequence of stateAttributes must be defined in this stateValue element.</xs:documentation></xs:annotation></xs:enumeration>
+                               </xs:restriction>
+                       </xs:simpleType>
+               </xs:attribute>
+               <xs:attribute name="increment" type="xs:boolean" >
+                       <xs:annotation>
+                               <xs:documentation>Indicate that the current value will be added to any previously available value.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="stack">
+                       <xs:annotation>
+                               <xs:documentation>Indicate that a stack operation will be performed with the value</xs:documentation></xs:annotation>
+                       <xs:simpleType>
+                               <xs:restriction base="xs:string">
+                                       <xs:enumeration value="pop">
+                                               <xs:annotation>
+                                                       <xs:documentation>The value will be popped from the stack</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="push">
+                                               <xs:annotation>
+                                                       <xs:documentation>The value will be pushed on a stack</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="peek">
+                                               <xs:annotation>
+                                                       <xs:documentation>The value will be peeked from the top of the stack, but it will stay there</xs:documentation></xs:annotation></xs:enumeration>
+                               </xs:restriction>
+                       </xs:simpleType>
+               </xs:attribute>
+               <xs:attribute name="forcedType">
+                       <xs:annotation>
+                               <xs:documentation>Indicate the desired type for the state value. If the value is not already of this type, a conversion will be attempted. The forcedType is used to convert values of event fields.</xs:documentation></xs:annotation>
+                       <xs:simpleType>
+                               <xs:restriction base="xs:string">
+                                       <xs:enumeration value="int" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The value should be an integer</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="long" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The value should be a long</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="string" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The value should be a string</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="double" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The value should be a double</xs:documentation></xs:annotation></xs:enumeration>
+                               </xs:restriction>
+                       </xs:simpleType>
+               </xs:attribute>
+               <xs:attribute name="value" type="xs:string" >
+                       <xs:annotation>
+                               <xs:documentation>Indicate what the value is. A value should be specified only if the type is int, long, string or event_field. See the documentation on types for information on what to put for value.</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="eventField">
+               <xs:annotation>
+                       <xs:documentation>This element is used in conditions where the value of an event field is compared to something else. It is not the same as the stateAttribute's type eventField, where the eventField is used as the name for an attribute to the state system.</xs:documentation></xs:annotation>
+               <xs:attribute name="name" type="xs:string" use="required" >
+                       <xs:annotation>
+                               <xs:documentation>Indicate which field to use.</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+</xs:schema>
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlView.xsd b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/module/xmlView.xsd
new file mode 100644 (file)
index 0000000..1931843
--- /dev/null
@@ -0,0 +1,178 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- ***************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Florian Wininger - Initial API and implementation
+ *************************************************************************** -->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+       attributeFormDefault="unqualified" elementFormDefault="qualified">
+
+       <xs:complexType name="timeGraphView">
+               <xs:annotation>
+                       <xs:documentation>Declares a data-driven time graph view, which defines how the view will display the results of an analysis. For now, only state system analysis are supported by this view.</xs:documentation></xs:annotation>
+               <xs:sequence>
+                       <xs:element maxOccurs="1" minOccurs="0" name="head" type="headOutput" >
+                               <xs:annotation>
+                                       <xs:documentation>Provider meta-information on this view, like labels and analysis it applies to.</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="unbounded" minOccurs="0" name="definedValue" type="definedValue" >
+                               <xs:annotation>
+                                       <xs:documentation>Define a mapping between a human-readable text and the value used in the analysis. The "definedValue"'s optional "color" attribute is the color with which this value will be displayed.</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="unbounded" minOccurs="0" name="entry" type="viewEntry" >
+                               <xs:annotation>
+                                       <xs:documentation>Define how to determine the entries (lines) to show on the time graph view. An entry may have children entry elements defined as children, where children are sub-elements of this one (for example, child attributes in the state system). A parent/child relationship may be defined for entries of the same level. See the viewEntry element documentation for more details.</xs:documentation></xs:annotation></xs:element>
+               </xs:sequence>
+               <xs:attribute name="id" type="xs:string" use="required" >
+                       <xs:annotation>
+                               <xs:documentation>The unique identifier of this view element. It will be used by the framework to identify this view.</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="xyView">
+               <xs:annotation>
+                       <xs:documentation>Declares a data-driven XY chart view, which defines how the view will display the results of an analysis. For now, only state system analyses are supported by this view.</xs:documentation></xs:annotation>
+               <xs:sequence>
+                       <xs:element maxOccurs="1" minOccurs="0" name="head" type="headOutput" >
+                               <xs:annotation>
+                                       <xs:documentation>Provider meta-information on this view, like labels and analyses it applies to.</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="1" minOccurs="1" name="entry" type="xyViewEntry" >
+                               <xs:annotation>
+                                       <xs:documentation>Define how to determine the entries (series) to show on the XY view. See the xyViewEntry element documentation for more details.</xs:documentation></xs:annotation></xs:element>
+               </xs:sequence>
+               <xs:attribute name="id" type="xs:string" use="required" >
+                       <xs:annotation>
+                               <xs:documentation>The unique identifier of this view element. It will be used by the framework to identify this view.</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="headOutput">
+               <xs:annotation>
+                       <xs:documentation>Declares the meta-information that can be defined for an XML time graph view.</xs:documentation></xs:annotation>
+               <xs:sequence>
+                       <xs:element maxOccurs="unbounded" minOccurs="0" name="analysis">
+                               <xs:annotation>
+                                       <xs:documentation>Indicate that the view applies to the analysis identified with the given ID. To have a view apply to an XML-defined state system analysis, you'd use the state provider ID in the "stateProvider" element.</xs:documentation></xs:annotation>
+                               <xs:complexType>
+                                       <xs:attribute name="id" type="xs:string" use="required" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The ID of the analysis this view applies to.</xs:documentation></xs:annotation></xs:attribute>
+                                       <xs:attribute name="ssid" type="xs:string" use="optional" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The ID of the state system this view applies to. The attribute is used only if the analysis contains more than one state system.</xs:documentation></xs:annotation></xs:attribute>
+                               </xs:complexType>
+                       </xs:element>
+                       <xs:element maxOccurs="1" minOccurs="0" name="label">
+                               <xs:annotation>
+                                       <xs:documentation>Add a label to the time graph view. If provided, this text will be displayed to the user to identify this view, otherwise, the view's ID will be used.</xs:documentation></xs:annotation>
+                               <xs:complexType>
+                                       <xs:attribute name="value" use="required" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The text used as a name for this time graph view.</xs:documentation></xs:annotation></xs:attribute>
+                               </xs:complexType>
+                       </xs:element>
+               </xs:sequence>
+       </xs:complexType>
+
+       <xs:complexType name="viewEntry">
+               <xs:annotation>
+                       <xs:documentation>Define a path to entries in the view. If this element is at the top level, the base path to reach the entry is the root of the state system. Otherwise, it will use the parent element's corresponding attribute as the base. Each view entry element corresponds to a time graph view entry that will actually be displayed.</xs:documentation></xs:annotation>
+               <xs:sequence>
+                       <xs:element maxOccurs="1" minOccurs="0" name="display" type="viewStateAttribute" >
+                               <xs:annotation>
+                                       <xs:documentation>Indicate the attribute whose value will be displayed in the time graph (the value that changes over time). If this element is not specified, no entry will be created for this element, and all other elements will be ignored.</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="1" minOccurs="0" name="id" type="viewStateAttribute" >
+                               <xs:annotation>
+                                       <xs:documentation>Specify which attribute to use as ID for this entry. This ID will be used in the ID column in the view, and will also be used to build the tree if a parent element is specified. If this element is not present, the display attribute's name will be used as ID.</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="1" minOccurs="0" name="parent" type="viewStateAttribute" >
+                               <xs:annotation>
+                                       <xs:documentation>Specify how to find the parent's ID of this entry. By default, the parent/child hierarchy is the same as defined in the timeGraphView element of the XML file. This element will add to this default parent/child relationship so that elements at the same XML-defined level can still have a relationship.</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="1" minOccurs="0" name="name" type="viewStateAttribute" >
+                               <xs:annotation>
+                                       <xs:documentation>Specify how to find the name of this entry. Typically, the name will be human-readable. If not specified, the display attribute's name will be used as the name.</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="unbounded" minOccurs="0" name="entry" type="viewEntry" >
+                               <xs:annotation>
+                                       <xs:documentation>Define child entries for this entry. Child entries will be shown as children of this entry (with or without additional parent/child relationship defined through the viewEntry element's "parent" element).</xs:documentation></xs:annotation></xs:element>
+               </xs:sequence>
+               <xs:attribute name="path" type="xs:string" use="required" >
+                       <xs:annotation>
+                               <xs:documentation>The path of the entry in the state system. Wildcards '*' may be used. For example, to display entries from all CPUs, the path could be "CPUs/*" and one entry will be created for each sub-attribute of the "CPUs" attribute. Each entry will be used as the base for all child elements, unless specified otherwise.</xs:documentation></xs:annotation></xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="xyViewEntry">
+               <xs:annotation>
+                       <xs:documentation>Define a path to entries in the view. If this element is at the top level, the base path to reach the entry is the root of the state system. Otherwise, it will use the parent element's corresponding attribute as the base. Each XY view entry element corresponds to a series in the resulting view.</xs:documentation></xs:annotation>
+               <xs:sequence>
+                       <xs:element maxOccurs="1" minOccurs="0" name="display" type="viewStateAttribute" >
+                               <xs:annotation>
+                                       <xs:documentation>Indicate the attribute whose value will be displayed in the time graph (the value that changes over time). If this element is not specified, no entry will be created for this element, and all other elements will be ignored.</xs:documentation></xs:annotation></xs:element>
+                       <xs:element maxOccurs="1" minOccurs="0" name="name" type="viewStateAttribute" >
+                               <xs:annotation>
+                                       <xs:documentation>Specify how to find the name of this entry. Typically, the name will be human-readable. If not specified, the display attribute's name will be used as the name.</xs:documentation></xs:annotation></xs:element>
+               </xs:sequence>
+               <xs:attribute name="path" type="xs:string" use="required" >
+                       <xs:annotation>
+                               <xs:documentation>The path of the entry in the state system. Wildcards '*' may be used. For example, to display entries from all CPUs, the path could be "CPUs/*" and one series will be created for each sub-attribute of the "CPUs" attribute. Each entry will be used as the base for all child elements, unless specified otherwise.</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="displayType" use="optional" default="absolute" >
+                       <xs:annotation>
+                               <xs:documentation>Indicate how to display the value, compared with preceding values.</xs:documentation></xs:annotation>
+                       <xs:simpleType>
+                               <xs:restriction base="xs:string">
+                                       <xs:enumeration value="absolute" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The value is shown as is.</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="delta" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The value is the difference between the value at current timestamp and the value at the preceding timestamp.</xs:documentation></xs:annotation></xs:enumeration>
+                               </xs:restriction>
+                       </xs:simpleType>
+               </xs:attribute>
+       </xs:complexType>
+
+       <xs:complexType name="viewStateAttribute">
+               <xs:sequence>
+                       <xs:element maxOccurs="unbounded" minOccurs="0" name="stateAttribute" type="viewStateAttribute" >
+                               <xs:annotation>
+                                       <xs:documentation>If the type is a "query", those stateAttribute elements describe the  elements of the query.</xs:documentation></xs:annotation></xs:element>
+               </xs:sequence>
+               <xs:attribute name="type" use="required">
+                       <xs:annotation>
+                               <xs:documentation>The type of path to this attribute. The value of the other attributes will depend on the selected type.</xs:documentation></xs:annotation>
+                       <xs:simpleType>
+                               <xs:restriction base="xs:string">
+                                       <xs:enumeration value="constant" >
+                                               <xs:annotation>
+                                                       <xs:documentation>This type identifies the state system attribute by a constant string. For instance, if the state system attribute to display is "Status", it would be a constant type with value "Status".</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="location" >
+                                               <xs:annotation>
+                                                       <xs:documentation>This type indicates that the path to the attribute is at the specified location. A location avoids having to write the full path to an attribute every time it is being used. The location itself is a sequence of stateAttribute elements. For example, if we previously defined a location named "Procname" for path "Threads/tid/Procname", we can use a stateAttribute of type location with "Procname" value.</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="query" >
+                                               <xs:annotation>
+                                                       <xs:documentation>This type indicates that the path to the attribute is the result of a query. If this type is selected, a sequence of stateAttribute elements needs to be specified for this viewStateAttribute. The result of the query is the attribute name of the current element. For example, if the attribute we want is the PID of the current process on CPU 0, that PID can be found through the query "CPUs/0/CurrentThread". The value of this attribute would be for example 1234, which is the attribute we are looking for.</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="self" >
+                                               <xs:annotation>
+                                                       <xs:documentation>This type indicates that the requested attribute is the attribute itself. For this attribute, the reference is always relative (setting it to absolute will be ignored).</xs:documentation></xs:annotation></xs:enumeration>
+                               </xs:restriction>
+                       </xs:simpleType>
+               </xs:attribute>
+               <xs:attribute name="value" type="xs:string" >
+                       <xs:annotation>
+                               <xs:documentation>The value of this state attribute. A value should be specified if the type is "constant" or "location".</xs:documentation></xs:annotation></xs:attribute>
+               <xs:attribute name="reference" use="optional" default="relative">
+                       <xs:annotation>
+                               <xs:documentation>Specify which state system attribute to use as the base to reach this path. It is either absolute or relative. By default, it is relative to the current entry.</xs:documentation></xs:annotation>
+                       <xs:simpleType>
+                               <xs:restriction base="xs:string">
+                                       <xs:enumeration value="relative" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The path will be calculated starting from the entry under which this viewStateAttribute element is defined.</xs:documentation></xs:annotation></xs:enumeration>
+                                       <xs:enumeration value="absolute" >
+                                               <xs:annotation>
+                                                       <xs:documentation>The path will be calculated starting from the root of the state system. That means that if the entry itself is one of "CPUs/*", we could reach another attribute from the root of the state system, like "Threads/tid".</xs:documentation></xs:annotation></xs:enumeration>
+                               </xs:restriction>
+                       </xs:simpleType>
+               </xs:attribute>
+       </xs:complexType>
+</xs:schema>
index 85c580ace7c4186735d92e47683141d7e5b96ccf..fd38487af76781095792d1f0c359d48e1b2c08f0 100644 (file)
@@ -23,11 +23,11 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.analysis.timing.core.segmentstore.IAnalysisProgressListener;
 import org.eclipse.tracecompass.analysis.timing.core.segmentstore.ISegmentStoreProvider;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlPatternSegmentBuilder;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.segment.TmfXmlPatternSegment;
 import org.eclipse.tracecompass.segmentstore.core.ISegment;
 import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlPatternSegmentBuilder;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.segment.TmfXmlPatternSegment;
 import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
 import org.eclipse.tracecompass.tmf.core.segment.ISegmentAspect;
index dd6e5f3ae176f8fe4847033592beb0dc7d886eeb..ed34719cbc6e888a1e4932aa25191eb278363891 100644 (file)
@@ -12,9 +12,9 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.analysis.timing.core.segmentstore.ISegmentStoreProvider;
 import org.eclipse.tracecompass.analysis.timing.core.segmentstore.statistics.AbstractSegmentStatisticsAnalysis;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlPatternSegmentBuilder;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.segment.TmfXmlPatternSegment;
 import org.eclipse.tracecompass.segmentstore.core.ISegment;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlPatternSegmentBuilder;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.segment.TmfXmlPatternSegment;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
 
index 8374b020a54ec73ebeef9f1ab8b46896c8eb190e..3712dad1e27e762b75bbffe5fc242e68fe1a990e 100644 (file)
@@ -19,15 +19,15 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.common.core.NonNullUtils;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlLocation;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlPatternEventHandler;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlScenarioHistoryBuilder;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readwrite.TmfXmlReadWriteModelFactory;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlLocation;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlPatternEventHandler;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlScenarioHistoryBuilder;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.readwrite.TmfXmlReadWriteModelFactory;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider;
 import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/segment/TmfXmlPatternSegment.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/segment/TmfXmlPatternSegment.java
new file mode 100644 (file)
index 0000000..9ecaf9a
--- /dev/null
@@ -0,0 +1,234 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ ******************************************************************************/
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.segment;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.segmentstore.core.ISegment;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
+
+/**
+ * This class implements an XML Pattern Segment. This type of segment has
+ * content and a default timestamp, which is the start time of the segment.
+ *
+ * @author Jean-Christian Kouame
+ */
+public class TmfXmlPatternSegment implements ISegment {
+
+    /**
+     * The serial version UID
+     */
+    private static final long serialVersionUID = 3556323761465412078L;
+
+    /* 'Byte' equivalent for state values types */
+    private static final byte TYPE_NULL = -1;
+    private static final byte TYPE_INTEGER = 0;
+    private static final byte TYPE_STRING = 1;
+    private static final byte TYPE_LONG = 2;
+
+    private final int fScale;
+    private final long fStart;
+    private final long fEnd;
+    private final String fSegmentName;
+    private transient Map<@NonNull String, @NonNull ITmfStateValue> fContent;
+
+    /**
+     * Constructs an XML pattern segment
+     *
+     * @param start
+     *            Start time of the pattern segment
+     * @param end
+     *            End time of the pattern segment
+     * @param scale
+     *            Scale of the pattern segment
+     * @param segmentName
+     *            Name of the pattern segment
+     * @param fields
+     *            Fields of the pattern segment
+     */
+    public TmfXmlPatternSegment(long start, long end, int scale, String segmentName, @NonNull Map<@NonNull String, @NonNull ITmfStateValue> fields) {
+        fStart = start;
+        fEnd = end;
+        fScale = scale;
+        fSegmentName = segmentName;
+        fContent = Collections.unmodifiableMap(fields);
+    }
+
+    /**
+     * Get the start timestamp of the segment
+     *
+     * @return The start timestamp
+     */
+    public @NonNull ITmfTimestamp getTimestampStart() {
+        return TmfTimestamp.create(fStart, fScale);
+    }
+
+    /**
+     * Get the end timestamp of this segment
+     *
+     * @return The end timestamp
+     */
+    public @NonNull ITmfTimestamp getTimestampEnd() {
+        return TmfTimestamp.create(fEnd, fScale);
+    }
+
+    /**
+     * Get the content of the pattern segment
+     * @return The content
+     */
+    public Map<@NonNull String, @NonNull ITmfStateValue> getContent() {
+        return fContent;
+    }
+
+    /**
+     * Get the name of pattern segment
+     * @return The name
+     */
+    public String getName() {
+        return fSegmentName;
+    }
+
+    /**
+     * Get the timestamp scale of the pattern segment
+     * @return The timestamp scale
+     */
+    public int getScale() {
+        return fScale;
+    }
+
+    @Override
+    public int compareTo(@NonNull ISegment o) {
+        int ret = ISegment.super.compareTo(o);
+        if (ret != 0) {
+            return ret;
+        }
+        return toString().compareTo(o.toString());
+    }
+
+    @Override
+    public long getStart() {
+        return fStart;
+    }
+
+    @Override
+    public long getEnd() {
+        return fEnd;
+    }
+
+    @Override
+    public String toString() {
+        return new StringBuilder(getClass().getSimpleName())
+                .append(", [fTimestampStart=").append(getTimestampStart()) //$NON-NLS-1$
+                .append(", fTimestampEnd=").append(getTimestampEnd()) //$NON-NLS-1$
+                .append(", duration= ").append(getLength()) //$NON-NLS-1$
+                .append(", fName=").append(getName()) //$NON-NLS-1$
+                .append(", fContent=").append(getContent()) //$NON-NLS-1$
+                .append("]").toString(); //$NON-NLS-1$
+    }
+
+    private void writeObject(ObjectOutputStream out) throws IOException {
+        out.defaultWriteObject();
+
+        // Write the number of fields
+        out.writeInt(fContent.size());
+
+        // Write the fields
+        for (Map.Entry<String, ITmfStateValue> entry : fContent.entrySet()) {
+            out.writeInt(entry.getKey().length());
+            out.writeBytes(entry.getKey());
+            final ITmfStateValue value = entry.getValue();
+            final byte type = getByteFromType(value.getType());
+            out.writeByte(type);
+            switch (type) {
+            case TYPE_NULL:
+                break;
+            case TYPE_INTEGER:
+                out.writeInt(value.unboxInt());
+                break;
+            case TYPE_LONG:
+                out.writeLong(value.unboxLong());
+                break;
+            case TYPE_STRING:
+                final @NonNull String string = value.unboxStr();
+                out.writeInt(string.length());
+                out.writeBytes(string);
+                break;
+            default:
+                throw new IOException("Write object failed : Invalid data"); //$NON-NLS-1$
+            }
+        }
+    }
+
+    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+        in.defaultReadObject();
+        int contentSize = in.readInt();
+
+        final Map<@NonNull String, @NonNull ITmfStateValue> content = new HashMap<>();
+        for (int i = 0; i < contentSize; i++) {
+            int length = in.readInt();
+            byte[] bytes = new byte[length];
+            in.read(bytes, 0, length);
+            String name = new String(bytes).intern();
+
+            Byte type = in.readByte();
+            ITmfStateValue value;
+            switch (type) {
+            case TYPE_NULL:
+                value = TmfStateValue.nullValue();
+                break;
+            case TYPE_INTEGER:
+                value = TmfStateValue.newValueInt(in.readInt());
+                break;
+            case TYPE_LONG:
+                value = TmfStateValue.newValueLong(in.readLong());
+                break;
+            case TYPE_STRING:
+                length = in.readInt();
+                bytes = new byte[length];
+                in.read(bytes, 0, length);
+                value = TmfStateValue.newValueString(new String(bytes).intern());
+                break;
+            default:
+                throw new IOException("Read object failed : Invalid data"); //$NON-NLS-1$
+            }
+            content.put(name, value);
+        }
+        fContent = content;
+    }
+
+    /**
+     * Here we determine how state values "types" are written in the 8-bit field
+     * that indicates the value type in the file.
+     */
+    private static byte getByteFromType(ITmfStateValue.Type type) {
+        switch (type) {
+        case NULL:
+            return TYPE_NULL;
+        case INTEGER:
+            return TYPE_INTEGER;
+        case STRING:
+            return TYPE_STRING;
+        case LONG:
+            return TYPE_LONG;
+        case DOUBLE:
+        default:
+            /* Should not happen if the switch is fully covered */
+            throw new IllegalStateException("Data type " + type + " not supported"); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/stateprovider/TmfXmlStrings.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/stateprovider/TmfXmlStrings.java
new file mode 100644 (file)
index 0000000..b730c2d
--- /dev/null
@@ -0,0 +1,167 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ecole Polytechnique
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Florian Wininger - Initial implementation
+ ******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * This file defines all name in the XML Structure for the State Provider
+ *
+ * @author Florian Wininger
+ * @noimplement This interface only contains static defines
+ */
+@SuppressWarnings({ "javadoc", "nls" })
+@NonNullByDefault
+public interface TmfXmlStrings {
+
+    /* XML generic Element attribute names */
+    String VALUE = "value";
+    String NAME = "name";
+    String VERSION = "version";
+    String TYPE = "type";
+
+    /* XML header element */
+    String HEAD = "head";
+    String TRACETYPE = "traceType";
+    String ID = "id";
+    String LABEL = "label";
+    String ANALYSIS = "analysis";
+
+    /* XML String */
+    String NULL = "";
+    String WILDCARD = "*";
+    String VARIABLE_PREFIX = "$";
+    String COLOR = "color";
+    String COLOR_PREFIX = "#";
+
+    /* XML Element Name */
+    String STATE_PROVIDER = "stateProvider";
+    String DEFINED_VALUE = "definedValue";
+    String LOCATION = "location";
+    String EVENT_HANDLER = "eventHandler";
+    String STATE_ATTRIBUTE = "stateAttribute";
+    String STATE_VALUE = "stateValue";
+    String STATE_CHANGE = "stateChange";
+    String ELEMENT_FIELD = "field";
+
+    /* XML Condition strings */
+    String IF = "if";
+    String CONDITION = "condition";
+    String THEN = "then";
+    String ELSE = "else";
+
+    /* XML event handler strings */
+    String HANDLER_EVENT_NAME = "eventName";
+
+    /* XML constant for Type of Attribute and Value */
+    String TYPE_NULL = "null";
+    String TYPE_CONSTANT = "constant";
+    String EVENT_FIELD = "eventField";
+    String TYPE_LOCATION = "location";
+    String TYPE_QUERY = "query";
+    String TYPE_SELF = "self";
+    String TYPE_INT = "int";
+    String TYPE_LONG = "long";
+    String TYPE_DOUBLE = "double";
+    String TYPE_STRING = "string";
+    String TYPE_EVENT_NAME = "eventName";
+    String TYPE_DELETE = "delete";
+    String INCREMENT = "increment";
+    String FORCED_TYPE = "forcedType";
+    String ATTRIBUTE_STACK = "stack";
+    String STACK_POP = "pop";
+    String STACK_PUSH = "push";
+    String STACK_PEEK = "peek";
+    String CPU = "cpu";
+
+    String TIMESTAMP = "timestamp";
+
+    /* Operator type */
+    String NOT = "not";
+    String AND = "and";
+    String OR = "or";
+
+    String OPERATOR = "operator";
+
+    /* Comparison/Condition operator types */
+    String EQ = "eq";
+    String NE = "ne";
+    String GE = "ge";
+    String GT = "gt";
+    String LE = "le";
+    String LT = "lt";
+
+    /* XML pattern elements */
+    String PATTERN = "pattern";
+
+    String STORED_FIELD = "storedField";
+    String STORED_FIELDS = "storedFields";
+
+    String PATTERN_HANDLER = "patternHandler";
+
+    /* XML synthetic event elements */
+    String SEGMENT_NAME = "segName";
+    String SEGMENT = "segment";
+    String SEGMENT_TYPE = "segType";
+    String SEGMENT_CONTENT = "segContent";
+    String SEGMENT_FIELD = "segField";
+
+    String INITIAL = "initial";
+    String TEST = "test";
+    String ACTION = "action";
+    String FSM = "fsm";
+    String STATE = "state";
+    String EVENT_INFO = "eventInfo";
+    String TIME_INFO = "timeInfo";
+    String EVENT = "event";
+    String CONSTANT_PREFIX = "#";
+    String FSM_SCHEDULE_ACTION = "fsmScheduleAction";
+    String MULTIPLE = "multiple";
+    String PRECONDITION = "precondition";
+    String COND = "cond";
+    String FINAL = "final";
+    String ABANDON_STATE = "abandonState";
+    String STATE_TABLE = "stateTable";
+    String STATE_DEFINITION = "stateDefinition";
+    String EMPTY_STRING = "";
+    String TRANSITION = "transition";
+    String TARGET = "target";
+    String SAVE_STORED_FIELDS = "saveStoredFields";
+    String CLEAR_STORED_FIELDS = "clearStoredFields";
+
+    /* Time conditions */
+    String TIME_RANGE = "timerange";
+    String ELAPSED_TIME = "elapsedTime";
+    String NS = "ns";
+    String US = "us";
+    String MS = "ms";
+    String S = "s";
+    String UNIT = "unit";
+    String IN = "in";
+    String OUT = "out";
+    String BEGIN = "begin";
+    String END = "end";
+    String LESS = "less";
+    String EQUAL = "equal";
+    String MORE = "more";
+    String SINCE = "since";
+
+    String ARG = "arg";
+    String SCENARIOS = "scenarios";
+    String ONENTRY = "onentry";
+    String ONEXIT = "onexit";
+    String OR_SEPARATOR = "\\|";
+    String AND_SEPARATOR = ":";
+    String ALIAS = "alias";
+    String ABANDON = "abandon";
+}
\ No newline at end of file
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/stateprovider/XmlStateProvider.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/stateprovider/XmlStateProvider.java
new file mode 100644 (file)
index 0000000..13a0a33
--- /dev/null
@@ -0,0 +1,188 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2015 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Florian Wininger - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlEventHandler;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlLocation;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readwrite.TmfXmlReadWriteModelFactory;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * This is the state change input plug-in for TMF's state system which handles
+ * the XML Format
+ *
+ * @author Florian Wininger
+ */
+public class XmlStateProvider extends AbstractTmfStateProvider implements IXmlStateSystemContainer {
+
+    private final IPath fFilePath;
+    private final @NonNull String fStateId;
+
+    /** List of all Event Handlers */
+    private final List<TmfXmlEventHandler> fEventHandlers = new ArrayList<>();
+
+    /** List of all Locations */
+    private final @NonNull Set<@NonNull TmfXmlLocation> fLocations;
+
+    /** Map for defined values */
+    private final Map<String, String> fDefinedValues = new HashMap<>();
+
+    // ------------------------------------------------------------------------
+    // Constructor
+    // ------------------------------------------------------------------------
+
+    /**
+     * Instantiate a new state provider plug-in.
+     *
+     * @param trace
+     *            The trace
+     * @param stateid
+     *            The state system id, corresponding to the analysis_id
+     *            attribute of the state provider element of the XML file
+     * @param file
+     *            Path to the XML file containing the state provider definition
+     */
+    public XmlStateProvider(@NonNull ITmfTrace trace, @NonNull String stateid, IPath file) {
+        super(trace, stateid);
+        fStateId = stateid;
+        fFilePath = file;
+        Element doc = XmlUtils.getElementInFile(fFilePath.makeAbsolute().toOSString(), TmfXmlStrings.STATE_PROVIDER, fStateId);
+        if (doc == null) {
+            fLocations = new HashSet<>();
+            return;
+        }
+
+        ITmfXmlModelFactory modelFactory = TmfXmlReadWriteModelFactory.getInstance();
+        /* parser for defined Values */
+        NodeList definedStateNodes = doc.getElementsByTagName(TmfXmlStrings.DEFINED_VALUE);
+        for (int i = 0; i < definedStateNodes.getLength(); i++) {
+            Element element = (Element) definedStateNodes.item(i);
+            fDefinedValues.put(element.getAttribute(TmfXmlStrings.NAME), element.getAttribute(TmfXmlStrings.VALUE));
+        }
+
+        /* parser for the locations */
+        List<Element> childElements = XmlUtils.getChildElements(doc, TmfXmlStrings.LOCATION);
+        Set<@NonNull TmfXmlLocation> locations = new HashSet<>();
+        for (Element element : childElements) {
+            if (element == null) {
+                continue;
+            }
+            TmfXmlLocation location = modelFactory.createLocation(element, this);
+            locations.add(location);
+        }
+        fLocations = Collections.unmodifiableSet(locations);
+
+        /* parser for the event handlers */
+        childElements = XmlUtils.getChildElements(doc, TmfXmlStrings.EVENT_HANDLER);
+        for (Element element : childElements) {
+            if (element == null) {
+                continue;
+            }
+            TmfXmlEventHandler handler = modelFactory.createEventHandler(element, this);
+            fEventHandlers.add(handler);
+        }
+    }
+
+    /**
+     * Get the state id of the state provider
+     *
+     * @return The state id of the state provider
+     */
+    @NonNull
+    public String getStateId() {
+        return fStateId;
+    }
+
+    // ------------------------------------------------------------------------
+    // IStateChangeInput
+    // ------------------------------------------------------------------------
+
+    @Override
+    public int getVersion() {
+        Element ssNode = XmlUtils.getElementInFile(fFilePath.makeAbsolute().toOSString(), TmfXmlStrings.STATE_PROVIDER, fStateId);
+        if (ssNode != null) {
+            return Integer.parseInt(ssNode.getAttribute(TmfXmlStrings.VERSION));
+        }
+        /*
+         * The version attribute is mandatory and XML files that don't validate
+         * with the XSD are ignored, so this should never happen
+         */
+        throw new IllegalStateException("The state provider XML node should have a version attribute"); //$NON-NLS-1$
+    }
+
+    @Override
+    public XmlStateProvider getNewInstance() {
+        return new XmlStateProvider(this.getTrace(), getStateId(), fFilePath);
+    }
+
+    @Override
+    protected void eventHandle(ITmfEvent event) {
+        for (TmfXmlEventHandler eventHandler : fEventHandlers) {
+            eventHandler.handleEvent(event);
+        }
+    }
+
+    @Override
+    public ITmfStateSystem getStateSystem() {
+        return getStateSystemBuilder();
+    }
+
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+
+    @Override
+    public Iterable<TmfXmlLocation> getLocations() {
+        return fLocations;
+    }
+
+    /**
+     * Get the defined value associated with a constant
+     *
+     * @param constant
+     *            The constant defining this value
+     * @return The actual value corresponding to this constant
+     */
+    public String getDefinedValue(String constant) {
+        return fDefinedValues.get(constant);
+    }
+
+    @Override
+    public String getAttributeValue(String name) {
+        String attribute = name;
+        if (attribute.startsWith(TmfXmlStrings.VARIABLE_PREFIX)) {
+            /* search the attribute in the map without the fist character $ */
+            attribute = getDefinedValue(attribute.substring(1));
+        }
+        return attribute;
+    }
+
+}
\ No newline at end of file
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/stateprovider/XmlStateSystemModule.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/core/stateprovider/XmlStateSystemModule.java
new file mode 100644 (file)
index 0000000..3b13531
--- /dev/null
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2015 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider;
+
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
+import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
+import org.w3c.dom.Element;
+
+/**
+ * Analysis module for the data-driven state systems, defined in XML.
+ *
+ * @author Geneviève Bastien
+ */
+public class XmlStateSystemModule extends TmfStateSystemAnalysisModule {
+
+    private @Nullable IPath fXmlFile;
+
+    @Override
+    protected StateSystemBackendType getBackendType() {
+        return StateSystemBackendType.FULL;
+    }
+
+    @Override
+    @NonNull
+    protected ITmfStateProvider createStateProvider() {
+        return new XmlStateProvider(checkNotNull(getTrace()), getId(), fXmlFile);
+    }
+
+    @Override
+    public String getName() {
+        String id = getId();
+        IPath xmlFile = fXmlFile;
+        if (xmlFile == null) {
+            return id;
+        }
+        Element doc = XmlUtils.getElementInFile(xmlFile.makeAbsolute().toString(), TmfXmlStrings.STATE_PROVIDER, id);
+        /* Label may be available in XML header */
+        List<Element> head = XmlUtils.getChildElements(doc, TmfXmlStrings.HEAD);
+        String name = null;
+        if (head.size() == 1) {
+            List<Element> labels = XmlUtils.getChildElements(head.get(0), TmfXmlStrings.LABEL);
+            if (!labels.isEmpty()) {
+                name = labels.get(0).getAttribute(TmfXmlStrings.VALUE);
+            }
+        }
+        return (name == null) ? id : name;
+    }
+
+    /**
+     * Sets the file path of the XML file containing the state provider
+     *
+     * @param file
+     *            The absolute path to the XML file
+     */
+    public void setXmlFile(IPath file) {
+        fXmlFile = file;
+    }
+
+    /**
+     * Get the path to the XML file containing this state provider definition.
+     *
+     * @return XML file path
+     */
+    public IPath getXmlFile() {
+        return fXmlFile;
+    }
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/ITmfXmlAction.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/ITmfXmlAction.java
deleted file mode 100644 (file)
index cd1b191..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- ******************************************************************************/
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-
-/**
- * Interface for an action behavior. An action is an output of the pattern.
- * Basically something that the pattern needs to do if it reaches a given state.
- *
- * @author Jean-Christian Kouame
- * @since 2.0
- */
-public interface ITmfXmlAction {
-
-    /** The save stored fields action label */
-    String SAVE_STORED_FIELDS_STRING = "saveStoredFields"; //$NON-NLS-1$
-
-    /** The clear stored fields action label */
-    String CLEAR_STORED_FIELDS_STRING = "clearStoredFields"; //$NON-NLS-1$
-
-    /**
-     * Execute the action
-     *
-     * @param event
-     *            The active event
-     * @param scenarioInfo
-     *            The active scenario details. Or <code>null</code> if there is
-     *            no scenario.
-     */
-    void execute(ITmfEvent event, TmfXmlScenarioInfo scenarioInfo);
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/ITmfXmlCondition.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/ITmfXmlCondition.java
deleted file mode 100644 (file)
index 677203c..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- ******************************************************************************/
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-
-/**
- * Determines a true or false value for a given input. The input is an event and
- * an optional scenarioInfo.
- *
- * @author Matthew Khouzam
- * @since 2.0
- */
-public interface ITmfXmlCondition {
-
-    /**
-     * Test the result of the condition for an event
-     *
-     * @param event
-     *            The event on which to test the condition
-     * @param scenarioInfo
-     *            The active scenario details. Or <code>null</code> if there is
-     *            no scenario.
-     * @return Whether the condition is true or not
-     * @since 2.0
-     */
-    boolean test(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo);
-
-}
\ No newline at end of file
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/ITmfXmlModelFactory.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/ITmfXmlModelFactory.java
deleted file mode 100644 (file)
index cfeeb81..0000000
+++ /dev/null
@@ -1,210 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.List;
-
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.w3c.dom.Element;
-
-/**
- * Interface to create XML model elements in different contexts. This allows to
- * reuse the same XML syntax and parsers, but use the elements differently
- * depending on the what is intended to be done with them.
- *
- * @author Geneviève Bastien
- */
-public interface ITmfXmlModelFactory {
-
-    /**
-     * Create a new XML state attribute
-     *
-     * @param attribute
-     *            XML element of the attribute
-     * @param container
-     *            The state system container this state attribute belongs to
-     * @return The new state attribute
-     */
-    ITmfXmlStateAttribute createStateAttribute(Element attribute, IXmlStateSystemContainer container);
-
-    /**
-     * Create a new state value where the value corresponds to a path of
-     * {@link ITmfXmlStateAttribute}
-     *
-     * @param node
-     *            The state value XML element
-     * @param container
-     *            The state system container this state value belongs to
-     * @param attributes
-     *            The attributes representing the path to this value
-     * @return The new state value
-     */
-    ITmfXmlStateValue createStateValue(Element node, IXmlStateSystemContainer container, List<ITmfXmlStateAttribute> attributes);
-
-    /**
-     * Create a new state value where the value corresponds to a field in an
-     * event
-     *
-     * @param node
-     *            The state value XML element
-     * @param container
-     *            The state system container this state value belongs to
-     * @param eventField
-     *            The event field where to get the value
-     * @return The new state value
-     */
-    ITmfXmlStateValue createStateValue(Element node, IXmlStateSystemContainer container, String eventField);
-
-    /**
-     * Create a new XML condition
-     *
-     * @param node
-     *            The XML root of this condition
-     * @param container
-     *            The state system container this condition belongs to
-     * @return The new XML condition
-     */
-    TmfXmlCondition createCondition(Element node, IXmlStateSystemContainer container);
-
-    /**
-     * Create a new XML event handler
-     *
-     * @param node
-     *            The XML event handler element
-     * @param container
-     *            The state system container this state value belongs to
-     * @return The new XML event handler
-     */
-    TmfXmlEventHandler createEventHandler(Element node, IXmlStateSystemContainer container);
-
-    /**
-     * Create a new XML state change
-     *
-     * @param node
-     *            The XML state change element
-     * @param container
-     *            The state system container this state change belongs to
-     * @return The new XML state change
-     */
-    TmfXmlStateChange createStateChange(Element node, IXmlStateSystemContainer container);
-
-    /**
-     * Create a new XML location
-     *
-     * @param node
-     *            The XML location element
-     * @param container
-     *            The state system container this location belongs to
-     * @return The new XML location
-     */
-    TmfXmlLocation createLocation(Element node, IXmlStateSystemContainer container);
-
-    /**
-     * Create a new XML pattern event handler
-     *
-     * @param node
-     *            The XML pattern event handler element
-     * @param container
-     *            The state system container this pattern event handler belongs to
-     * @return The new XML pattern event handler
-     * @since 2.0
-     */
-    TmfXmlPatternEventHandler createPatternEventHandler(Element node, IXmlStateSystemContainer container);
-
-    /**
-     * Create a new XML transition validator
-     *
-     * @param node
-     *            The XML test element
-     * @param container
-     *            The state system container this test belongs to
-     * @return The new {@link TmfXmlTransitionValidator}
-     * @since 2.0
-     */
-    TmfXmlTransitionValidator createTransitionValidator(Element node, IXmlStateSystemContainer container);
-
-    /**
-     * Create a new XML action
-     *
-     * @param node
-     *            The XML action element
-     * @param container
-     *            The state system container this action belongs to
-     * @return The new {@link TmfXmlAction}
-     * @since 2.0
-     */
-    TmfXmlAction createAction(Element node, IXmlStateSystemContainer container);
-
-    /**
-     * Create a new XML FSM
-     *
-     * @param node
-     *            The XML FSM element
-     * @param container
-     *            The state system container this FSM belongs to
-     * @return The new {@link TmfXmlFsm}
-     * @since 2.0
-     */
-    TmfXmlFsm createFsm(Element node, IXmlStateSystemContainer container);
-
-    /**
-     * Create a new XML state
-     *
-     * @param node
-     *            The XML state element
-     * @param container
-     *            The state system container this state belongs to
-     * @param parent
-     *            The parent state
-     * @return The new {@link TmfXmlState}
-     * @since 2.0
-     */
-    TmfXmlState createState(Element node, IXmlStateSystemContainer container, @Nullable TmfXmlState parent);
-
-    /**
-     * Create a new XML state transition
-     *
-     * @param node
-     *            The XML state transition element
-     * @param container
-     *            The state system container this state transition belongs to
-     * @return The new XML {@link TmfXmlStateTransition}
-     * @since 2.0
-     */
-    TmfXmlStateTransition createStateTransition(Element node, IXmlStateSystemContainer container);
-
-    /**
-     * Create a new XML timestamp condition
-     *
-     * @param node
-     *            The XML timestamp condition element
-     * @param container
-     *            The state system container this timestamp condition belongs to
-     * @return The new {@link TmfXmlTimestampCondition}
-     * @since 2.0
-     */
-    TmfXmlTimestampCondition createTimestampsCondition(Element node, IXmlStateSystemContainer container);
-
-    /**
-     * Create a new pattern segment builder
-     *
-     * @param node
-     *            The XML pattern segment builder
-     * @param container
-     *            The state system container this pattern segment builder belongs to
-     * @return The new {@link TmfXmlPatternSegmentBuilder}
-     * @since 2.0
-     */
-    TmfXmlPatternSegmentBuilder createPatternSegmentBuilder(Element node, IXmlStateSystemContainer container);
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/ITmfXmlStateAttribute.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/ITmfXmlStateAttribute.java
deleted file mode 100644 (file)
index d74fcc7..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-
-/**
- * Interface that describe a state attribute defined in an XML element
- *
- * @author Geneviève Bastien
- */
-public interface ITmfXmlStateAttribute {
-
-    /**
-     * This method gets the quark for this state attribute in the State System.
-     *
-     * Unless this attribute is a location, in which case the quark must exist,
-     * the quark will be added to the state system if the state system is in
-     * builder mode.
-     *
-     * @param startQuark
-     *            root quark, use {@link IXmlStateSystemContainer#ROOT_QUARK} to
-     *            search the full attribute tree
-     * @param scenarioInfo
-     *            The active scenario details. Or <code>null</code> if there is
-     *            no scenario.
-     * @return the quark described by attribute or
-     *         {@link IXmlStateSystemContainer#ERROR_QUARK} if quark cannot be
-     *         found
-     * @since 2.0
-     */
-    int getAttributeQuark(int startQuark, @Nullable TmfXmlScenarioInfo scenarioInfo);
-
-    /**
-     * This method gets the quark for this state attribute in the State System.
-     *
-     * Unless this attribute is a location, in which case the quark must exist,
-     * the quark will be added to the state system if the state system is in
-     * builder mode. This state attribute path uses runtime data queried using
-     * the current event.
-     *
-     * @param event
-     *            The current event being handled
-     * @param startQuark
-     *            root quark, use {@link IXmlStateSystemContainer#ROOT_QUARK} to
-     *            search the full attribute tree
-     * @param scenarioInfo
-     *            The active scenario details. Or <code>null</code> if there is
-     *            no scenario.
-     * @return the quark described by attribute or
-     *         {@link IXmlStateSystemContainer#ERROR_QUARK} if quark cannot be
-     *         found
-     * @since 2.0
-     */
-    int getAttributeQuark(@Nullable ITmfEvent event, int startQuark, @Nullable TmfXmlScenarioInfo scenarioInfo);
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/ITmfXmlStateValue.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/ITmfXmlStateValue.java
deleted file mode 100644 (file)
index 4b38263..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.List;
-
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
-import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-
-/**
- * Interface that describe operations on a state value described in an XML
- * element
- *
- * @author Geneviève Bastien
- */
-public interface ITmfXmlStateValue {
-
-    /**
-     * Get the current {@link ITmfStateValue} of this state value for an event.
-     * It does not increment the value and does not any other processing of the
-     * value.
-     *
-     * @param event
-     *            The current event or <code>null</code> if no event is
-     *            available.
-     * @param scenarioInfo
-     *            The active scenario details. Or <code>null</code> if there is
-     *            no scenario.
-     * @return the {@link ITmfStateValue}
-     * @throws AttributeNotFoundException
-     *             May be thrown by the state system during the query
-     * @since 2.0
-     */
-    ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException;
-
-    /**
-     * Get the value of the event field that is the path of this state value
-     *
-     * @param event
-     *            The current event
-     * @return the value of the event field
-     */
-    ITmfStateValue getEventFieldValue(ITmfEvent event);
-
-    /**
-     * Get the list of state attributes, the path to the state value
-     *
-     * @return the list of Attribute to have the path in the State System
-     */
-    List<ITmfXmlStateAttribute> getAttributes();
-
-    /**
-     * Handles an event, by setting the value of the attribute described by the
-     * state attribute path in the state system.
-     *
-     * @param event
-     *            The event to process
-     * @param scenarioInfo
-     *            The active scenario details. Or <code>null</code> if there is
-     *            no scenario.
-     * @throws AttributeNotFoundException
-     *             Pass through the exception it received
-     * @throws TimeRangeException
-     *             Pass through the exception it received
-     * @throws StateValueTypeException
-     *             Pass through the exception it received
-     * @since 2.0
-     */
-    void handleEvent(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException;
-
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/ResetStoredFieldsAction.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/ResetStoredFieldsAction.java
deleted file mode 100644 (file)
index 0a1a7e1..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- ******************************************************************************/
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.Map.Entry;
-
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternStateProvider;
-import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-
-/**
- * This action will reset the value of each stored values to a null
- * {@link ITmfStateValue} in the state system
- *
- * @since 2.0
- */
-public class ResetStoredFieldsAction implements ITmfXmlAction {
-
-    private final IXmlStateSystemContainer fParent;
-
-    /**
-     * Constructor
-     *
-     * @param parent
-     *            The state system container this action belongs to
-     */
-    public ResetStoredFieldsAction(IXmlStateSystemContainer parent) {
-        fParent = parent;
-    }
-
-    @Override
-    public void execute(ITmfEvent event, TmfXmlScenarioInfo scenarioInfo) {
-        if (fParent instanceof XmlPatternStateProvider) {
-            for (Entry<String, String> entry : ((XmlPatternStateProvider) fParent).getStoredFields().entrySet()) {
-                ((XmlPatternStateProvider) fParent).getHistoryBuilder().resetStoredFields(fParent, entry.getValue(), scenarioInfo, event);
-            }
-        }
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlAction.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlAction.java
deleted file mode 100644 (file)
index 7f97ab3..0000000
+++ /dev/null
@@ -1,165 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- ******************************************************************************/
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.common.core.NonNullUtils;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternStateProvider;
-import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
-import org.w3c.dom.Element;
-
-/**
- * This Class implements an action tree in the XML-defined state system.
- * An action is a collection of {@link ITmfXmlAction} that are executed when necessary.
- *
- * @author Jean-Christian Kouame
- * @since 2.0
- */
-public class TmfXmlAction implements ITmfXmlAction {
-
-    private final IXmlStateSystemContainer fParent;
-    private final String fId;
-    private final List<ITmfXmlAction> fActionList = new ArrayList<>();
-
-    /**
-     * Constructor
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param node
-     *            The XML root of this action
-     * @param container
-     *            The state system container this action belongs to
-     */
-    public TmfXmlAction(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container) {
-        fParent = container;
-        fId = NonNullUtils.checkNotNull(node.getAttribute(TmfXmlStrings.ID));
-        List<@Nullable Element> childElements = XmlUtils.getChildElements(node);
-        for (Element child : childElements) {
-            final @NonNull Element nonNullChild = NonNullUtils.checkNotNull(child);
-            switch (nonNullChild.getNodeName()) {
-            case TmfXmlStrings.STATE_CHANGE:
-                fActionList.add(new StateChange(modelFactory, nonNullChild, fParent));
-                break;
-            case TmfXmlStrings.FSM_SCHEDULE_ACTION:
-                fActionList.add(new ScheduleNewScenario(modelFactory, nonNullChild, fParent));
-                break;
-            case TmfXmlStrings.SEGMENT:
-                fActionList.add(new GeneratePatternSegment(modelFactory, nonNullChild, fParent));
-                break;
-            case TmfXmlStrings.ACTION:
-                fActionList.add(new TmfXmlAction(modelFactory, nonNullChild, fParent));
-                break;
-            default:
-                Activator.logError("Invalid action type : " + nonNullChild.getNodeName()); //$NON-NLS-1$
-            }
-        }
-
-    }
-
-    /**
-     * Get the ID of this action
-     *
-     * @return The id of this action
-     */
-    public String getId() {
-        return fId;
-    }
-
-    @Override
-    public void execute(@NonNull ITmfEvent event, TmfXmlScenarioInfo scenarioInfo) {
-        // the order of the actions is important, do not parallelize.
-        for (ITmfXmlAction action : fActionList) {
-            action.execute(event, scenarioInfo);
-        }
-    }
-
-    /**
-     * Private class for an action that will create a state change in the state
-     * system
-     */
-    private class StateChange implements ITmfXmlAction {
-
-        private final TmfXmlStateChange fStateChange;
-
-        public StateChange(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer parent) {
-            fStateChange = modelFactory.createStateChange(node, parent);
-        }
-
-        @Override
-        public void execute(@NonNull ITmfEvent event, TmfXmlScenarioInfo scenarioInfo) {
-            try {
-                fStateChange.handleEvent(event, scenarioInfo);
-            } catch (StateValueTypeException | AttributeNotFoundException e) {
-                Activator.logError("Exception when executing action state change", e); //$NON-NLS-1$
-            }
-        }
-    }
-
-    /**
-     * Private class for an action that will instantiate and schedule a new instance of
-     * an fsm
-     */
-    private static class ScheduleNewScenario implements ITmfXmlAction {
-
-        /**
-         * Constructor
-         *
-         * @param modelFactory
-         *            The factory used to create XML model elements
-         * @param node
-         *            The XML root of this action
-         * @param container
-         *            The state system container this action belongs to
-         */
-        public ScheduleNewScenario(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container) {
-        }
-
-        @Override
-        public void execute(ITmfEvent event, TmfXmlScenarioInfo scenarioInfo) {
-            // TODO This action needs to be implemented
-            throw new UnsupportedOperationException("Schedule an FSM is not yet supported"); //$NON-NLS-1$
-        }
-    }
-
-    /**
-     * Private class for an action that will generate pattern segment
-     */
-    private static class GeneratePatternSegment implements ITmfXmlAction {
-
-        private final TmfXmlPatternSegmentBuilder fSegmentBuilder;
-        private final XmlPatternStateProvider fProvider;
-
-        public GeneratePatternSegment(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer parent) {
-            fProvider = ((XmlPatternStateProvider) parent);
-            fSegmentBuilder = modelFactory.createPatternSegmentBuilder(node, parent);
-        }
-
-        @Override
-        public void execute(ITmfEvent event, TmfXmlScenarioInfo scenarioInfo) {
-            long ts = fProvider.getHistoryBuilder().getStartTime(fProvider, scenarioInfo, event);
-            // FIXME Should the scale always be nanoseconds?
-            ITmfTimestamp start = TmfTimestamp.fromNanos(ts);
-            ITmfTimestamp end = event.getTimestamp();
-            fSegmentBuilder.generatePatternSegment(event, start, end, scenarioInfo);
-        }
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlBasicTransition.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlBasicTransition.java
deleted file mode 100644 (file)
index c23e610..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- ******************************************************************************/
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Pattern;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.w3c.dom.Element;
-
-/**
- * Implementation of a basic transition in the XML file
- *
- * @author Jean-Christian Kouame
- * @since 2.0
- */
-public class TmfXmlBasicTransition {
-
-    private static final Pattern WILDCARD_PATTERN = Pattern.compile("\\*"); //$NON-NLS-1$
-
-    private final List<String> fCond;
-    private final List<Pattern> fAcceptedEvents;
-
-
-    /**
-     * Constructor
-     *
-     * @param element
-     *            the XML basic transition element
-     */
-    public TmfXmlBasicTransition(Element element) {
-        final @NonNull String events = element.getAttribute(TmfXmlStrings.EVENT);
-        fAcceptedEvents = new ArrayList<>();
-        for (String eventName : Arrays.asList(events.split(TmfXmlStrings.OR_SEPARATOR))) {
-            String name = WILDCARD_PATTERN.matcher(eventName).replaceAll(".*"); //$NON-NLS-1$
-            fAcceptedEvents.add(Pattern.compile(name));
-        }
-        final @NonNull String conditions = element.getAttribute(TmfXmlStrings.COND);
-        fCond = conditions.isEmpty() ? new ArrayList<>() : Arrays.asList(conditions.split(TmfXmlStrings.AND_SEPARATOR));
-    }
-
-    /**
-     * Validate the transition with the current event
-     *
-     * @param event
-     *            The active event
-     * @param scenarioInfo
-     *            The active scenario details.
-     * @param tests
-     *            The map of test in the XML file
-     * @return true if the transition is validate false if not
-     */
-    public boolean test(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo, Map<String, TmfXmlTransitionValidator> tests) {
-        if (!validateEvent(event)) {
-            return false;
-        }
-
-        for (String cond : fCond) {
-            TmfXmlTransitionValidator test = tests.get(cond);
-            if (test == null) {
-                throw new IllegalStateException("Failed to find cond " + cond); //$NON-NLS-1$
-            }
-            if (!test.test(event, scenarioInfo)) {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    private boolean validateEvent(ITmfEvent event) {
-        String eventName = event.getName();
-
-        /*
-         * This validates the event name with the accepted regular expressions
-         */
-        for (Pattern nameRegex : fAcceptedEvents) {
-            if (nameRegex.matcher(eventName).matches()) {
-                return true;
-            }
-        }
-        return false;
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlCondition.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlCondition.java
deleted file mode 100644 (file)
index 573123f..0000000
+++ /dev/null
@@ -1,357 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014, 2015 Ecole Polytechnique de Montreal and others
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Florian Wininger - Initial API and implementation
- *   Naser Ezzati - Add the comparison operators
- *   Patrick Tasse - Add message to exceptions
- *   Jean-Christian Kouame - Add comparison between two state values
- ******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.common.core.NonNullUtils;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
-import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
-import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.w3c.dom.Element;
-
-/**
- * This Class implement a condition tree in the XML-defined state system.
- *
- * <pre>
- * example:
- * <and>
- *   <condition>
- *       <stateAttribute type="location" value="CurrentThread" />
- *       <stateAttribute type="constant" value="System_call" />
- *       <stateValue type="null" />
- *   </condition>
- *   <condition>
- *      <stateValue type="long" value="2" />
- *      <stateValue type="long" value="5" />
- *   </condition>
- * </and>
- * </pre>
- *
- * @author Florian Wininger
- */
-public class TmfXmlCondition implements ITmfXmlCondition {
-
-    private final List<TmfXmlCondition> fConditions = new ArrayList<>();
-    private final List<ITmfXmlStateValue> fStateValues;
-    private final LogicalOperator fOperator;
-    private final IXmlStateSystemContainer fContainer;
-    private final ConditionOperator fConditionOperator;
-    private ConditionType fType;
-    private @Nullable TmfXmlTimestampCondition fTimeCondition;
-
-    private enum LogicalOperator {
-        NONE,
-        NOT,
-        AND,
-        OR
-    }
-
-    private enum ConditionOperator {
-        NONE,
-        EQ,
-        NE,
-        GE,
-        GT,
-        LE,
-        LT
-    }
-
-    // TODO The XmlCondition needs to be split into several classes of condition
-    // instead of using an enum
-    private enum ConditionType {
-        DATA,
-        TIME,
-        NONE
-    }
-
-    /**
-     * Factory to create {@link TmfXmlCondition}
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param node
-     *            The XML root of this condition
-     * @param container
-     *            The state system container this condition belongs to
-     * @return The new {@link TmfXmlCondition}
-     * @since 2.0
-     */
-    public static TmfXmlCondition create(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container) {
-        Element rootNode = node;
-        /* Process the conditions: in each case, only process Element nodes */
-        List<@Nullable Element> childElements = XmlUtils.getChildElements(rootNode);
-
-        /*
-         * If the node is an if, take the child as the root condition
-         *
-         * FIXME: Maybe the caller should do this instead.
-         */
-        if (node.getNodeName().equals(TmfXmlStrings.IF)) {
-            if (childElements.isEmpty()) {
-                throw new IllegalArgumentException("TmfXmlCondition constructor: IF node with no child element"); //$NON-NLS-1$
-            }
-            rootNode = NonNullUtils.checkNotNull(childElements.get(0));
-            childElements = XmlUtils.getChildElements(rootNode);
-        }
-
-        List<@NonNull TmfXmlCondition> conditions = new ArrayList<>();
-        switch (rootNode.getNodeName()) {
-        case TmfXmlStrings.CONDITION:
-            return createPatternCondition(modelFactory, container, rootNode, childElements);
-        case TmfXmlStrings.NOT:
-            return createMultipleCondition(modelFactory, container, childElements, LogicalOperator.NOT, conditions);
-        case TmfXmlStrings.AND:
-            return createMultipleCondition(modelFactory, container, childElements, LogicalOperator.AND, conditions);
-        case TmfXmlStrings.OR:
-            return createMultipleCondition(modelFactory, container, childElements, LogicalOperator.OR, conditions);
-        default:
-            throw new IllegalArgumentException("TmfXmlCondition constructor: XML node " + rootNode.getNodeName() + " is of the wrong type"); //$NON-NLS-1$ //$NON-NLS-2$
-        }
-    }
-
-    private static TmfXmlCondition createPatternCondition(ITmfXmlModelFactory modelFactory, IXmlStateSystemContainer container, Element rootNode, List<@Nullable Element> childElements) {
-        ArrayList<ITmfXmlStateValue> stateValues;
-        ConditionOperator conditionOperator;
-        TmfXmlTimestampCondition timeCondition = null;
-        int size = rootNode.getElementsByTagName(TmfXmlStrings.STATE_VALUE).getLength();
-        if (size != 0) {
-            stateValues = new ArrayList<>(size);
-            if (size == 1) {
-                conditionOperator = getConditionOperator(rootNode);
-                getStateValuesForXmlCondition(modelFactory, NonNullUtils.checkNotNull(childElements), stateValues, container);
-            } else {
-                // No need to test if the childElements size is actually 2.
-                // The XSD validation do this check already.
-                conditionOperator = ConditionOperator.EQ;
-                stateValues.add(modelFactory.createStateValue(NonNullUtils.checkNotNull(childElements.get(0)), container, new ArrayList<ITmfXmlStateAttribute>()));
-                stateValues.add(modelFactory.createStateValue(NonNullUtils.checkNotNull(childElements.get(1)), container, new ArrayList<ITmfXmlStateAttribute>()));
-            }
-            return new TmfXmlCondition(ConditionType.DATA, stateValues, LogicalOperator.NONE, conditionOperator, null, new ArrayList<>(), container);
-        }
-        final Element firstElement = NonNullUtils.checkNotNull(childElements.get(0));
-        timeCondition = modelFactory.createTimestampsCondition(firstElement, container);
-        return new TmfXmlCondition(ConditionType.TIME, new ArrayList<>(), LogicalOperator.NONE, ConditionOperator.EQ, timeCondition, new ArrayList<>(), container);
-    }
-
-    private static TmfXmlCondition createMultipleCondition(ITmfXmlModelFactory modelFactory, IXmlStateSystemContainer container, List<@Nullable Element> childElements, LogicalOperator op,
-            List<@NonNull TmfXmlCondition> conditions) {
-        for (Element condition : childElements) {
-            if (condition == null) {
-                continue;
-            }
-            conditions.add(modelFactory.createCondition(condition, container));
-        }
-        return new TmfXmlCondition(ConditionType.NONE, new ArrayList<>(), op, ConditionOperator.NONE, null, conditions, container);
-    }
-
-    private TmfXmlCondition(ConditionType type, ArrayList<@NonNull ITmfXmlStateValue> stateValues, LogicalOperator operator, ConditionOperator conditionOperator, @Nullable TmfXmlTimestampCondition timeCondition, List<@NonNull TmfXmlCondition> conditions,
-            IXmlStateSystemContainer container) {
-        fType = type;
-        fStateValues = stateValues;
-        fOperator = operator;
-        fTimeCondition = timeCondition;
-        fContainer = container;
-        fConditions.addAll(conditions);
-        fConditionOperator = conditionOperator;
-    }
-
-    private static void getStateValuesForXmlCondition(ITmfXmlModelFactory modelFactory, List<@Nullable Element> childElements, List<ITmfXmlStateValue> stateValues, IXmlStateSystemContainer container) {
-        Element stateValueElement = NonNullUtils.checkNotNull(childElements.remove(childElements.size() - 1));
-        /*
-         * A state value is either preceded by an eventField or a number of
-         * state attributes
-         */
-        final Element firstElement = NonNullUtils.checkNotNull(childElements.get(0));
-        if (childElements.size() == 1 && firstElement.getNodeName().equals(TmfXmlStrings.ELEMENT_FIELD)) {
-            String attribute = firstElement.getAttribute(TmfXmlStrings.NAME);
-            stateValues.add(modelFactory.createStateValue(stateValueElement, container, attribute));
-        } else {
-            List<ITmfXmlStateAttribute> attributes = new ArrayList<>();
-            for (Element element : childElements) {
-                if (element == null) {
-                    throw new NullPointerException("There should be at list one element"); //$NON-NLS-1$
-                }
-                if (!element.getNodeName().equals(TmfXmlStrings.STATE_ATTRIBUTE)) {
-                    throw new IllegalArgumentException("TmfXmlCondition: a condition either has a eventField element or a number of TmfXmlStateAttribute elements before the state value"); //$NON-NLS-1$
-                }
-                ITmfXmlStateAttribute attribute = modelFactory.createStateAttribute(element, container);
-                attributes.add(attribute);
-            }
-            stateValues.add(modelFactory.createStateValue(stateValueElement, container, attributes));
-        }
-    }
-
-    private static ConditionOperator getConditionOperator(Element rootNode) {
-        String equationType = rootNode.getAttribute(TmfXmlStrings.OPERATOR);
-        switch (equationType) {
-        case TmfXmlStrings.EQ:
-            return ConditionOperator.EQ;
-        case TmfXmlStrings.NE:
-            return ConditionOperator.NE;
-        case TmfXmlStrings.GE:
-            return ConditionOperator.GE;
-        case TmfXmlStrings.GT:
-            return ConditionOperator.GT;
-        case TmfXmlStrings.LE:
-            return ConditionOperator.LE;
-        case TmfXmlStrings.LT:
-            return ConditionOperator.LT;
-        case TmfXmlStrings.NULL:
-            return ConditionOperator.EQ;
-        default:
-            throw new IllegalArgumentException("TmfXmlCondition: invalid comparison operator."); //$NON-NLS-1$
-        }
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public boolean test(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
-        ITmfStateSystem ss = fContainer.getStateSystem();
-        if (fType == ConditionType.DATA) {
-            try {
-                return testForEvent(event, NonNullUtils.checkNotNull(ss), scenarioInfo);
-            } catch (AttributeNotFoundException e) {
-                Activator.logError("Attribute not found", e); //$NON-NLS-1$
-                return false;
-            }
-        } else if (fType == ConditionType.TIME) {
-            if (fTimeCondition != null) {
-                return fTimeCondition.test(event, scenarioInfo);
-            }
-        } else if (!fConditions.isEmpty()) {
-            /* Verify a condition tree */
-            switch (fOperator) {
-            case AND:
-                for (ITmfXmlCondition childCondition : fConditions) {
-                    if (!childCondition.test(event, scenarioInfo)) {
-                        return false;
-                    }
-                }
-                return true;
-            case NONE:
-                break;
-            case NOT:
-                return !fConditions.get(0).test(event, scenarioInfo);
-            case OR:
-                for (ITmfXmlCondition childCondition : fConditions) {
-                    if (childCondition.test(event, scenarioInfo)) {
-                        return true;
-                    }
-                }
-                return false;
-            default:
-                break;
-
-            }
-        }
-        return true;
-    }
-
-    private boolean testForEvent(ITmfEvent event, ITmfStateSystem ss, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
-        /*
-         * The condition is either the equality check of a state value or a
-         * boolean operation on other conditions
-         */
-        if (fStateValues.size() == 1) {
-            ITmfXmlStateValue filter = fStateValues.get(0);
-            int quark = IXmlStateSystemContainer.ROOT_QUARK;
-            for (ITmfXmlStateAttribute attribute : filter.getAttributes()) {
-                quark = attribute.getAttributeQuark(event, quark, scenarioInfo);
-                /*
-                 * When verifying a condition, the state attribute must exist,
-                 * if it does not, the query is not valid, we stop the condition
-                 * check
-                 */
-                if (quark == IXmlStateSystemContainer.ERROR_QUARK) {
-                    throw new AttributeNotFoundException(ss.getSSID() + " Attribute:" + attribute); //$NON-NLS-1$
-                }
-            }
-
-            /*
-             * The actual value: it can be either queried in the state system or
-             * found in the event
-             */
-            ITmfStateValue valueState = (quark != IXmlStateSystemContainer.ROOT_QUARK) ? ss.queryOngoingState(quark) : filter.getEventFieldValue(event);
-
-            /* Get the value to compare to from the XML file */
-            ITmfStateValue valueXML;
-            valueXML = filter.getValue(event, scenarioInfo);
-            return compare(valueState, valueXML, fConditionOperator);
-        }
-        /* Get the two values needed for the comparison */
-        ITmfStateValue valuesXML1 = fStateValues.get(0).getValue(event, scenarioInfo);
-        ITmfStateValue valuesXML2 = fStateValues.get(1).getValue(event, scenarioInfo);
-        return valuesXML1.equals(valuesXML2);
-    }
-
-    @Override
-    public String toString() {
-        StringBuilder output = new StringBuilder("TmfXmlCondition: "); //$NON-NLS-1$
-        if (fOperator != LogicalOperator.NONE) {
-            output.append(fOperator).append(" on ").append(fConditions); //$NON-NLS-1$
-        } else {
-            output.append(fConditionOperator).append(" {").append(fStateValues.get(0)); //$NON-NLS-1$
-            if (fStateValues.size() == 2) {
-                output.append(", ").append(fStateValues.get(1)); //$NON-NLS-1$
-            }
-            output.append("}"); //$NON-NLS-1$
-        }
-        return output.toString();
-    }
-
-    /**
-     * Compare two ITmfStateValues based on the given comparison operator
-     *
-     * @param source
-     *            the state value to compare to
-     * @param dest
-     *            the state value to be compared with
-     * @param comparisonOperator
-     *            the operator to compare the inputs
-     * @return the boolean result of the comparison
-     */
-    public boolean compare(ITmfStateValue source, ITmfStateValue dest, ConditionOperator comparisonOperator) {
-        switch (comparisonOperator) {
-        // TODO The comparison operator should have a compareHelper that calls compare
-        case EQ:
-            return (source.compareTo(dest) == 0);
-        case NE:
-            return (source.compareTo(dest) != 0);
-        case GE:
-            return (source.compareTo(dest) >= 0);
-        case GT:
-            return (source.compareTo(dest) > 0);
-        case LE:
-            return (source.compareTo(dest) <= 0);
-        case LT:
-            return (source.compareTo(dest) < 0);
-        case NONE:
-        default:
-            throw new IllegalArgumentException("TmfXmlCondition: invalid comparison operator."); //$NON-NLS-1$
-        }
-    }
-}
\ No newline at end of file
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlEventHandler.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlEventHandler.java
deleted file mode 100644 (file)
index e91fbd5..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 Ecole Polytechnique de Montreal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Florian Wininger - Initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
-import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.w3c.dom.Element;
-
-/**
- * This Class implements an EventHandler in the XML-defined state system
- *
- * <pre>
- * example:
- * <eventHandler eventName="eventName">
- *  <stateChange>
- *      ...
- *  </stateChange>
- *  <stateChange>
- *      ...
- *  </stateChange>
- * </eventHandler>
- * </pre>
- *
- * @author Florian Wininger
- */
-public class TmfXmlEventHandler {
-
-    /* list of states changes */
-    private final List<TmfXmlStateChange> fStateChangeList = new ArrayList<>();
-    private final String fName;
-    private final IXmlStateSystemContainer fParent;
-
-    /**
-     * Constructor
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param node
-     *            XML event handler element
-     * @param parent
-     *            The state system container this event handler belongs to
-     */
-    public TmfXmlEventHandler(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer parent) {
-        fParent = parent;
-        String name = node.getAttribute(TmfXmlStrings.HANDLER_EVENT_NAME);
-        fName = name;
-
-        List<@NonNull Element> childElements = XmlUtils.getChildElements(node, TmfXmlStrings.STATE_CHANGE);
-        /* load state changes */
-        for (Element childElem : childElements) {
-            TmfXmlStateChange stateChange = modelFactory.createStateChange(childElem, fParent);
-            fStateChangeList.add(stateChange);
-        }
-    }
-
-    private boolean appliesToEvent(ITmfEvent event) {
-        String eventName = event.getName();
-
-        /* test for full name */
-        if (eventName.equals(fName)) {
-            return true;
-        }
-
-        /* test for the wildcard at the end */
-        if ((fName.endsWith(TmfXmlStrings.WILDCARD) && eventName.startsWith(fName.replace(TmfXmlStrings.WILDCARD, TmfXmlStrings.NULL)))) {
-            return true;
-        }
-        return false;
-    }
-
-    /**
-     * If the event handler can handle the event, it applies all state changes
-     * to modify the state system accordingly
-     *
-     * @param event
-     *            The trace event to handle
-     */
-    public void handleEvent(ITmfEvent event) {
-        if (!appliesToEvent(event)) {
-            return;
-        }
-
-        /* Process all state changes */
-        for (TmfXmlStateChange stateChange : fStateChangeList) {
-            try {
-                stateChange.handleEvent(event, null);
-            } catch (AttributeNotFoundException ae) {
-                /*
-                 * This would indicate a problem with the logic of the manager
-                 * here, so it shouldn't happen.
-                 */
-                Activator.logError("Attribute not found", ae); //$NON-NLS-1$
-            } catch (TimeRangeException tre) {
-                /*
-                 * This would happen if the events in the trace aren't ordered
-                 * chronologically, which should never be the case ...
-                 */
-                Activator.logError("TimeRangeException caught in the state system's event manager.  Are the events in the trace correctly ordered?", tre); //$NON-NLS-1$
-            } catch (StateValueTypeException sve) {
-                /*
-                 * This would happen if we were trying to push/pop attributes
-                 * not of type integer. Which, once again, should never happen.
-                 */
-                Activator.logError("State value type error", sve); //$NON-NLS-1$
-            }
-
-        }
-
-    }
-
-    @Override
-    public String toString() {
-        return "TmfXmlEventHandler: " + fName; //$NON-NLS-1$
-    }
-
-}
\ No newline at end of file
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlFsm.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlFsm.java
deleted file mode 100644 (file)
index be8bf40..0000000
+++ /dev/null
@@ -1,309 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- ******************************************************************************/
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.common.core.NonNullUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlScenarioHistoryBuilder.ScenarioStatusType;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-
-/**
- * This Class implements a state machine (FSM) tree in the XML-defined state
- * system.
- *
- * @author Jean-Christian Kouame
- * @since 2.0
- */
-public class TmfXmlFsm {
-
-    private final Map<String, TmfXmlState> fStatesMap;
-    private final List<TmfXmlScenario> fActiveScenariosList;
-    private final List<TmfXmlBasicTransition> fPreconditions;
-    private final String fId;
-    private final ITmfXmlModelFactory fModelFactory;
-    private final IXmlStateSystemContainer fContainer;
-    private final String fFinalStateId;
-    private final String fAbandonStateId;
-    private final boolean fInstanceMultipleEnabled;
-    private final String fInitialStateId;
-    private int fTotalScenarios;
-
-    /**
-     * Factory to create a {@link TmfXmlFsm}
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param node
-     *            The XML root of this fsm
-     * @param container
-     *            The state system container this fsm belongs to
-     * @return The new {@link TmfXmlFsm}
-     */
-    public static TmfXmlFsm create(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container) {
-        String id = node.getAttribute(TmfXmlStrings.ID);
-        boolean instanceMultipleEnabled = node.getAttribute(TmfXmlStrings.MULTIPLE).isEmpty() ? true : Boolean.parseBoolean(node.getAttribute(TmfXmlStrings.MULTIPLE));
-        final List<@NonNull TmfXmlBasicTransition> preconditions = new ArrayList<>();
-
-        // Get the preconditions
-        NodeList nodesPreconditions = node.getElementsByTagName(TmfXmlStrings.PRECONDITION);
-        for (int i = 0; i < nodesPreconditions.getLength(); i++) {
-            preconditions.add(new TmfXmlBasicTransition(((Element) NonNullUtils.checkNotNull(nodesPreconditions.item(i)))));
-        }
-
-        // Get the initial state and the preconditions
-        String initialState = node.getAttribute(TmfXmlStrings.INITIAL);
-        if (initialState.isEmpty()) {
-            NodeList nodesInitialState = node.getElementsByTagName(TmfXmlStrings.INITIAL);
-            if (nodesInitialState.getLength() == 1) {
-                NodeList nodesTransition = ((Element) nodesInitialState.item(0)).getElementsByTagName(TmfXmlStrings.TRANSITION);
-                if (nodesInitialState.getLength() != 1) {
-                    throw new IllegalArgumentException("initial state : there should be one and only one initial state."); //$NON-NLS-1$
-                }
-                initialState = ((Element) nodesTransition.item(0)).getAttribute(TmfXmlStrings.TARGET);
-            }
-        }
-
-        Map<@NonNull String, @NonNull TmfXmlState> statesMap = new HashMap<>();
-        // Get the FSM states
-        NodeList nodesState = node.getElementsByTagName(TmfXmlStrings.STATE);
-        for (int i = 0; i < nodesState.getLength(); i++) {
-            Element element = (Element) NonNullUtils.checkNotNull(nodesState.item(i));
-            TmfXmlState state = modelFactory.createState(element, container, null);
-            statesMap.put(state.getId(), state);
-
-            // If the initial state was not already set, we use the first state
-            // declared in the fsm description as initial state
-            if (initialState.isEmpty()) {
-                initialState = state.getId();
-            }
-        }
-
-        if (initialState.isEmpty()) {
-            throw new IllegalStateException("No initial state has been declared in fsm " + id); //$NON-NLS-1$
-        }
-
-        // Get the FSM final state
-        String finalStateId = TmfXmlStrings.NULL;
-        NodeList nodesFinalState = node.getElementsByTagName(TmfXmlStrings.FINAL);
-        if (nodesFinalState.getLength() == 1) {
-            final Element finalElement = NonNullUtils.checkNotNull((Element) nodesFinalState.item(0));
-            finalStateId = finalElement.getAttribute(TmfXmlStrings.ID);
-            if (!finalStateId.isEmpty()) {
-                TmfXmlState finalState = modelFactory.createState(finalElement, container, null);
-                statesMap.put(finalState.getId(), finalState);
-            }
-        }
-
-        // Get the FSM abandon state
-        String abandonStateId = TmfXmlStrings.NULL;
-        NodeList nodesAbandonState = node.getElementsByTagName(TmfXmlStrings.ABANDON_STATE);
-        if (nodesAbandonState.getLength() == 1) {
-            final Element abandonElement = NonNullUtils.checkNotNull((Element) nodesAbandonState.item(0));
-            abandonStateId = abandonElement.getAttribute(TmfXmlStrings.ID);
-            if (!abandonStateId.isEmpty()) {
-                TmfXmlState abandonState = modelFactory.createState(abandonElement, container, null);
-                statesMap.put(abandonState.getId(), abandonState);
-            }
-        }
-        return new TmfXmlFsm(modelFactory, container, id, instanceMultipleEnabled, initialState, finalStateId, abandonStateId, preconditions, statesMap);
-    }
-
-    private TmfXmlFsm(ITmfXmlModelFactory modelFactory, IXmlStateSystemContainer container, String id, boolean multiple,
-            String initialState, String finalState, String abandonState, List<TmfXmlBasicTransition> preconditions,
-            Map<String, TmfXmlState> states) {
-        fModelFactory = modelFactory;
-        fTotalScenarios = 0;
-        fContainer = container;
-        fId = id;
-        fInstanceMultipleEnabled = multiple;
-        fInitialStateId = initialState;
-        fFinalStateId = finalState;
-        fAbandonStateId = abandonState;
-        fPreconditions = ImmutableList.copyOf(preconditions);
-        fStatesMap = ImmutableMap.copyOf(states);
-        fActiveScenariosList = new ArrayList<>();
-    }
-
-    /**
-     * Get the fsm ID
-     *
-     * @return the id of this fsm
-     */
-    public String getId() {
-        return fId;
-    }
-
-    /**
-     * Get the initial state ID of this fsm
-     *
-     * @return the id of the initial state of this finite state machine
-     */
-    public String getInitialStateId() {
-        return fInitialStateId;
-    }
-
-    /**
-     * Get the final state ID of this fsm
-     *
-     * @return the id of the final state of this finite state machine
-     */
-    public String getFinalStateId() {
-        return fFinalStateId;
-    }
-
-    /**
-     * Get the abandon state ID fo this fsm
-     *
-     * @return the id of the abandon state of this finite state machine
-     */
-    public String getAbandonStateId() {
-        return fAbandonStateId;
-    }
-
-    /**
-     * Get the states table of this fsm in map
-     *
-     * @return The map containing all state definition for this fsm
-     */
-    public Map<String, TmfXmlState> getStatesMap() {
-        return Collections.unmodifiableMap(fStatesMap);
-    }
-
-    /**
-     * Process the active event and determine the next step of this fsm
-     *
-     * @param event
-     *            The event to process
-     * @param tests
-     *            The list of possible transitions of the state machine
-     * @param scenarioInfo
-     *            The active scenario details.
-     * @return A pair containing the next state of the state machine and the
-     *         actions to execute
-     */
-    public @Nullable TmfXmlStateTransition next(ITmfEvent event, Map<String, TmfXmlTransitionValidator> tests, TmfXmlScenarioInfo scenarioInfo) {
-        boolean matched = false;
-        TmfXmlStateTransition stateTransition = null;
-        TmfXmlState state = NonNullUtils.checkNotNull(fStatesMap.get(scenarioInfo.getActiveState()));
-        for (int i = 0; i < state.getTransitionList().size() && !matched; i++) {
-            stateTransition = state.getTransitionList().get(i);
-            matched = stateTransition.test(event, scenarioInfo, tests);
-        }
-        return matched ? stateTransition : null;
-    }
-
-
-
-    /**
-     * Validate the preconditions of this fsm. If not validate, the fsm will
-     * skip the active event.
-     *
-     * @param event
-     *            The current event
-     * @param tests
-     *            The transition inputs
-     * @return True if one of the precondition is validated, false otherwise
-     */
-    private boolean validatePreconditions(ITmfEvent event, Map<String, TmfXmlTransitionValidator> tests) {
-        if (fPreconditions.isEmpty()) {
-            return true;
-        }
-        for (TmfXmlBasicTransition precondition : fPreconditions) {
-            if (precondition.test(event, null, tests)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /**
-     * Handle the current event
-     *
-     * @param event
-     *            The current event
-     * @param transitionMap
-     *            The transitions of the pattern
-     */
-    public void handleEvent(ITmfEvent event, Map<String, TmfXmlTransitionValidator> transitionMap) {
-        if (!validatePreconditions(event, transitionMap)) {
-            return;
-        }
-        for (Iterator<TmfXmlScenario> currentItr = fActiveScenariosList.iterator(); currentItr.hasNext();) {
-            TmfXmlScenario scenario = currentItr.next();
-            // Remove inactive scenarios or handle the active ones.
-            if (!scenario.isActive()) {
-                currentItr.remove();
-            } else {
-                handleScenario(scenario, event);
-            }
-        }
-    }
-
-    /**
-     * Abandon all ongoing scenarios
-     */
-    public void dispose() {
-        for (TmfXmlScenario scenario : fActiveScenariosList) {
-            if (scenario.isActive()) {
-                scenario.cancel();
-            }
-        }
-    }
-
-    private static void handleScenario(TmfXmlScenario scenario, ITmfEvent event) {
-        if (scenario.isActive()) {
-            scenario.handleEvent(event);
-        }
-    }
-
-    /**
-     * Create a new scenario of this fsm
-     *
-     * @param event
-     *            The current event, null if not
-     * @param eventHandler
-     *            The event handler this fsm belongs
-     * @param force
-     *            True to force the creation of the scenario, false otherwise
-     */
-    public synchronized void createScenario(@Nullable ITmfEvent event, TmfXmlPatternEventHandler eventHandler, boolean force) {
-        if (force || isNewScenarioAllowed()) {
-            TmfXmlScenario scenario = new TmfXmlScenario(event, eventHandler, fId, fContainer, fModelFactory);
-            fTotalScenarios++;
-            fActiveScenariosList.add(scenario);
-        }
-    }
-
-    /**
-     * Check if we have the right to create a new scenario. A new scenario could
-     * be created if it is not the first scenario of an FSM and the FSM is not a
-     * singleton and the status of the last created scenario is not PENDING.
-     *
-     * @return True if the start of a new scenario is allowed, false otherwise
-     */
-    public synchronized boolean isNewScenarioAllowed() {
-        return !fActiveScenariosList.get(fActiveScenariosList.size() - 1).getScenarioInfos().getStatus().equals(ScenarioStatusType.PENDING)
-                && fInstanceMultipleEnabled && fTotalScenarios > 0;
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlLocation.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlLocation.java
deleted file mode 100644 (file)
index 6a46e77..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 Ecole Polytechnique de Montreal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Florian Wininger - Initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.w3c.dom.Element;
-
-/**
- * This Class implements a Location in the XML-defined state system, ie a named
- * shortcut to reach a given attribute, used in state attributes
- *
- * <pre>
- * example:
- *  <location id="CurrentCPU">
- *    <stateAttribute type="constant" value="CPUs" />
- *    <stateAttribute type="eventField" name="cpu" />
- *    ...
- *  </location>
- * </pre>
- *
- * @author Florian Wininger
- */
-public class TmfXmlLocation {
-
-    /** Path in the State System */
-    private final List<ITmfXmlStateAttribute> fPath = new LinkedList<>();
-
-    /** ID : name of the location */
-    private final String fId;
-    private final IXmlStateSystemContainer fContainer;
-
-    /**
-     * Constructor
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param location
-     *            XML node element
-     * @param container
-     *            The state system container this location belongs to
-     */
-    public TmfXmlLocation(ITmfXmlModelFactory modelFactory, Element location, IXmlStateSystemContainer container) {
-        String id = location.getAttribute(TmfXmlStrings.ID);
-        fId = id;
-        fContainer = container;
-
-        List<@Nullable Element> childElements = XmlUtils.getChildElements(location);
-        for (Element attribute : childElements) {
-            if (attribute == null) {
-                continue;
-            }
-            ITmfXmlStateAttribute xAttribute = modelFactory.createStateAttribute(attribute, fContainer);
-            fPath.add(xAttribute);
-        }
-    }
-
-    /**
-     * Get the id of the location
-     *
-     * @return The id of a location
-     */
-    public String getId() {
-        return fId;
-    }
-
-    /**
-     * Get the quark for the path represented by this location
-     *
-     * @param event
-     *            The event being handled
-     *
-     * @param startQuark
-     *            The starting quark for relative search, use
-     *            {@link IXmlStateSystemContainer#ROOT_QUARK} for the root of
-     *            the attribute tree
-     * @param scenarioInfo
-     *            The active scenario details. Or <code>null</code> if there is
-     *            no scenario.
-     * @return The quark at the leaf of the path
-     * @since 2.0
-     */
-    public int getLocationQuark(@Nullable ITmfEvent event, int startQuark, @Nullable TmfXmlScenarioInfo scenarioInfo) {
-        int quark = startQuark;
-        for (ITmfXmlStateAttribute attrib : fPath) {
-            quark = attrib.getAttributeQuark(event, quark, scenarioInfo);
-            if (quark == IXmlStateSystemContainer.ERROR_QUARK) {
-                break;
-            }
-        }
-        return quark;
-    }
-
-    /**
-     * Get the quark for the path represented by this location
-     *
-     * @param startQuark
-     *            The starting quark for relative search, use
-     *            {@link IXmlStateSystemContainer#ROOT_QUARK} for the root of
-     *            the attribute tree
-     * @param scenarioInfo
-     *            The active scenario details. Or <code>null</code> if there is
-     *            no scenario.
-     * @return The quark at the leaf of the path
-     * @since 2.0
-     */
-    public int getLocationQuark(int startQuark, @Nullable TmfXmlScenarioInfo scenarioInfo) {
-        int quark = startQuark;
-        for (ITmfXmlStateAttribute attrib : fPath) {
-            quark = attrib.getAttributeQuark(quark, scenarioInfo);
-            if (quark == IXmlStateSystemContainer.ERROR_QUARK) {
-                break;
-            }
-        }
-        return quark;
-    }
-
-    @Override
-    public String toString() {
-        return "TmfXmlLocation " + fId + ": " + fPath; //$NON-NLS-1$ //$NON-NLS-2$
-    }
-
-}
\ No newline at end of file
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlPatternEventHandler.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlPatternEventHandler.java
deleted file mode 100644 (file)
index 9c7cb5d..0000000
+++ /dev/null
@@ -1,198 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- ******************************************************************************/
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.common.core.NonNullUtils;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternStateProvider;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
-import com.google.common.collect.ImmutableMap;
-
-/**
- * This Class implements a pattern handler tree in the XML-defined state system.
- * It receives events and dispatches it to Active finite state machines.
- *
- * @author Jean-Christian Kouame
- * @since 2.0
- */
-public class TmfXmlPatternEventHandler {
-
-    /* list of states changes */
-    private final XmlPatternStateProvider fParent;
-
-    private final List<String> fInitialFsm;
-    private final Map<String, TmfXmlTransitionValidator> fTestMap = new HashMap<>();
-    private final Map<String, ITmfXmlAction> fActionMap = new HashMap<>();
-    private final Map<String, TmfXmlFsm> fFsmMap = new HashMap<>();
-    private final List<TmfXmlFsm> fActiveFsmList = new ArrayList<>();
-
-    /**
-     * Constructor
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param node
-     *            The XML root of this event handler
-     * @param parent
-     *            The state system container this event handler belongs to
-     */
-    public TmfXmlPatternEventHandler(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer parent) {
-        fParent = (XmlPatternStateProvider) parent;
-        String initialFsm = node.getAttribute(TmfXmlStrings.INITIAL);
-        fInitialFsm = initialFsm.isEmpty() ? Collections.EMPTY_LIST : Arrays.asList(initialFsm.split(TmfXmlStrings.AND_SEPARATOR));
-
-        NodeList nodesTest = node.getElementsByTagName(TmfXmlStrings.TEST);
-        /* load transition input */
-        for (int i = 0; i < nodesTest.getLength(); i++) {
-            Element element = (Element) nodesTest.item(i);
-            if (element == null) {
-                throw new IllegalArgumentException();
-            }
-            TmfXmlTransitionValidator test = modelFactory.createTransitionValidator(element, fParent);
-            fTestMap.put(test.getId(), test);
-        }
-
-        NodeList nodesAction = node.getElementsByTagName(TmfXmlStrings.ACTION);
-        /* load actions */
-        for (int i = 0; i < nodesAction.getLength(); i++) {
-            Element element = (Element) nodesAction.item(i);
-            if (element == null) {
-                throw new IllegalArgumentException();
-            }
-            ITmfXmlAction action = modelFactory.createAction(element, fParent);
-            fActionMap.put(((TmfXmlAction) action).getId(), action);
-        }
-        fActionMap.put(TmfXmlStrings.CONSTANT_PREFIX + ITmfXmlAction.CLEAR_STORED_FIELDS_STRING, new ResetStoredFieldsAction(fParent));
-        fActionMap.put(TmfXmlStrings.CONSTANT_PREFIX + ITmfXmlAction.SAVE_STORED_FIELDS_STRING, new UpdateStoredFieldsAction(fParent));
-
-        NodeList nodesFsm = node.getElementsByTagName(TmfXmlStrings.FSM);
-        /* load fsm */
-        for (int i = 0; i < nodesFsm.getLength(); i++) {
-            Element element = (Element) nodesFsm.item(i);
-            if (element == null) {
-                throw new IllegalArgumentException();
-            }
-            TmfXmlFsm fsm = modelFactory.createFsm(element, fParent);
-            fFsmMap.put(fsm.getId(), fsm);
-        }
-    }
-
-    /**
-     * Start a new scenario for this specific fsm id. If the fsm support only a
-     * single instance and this instance already exist, no new scenario is then
-     * started. If the scenario is created we handle the current event directly.
-     *
-     * @param fsmIds
-     *            The IDs of the fsm to start
-     * @param event
-     *            The current event
-     * @param force
-     *            True to force the creation of the scenario, false otherwise
-     */
-    public void startScenario(List<String> fsmIds, @Nullable ITmfEvent event, boolean force) {
-        for (String fsmId : fsmIds) {
-            TmfXmlFsm fsm = NonNullUtils.checkNotNull(fFsmMap.get(fsmId));
-            if (!fActiveFsmList.contains(fsm)) {
-                fActiveFsmList.add(fsm);
-            }
-            fsm.createScenario(event, this, force);
-        }
-    }
-
-    /**
-     * Get all the defined transition tests
-     *
-     * @return The tests in a map
-     */
-    public Map<String, TmfXmlTransitionValidator> getTestMap() {
-        return ImmutableMap.copyOf(fTestMap);
-    }
-
-    /**
-     * Get all the defined actions
-     *
-     * @return The actions
-     */
-    public Map<String, ITmfXmlAction> getActionMap() {
-        return ImmutableMap.copyOf(fActionMap);
-    }
-
-    /**
-     * If the pattern handler can handle the event, it send the event to all
-     * finite state machines with ongoing scenarios
-     *
-     * @param event
-     *            The trace event to handle
-     */
-    public void handleEvent(ITmfEvent event) {
-        /*
-         * Order is important so cannot be parallelized
-         */
-        final @NonNull List<@NonNull TmfXmlFsm> activeFsmList = fActiveFsmList;
-        final @NonNull Map<@NonNull String, @NonNull TmfXmlFsm> fsmMap = fFsmMap;
-        if (activeFsmList.isEmpty()) {
-            List<String> fsmIds = fInitialFsm;
-            if (fsmIds.isEmpty()) {
-                fsmIds = new ArrayList<>();
-                for (TmfXmlFsm fsm : fsmMap.values()) {
-                    fsmIds.add(fsm.getId());
-                }
-            }
-            if (!fsmIds.isEmpty()) {
-                startScenario(fsmIds, null, true);
-            }
-        } else {
-            List<String> fsmToStart = new ArrayList<>();
-            for (Map.Entry<String, TmfXmlFsm> entry : fsmMap.entrySet()) {
-                if (entry.getValue().isNewScenarioAllowed()) {
-                    fsmToStart.add(entry.getKey());
-                }
-            }
-            if (!fsmToStart.isEmpty()) {
-                startScenario(fsmToStart, null, false);
-            }
-        }
-        for (TmfXmlFsm fsm : activeFsmList) {
-            fsm.handleEvent(event, fTestMap);
-        }
-    }
-
-    /**
-     * Abandon all the ongoing scenarios
-     */
-    public void dispose() {
-        for (TmfXmlFsm fsm : fActiveFsmList) {
-            fsm.dispose();
-        }
-    }
-
-    /**
-     * Get the fsm corresponding to the specified id
-     *
-     * @param fsmId
-     *            The id of the fsm
-     * @return The fsm found, null if nothing found
-     */
-    public @Nullable TmfXmlFsm getFsm(String fsmId) {
-        return fFsmMap.get(fsmId);
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlPatternSegmentBuilder.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlPatternSegmentBuilder.java
deleted file mode 100644 (file)
index d04068c..0000000
+++ /dev/null
@@ -1,344 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- ******************************************************************************/
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-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.pattern.stateprovider.XmlPatternStateProvider;
-import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
-import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
-import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.segment.TmfXmlPatternSegment;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
-/**
- * This class defines a pattern segment builder. It will use the XML description
- * of the pattern segment to generate it at runtime.
- *
- * @author Jean-Christian Kouame
- * @since 2.0
- *
- */
-public class TmfXmlPatternSegmentBuilder {
-
-    /**
-     * The string unknown
-     */
-    public static final String UNKNOWN_STRING = "unknown"; //$NON-NLS-1$
-    /**
-     * Prefix for the pattern segment name
-     */
-    public static final String PATTERN_SEGMENT_NAME_PREFIX = "seg_"; //$NON-NLS-1$
-    private final ITmfXmlModelFactory fModelFactory;
-    private final IXmlStateSystemContainer fContainer;
-    private final List<TmfXmlPatternSegmentField> fFields = new ArrayList<>();
-    private final TmfXmlPatternSegmentType fSegmentType;
-
-    /**
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param node
-     *            XML element of the pattern segment builder
-     * @param parent
-     *            The state system container this pattern segment builder
-     *            belongs to
-     */
-    public TmfXmlPatternSegmentBuilder(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer parent) {
-        fModelFactory = modelFactory;
-        fContainer = parent;
-
-        //Set the XML type of the segment
-        NodeList nodesSegmentType = node.getElementsByTagName(TmfXmlStrings.SEGMENT_TYPE);
-        Element element = (Element) nodesSegmentType.item(0);
-        if (element == null) {
-            throw new IllegalArgumentException();
-        }
-        fSegmentType = new TmfXmlPatternSegmentType(element);
-
-        //Set the XML content of the segment
-        NodeList nodesSegmentContent = node.getElementsByTagName(TmfXmlStrings.SEGMENT_CONTENT);
-        Element fContentElement = (Element) nodesSegmentContent.item(0);
-        if (fContentElement != null) {
-            NodeList nodesSegmentField = fContentElement.getElementsByTagName(TmfXmlStrings.SEGMENT_FIELD);
-            for (int i = 0; i < nodesSegmentField.getLength(); i++) {
-                fFields.add(new TmfXmlPatternSegmentField(checkNotNull((Element) nodesSegmentField.item(i))));
-            }
-        }
-    }
-
-    /**
-     * Generate a pattern segment
-     *
-     * @param event
-     *            The active event
-     * @param start
-     *            Start time of the pattern segment to generate
-     * @param end
-     *            End time of the pattern segment to generate
-     * @param scenarioInfo
-     *            The active scenario details. Or <code>null</code> if there is
-     *            no scenario.
-     * @return The pattern segment generated
-     */
-    public TmfXmlPatternSegment generatePatternSegment(ITmfEvent event, ITmfTimestamp start, ITmfTimestamp end, @Nullable TmfXmlScenarioInfo scenarioInfo) {
-        int scale = event.getTimestamp().getScale();
-        long startValue = start.toNanos();
-        long endValue = end.toNanos();
-        String segmentName = getPatternSegmentName(event, scenarioInfo);
-        Map<String, ITmfStateValue> fields = new HashMap<>();
-        setPatternSegmentContent(event, start, end, fields, scenarioInfo);
-        TmfXmlPatternSegment segment = new TmfXmlPatternSegment(startValue, endValue, scale, segmentName, fields);
-        if (fContainer instanceof XmlPatternStateProvider) {
-            ((XmlPatternStateProvider) fContainer).getListener().onNewSegment(segment);
-        }
-        return segment;
-    }
-
-    /**
-     * Get the pattern segment name
-     *
-     * @param event
-     *            The active event
-     * @param scenarioInfo
-     *            The active scenario details. Or <code>null</code> if there is
-     *            no scenario.
-     * @return The name of the segment
-     */
-    private String getPatternSegmentName(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
-        return fSegmentType.getName(event, scenarioInfo);
-    }
-
-    /**
-     * Compute all the fields and their values for this pattern segment. The
-     * fields could be constant values or values queried from the state system.
-     *
-     * @param event
-     *            The current event
-     * @param start
-     *            The start timestamp of this segment
-     * @param end
-     *            The end timestamp of this segment
-     * @param fields
-     *            The map that will contained all the fields
-     * @param scenarioInfo
-     *            The active scenario details. Or <code>null</code> if there is
-     *            no scenario.
-     */
-    private void setPatternSegmentContent(ITmfEvent event, ITmfTimestamp start, ITmfTimestamp end, Map<String, ITmfStateValue> fields, @Nullable TmfXmlScenarioInfo scenarioInfo) {
-        for (TmfXmlPatternSegmentField field : fFields) {
-            fields.put(field.getName().intern(), field.getValue(event, scenarioInfo));
-        }
-        if (scenarioInfo != null) {
-            addStoredFieldsContent(event, fields, scenarioInfo);
-        }
-    }
-
-    /**
-     * Query the stored fields path and add them to the content of the pattern
-     * segment. This is specific to pattern analysis.
-     *
-     * @param event
-     *            The active event
-     * @param fields
-     *            The segment fields
-     * @param info
-     *            The active scenario details
-     */
-    protected void addStoredFieldsContent(ITmfEvent event, Map<String, ITmfStateValue> fields, final TmfXmlScenarioInfo info) {
-        if (fContainer instanceof XmlPatternStateProvider) {
-            for (Entry<String, String> entry : ((XmlPatternStateProvider) fContainer).getStoredFields().entrySet()) {
-                ITmfStateValue value = ((XmlPatternStateProvider) fContainer).getHistoryBuilder().getStoredFieldValue(fContainer, entry.getValue(), info, event);
-                if (!value.isNull()) {
-                    fields.put(entry.getValue().intern(), value);
-                }
-            }
-        }
-    }
-
-    private static ITmfStateValue getStateValueFromConstant(String constantValue, String type) {
-        switch (type) {
-        case TmfXmlStrings.TYPE_INT:
-            return TmfStateValue.newValueInt(Integer.parseInt(constantValue));
-        case TmfXmlStrings.TYPE_LONG:
-            return TmfStateValue.newValueLong(Long.parseLong(constantValue));
-        case TmfXmlStrings.TYPE_STRING:
-            return TmfStateValue.newValueString(constantValue);
-        case TmfXmlStrings.TYPE_NULL:
-            return TmfStateValue.nullValue();
-        default:
-            throw new IllegalArgumentException("Invalid type of field : " + type); //$NON-NLS-1$
-        }
-    }
-
-    private static void getNameFromXmlStateValue(ITmfEvent event, StringBuilder builder, ITmfXmlStateValue xmlStateValue, @Nullable TmfXmlScenarioInfo scenarioInfo) {
-        try {
-            ITmfStateValue value = xmlStateValue.getValue(event, scenarioInfo);
-            switch (value.getType()) {
-            case DOUBLE:
-                builder.append(value.unboxDouble());
-                break;
-            case INTEGER:
-                builder.append(value.unboxInt());
-                break;
-            case LONG:
-                builder.append(value.unboxLong());
-                break;
-            case NULL:
-                builder.append(UNKNOWN_STRING);
-                break;
-            case STRING:
-                builder.append(value.unboxStr());
-                break;
-            default:
-                throw new StateValueTypeException("Invalid type of state value"); //$NON-NLS-1$
-            }
-        } catch (AttributeNotFoundException e) {
-            Activator.logInfo("Impossible to get the state value", e); //$NON-NLS-1$
-        }
-    }
-
-    /**
-     * This class represents the segment fields described in the XML. The real
-     * value of the field will be set at runtime using the active event.
-     *
-     * @author Jean-Christian Kouame
-     *
-     */
-    private class TmfXmlPatternSegmentField {
-        private final String fName;
-        private final String fType;
-        private final @Nullable ITmfStateValue fStateValue;
-        private final @Nullable ITmfXmlStateValue fXmlStateValue;
-
-        /**
-         * Constructor
-         *
-         * @param element
-         *            The pattern segment field node
-         */
-        public TmfXmlPatternSegmentField(Element element) {
-            // The name, the type and the value of each field could respectively
-            // be found from the attributes name, type and value. If the value
-            // attribute is not available, try to find it from the child state
-            // value.
-            fName = element.getAttribute(TmfXmlStrings.NAME);
-            fType = element.getAttribute(TmfXmlStrings.TYPE);
-            String constantValue = element.getAttribute(TmfXmlStrings.VALUE);
-            if (constantValue.isEmpty() && !fType.equals(TmfXmlStrings.TYPE_NULL)) {
-                fStateValue = null;
-                Element elementFieldStateValue = (Element) element.getElementsByTagName(TmfXmlStrings.STATE_VALUE).item(0);
-                if (elementFieldStateValue == null) {
-                    throw new IllegalArgumentException("The value of the field " + fName + " is missing"); //$NON-NLS-1$ //$NON-NLS-2$
-                }
-                fXmlStateValue = fModelFactory.createStateValue(elementFieldStateValue, fContainer, new ArrayList<>());
-            } else {
-                fStateValue = getStateValueFromConstant(constantValue, fType);
-                fXmlStateValue = null;
-            }
-        }
-
-        /**
-         * Get the real value of the XML pattern segment field
-         *
-         * @param event
-         *            The active event
-         * @return The state value representing the value of the XML pattern
-         *         segment field
-         * @param scenarioInfo
-         *            The active scenario details. Or <code>null</code> if there
-         *            is no scenario.
-         */
-        public ITmfStateValue getValue(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
-            if (fStateValue != null) {
-                return fStateValue;
-            }
-            try {
-                return checkNotNull(fXmlStateValue).getValue(event, scenarioInfo);
-            } catch (AttributeNotFoundException e) {
-                Activator.logError("Failed to get the state value", e); //$NON-NLS-1$
-            }
-            throw new IllegalStateException("Failed to get the value for the segment field " + fName); //$NON-NLS-1$
-        }
-
-        /**
-         * Get the name of the XML pattern segment field
-         *
-         * @return The name
-         */
-        public String getName() {
-            return fName;
-        }
-    }
-
-    /**
-     * This class represents the segment type described in XML.
-     *
-     * @author Jean-Christian Kouame
-     *
-     */
-    private class TmfXmlPatternSegmentType {
-        private final String fSegmentNameAttribute;
-        private final @Nullable ITmfXmlStateValue fNameStateValue;
-
-        /**
-         * Constructor
-         *
-         * @param element
-         *            The pattern segment type node
-         */
-        public TmfXmlPatternSegmentType(Element element) {
-            // Try to find the segment name from the name attribute. If
-            // attribute not available, try to find it from the child state value
-            fSegmentNameAttribute = element.getAttribute(TmfXmlStrings.SEGMENT_NAME);
-            if (!fSegmentNameAttribute.isEmpty()) {
-                fNameStateValue = null;
-            } else {
-                Element elementSegmentNameStateValue = (Element) element.getElementsByTagName(TmfXmlStrings.STATE_VALUE).item(0);
-                if (elementSegmentNameStateValue == null) {
-                    throw new IllegalArgumentException("Failed to get the segment name. A state value is needed."); //$NON-NLS-1$
-                }
-                fNameStateValue = fModelFactory.createStateValue(elementSegmentNameStateValue, fContainer, new ArrayList<>());
-            }
-        }
-
-        /**
-         * Get the name of the segment
-         *
-         * @param event
-         *            The active event
-         * @param scenarioInfo
-         *            The active scenario details. Or <code>null</code> if there
-         *            is no scenario.
-         * @return The segment name
-         */
-        public String getName(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
-            StringBuilder name = new StringBuilder(PATTERN_SEGMENT_NAME_PREFIX);
-            if (fNameStateValue != null) {
-                getNameFromXmlStateValue(event, name, fNameStateValue, scenarioInfo);
-            } else {
-                name.append(fSegmentNameAttribute);
-            }
-            return name.toString().intern();
-        }
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlScenario.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlScenario.java
deleted file mode 100644 (file)
index 249d60e..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- ******************************************************************************/
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.List;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternStateProvider;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlScenarioHistoryBuilder.ScenarioStatusType;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-
-/**
- * This Class implements a Scenario in the XML-defined state system
- *
- * @since 2.0
- */
-public class TmfXmlScenario {
-
-    private final IXmlStateSystemContainer fContainer;
-    private final TmfXmlFsm fFsm;
-    private TmfXmlPatternEventHandler fPatternHandler;
-    private TmfXmlScenarioInfo fScenarioInfo;
-    TmfXmlScenarioHistoryBuilder fHistoryBuilder;
-
-    /**
-     * Constructor
-     *
-     * @param event
-     *            The event at which this scenario is created
-     * @param patternHandler
-     *            The filter handler
-     * @param fsmId
-     *            the id of the fsm executed by this scenario
-     * @param container
-     *            The state system container this scenario belongs to
-     * @param modelFactory
-     *            The model factory
-     */
-    public TmfXmlScenario(@Nullable ITmfEvent event, TmfXmlPatternEventHandler patternHandler, String fsmId, IXmlStateSystemContainer container, ITmfXmlModelFactory modelFactory) {
-        TmfXmlFsm fsm = patternHandler.getFsm(fsmId);
-        if (fsm == null) {
-            throw new IllegalArgumentException(fsmId + "has not been declared."); //$NON-NLS-1$
-        }
-        fFsm = fsm;
-        fContainer = container;
-        fHistoryBuilder = ((XmlPatternStateProvider) container).getHistoryBuilder();
-        fPatternHandler = patternHandler;
-        int quark = fHistoryBuilder.assignScenarioQuark(fContainer, fsmId);
-        int statusQuark = fHistoryBuilder.getScenarioStatusQuark(fContainer, quark);
-        fScenarioInfo = new TmfXmlScenarioInfo(fFsm.getInitialStateId(), ScenarioStatusType.PENDING, quark, statusQuark, fFsm);
-        fHistoryBuilder.update(fContainer, fScenarioInfo, event);
-    }
-
-    /**
-     * Get this scenario infos
-     *
-     * @return The scenario info
-     */
-    public TmfXmlScenarioInfo getScenarioInfos() {
-        return fScenarioInfo;
-    }
-
-    /**
-     * Cancel the execution of this scenario
-     */
-    public void cancel() {
-        fScenarioInfo.setStatus(ScenarioStatusType.ABANDONED);
-        if (fScenarioInfo.getStatus() != ScenarioStatusType.PENDING) {
-            fHistoryBuilder.completeScenario(fContainer, fScenarioInfo, null);
-        }
-    }
-
-    /**
-     * Test if the scenario is active or not
-     *
-     * @return True if the scenario is active, false otherwise
-     */
-    public boolean isActive() {
-        return fScenarioInfo.getStatus().equals(ScenarioStatusType.PENDING) || fScenarioInfo.getStatus().equals(ScenarioStatusType.IN_PROGRESS);
-    }
-
-    /**
-     * Handle the ongoing event
-     *
-     * @param event
-     *            The ongoing event
-     */
-    public void handleEvent(ITmfEvent event) {
-
-        TmfXmlStateTransition out = fFsm.next(event, fPatternHandler.getTestMap(), fScenarioInfo);
-        if (out == null) {
-            return;
-        }
-
-        // Processing the actions in the transition
-        final List<String> actions = out.getAction();
-        for (String actionId : actions) {
-            ITmfXmlAction action = fPatternHandler.getActionMap().get(actionId);
-            if (action != null) {
-                action.execute(event, fScenarioInfo);
-            } else {
-                throw new IllegalStateException("Action " + actionId + " cannot be found."); //$NON-NLS-1$ //$NON-NLS-2$
-            }
-        }
-
-        // Change the activeState
-        final @NonNull String nextState = out.getTarget();
-        if (fScenarioInfo.getStatus().equals(ScenarioStatusType.PENDING)) {
-            fScenarioInfo.setStatus(ScenarioStatusType.IN_PROGRESS);
-            fHistoryBuilder.startScenario(fContainer, fScenarioInfo, event);
-        } else if (nextState.equals(fFsm.getAbandonStateId())) {
-            fScenarioInfo.setStatus(ScenarioStatusType.ABANDONED);
-            fHistoryBuilder.completeScenario(fContainer, fScenarioInfo, event);
-        } else if (nextState.equals(fFsm.getFinalStateId())) {
-            fScenarioInfo.setStatus(ScenarioStatusType.MATCHED);
-            fHistoryBuilder.completeScenario(fContainer, fScenarioInfo, event);
-        }
-        fScenarioInfo.setActiveState(nextState);
-        fHistoryBuilder.update(fContainer, fScenarioInfo, event);
-    }
-
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlScenarioHistoryBuilder.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlScenarioHistoryBuilder.java
deleted file mode 100644 (file)
index 9f87600..0000000
+++ /dev/null
@@ -1,440 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- ******************************************************************************/
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.common.core.NonNullUtils;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
-import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
-import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
-import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
-import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
-import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.eclipse.tracecompass.tmf.core.statesystem.TmfAttributePool;
-
-import com.google.common.collect.BiMap;
-import com.google.common.collect.ImmutableBiMap;
-
-/**
- * This class is responsible for creating scenarios, updating their status and
- * data, and saving the scenario data to the state system
- *
- * @since 2.0
- */
-public class TmfXmlScenarioHistoryBuilder {
-
-    /** The string 'status' */
-    public static final String STATUS = "status"; //$NON-NLS-1$
-    /** The string for "nbScenarios" */
-    public static final String SCENARIO_COUNT = "nbScenarios"; //$NON-NLS-1$
-
-    /** The string for start time */
-    private static final String START_TIME = "startTime"; //$NON-NLS-1$
-    /** Error message */
-    private static final String ERROR_MESSAGE = "The state system is null"; //$NON-NLS-1$
-
-    private final Map<String, TmfAttributePool> fFsmPools = new HashMap<>();
-
-    /**
-     * All possible types of status for a scenario
-     */
-    public enum ScenarioStatusType {
-        /**
-         * scenario pending for start point
-         */
-        PENDING,
-        /**
-         * scenario in progress
-         */
-        IN_PROGRESS,
-        /**
-         * scenario abandoned
-         */
-        ABANDONED,
-        /**
-         * scenario match with the pattern
-         */
-        MATCHED
-    }
-
-    /**
-     * Cache the available status in a map
-     */
-    protected static final BiMap<ScenarioStatusType, ITmfStateValue> STATUS_MAP = NonNullUtils.checkNotNull(ImmutableBiMap.of(
-            ScenarioStatusType.PENDING, TmfStateValue.newValueInt(0),
-            ScenarioStatusType.IN_PROGRESS, TmfStateValue.newValueInt(1),
-            ScenarioStatusType.MATCHED, TmfStateValue.newValueInt(2),
-            ScenarioStatusType.ABANDONED, TmfStateValue.newValueInt(3)));
-
-    /**
-     * Get the scenario matched process start time
-     *
-     * @param container
-     *            The state system container this class use
-     * @param info
-     *            The scenario details
-     * @param event
-     *            The current event
-     *
-     * @return The start time of the matching process for the specified scenario
-     */
-    public long getStartTime(final IXmlStateSystemContainer container, final TmfXmlScenarioInfo info, final ITmfEvent event) {
-        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
-        long ts = getTimestamp(event, ss);
-        try {
-            int attributeQuark = getQuarkRelativeAndAdd(ss, info.getQuark(), START_TIME);
-            ITmfStateInterval state = ss.querySingleState(ts, attributeQuark);
-            return state.getStartTime();
-        } catch (AttributeNotFoundException | StateSystemDisposedException e) {
-            Activator.logError("failed to get the start time of the scenario", e); //$NON-NLS-1$
-        }
-        return -1L;
-    }
-
-    /**
-     * Save the stored fields
-     *
-     * @param container
-     *            The state system container this class use
-     * @param attributeName
-     *            The name of the attribute to save
-     * @param value
-     *            The value of the attribute to save
-     * @param info
-     *            The scenario details
-     * @param event
-     *            The current event
-     */
-    public void updateStoredFields(final IXmlStateSystemContainer container, final String attributeName, final ITmfStateValue value, final TmfXmlScenarioInfo info, final ITmfEvent event) {
-        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
-        long ts = getTimestamp(event, ss);
-        try {
-            int attributeQuark = getQuarkRelativeAndAdd(ss, info.getQuark(), TmfXmlStrings.STORED_FIELDS, attributeName);
-            ss.modifyAttribute(ts, value, attributeQuark);
-        } catch (StateValueTypeException | AttributeNotFoundException e) {
-            Activator.logError("failed to save the stored field " + attributeName, e); //$NON-NLS-1$
-        }
-    }
-
-    /**
-     * Clear the special fields
-     *
-     * @param container
-     *            The state system container this class use
-     * @param attributeName
-     *            The name of the attribute to save
-     * @param info
-     *            The scenario details
-     * @param event
-     *            The current event
-     */
-    public void resetStoredFields(final IXmlStateSystemContainer container, final String attributeName, final TmfXmlScenarioInfo info, final ITmfEvent event) {
-        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
-        long ts = getTimestamp(event, ss);
-        ITmfStateValue value = TmfStateValue.nullValue();
-        try {
-            int attributeQuark = getQuarkRelativeAndAdd(ss, info.getQuark(), TmfXmlStrings.STORED_FIELDS, attributeName);
-            ss.modifyAttribute(ts, value, attributeQuark);
-        } catch (StateValueTypeException | AttributeNotFoundException e) {
-            Activator.logError("failed to clear the stored fields", e); //$NON-NLS-1$
-        }
-    }
-
-    /**
-     * Get the value of a special field in the state system
-     *
-     * @param container
-     *            The state system container this class use
-     * @param attributeName
-     *            The attribute name of the special field
-     * @param info
-     *            The scenario details
-     * @param event
-     *            The current event
-     *
-     * @return The value of a special field saved into the state system
-     */
-    public ITmfStateValue getStoredFieldValue(IXmlStateSystemContainer container, String attributeName, final TmfXmlScenarioInfo info, ITmfEvent event) {
-        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
-        long ts = event.getTimestamp().toNanos();
-        ITmfStateInterval state = null;
-        try {
-            int attributeQuark = getQuarkRelativeAndAdd(ss, info.getQuark(), TmfXmlStrings.STORED_FIELDS, attributeName);
-            state = ss.querySingleState(ts, attributeQuark);
-        } catch (AttributeNotFoundException | StateSystemDisposedException e) {
-            Activator.logError("failed to get the value of the stored field " + attributeName, e); //$NON-NLS-1$
-        }
-        return (state != null) ? NonNullUtils.checkNotNull(state.getStateValue()) : TmfStateValue.nullValue();
-    }
-
-    /**
-     * Get the attribute pool for this fsm
-     *
-     * @param container
-     *            The state system container
-     * @param fsmId
-     *            The ID of the FSM
-     * @return The attribute pool associated with this FSM
-     */
-    protected TmfAttributePool getPoolFor(IXmlStateSystemContainer container, String fsmId) {
-        TmfAttributePool pool = fFsmPools.get(fsmId);
-        if (pool != null) {
-            return pool;
-        }
-        ITmfStateSystemBuilder ss = NonNullUtils.checkNotNull((ITmfStateSystemBuilder) container.getStateSystem());
-        String[] fsmPath = new String[] { TmfXmlStrings.SCENARIOS, fsmId };
-        int quark = getQuarkAbsoluteAndAdd(ss, fsmPath);
-        pool = new TmfAttributePool(ss, quark);
-        fFsmPools.put(fsmId, pool);
-        return pool;
-    }
-
-    /**
-     * Get the scenario quark
-     *
-     * @param container
-     *            The state system container this class use
-     * @param fsmId
-     *            Id of the fsm this scenario is associated to
-     * @return The scenario quark
-     */
-    public int assignScenarioQuark(IXmlStateSystemContainer container, String fsmId) {
-        TmfAttributePool pool = getPoolFor(container, fsmId);
-        return pool.getAvailable();
-    }
-
-    /**
-     * Get the scenario status quark
-     *
-     * @param container
-     *            The state system container this class use
-     * @param scenarioQuark
-     *            The scenario quark
-     * @return The scenario quark
-     */
-    public int getScenarioStatusQuark(IXmlStateSystemContainer container, int scenarioQuark) {
-        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
-        return getQuarkRelativeAndAdd(ss, scenarioQuark, STATUS);
-    }
-
-    /**
-     * Get the start time of a specific state of the scenario
-     *
-     * @param container
-     *            The state system container this class use
-     * @param stateName
-     *            The name of the current state of the scenario
-     * @param info
-     *            The scenario details
-     * @param event
-     *            The current event
-     *
-     * @return The start time for the specified state
-     */
-    public long getSpecificStateStartTime(final IXmlStateSystemContainer container, final String stateName, final TmfXmlScenarioInfo info, final ITmfEvent event) {
-        long ts = event.getTimestamp().getValue();
-        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
-        try {
-            int attributeQuark = getQuarkRelativeAndAdd(ss, info.getQuark(), TmfXmlStrings.STATE, stateName, START_TIME);
-            ITmfStateInterval state = ss.querySingleState(ts, attributeQuark);
-            return state.getStartTime();
-        } catch (AttributeNotFoundException | StateSystemDisposedException e) {
-            Activator.logError("failed the start time of the state " + stateName, e); //$NON-NLS-1$
-        }
-        return -1l;
-    }
-
-    /**
-     * Basic quark-retrieving method. Pass an attribute in parameter as an array
-     * of strings, the matching quark will be returned. If the attribute does
-     * not exist, it will add the quark to the state system if the context
-     * allows it.
-     *
-     * See {@link ITmfStateSystemBuilder#getQuarkAbsoluteAndAdd(String...)}
-     *
-     * @param ss
-     *            The state system the attribute belongs to
-     * @param path
-     *            Full path to the attribute
-     * @return The quark for this attribute
-     */
-    private static int getQuarkAbsoluteAndAdd(@Nullable ITmfStateSystemBuilder ss, String... path) {
-        if (ss == null) {
-            throw new NullPointerException(ERROR_MESSAGE);
-        }
-        return ss.getQuarkAbsoluteAndAdd(path);
-    }
-
-    /**
-     * Quark-retrieving method, but the attribute is queried starting from the
-     * startNodeQuark. If the attribute does not exist, it will add it to the
-     * state system if the context allows it.
-     *
-     * See {@link ITmfStateSystemBuilder#getQuarkRelativeAndAdd(int, String...)}
-     *
-     ** @param ss
-     *            The state system the attribute belongs to
-     * @param startNodeQuark
-     *            The quark of the attribute from which 'path' originates.
-     * @param path
-     *            Relative path to the attribute
-     * @return The quark for this attribute
-     */
-    private static int getQuarkRelativeAndAdd(@Nullable ITmfStateSystemBuilder ss, int startNodeQuark, String... path) {
-        if (ss == null) {
-            throw new NullPointerException(ERROR_MESSAGE);
-        }
-        return ss.getQuarkRelativeAndAdd(startNodeQuark, path);
-    }
-
-    /**
-     * Update the scenario internal data
-     *
-     * @param container
-     *            The state system container this class use
-     * @param info
-     *            The scenario details
-     * @param event
-     *            The current event
-     */
-    public void update(final IXmlStateSystemContainer container, final TmfXmlScenarioInfo info, final @Nullable ITmfEvent event) {
-        updateScenarioSpecificStateStartTime(event, container, info);
-        updateScenarioState(event, container, info);
-        updateScenarioStatus(event, container, info);
-    }
-
-    private static void updateScenarioStatus(@Nullable ITmfEvent event, IXmlStateSystemContainer container, final TmfXmlScenarioInfo info) {
-        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
-        long ts = getTimestamp(event, ss);
-        ITmfStateValue value;
-        try {
-            // save the status
-            switch (info.getStatus()) {
-            case IN_PROGRESS:
-                value = STATUS_MAP.get(ScenarioStatusType.IN_PROGRESS);
-                break;
-            case ABANDONED:
-                value = STATUS_MAP.get(ScenarioStatusType.ABANDONED);
-                break;
-            case MATCHED:
-                value = STATUS_MAP.get(ScenarioStatusType.MATCHED);
-                break;
-            case PENDING:
-                value = STATUS_MAP.get(ScenarioStatusType.PENDING);
-                break;
-            default:
-                value = TmfStateValue.nullValue();
-                break;
-            }
-            ss.modifyAttribute(ts, value, info.getStatusQuark());
-        } catch (StateValueTypeException | AttributeNotFoundException e) {
-            Activator.logError("failed to update scenario status"); //$NON-NLS-1$
-        }
-    }
-
-    private static long getTimestamp(@Nullable ITmfEvent event, @Nullable ITmfStateSystemBuilder ss) {
-        if (event != null) {
-            return event.getTimestamp().toNanos();
-        }
-        if (ss != null) {
-            return ss.getCurrentEndTime();
-        }
-        throw new IllegalArgumentException("Event and state system cannot be null at the same time."); //$NON-NLS-1$
-    }
-
-    private static void updateScenarioState(final @Nullable ITmfEvent event, final IXmlStateSystemContainer container, final TmfXmlScenarioInfo info) {
-        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
-        long ts = getTimestamp(event, ss);
-        try {
-            // save the status
-            ITmfStateValue value = TmfStateValue.newValueString(info.getActiveState());
-            int attributeQuark = ss.getQuarkRelativeAndAdd(info.getQuark(), TmfXmlStrings.STATE);
-            ss.modifyAttribute(ts, value, attributeQuark);
-        } catch (StateValueTypeException | AttributeNotFoundException e) {
-            Activator.logError("failed to update scenario state"); //$NON-NLS-1$
-        }
-    }
-
-    /**
-     * Update the start time of specified state
-     *
-     * @param event
-     *            The current event
-     * @param container
-     *            The state system container this class use
-     * @param info
-     *            The scenario details
-     */
-    private static void updateScenarioSpecificStateStartTime(final @Nullable ITmfEvent event, final IXmlStateSystemContainer container, final TmfXmlScenarioInfo info) {
-        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
-        long ts = getTimestamp(event, ss);
-        try {
-            int stateQuark = ss.getQuarkRelativeAndAdd(info.getQuark(), TmfXmlStrings.STATE);
-            String activeState = ss.queryOngoingState(stateQuark).unboxStr();
-            if (activeState.compareTo(info.getActiveState()) != 0) {
-                int attributeQuark = ss.getQuarkRelativeAndAdd(stateQuark, info.getActiveState(), START_TIME);
-                ITmfStateValue value = TmfStateValue.newValueLong(ts);
-                ss.modifyAttribute(ts, value, attributeQuark);
-            }
-        } catch (StateValueTypeException | AttributeNotFoundException e) {
-            Activator.logError("failed to update the start time of the state"); //$NON-NLS-1$
-        }
-    }
-
-    /**
-     * Start the scenario, sets the start time for the time of the event
-     *
-     * @param container
-     *            The state system container this class use
-     * @param info
-     *            The scenario details. The value should be null if there is no
-     *            scenario
-     * @param event
-     *            The active event
-     */
-    public void startScenario(final IXmlStateSystemContainer container, final TmfXmlScenarioInfo info, final ITmfEvent event) {
-        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
-        long ts = getTimestamp(event, ss);
-        try {
-            // save the status
-            ITmfStateValue value = TmfStateValue.newValueLong(ts);
-            int attributeQuark = ss.getQuarkRelativeAndAdd(info.getQuark(), START_TIME);
-            ss.modifyAttribute(ts, value, attributeQuark);
-        } catch (StateValueTypeException | AttributeNotFoundException e) {
-            Activator.logError("failed to update the start time of the scenario"); //$NON-NLS-1$
-        }
-    }
-
-    /**
-     * Set the end time of the scenario to the time of the event, or current
-     * state system end time if null, and recycle the attribute quark
-     *
-     * @param container
-     *            The state system container this class use
-     * @param info
-     *            The scenario details. The value should be null if there is no
-     *            scenario
-     * @param event
-     *            The active event
-     */
-    public void completeScenario(final IXmlStateSystemContainer container, final TmfXmlScenarioInfo info, final @Nullable ITmfEvent event) {
-        ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
-        long ts = getTimestamp(event, ss);
-        TmfAttributePool pool = getPoolFor(container, info.getFsmId());
-        pool.recycle(info.getQuark(), ts);
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlScenarioInfo.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlScenarioInfo.java
deleted file mode 100644 (file)
index c181b6f..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- ******************************************************************************/
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlScenarioHistoryBuilder.ScenarioStatusType;
-
-/**
- * This class gives basic details about a scenario (quark, scenarioName, ...)
- *
- * @author Jean-Christian Kouame
- * @since 2.0
- */
-public class TmfXmlScenarioInfo {
-
-    private final int fQuark;
-    private final TmfXmlFsm fFsm;
-    private final int fStatusQuark;
-    private String fActiveState;
-    private ScenarioStatusType fStatus;
-
-    /**
-     * Constructor
-     *
-     * @param activeState
-     *            The active state
-     * @param status
-     *            The scenario status
-     * @param quark
-     *            The scenario quark
-     * @param statusQuark
-     *            The scenario status quark
-     * @param fsm
-     *            The FSM this scenario is part of
-     */
-    public TmfXmlScenarioInfo(String activeState, ScenarioStatusType status, int quark, int statusQuark, TmfXmlFsm fsm) {
-        fActiveState = activeState;
-        fQuark = quark;
-        fStatus = status;
-        fStatusQuark = statusQuark;
-        fFsm = fsm;
-    }
-
-    /**
-     * Set the active state
-     *
-     * @param activeState
-     *            The active state
-     */
-    public void setActiveState(String activeState) {
-        fActiveState = activeState;
-    }
-
-    /**
-     * Set the status of this active scenario
-     *
-     * @param status
-     *            The scenario status
-     */
-    public void setStatus(ScenarioStatusType status) {
-        fStatus = status;
-    }
-
-    /**
-     * Get the scenario quark
-     *
-     * @return The quark
-     */
-    public int getQuark() {
-        return fQuark;
-    }
-
-    /**
-     * Get the scenario active state
-     *
-     * @return The active state
-     */
-    public String getActiveState() {
-        return fActiveState;
-    }
-
-    /**
-     * Get the active scenario status
-     *
-     * @return The status
-     */
-    public ScenarioStatusType getStatus() {
-        return fStatus;
-    }
-
-    /**
-     * Get the scenario status quark
-     *
-     * @return The quark
-     */
-    public int getStatusQuark() {
-        return fStatusQuark;
-    }
-
-    /**
-     * Get the ID of the FSM this scenario is part of
-     *
-     * @return The ID of the FSM
-     */
-    public String getFsmId() {
-        return fFsm.getId();
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlState.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlState.java
deleted file mode 100644 (file)
index b84df18..0000000
+++ /dev/null
@@ -1,294 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- ******************************************************************************/
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.common.core.NonNullUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
-/**
- * This class implements a state tree described in XML-defined pattern
- *
- * @author Jean-Christian Kouame
- * @since 2.0
- */
-public class TmfXmlState {
-
-    private final String fId;
-    private final IXmlStateSystemContainer fContainer;
-    private final List<TmfXmlStateTransition> fTransitions;
-    private @Nullable TmfXmlState fparent;
-    private List<String> fOnEntryActions;
-    private List<String> fOnExitActions;
-    //TODO Sub-state are not yet supported.
-    private Map<String, TmfXmlState> fChildren;
-    private @Nullable TmfXmlStateTransition fInitialTransition;
-    private @Nullable String fInitialStateId;
-    private @Nullable String fFinalStateId;
-    private Type fType;
-
-    /**
-     * Enum for the type of state
-     */
-    public enum Type {
-        /**
-         * Final state type
-         */
-        FINAL,
-        /**
-         * Initial state type
-         */
-        INITIAL,
-        /**
-         * Fail state type, the pattern has failed to match
-         */
-        FAIL,
-        /**
-         * This is the normal state type, for states that are not the first,
-         * final or failing state
-         */
-        DEFAULT
-    }
-
-    private TmfXmlState(IXmlStateSystemContainer container, Type type, String id, @Nullable TmfXmlState parent, List<@NonNull TmfXmlStateTransition> transitions, Map<@NonNull String, @NonNull TmfXmlState> children, List<String> onentryActions, List<String> onexitActions) {
-        fContainer = container;
-        fType = type;
-        fId = id;
-        fparent = parent;
-        fTransitions = transitions;
-        fChildren = children;
-        fOnEntryActions = onentryActions;
-        fOnExitActions = onexitActions;
-    }
-
-    /**
-     * Constructor
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param node
-     *            The XML root of this state
-     * @param container
-     *            The state system container this state definition belongs to
-     * @param parent
-     *            The parent state of this state
-     * @return The new {@link TmfXmlState}
-     */
-    public static TmfXmlState create(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container, @Nullable TmfXmlState parent) {
-        Type type = getStateType(node);
-        String id = node.getAttribute(TmfXmlStrings.ID);
-        List<TmfXmlStateTransition> transitions = getTransitions(modelFactory, container, node);
-
-        NodeList nodesOnentry = node.getElementsByTagName(TmfXmlStrings.ONENTRY);
-        List<String> onentryActions = nodesOnentry.getLength() > 0 ? Arrays.asList(((Element) nodesOnentry.item(0)).getAttribute(TmfXmlStrings.ACTION).split(TmfXmlStrings.AND_SEPARATOR)) : Collections.EMPTY_LIST;
-
-        NodeList nodesOnexit = node.getElementsByTagName(TmfXmlStrings.ONEXIT);
-        List<String> onexitActions = nodesOnexit.getLength() > 0 ? Arrays.asList(((Element) nodesOnexit.item(0)).getAttribute(TmfXmlStrings.ACTION).split(TmfXmlStrings.AND_SEPARATOR)) : Collections.EMPTY_LIST;
-
-        TmfXmlState state = new TmfXmlState(container, type, id, parent, transitions, new HashMap<>(), onentryActions, onexitActions);
-        initState(state, modelFactory, container, node);
-
-        return state;
-    }
-
-    private static void getFinalState(TmfXmlState parentState, ITmfXmlModelFactory modelFactory, IXmlStateSystemContainer container, Element node) {
-        NodeList nodesFinal = node.getElementsByTagName(TmfXmlStrings.FINAL);
-        String finalStateId = null;
-        if (nodesFinal.getLength() > 0) {
-            final Element finalElement = NonNullUtils.checkNotNull((Element) nodesFinal.item(0));
-            finalStateId = nodesFinal.getLength() > 0 ? finalElement.getAttribute(TmfXmlStrings.ID) : null;
-            TmfXmlState finalState = modelFactory.createState(finalElement, container, parentState);
-            parentState.getChildren().put(finalState.getId(), finalState);
-        }
-        parentState.fFinalStateId = finalStateId;
-    }
-
-    private static void getSubStates(TmfXmlState parentState, ITmfXmlModelFactory modelFactory, IXmlStateSystemContainer container, Element node) {
-        String initial = node.getAttribute(TmfXmlStrings.INITIAL);
-        TmfXmlStateTransition initialTransition = null;
-        if (initial.isEmpty()) {
-            NodeList nodesInitial = node.getElementsByTagName(TmfXmlStrings.INITIAL);
-            if (nodesInitial.getLength() == 1) {
-                final @NonNull Element transitionElement = NonNullUtils.checkNotNull((Element) ((Element) nodesInitial.item(0)).getElementsByTagName(TmfXmlStrings.TRANSITION).item(0));
-                initialTransition = modelFactory.createStateTransition(transitionElement, container);
-                initial = initialTransition.getTarget();
-            }
-        }
-
-        NodeList nodesState = node.getElementsByTagName(TmfXmlStrings.STATE);
-        for (int i = 0; i < nodesState.getLength(); i++) {
-            TmfXmlState child = modelFactory.createState(NonNullUtils.checkNotNull((Element) nodesState.item(i)), container, parentState);
-            parentState.getChildren().put(child.getId(), child);
-
-            if (i == 0 && initial.isEmpty()) {
-                initial = child.getId();
-            }
-        }
-        parentState.fInitialStateId = initial.isEmpty() ? null : initial;
-        parentState.fInitialTransition = initialTransition;
-    }
-
-    private static void initState(TmfXmlState state, ITmfXmlModelFactory modelFactory, IXmlStateSystemContainer container, Element node) {
-        getSubStates(state, modelFactory, container, node);
-        getFinalState(state, modelFactory, container, node);
-    }
-
-    /**
-     * Get the List of transitions for this state
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param node
-     *            The XML root of this state definition
-     * @return The list of transitions
-     */
-    private static List<@NonNull TmfXmlStateTransition> getTransitions(ITmfXmlModelFactory modelFactory, IXmlStateSystemContainer container, Element node) {
-        List<@NonNull TmfXmlStateTransition> transitions = new ArrayList<>();
-        NodeList nodesTransition = node.getElementsByTagName(TmfXmlStrings.TRANSITION);
-        for (int i = 0; i < nodesTransition.getLength(); i++) {
-            final Element element = (Element) nodesTransition.item(i);
-            if (element == null) {
-                throw new IllegalArgumentException();
-            }
-            TmfXmlStateTransition transition = modelFactory.createStateTransition(element, container);
-            transitions.add(transition);
-        }
-        return transitions;
-    }
-
-    /**
-     * Get the state type from its XML definition
-     * @param node
-     *            The XML definition of the state
-     * @return The state type
-     */
-    private static Type getStateType(Element node) {
-        switch (node.getNodeName()) {
-        case TmfXmlStrings.FINAL:
-            return Type.FINAL;
-        case TmfXmlStrings.INITIAL:
-            return Type.INITIAL;
-        case TmfXmlStrings.ABANDON:
-            return Type.FAIL;
-        case TmfXmlStrings.STATE:
-        default:
-            return Type.DEFAULT;
-        }
-    }
-
-    /**
-     * Get the state id
-     *
-     * @return The state id
-     */
-    public String getId() {
-        return fId;
-    }
-
-    /**
-     * Get the container
-     *
-     * @return The container
-     */
-    public IXmlStateSystemContainer getContainer() {
-        return fContainer;
-    }
-
-    /**
-     * The list of transitions of this state
-     *
-     * @return The list of transitions
-     */
-    public List<TmfXmlStateTransition> getTransitionList() {
-        return fTransitions;
-    }
-
-    /**
-     * Get the actions to execute when entering this state, in an array
-     *
-     * @return The array of actions
-     */
-    public List<String> getOnEntryActions() {
-        return fOnEntryActions;
-    }
-
-    /**
-     * Get the actions to execute when leaving this state, in an array
-     *
-     * @return The array of actions
-     */
-    public List<String> getOnExitActions() {
-        return fOnExitActions;
-    }
-
-    /**
-     * Get children states of this state into a map
-     *
-     * @return The map of children state
-     */
-    public Map<String, TmfXmlState> getChildren() {
-        return fChildren;
-    }
-
-    /**
-     * Get the initial transition of this state
-     *
-     * @return The initial transition
-     */
-    public @Nullable TmfXmlStateTransition getInitialTransition() {
-        return fInitialTransition;
-    }
-
-    /**
-     * Get the initial state ID
-     *
-     * @return The initial state ID
-     */
-    public @Nullable String getInitialStateId() {
-        return fInitialStateId;
-    }
-
-    /**
-     * Get the final state ID
-     *
-     * @return The final state ID
-     */
-    public @Nullable String getFinalStateId() {
-        return fFinalStateId;
-    }
-
-    /**
-     * Get the parent state
-     *
-     * @return The parent state
-     */
-    public @Nullable TmfXmlState getParent() {
-        return fparent;
-    }
-
-    /**
-     * Get the type of this state
-     *
-     * @return The type of the state
-     */
-    public Type getType() {
-        return fType;
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlStateAttribute.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlStateAttribute.java
deleted file mode 100644 (file)
index bae5c4e..0000000
+++ /dev/null
@@ -1,354 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014, 2015 Ecole Polytechnique de Montreal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Florian Wininger - Initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.jdt.annotation.Nullable;
-import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString;
-import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
-
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
-import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
-import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
-import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
-import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
-import org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect;
-import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
-import org.w3c.dom.Element;
-
-/**
- * This Class implements a single attribute value in the XML-defined state
- * system.
- *
- * <pre>
- * Examples:
- * <stateAttribute type="constant" value="Threads" />
- * <stateAttribute type="query" />
- *      <stateAttribute type="constant" value="CPUs" />
- *      <stateAttribute type="eventField" value="cpu" />
- *      <stateAttribute type="constant" value="Current_thread" />
- * </attribute>
- * </pre>
- *
- * @author Florian Wininger
- */
-public abstract class TmfXmlStateAttribute implements ITmfXmlStateAttribute {
-
-    private enum StateAttributeType {
-        NONE,
-        CONSTANT,
-        EVENTFIELD,
-        QUERY,
-        LOCATION,
-        SELF,
-        EVENTNAME
-    }
-
-    private final String CURRENT_STATE = "#currentState"; //$NON-NLS-1$
-
-    private final String CURRENT_SCENARIO = "#CurrentScenario"; //$NON-NLS-1$
-
-    /** Type of attribute */
-    private final StateAttributeType fType;
-
-    /** Attribute's name */
-    private final @Nullable String fName;
-
-    /** List of attributes for a query */
-    private final List<ITmfXmlStateAttribute> fQueryList = new LinkedList<>();
-
-    private final IXmlStateSystemContainer fContainer;
-
-    /**
-     * Constructor
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param attribute
-     *            XML element of the attribute
-     * @param container
-     *            The state system container this state attribute belongs to
-     */
-    protected TmfXmlStateAttribute(ITmfXmlModelFactory modelFactory, Element attribute, IXmlStateSystemContainer container) {
-        fContainer = container;
-
-        switch (attribute.getAttribute(TmfXmlStrings.TYPE)) {
-        case TmfXmlStrings.TYPE_CONSTANT:
-            fType = StateAttributeType.CONSTANT;
-            fName = getAttributeName(attribute);
-            break;
-        case TmfXmlStrings.EVENT_FIELD:
-            fType = StateAttributeType.EVENTFIELD;
-            fName = getAttributeName(attribute);
-            break;
-        case TmfXmlStrings.TYPE_LOCATION:
-            fType = StateAttributeType.LOCATION;
-            fName = getAttributeName(attribute);
-            break;
-        case TmfXmlStrings.TYPE_QUERY:
-            List<@Nullable Element> childElements = XmlUtils.getChildElements(attribute);
-            for (Element subAttributeNode : childElements) {
-                if (subAttributeNode == null) {
-                    continue;
-                }
-                ITmfXmlStateAttribute subAttribute = modelFactory.createStateAttribute(subAttributeNode, fContainer);
-                fQueryList.add(subAttribute);
-            }
-            fType = StateAttributeType.QUERY;
-            fName = null;
-            break;
-        case TmfXmlStrings.TYPE_EVENT_NAME:
-            fType = StateAttributeType.EVENTNAME;
-            fName = getAttributeName(attribute);
-            break;
-        case TmfXmlStrings.NULL:
-            fType = StateAttributeType.NONE;
-            fName = null;
-            break;
-        case TmfXmlStrings.TYPE_SELF:
-            fType = StateAttributeType.SELF;
-            fName = null;
-            break;
-        default:
-            throw new IllegalArgumentException("TmfXmlStateAttribute constructor: The XML element is not of the right type"); //$NON-NLS-1$
-        }
-    }
-
-    private String getAttributeName(Element attribute) {
-        return fContainer.getAttributeValue(attribute.getAttribute(TmfXmlStrings.VALUE)).intern();
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public int getAttributeQuark(int startQuark, @Nullable TmfXmlScenarioInfo scenarioInfo) {
-        return getAttributeQuark(null, startQuark, scenarioInfo);
-    }
-
-    /**
-     * Basic quark-retrieving method. Pass an attribute in parameter as an array
-     * of strings, the matching quark will be returned. If the attribute does
-     * not exist, it will add the quark to the state system if the context
-     * allows it.
-     *
-     * See {@link ITmfStateSystemBuilder#getQuarkAbsoluteAndAdd(String...)}
-     *
-     * @param path
-     *            Full path to the attribute
-     * @return The quark for this attribute
-     * @throws AttributeNotFoundException
-     *             The attribute does not exist and cannot be added
-     */
-    protected abstract int getQuarkAbsoluteAndAdd(String... path) throws AttributeNotFoundException;
-
-    /**
-     * Quark-retrieving method, but the attribute is queried starting from the
-     * startNodeQuark. If the attribute does not exist, it will add it to the
-     * state system if the context allows it.
-     *
-     * See {@link ITmfStateSystemBuilder#getQuarkRelativeAndAdd(int, String...)}
-     *
-     * @param startNodeQuark
-     *            The quark of the attribute from which 'path' originates.
-     * @param path
-     *            Relative path to the attribute
-     * @return The quark for this attribute
-     * @throws AttributeNotFoundException
-     *             The attribute does not exist and cannot be added
-     */
-    protected abstract int getQuarkRelativeAndAdd(int startNodeQuark, String... path) throws AttributeNotFoundException;
-
-    /**
-     * Get the state system associated with this attribute's container
-     *
-     * @return The state system associated with this state attribute
-     */
-    protected @Nullable ITmfStateSystem getStateSystem() {
-        return fContainer.getStateSystem();
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public int getAttributeQuark(@Nullable ITmfEvent event, int startQuark, @Nullable TmfXmlScenarioInfo scenarioInfo) {
-        ITmfStateSystem ss = getStateSystem();
-        if (ss == null) {
-            throw new IllegalStateException("The state system hasn't been initialized yet"); //$NON-NLS-1$
-        }
-        String name = nullToEmptyString(fName);
-        if (name.length() > 0 && name.charAt(0) == '#' && scenarioInfo == null) {
-            throw new IllegalStateException("XML Attribute needs " + fName + " but the data is not available.");  //$NON-NLS-1$//$NON-NLS-2$
-        }
-        name = name.equals(CURRENT_STATE) ? checkNotNull(scenarioInfo).getActiveState()
-                        : fName;
-
-        try {
-            switch (fType) {
-            case CONSTANT: {
-                int quark;
-                if (name == null) {
-                    throw new IllegalStateException("Invalid attribute name"); //$NON-NLS-1$
-                }
-                if (name.equals(CURRENT_SCENARIO)) {
-                    return checkNotNull(scenarioInfo).getQuark();
-                }
-                if (startQuark == IXmlStateSystemContainer.ROOT_QUARK) {
-                    quark = getQuarkAbsoluteAndAdd(name);
-                } else {
-                    quark = getQuarkRelativeAndAdd(startQuark, name);
-                }
-                return quark;
-            }
-            case EVENTFIELD: {
-                int quark = IXmlStateSystemContainer.ERROR_QUARK;
-                if (event == null) {
-                    Activator.logWarning("XML State attribute: looking for an event field, but event is null"); //$NON-NLS-1$
-                    return quark;
-                }
-                if (name == null) {
-                    throw new IllegalStateException("Invalid attribute name"); //$NON-NLS-1$
-                }
-                if (name.equals(TmfXmlStrings.CPU)) {
-                    /* See if the event advertises a CPU aspect */
-                    Integer cpu = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(
-                            event.getTrace(), TmfCpuAspect.class, event);
-                    if (cpu != null) {
-                        quark = getQuarkRelativeAndAdd(startQuark, cpu.toString());
-                    }
-                } else {
-                    final ITmfEventField content = event.getContent();
-                    /* stop if the event field doesn't exist */
-                    if (content.getField(name) == null) {
-                        return IXmlStateSystemContainer.ERROR_QUARK;
-                    }
-
-                    Object field = content.getField(name).getValue();
-
-                    if (field instanceof String) {
-                        String fieldString = (String) field;
-                        quark = getQuarkRelativeAndAdd(startQuark, fieldString);
-                    } else if (field instanceof Long) {
-                        Long fieldLong = (Long) field;
-                        quark = getQuarkRelativeAndAdd(startQuark, fieldLong.toString());
-                    } else if (field instanceof Integer) {
-                        Integer fieldInterger = (Integer) field;
-                        quark = getQuarkRelativeAndAdd(startQuark, fieldInterger.toString());
-                    }
-                }
-                return quark;
-            }
-            case QUERY: {
-                int quark;
-                ITmfStateValue value = TmfStateValue.nullValue();
-                int quarkQuery = IXmlStateSystemContainer.ROOT_QUARK;
-
-                for (ITmfXmlStateAttribute attrib : fQueryList) {
-                    quarkQuery = attrib.getAttributeQuark(event, quarkQuery, scenarioInfo);
-                    if (quarkQuery == IXmlStateSystemContainer.ERROR_QUARK) {
-                        break;
-                    }
-                }
-
-                // the query may fail: for example CurrentThread if there
-                // has not been a sched_switch event
-                if (quarkQuery != IXmlStateSystemContainer.ERROR_QUARK) {
-                    value = ss.queryOngoingState(quarkQuery);
-                }
-
-                switch (value.getType()) {
-                case INTEGER: {
-                    int result = value.unboxInt();
-                    quark = getQuarkRelativeAndAdd(startQuark, String.valueOf(result));
-                    break;
-                }
-                case LONG: {
-                    long result = value.unboxLong();
-                    quark = getQuarkRelativeAndAdd(startQuark, String.valueOf(result));
-                    break;
-                }
-                case STRING: {
-                    String result = value.unboxStr();
-                    quark = getQuarkRelativeAndAdd(startQuark, result);
-                    break;
-                }
-                case DOUBLE:
-                case NULL:
-                default:
-                    quark = IXmlStateSystemContainer.ERROR_QUARK; // error
-                    break;
-                }
-                return quark;
-            }
-            case LOCATION: {
-                int quark = startQuark;
-                String idLocation = name;
-
-                /* TODO: Add a fContainer.getLocation(id) method */
-                for (TmfXmlLocation location : fContainer.getLocations()) {
-                    if (location.getId().equals(idLocation)) {
-                        quark = location.getLocationQuark(event, quark, scenarioInfo);
-                        if (quark == IXmlStateSystemContainer.ERROR_QUARK) {
-                            break;
-                        }
-                    }
-                }
-                return quark;
-            }
-            case EVENTNAME: {
-                int quark = IXmlStateSystemContainer.ERROR_QUARK;
-                if (event == null) {
-                    Activator.logWarning("XML State attribute: looking for an eventname, but event is null"); //$NON-NLS-1$
-                    return quark;
-                }
-                quark = getQuarkRelativeAndAdd(startQuark, event.getName());
-                return quark;
-            }
-            case SELF:
-                return startQuark;
-            case NONE:
-            default:
-                return startQuark;
-            }
-        } catch (AttributeNotFoundException ae) {
-            /*
-             * This can be happen before the creation of the node for a query in
-             * the state system. Example : current thread before a sched_switch
-             */
-            return IXmlStateSystemContainer.ERROR_QUARK;
-        } catch (StateValueTypeException e) {
-            /*
-             * This would happen if we were trying to push/pop attributes not of
-             * type integer. Which, once again, should never happen.
-             */
-            Activator.logError("StateValueTypeException", e); //$NON-NLS-1$
-            return IXmlStateSystemContainer.ERROR_QUARK;
-        }
-    }
-
-    @Override
-    public String toString() {
-        return "TmfXmlStateAttribute " + fType + ": " + fName; //$NON-NLS-1$ //$NON-NLS-2$
-    }
-
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlStateChange.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlStateChange.java
deleted file mode 100644 (file)
index 25028b3..0000000
+++ /dev/null
@@ -1,221 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 Ecole Polytechnique de Montreal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Florian Wininger - Initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-/**
- * This Class implement a State Change in the XML-defined state system
- *
- * <pre>
- *  example 1: Simple state change
- *  <stateChange>
- *      <stateAttribute type="location" value="CurrentThread" />
- *      <stateAttribute type="constant" value="System_call" />
- *      <stateValue type="null" />
- *  </stateChange>
- *
- *  example 2: Conditional state change
- *  <stateChange>
- *     <if>
- *      <condition>
- *        <stateAttribute type="location" value="CurrentThread" />
- *        <stateAttribute type="constant" value="System_call" />
- *        <stateValue type="null" />
- *      </condition>
- *     </if>
- *    <then>
- *      <stateAttribute type="location" value="CurrentThread" />
- *      <stateAttribute type="constant" value="Status" />
- *      <stateValue int="$PROCESS_STATUS_RUN_USERMODE"/>
- *    </then>
- *    <else>
- *      <stateAttribute type="location" value="CurrentThread" />
- *      <stateAttribute type="constant" value="Status" />
- *      <stateValue int="$PROCESS_STATUS_RUN_SYSCALL"/>
- *    </else>
- *  </stateChange>
- * </pre>
- *
- * @author Florian Wininger
- */
-public class TmfXmlStateChange {
-
-    private final IXmlStateChange fChange;
-    private final IXmlStateSystemContainer fContainer;
-
-    /**
-     * Constructor
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param statechange
-     *            XML node root of this state change
-     * @param container
-     *            The state system container this state change belongs to
-     */
-    public TmfXmlStateChange(ITmfXmlModelFactory modelFactory, Element statechange, IXmlStateSystemContainer container) {
-        fContainer = container;
-
-        /*
-         * child nodes is either a list of TmfXmlStateAttributes and
-         * TmfXmlStateValues, or an if-then-else series of nodes.
-         */
-        Node ifNode = statechange.getElementsByTagName(TmfXmlStrings.IF).item(0);
-        if (ifNode != null) {
-            /* the state change has a condition */
-            fChange = new XmlConditionalChange(modelFactory, statechange);
-        } else {
-            /* the state change does not have a condition */
-            fChange = new XmlStateValueChange(modelFactory, statechange);
-        }
-    }
-
-    /**
-     * Execute the state change for an event. If necessary, it validates the
-     * condition and executes the required change.
-     *
-     * @param event
-     *            The event to process
-     * @param scenarioInfo
-     *            The active scenario details. The value should be null if there
-     *            no scenario.
-     * @throws AttributeNotFoundException
-     *             Pass through the exception it received
-     * @throws TimeRangeException
-     *             Pass through the exception it received
-     * @throws StateValueTypeException
-     *             Pass through the exception it received
-     * @since 2.0
-     */
-    public void handleEvent(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException {
-        fChange.handleEvent(event, scenarioInfo);
-    }
-
-    @Override
-    public String toString() {
-        return "TmfXmlStateChange: " + fChange; //$NON-NLS-1$
-    }
-
-    /* Interface for both private classes to handle the event */
-    private interface IXmlStateChange {
-        void handleEvent(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException;
-    }
-
-    /**
-     * Conditional state change with a condition to verify
-     */
-    private class XmlConditionalChange implements IXmlStateChange {
-        private final ITmfXmlCondition fCondition;
-        private final TmfXmlStateChange fThenChange;
-        private final @Nullable TmfXmlStateChange fElseChange;
-
-        public XmlConditionalChange(ITmfXmlModelFactory modelFactory, Element statechange) {
-            /*
-             * The if node exists, it has been verified before calling this
-             */
-            Node ifNode = statechange.getElementsByTagName(TmfXmlStrings.IF).item(0);
-            if (ifNode == null) {
-                throw new IllegalArgumentException();
-            }
-            fCondition = modelFactory.createCondition((Element) ifNode, fContainer);
-
-            Node thenNode = statechange.getElementsByTagName(TmfXmlStrings.THEN).item(0);
-            if (thenNode == null) {
-                throw new IllegalArgumentException("Conditional state change: there should be a then clause."); //$NON-NLS-1$
-            }
-            fThenChange = modelFactory.createStateChange((Element) thenNode, fContainer);
-
-            Node elseNode = statechange.getElementsByTagName(TmfXmlStrings.ELSE).item(0);
-            if (elseNode != null) {
-                fElseChange = modelFactory.createStateChange((Element) elseNode, fContainer);
-            } else {
-                fElseChange = null;
-            }
-        }
-
-        @Override
-        public void handleEvent(@NonNull ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException {
-            TmfXmlStateChange toExecute = fThenChange;
-            if (!fCondition.test(event, scenarioInfo)) {
-                toExecute = fElseChange;
-            }
-
-            if (toExecute == null) {
-                return;
-            }
-            toExecute.handleEvent(event, scenarioInfo);
-        }
-
-        @Override
-        public String toString() {
-            return "Condition: " + fCondition; //$NON-NLS-1$
-        }
-    }
-
-    /**
-     * State change with no condition
-     */
-    private class XmlStateValueChange implements IXmlStateChange {
-        private final ITmfXmlStateValue fValue;
-
-        public XmlStateValueChange(ITmfXmlModelFactory modelFactory, Element statechange) {
-            List<@Nullable Element> childElements = XmlUtils.getChildElements(statechange);
-
-            /*
-             * Last child element is the state value, the others are attributes
-             * to reach to value to set
-             */
-            Element stateValueElement = childElements.remove(childElements.size() - 1);
-            if (stateValueElement == null) {
-                throw new IllegalStateException();
-            }
-            List<ITmfXmlStateAttribute> attributes = new ArrayList<>();
-            for (Element element : childElements) {
-                if (element == null || !element.getNodeName().equals(TmfXmlStrings.STATE_ATTRIBUTE)) {
-                    throw new IllegalArgumentException("TmfXmlStateChange: a state change must have only TmfXmlStateAttribute elements before the state value"); //$NON-NLS-1$
-                }
-                ITmfXmlStateAttribute attribute = modelFactory.createStateAttribute(element, fContainer);
-                attributes.add(attribute);
-            }
-            if (attributes.isEmpty()) {
-                throw new IllegalArgumentException("TmfXmlStateChange: a state change must have at least one TmfXmlStateAttribute element before the state value"); //$NON-NLS-1$
-            }
-            fValue = modelFactory.createStateValue(stateValueElement, fContainer, attributes);
-        }
-
-        @Override
-        public void handleEvent(@NonNull ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException {
-            fValue.handleEvent(event, scenarioInfo);
-        }
-
-        @Override
-        public String toString() {
-            return "Value: " + fValue; //$NON-NLS-1$
-        }
-    }
-
-}
\ No newline at end of file
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlStateTransition.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlStateTransition.java
deleted file mode 100644 (file)
index 16d47e0..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- ******************************************************************************/
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.w3c.dom.Element;
-
-/**
- * This Class implements a state transition tree in the XML-defined state
- * system.
- *
- * @author Jean-Christian Kouame
- * @since 2.0
- */
-public class TmfXmlStateTransition extends TmfXmlBasicTransition {
-
-    private static final String SAVED_STORED_FIELDS_ACTION_STRING = TmfXmlStrings.CONSTANT_PREFIX + ITmfXmlAction.SAVE_STORED_FIELDS_STRING;
-    private static final String CLEAR_STORED_FIELDS_ACTION_STRINGS = TmfXmlStrings.CONSTANT_PREFIX + ITmfXmlAction.CLEAR_STORED_FIELDS_STRING;
-
-    private final String fTarget;
-    private final List<String> fAction;
-    private final boolean fStoredFieldsToBeSaved;
-    private final boolean fStoredFieldsToBeCleared;
-
-    /**
-     * Constructor
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param node
-     *            The XML root of this state transition
-     * @param container
-     *            The state system container this state transition belongs to
-     */
-    public TmfXmlStateTransition(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container) {
-        super(node);
-        String target = node.getAttribute(TmfXmlStrings.TARGET);
-        if (target.isEmpty()) {
-            throw new IllegalStateException("No target state has been specified."); //$NON-NLS-1$
-        }
-        fTarget = target;
-        String action = node.getAttribute(TmfXmlStrings.ACTION);
-        List<String> actions = action.equals(TmfXmlStrings.NULL) ? Collections.EMPTY_LIST : Arrays.asList(action.split(TmfXmlStrings.AND_SEPARATOR));
-        fStoredFieldsToBeSaved = (node.getAttribute(TmfXmlStrings.SAVE_STORED_FIELDS).equals(TmfXmlStrings.EMPTY_STRING) ? false : Boolean.parseBoolean(node.getAttribute(TmfXmlStrings.SAVE_STORED_FIELDS)));
-        fStoredFieldsToBeCleared = (node.getAttribute(TmfXmlStrings.CLEAR_STORED_FIELDS).equals(TmfXmlStrings.EMPTY_STRING) ? false : Boolean.parseBoolean(node.getAttribute(TmfXmlStrings.CLEAR_STORED_FIELDS)));
-        fAction = new ArrayList<>();
-        if (fStoredFieldsToBeSaved) {
-            fAction.add(SAVED_STORED_FIELDS_ACTION_STRING);
-        }
-        fAction.addAll(actions);
-        if (fStoredFieldsToBeCleared) {
-            fAction.add(CLEAR_STORED_FIELDS_ACTION_STRINGS);
-        }
-    }
-
-    /**
-     * The next state of the state machine this state transition belongs to.
-     *
-     * @return the next state this transition try to reach
-     */
-    public String getTarget() {
-        return fTarget;
-    }
-
-    /**
-     * The action to be executed when the input of this state transition is
-     * validated
-     *
-     * @return the action to execute if the input is validate
-     */
-    public List<String> getAction() {
-        return fAction;
-    }
-
-    /**
-     * Tell if the stored fields have to be saved at this step of the scenario
-     *
-     * @return If the stored fields have to be saved or not
-     */
-    public boolean isStoredFieldsToBeSaved() {
-        return fStoredFieldsToBeSaved;
-    }
-
-    /**
-     * Tell if the stored fields have to be cleared at this moment of this scenario
-     *
-     * @return If the stored fields have to cleared or not
-     */
-    public boolean isStoredFieldsToBeCleared() {
-        return fStoredFieldsToBeCleared;
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlStateValue.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlStateValue.java
deleted file mode 100644 (file)
index d7e2d0b..0000000
+++ /dev/null
@@ -1,512 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014, 2015 Ecole Polytechnique de Montreal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Florian Wininger - Initial API and implementation
- ******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.List;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
-import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
-import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
-import org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect;
-import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
-import org.w3c.dom.Element;
-
-/**
- * This Class implements a State Value in the XML-defined state system, along
- * with the path to get to the value (either a list of state attributes or an
- * event field)
- *
- * <pre>
- * Example:
- *   <stateAttribute type="location" value="CurrentThread" />
- *   <stateAttribute type="constant" value="System_call" />
- *   <stateValue type="null" />
- * </pre>
- *
- * @author Florian Wininger
- */
-public abstract class TmfXmlStateValue implements ITmfXmlStateValue {
-
-    private final TmfXmlStateValueBase fStateValue;
-
-    /* Path in the State System */
-    private final List<ITmfXmlStateAttribute> fPath;
-    /* Event field to match with this state value */
-    private final @Nullable String fEventField;
-
-    /* Whether this state value is an increment of the previous value */
-    private final boolean fIncrement;
-    /* Stack value */
-    private final ValueTypeStack fStackType;
-    /* Forced value type */
-    private final ITmfStateValue.Type fForcedType;
-
-    private final IXmlStateSystemContainer fContainer;
-
-    /**
-     * Different behaviors of an attribute that is to be stacked
-     */
-    protected enum ValueTypeStack {
-        /** Not stacked */
-        NULL,
-        /** Peek at the value at the top of the stack */
-        PEEK,
-        /** Take the value at the top of the stack */
-        POP,
-        /** Push the value on the stack */
-        PUSH;
-
-        /**
-         * Get the type stack value corresponding to a string
-         *
-         * @param input
-         *            The string to match to a value
-         * @return The ValueTypeStack value
-         */
-        public static ValueTypeStack getTypeFromString(String input) {
-            switch (input) {
-            case TmfXmlStrings.STACK_PUSH:
-                return PUSH;
-            case TmfXmlStrings.STACK_POP:
-                return POP;
-            case TmfXmlStrings.STACK_PEEK:
-                return PEEK;
-            default:
-                return NULL;
-            }
-        }
-    }
-
-    /**
-     * Constructor
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param node
-     *            The state value XML element
-     * @param container
-     *            The state system container this state value belongs to
-     * @param eventField
-     *            The event field where to get the value
-     * @param attributes
-     *            The attributes representing the path to this value
-     */
-    protected TmfXmlStateValue(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container, List<ITmfXmlStateAttribute> attributes, @Nullable String eventField) {
-        fPath = attributes;
-        fContainer = container;
-        fEventField = eventField;
-        if (!node.getNodeName().equals(TmfXmlStrings.STATE_VALUE)) {
-            throw new IllegalArgumentException("TmfXmlStateValue constructor: Element is not a stateValue"); //$NON-NLS-1$
-        }
-
-        /* Check if there is an increment for the value */
-        fIncrement = Boolean.parseBoolean(node.getAttribute(TmfXmlStrings.INCREMENT));
-
-        /* Process the XML Element state value */
-        fStateValue = initializeStateValue(modelFactory, node);
-
-        /*
-         * 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
-         */
-        switch (node.getAttribute(TmfXmlStrings.FORCED_TYPE)) {
-        case TmfXmlStrings.TYPE_STRING:
-            fForcedType = ITmfStateValue.Type.STRING;
-            break;
-        case TmfXmlStrings.TYPE_INT:
-            fForcedType = ITmfStateValue.Type.INTEGER;
-            break;
-        case TmfXmlStrings.TYPE_LONG:
-            fForcedType = ITmfStateValue.Type.LONG;
-            break;
-        case TmfXmlStrings.TYPE_DOUBLE:
-            fForcedType = ITmfStateValue.Type.DOUBLE;
-            break;
-        default:
-            fForcedType = ITmfStateValue.Type.NULL;
-        }
-
-        /*
-         * Stack Actions : allow to define a stack with PUSH/POP/PEEK methods
-         */
-        String stack = node.getAttribute(TmfXmlStrings.ATTRIBUTE_STACK);
-        fStackType = ValueTypeStack.getTypeFromString(stack);
-    }
-
-    /**
-     * Initialize a {@link TmfXmlStateValueBase} object for the type and value
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param node
-     *            The state value XML element
-     * @return The internal state value type corresponding to this state value
-     */
-    protected TmfXmlStateValueBase initializeStateValue(ITmfXmlModelFactory modelFactory, Element node) {
-        return new TmfXmlStateValueNull();
-    }
-
-    /**
-     * Return the state system container this class is attached to
-     *
-     * @return The state system container
-     */
-    protected IXmlStateSystemContainer getSsContainer() {
-        return fContainer;
-    }
-
-    /**
-     * Get the state system associated with this value's container
-     *
-     * @return The state system associated with the state system container
-     */
-    protected @Nullable ITmfStateSystem getStateSystem() {
-        return fContainer.getStateSystem();
-    }
-
-    /**
-     * Return whether this value is an increment of the previous value
-     *
-     * @return <code>true</code> if the value is an increment
-     */
-    protected boolean isIncrement() {
-        return fIncrement;
-    }
-
-    /**
-     * 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
-     * implementation of the model.
-     *
-     * @return The stack type of the attribute
-     */
-    protected ValueTypeStack getStackType() {
-        return fStackType;
-    }
-
-    /**
-     * Get the forced type of the value. For example, if the value obtained from
-     * the attributes is not in this forced type, it will be converted to this.
-     *
-     * @return The desired type of the value
-     */
-    protected ITmfStateValue.Type getForcedType() {
-        return fForcedType;
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
-        return fStateValue.getValue(event, scenarioInfo);
-    }
-
-    /**
-     * Get the value of the event field that is the path of this state value
-     *
-     * @param event
-     *            The current event
-     * @return the value of the event field
-     */
-    @Override
-    public ITmfStateValue getEventFieldValue(@NonNull ITmfEvent event) {
-        String eventField = fEventField;
-        if (eventField == null) {
-            throw new IllegalStateException();
-        }
-        return getEventFieldValue(event, eventField);
-    }
-
-    /**
-     * Get the value of an event field
-     *
-     * @param event
-     *            The current event
-     * @param fieldName
-     *            The name of the field of which to get the value
-     * @return The value of the event field
-     */
-    protected ITmfStateValue getEventFieldValue(ITmfEvent event, String fieldName) {
-
-        ITmfStateValue value = TmfStateValue.nullValue();
-
-        final ITmfEventField content = event.getContent();
-
-        /* Exception for "CPU", returns the source of this event */
-        /* FIXME : Nameclash if a eventfield have "cpu" for name. */
-        if (fieldName.equals(TmfXmlStrings.CPU)) {
-            Integer cpu = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(event.getTrace(), TmfCpuAspect.class, event);
-            if (cpu != null) {
-                return TmfStateValue.newValueInt(cpu.intValue());
-            }
-        }
-        /* Exception also for "TIMESTAMP", returns the timestamp of this event */
-        if (fieldName.equals(TmfXmlStrings.TIMESTAMP)) {
-            return TmfStateValue.newValueLong(event.getTimestamp().getValue());
-        }
-        if (content.getField(fieldName) == null) {
-            return value;
-        }
-
-        Object field = content.getField(fieldName).getValue();
-
-        /*
-         * Try to find the right type. The type can be forced by
-         * "forcedType" argument.
-         */
-
-        if (field instanceof String) {
-            String fieldString = (String) field;
-
-            switch (fForcedType) {
-            case INTEGER:
-                value = TmfStateValue.newValueInt(Integer.parseInt(fieldString));
-                break;
-            case LONG:
-                value = TmfStateValue.newValueLong(Long.parseLong(fieldString));
-                break;
-            case DOUBLE:
-                value = TmfStateValue.newValueDouble(Double.parseDouble(fieldString));
-                break;
-            case NULL:
-            case STRING:
-            default:
-                value = TmfStateValue.newValueString(fieldString);
-                break;
-            }
-        } else if (field instanceof Long) {
-            Long fieldLong = (Long) field;
-
-            switch (fForcedType) {
-            case INTEGER:
-                value = TmfStateValue.newValueInt(fieldLong.intValue());
-                break;
-            case STRING:
-                value = TmfStateValue.newValueString(fieldLong.toString());
-                break;
-            case DOUBLE:
-                value = TmfStateValue.newValueDouble(fieldLong.doubleValue());
-                break;
-            case LONG:
-            case NULL:
-            default:
-                value = TmfStateValue.newValueLong(fieldLong);
-                break;
-            }
-        } else if (field instanceof Integer) {
-            Integer fieldInteger = (Integer) field;
-
-            switch (fForcedType) {
-            case LONG:
-                value = TmfStateValue.newValueLong(fieldInteger.longValue());
-                break;
-            case STRING:
-                value = TmfStateValue.newValueString(fieldInteger.toString());
-                break;
-            case DOUBLE:
-                value = TmfStateValue.newValueDouble(fieldInteger.doubleValue());
-                break;
-            case INTEGER:
-            case NULL:
-            default:
-                value = TmfStateValue.newValueInt(fieldInteger);
-                break;
-            }
-        } else if (field instanceof Double) {
-            Double fieldDouble = (Double) field;
-
-            switch (fForcedType) {
-            case LONG:
-                value = TmfStateValue.newValueLong(fieldDouble.longValue());
-                break;
-            case STRING:
-                value = TmfStateValue.newValueString(fieldDouble.toString());
-                break;
-            case INTEGER:
-                value = TmfStateValue.newValueInt(fieldDouble.intValue());
-                break;
-            case DOUBLE:
-            case NULL:
-            default:
-                value = TmfStateValue.newValueDouble(fieldDouble);
-                break;
-            }
-        }
-        return value;
-    }
-
-    /**
-     * Get the list of state attributes, the path to the state value
-     *
-     * @return the list of Attribute to have the path in the State System
-     */
-    @Override
-    public List<ITmfXmlStateAttribute> getAttributes() {
-        return fPath;
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public void handleEvent(@NonNull ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException {
-        int quark = IXmlStateSystemContainer.ROOT_QUARK;
-
-        for (ITmfXmlStateAttribute attribute : fPath) {
-            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$
-            }
-        }
-
-        long ts = event.getTimestamp().getValue();
-        fStateValue.handleEvent(event, quark, ts, scenarioInfo);
-    }
-
-    @Override
-    public String toString() {
-        StringBuilder builder = new StringBuilder("TmfXmlStateValue: "); //$NON-NLS-1$
-        if (fEventField != null) {
-            builder.append("Field=").append(fEventField).append("; "); //$NON-NLS-1$ //$NON-NLS-2$
-        } else if (!fPath.isEmpty()) {
-            builder.append("Path=").append(fPath).append("; "); //$NON-NLS-1$ //$NON-NLS-2$
-        }
-        builder.append(fStateValue);
-        return builder.toString();
-    }
-
-    /**
-     * Base class for all state values. Contain default methods to handle event,
-     * process or increment the value
-     */
-    protected abstract class TmfXmlStateValueBase {
-
-        /**
-         * Get the value associated with this state value.
-         *
-         * @param event
-         *            The event which can be used to retrieve the value if
-         *            necessary. The event can be <code>null</code> if no event
-         *            is required.
-         * @param scenarioInfo
-         *            The active scenario details. The value should be null if
-         *            there no scenario.
-         * @return The state value corresponding to this XML state value
-         * @throws AttributeNotFoundException
-         *             Pass through the exception it received
-         * @since 2.0
-         */
-        public abstract ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException;
-
-        /**
-         * Do something with the state value, possibly using an event
-         *
-         * @param event
-         *            The event being handled. If there is no event is
-         *            available, use <code>null</code>.
-         * @param quark
-         *            The quark for this value
-         * @param timestamp
-         *            The timestamp of the event
-         * @param scenarioInfo
-         *            The active scenario details. The value should be null if
-         *            there no scenario.
-         * @throws StateValueTypeException
-         *             Pass through the exception it received
-         * @throws TimeRangeException
-         *             Pass through the exception it received
-         * @throws AttributeNotFoundException
-         *             Pass through the exception it received
-         * @since 2.0
-         */
-        public void handleEvent(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
-            if (fIncrement) {
-                incrementValue(event, quark, timestamp, scenarioInfo);
-            } else {
-                ITmfStateValue value = getValue(event, scenarioInfo);
-                processValue(quark, timestamp, value);
-            }
-        }
-
-        /**
-         * Set the value of a quark at a given timestamp.
-         *
-         * @param quark
-         *            The quark for this value
-         * @param timestamp
-         *            The timestamp
-         * @param value
-         *            The value of this state value
-         * @throws TimeRangeException
-         *             Pass through the exception it received
-         * @throws StateValueTypeException
-         *             Pass through the exception it received
-         * @throws AttributeNotFoundException
-         *             Pass through the exception it received
-         */
-        @SuppressWarnings("unused")
-        protected void processValue(int quark, long timestamp, ITmfStateValue value) throws TimeRangeException, StateValueTypeException, AttributeNotFoundException {
-        }
-
-        /**
-         * Increments the value of the parameter
-         *
-         * @param event
-         *            The event being handled
-         * @param quark
-         *            The quark for this value
-         * @param timestamp
-         *            The timestamp of the event
-         * @param scenarioInfo
-         *            The active scenario details. The value should be null if
-         *            there no scenario.
-         * @throws StateValueTypeException
-         *             Pass through the exception it received
-         * @throws TimeRangeException
-         *             Pass through the exception it received
-         * @throws AttributeNotFoundException
-         *             Pass through the exception it received
-         * @since 2.0
-         */
-        @SuppressWarnings("unused")
-        protected void incrementValue(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
-        }
-    }
-
-    /* This state value uses a constant value, defined in the XML */
-    private class TmfXmlStateValueNull extends TmfXmlStateValueBase {
-
-        @Override
-        public ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
-            return TmfStateValue.nullValue();
-        }
-
-        @Override
-        public String toString() {
-            return "NULL"; //$NON-NLS-1$
-        }
-    }
-
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlTimestampCondition.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlTimestampCondition.java
deleted file mode 100644 (file)
index 422c126..0000000
+++ /dev/null
@@ -1,283 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- ******************************************************************************/
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.List;
-
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.common.core.NonNullUtils;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternStateProvider;
-import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.w3c.dom.Element;
-
-/**
- * This Class implements a timestamp condition tree in the XML-defined state
- * system.
- *
- * @author Jean-Christian Kouame
- * @since 2.0
- */
-public class TmfXmlTimestampCondition implements ITmfXmlCondition {
-
-    private enum TimeRangeOperator {
-        IN,
-        OUT,
-        OTHER
-    }
-
-    private enum ElapsedTimeOperator {
-        LESS,
-        EQUAL,
-        MORE,
-        NONE
-    }
-
-    private static final long US = 1000l;
-    private final IXmlTimestampsCondition fTimestampsCondition;
-    private final IXmlStateSystemContainer fParent;
-
-    /**
-     * Constructor
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param node
-     *            The XML root of this timestamp condition
-     * @param container
-     *            The state system container this timestamp condition belongs to
-     */
-    public TmfXmlTimestampCondition(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container) {
-        fParent = container;
-        String type = node.getNodeName();
-        switch (type) {
-        case TmfXmlStrings.TIME_RANGE:
-            fTimestampsCondition = new TmfXmlTimeRangeCondition(modelFactory, node, fParent);
-            break;
-        case TmfXmlStrings.ELAPSED_TIME:
-            fTimestampsCondition = new TmfXmlElapsedTimeCondition(modelFactory, node, fParent);
-            break;
-        default:
-            throw new IllegalArgumentException("Invalid timestampsChecker declaration in XML : Type should be timeRange or elapsedTime"); //$NON-NLS-1$
-        }
-    }
-
-    /**
-     * Normalize the value into a nanosecond time value
-     *
-     * @param timestamp
-     *            The timestamp value
-     * @param unit
-     *            The initial unit of the timestamp
-     * @return The value of the timestamp in nanoseconds
-     */
-    public static long valueToNanoseconds(long timestamp, String unit) {
-        switch (unit) {
-        case TmfXmlStrings.NS:
-            return timestamp;
-        case TmfXmlStrings.US:
-            return timestamp * US;
-        case TmfXmlStrings.MS:
-            return timestamp * US * US;
-        case TmfXmlStrings.S:
-            return timestamp * US * US * US;
-        default:
-            throw new IllegalArgumentException("The time unit is not yet supporting."); //$NON-NLS-1$
-        }
-    }
-
-    /**
-     * Validate the event
-     *
-     * @param event
-     *            The current event
-     * @param scenarioInfo
-     *            The active scenario details. The value should be null if there
-     *            is no scenario
-     * @return True if the test succeed, false otherwise
-     */
-    @Override
-    public boolean test(ITmfEvent event,@Nullable TmfXmlScenarioInfo scenarioInfo) {
-        return fTimestampsCondition.test(event, scenarioInfo);
-    }
-
-    private interface IXmlTimestampsCondition extends ITmfXmlCondition {
-    }
-
-    private class TmfXmlTimeRangeCondition implements IXmlTimestampsCondition {
-
-        private final TimeRangeOperator fType;
-        private final String fUnit;
-        private final String fBegin;
-        private final String fEnd;
-        private final IXmlStateSystemContainer fContainer;
-
-        /**
-         * Constructor
-         *
-         * @param modelFactory
-         *            The factory used to create XML model elements
-         * @param node
-         *            The XML root of this time range condition transition
-         * @param container
-         *            The state system container this time range condition
-         *            belongs to
-         */
-        public TmfXmlTimeRangeCondition(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container) {
-            fContainer = container;
-            String unit = node.getAttribute(TmfXmlStrings.UNIT);
-            fUnit = unit;
-            List<@Nullable Element> childElements = NonNullUtils.checkNotNull(XmlUtils.getChildElements(node));
-            if (childElements.size() != 1) {
-                throw new IllegalArgumentException("Invalid timestampsChecker declaration in XML : Only one timing condition is allowed"); //$NON-NLS-1$
-            }
-            final Element firstElement = NonNullUtils.checkNotNull(childElements.get(0));
-            String type = firstElement.getNodeName();
-            switch (type) {
-            case TmfXmlStrings.IN:
-                fType = TimeRangeOperator.IN;
-                break;
-            case TmfXmlStrings.OUT:
-                fType = TimeRangeOperator.OUT;
-                break;
-            default:
-                fType = TimeRangeOperator.OTHER;
-                break;
-            }
-
-            final String begin = firstElement.getAttribute(TmfXmlStrings.BEGIN);
-            final String end = firstElement.getAttribute(TmfXmlStrings.END);
-            fBegin = begin;
-            fEnd = end;
-        }
-
-        @Override
-        public boolean test(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
-            ITmfStateSystem ss = fContainer.getStateSystem();
-
-            long begin;
-            begin = valueToNanoseconds(Long.parseLong(fBegin), fUnit);
-
-            long end;
-            end = valueToNanoseconds(Long.parseLong(fEnd), fUnit);
-
-            // swap the value if begin > end
-            if (begin > end) {
-                begin = begin ^ end;
-                end = begin ^ end;
-                begin = begin ^ end;
-            }
-
-            begin = Math.max(ss.getStartTime(), begin);
-            end = Math.min(ss.getCurrentEndTime(), end);
-            begin = Math.min(begin, end);
-
-            long ts = event.getTimestamp().toNanos();
-            switch (fType) {
-            case IN:
-                return intersects(begin, end, ts);
-            case OUT:
-                return !intersects(begin, end, ts);
-            case OTHER:
-            default:
-                return false;
-            }
-        }
-
-        private boolean intersects(long begin, long end, long ts) {
-            return ts >= begin && ts <= end;
-        }
-
-    }
-
-    private class TmfXmlElapsedTimeCondition implements IXmlTimestampsCondition {
-
-        private final IXmlStateSystemContainer fContainer;
-        private final ElapsedTimeOperator fType;
-        private final String fUnit;
-        private final String fValue;
-        private final String fReferenceState;
-
-        /**
-         * Constructor
-         *
-         * @param modelFactory
-         *            The factory used to create XML model elements
-         * @param node
-         *            The XML root of this elapsed time condition
-         * @param container
-         *            The state system container this elapsed time condition
-         *            belongs to
-         */
-        public TmfXmlElapsedTimeCondition(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container) {
-            fContainer = container;
-            String unit = node.getAttribute(TmfXmlStrings.UNIT);
-            fUnit = unit;
-            List<@Nullable Element> childElements = XmlUtils.getChildElements(node);
-            if (childElements.size() != 1) {
-                throw new IllegalArgumentException("Invalid timestampsChecker declaration in XML : Only one timing condition is allowed"); //$NON-NLS-1$
-            }
-            final Element firstElement = NonNullUtils.checkNotNull(childElements.get(0));
-            String type = firstElement.getNodeName();
-            switch (type) {
-            case TmfXmlStrings.LESS:
-                fType = ElapsedTimeOperator.LESS;
-                break;
-            case TmfXmlStrings.EQUAL:
-                fType = ElapsedTimeOperator.EQUAL;
-                break;
-            case TmfXmlStrings.MORE:
-                fType = ElapsedTimeOperator.MORE;
-                break;
-            default:
-                fType = ElapsedTimeOperator.NONE;
-                break;
-            }
-            final String reference = firstElement.getAttribute(TmfXmlStrings.SINCE);
-            final String value = firstElement.getAttribute(TmfXmlStrings.VALUE);
-            fReferenceState = reference;
-            fValue = value;
-        }
-
-        @Override
-        public boolean test(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
-            if (scenarioInfo == null) {
-                Activator.logError("Elapse time conditions require scenarioInfos and scenarioInfos is null"); //$NON-NLS-1$
-                return false;
-            }
-            boolean success;
-            long ts = event.getTimestamp().toNanos();
-            long referenceTimestamps = ((XmlPatternStateProvider) fContainer).getHistoryBuilder().getSpecificStateStartTime(fContainer, fReferenceState, scenarioInfo, event);
-            if (ts < referenceTimestamps) {
-                throw new IllegalArgumentException("Timestamp is inferior to reference time"); //$NON-NLS-1$
-            }
-            switch (fType) {
-            case LESS:
-                success = (ts - referenceTimestamps) < valueToNanoseconds(Long.parseLong(fValue), fUnit);
-                break;
-            case EQUAL:
-                success = (ts - referenceTimestamps) == valueToNanoseconds(Long.parseLong(fValue), fUnit);
-                break;
-            case MORE:
-                success = (ts - referenceTimestamps) > valueToNanoseconds(Long.parseLong(fValue), fUnit);
-                break;
-            case NONE:
-            default:
-                success = false;
-                break;
-            }
-            return success;
-        }
-
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlTransitionValidator.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/TmfXmlTransitionValidator.java
deleted file mode 100644 (file)
index 7fe1dc0..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- ******************************************************************************/
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.List;
-
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.common.core.NonNullUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-/**
- * This Class implements a transition input tree in the XML-defined state
- * system.
- *
- * TODO We should merge this class with the current TmfXmlCondition, that should
- * be kept as is for compatibility with current stateProvider
- *
- * @author Jean-Christian Kouame
- * @since 2.0
- */
-public class TmfXmlTransitionValidator implements ITmfXmlCondition {
-
-    IXmlStateSystemContainer fParent;
-    private final String fId;
-    private final ITmfXmlCondition fCondition;
-
-    /**
-     * Constructor
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param node
-     *            The XML root of this transition input
-     * @param parent
-     *            The state system container this transition input belongs to
-     */
-    public TmfXmlTransitionValidator(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer parent) {
-        fParent = parent;
-        fId = node.getAttribute(TmfXmlStrings.ID);
-
-        List<@Nullable Element> childElements = XmlUtils.getChildElements(node);
-        Node child = NonNullUtils.checkNotNull(childElements.get(0));
-        fCondition = modelFactory.createCondition((Element) child, parent);
-    }
-
-    /**
-     * Get the ID of this transition input
-     *
-     * @return The id of this transition input
-     */
-    public String getId() {
-        return fId;
-    }
-
-    @Override
-    public boolean test(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
-        return fCondition.test(event, scenarioInfo);
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/UpdateStoredFieldsAction.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/UpdateStoredFieldsAction.java
deleted file mode 100644 (file)
index bea8ab5..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- ******************************************************************************/
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
-
-import java.util.Map.Entry;
-
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternStateProvider;
-import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
-import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
-
-/**
- * This action will update the value of the stored fields in the state system
- * based on the current event data.
- *
- * @author Jean-Christian Kouame
- * @since 2.0
- */
-public class UpdateStoredFieldsAction implements ITmfXmlAction {
-
-    private final IXmlStateSystemContainer fParent;
-
-    /**
-     * Constructor
-     *
-     * @param parent
-     *            The state system container this action belongs to
-     */
-    public UpdateStoredFieldsAction(IXmlStateSystemContainer parent) {
-        fParent = parent;
-    }
-
-    @Override
-    public void execute(ITmfEvent event, TmfXmlScenarioInfo scenarioInfo) {
-        if (fParent instanceof XmlPatternStateProvider) {
-            for (Entry<String, String> entry : ((XmlPatternStateProvider) fParent).getStoredFields().entrySet()) {
-                ITmfEventField eventField = event.getContent().getField(entry.getKey());
-                ITmfStateValue stateValue = null;
-                if (eventField != null) {
-                    final String alias = entry.getValue();
-                    Object field = eventField.getValue();
-                    if (field instanceof String) {
-                        stateValue = TmfStateValue.newValueString((String) field);
-                    } else if (field instanceof Long) {
-                        stateValue = TmfStateValue.newValueLong(((Long) field).longValue());
-                    } else if (field instanceof Integer) {
-                        stateValue = TmfStateValue.newValueInt(((Integer) field).intValue());
-                    } else if (field instanceof Double) {
-                        stateValue = TmfStateValue.newValueDouble(((Double) field).doubleValue());
-                    }
-                    if (stateValue == null) {
-                        throw new IllegalStateException("State value is null. Invalid type."); //$NON-NLS-1$
-                    }
-                    ((XmlPatternStateProvider) fParent).getHistoryBuilder().updateStoredFields(fParent, alias, stateValue, scenarioInfo, event);
-                }
-            }
-        }
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/package-info.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/package-info.java
deleted file mode 100644 (file)
index 398e7bf..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *    Ericsson - Initial API and implementation
- *******************************************************************************/
-
-@org.eclipse.jdt.annotation.NonNullByDefault package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyModelFactory.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyModelFactory.java
deleted file mode 100644 (file)
index 75292b7..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model.readonly;
-
-import java.util.List;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlStateValue;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlAction;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlCondition;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlEventHandler;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlFsm;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlLocation;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlPatternEventHandler;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlPatternSegmentBuilder;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlState;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlStateChange;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlStateTransition;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlTransitionValidator;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlTimestampCondition;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.w3c.dom.Element;
-
-/**
- * Concrete factory for XML model elements in read only mode
- *
- * @author Geneviève Bastien
- */
-public class TmfXmlReadOnlyModelFactory implements ITmfXmlModelFactory {
-
-    private static @Nullable ITmfXmlModelFactory fInstance = null;
-
-    /**
-     * Get the instance of this model creator
-     *
-     * @return The {@link TmfXmlReadOnlyModelFactory} instance
-     */
-    public static synchronized ITmfXmlModelFactory getInstance() {
-        ITmfXmlModelFactory instance = fInstance;
-        if (instance == null) {
-            instance = new TmfXmlReadOnlyModelFactory();
-            fInstance = instance;
-        }
-        return instance;
-    }
-
-    @Override
-    public ITmfXmlStateAttribute createStateAttribute(Element attribute, IXmlStateSystemContainer container) {
-        return new TmfXmlReadOnlyStateAttribute(this, attribute, container);
-    }
-
-    @Override
-    public ITmfXmlStateValue createStateValue(Element node, IXmlStateSystemContainer container, List<ITmfXmlStateAttribute> attributes) {
-        return new TmfXmlReadOnlyStateValue(this, node, container, attributes);
-    }
-
-    @Override
-    public ITmfXmlStateValue createStateValue(Element node, IXmlStateSystemContainer container, String eventField) {
-        return new TmfXmlReadOnlyStateValue(this, node, container, eventField);
-    }
-
-    @Override
-    public TmfXmlCondition createCondition(Element node, IXmlStateSystemContainer container) {
-        return TmfXmlCondition.create(this, node, container);
-    }
-
-    @Override
-    public TmfXmlEventHandler createEventHandler(Element node, IXmlStateSystemContainer container) {
-        return new TmfXmlEventHandler(this, node, container);
-    }
-
-    @Override
-    public TmfXmlStateChange createStateChange(Element node, IXmlStateSystemContainer container) {
-        return new TmfXmlStateChange(this, node, container);
-    }
-
-    @Override
-    public TmfXmlLocation createLocation(Element node, IXmlStateSystemContainer container) {
-        return new TmfXmlLocation(this, node, container);
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public TmfXmlPatternEventHandler createPatternEventHandler(Element node, IXmlStateSystemContainer container) {
-        return new TmfXmlPatternEventHandler(this, node, container);
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public TmfXmlTransitionValidator createTransitionValidator(Element node, IXmlStateSystemContainer container) {
-        return new TmfXmlTransitionValidator(this, node, container);
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public TmfXmlAction createAction(Element node, IXmlStateSystemContainer container) {
-        return new TmfXmlAction(this, node, container);
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public TmfXmlFsm createFsm(Element node, IXmlStateSystemContainer container) {
-        return TmfXmlFsm.create(this, node, container);
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public @NonNull TmfXmlState createState(Element node, IXmlStateSystemContainer container, @Nullable TmfXmlState parent) {
-        return TmfXmlState.create(this, node, container, parent);
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public TmfXmlStateTransition createStateTransition(Element node, IXmlStateSystemContainer container) {
-        return new TmfXmlStateTransition(this, node, container);
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public TmfXmlTimestampCondition createTimestampsCondition(Element node, IXmlStateSystemContainer container) {
-        return new TmfXmlTimestampCondition(this, node, container);
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public TmfXmlPatternSegmentBuilder createPatternSegmentBuilder(Element node, IXmlStateSystemContainer container) {
-        return new TmfXmlPatternSegmentBuilder(this, node, container);
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateAttribute.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateAttribute.java
deleted file mode 100644 (file)
index 4a580b7..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model.readonly;
-
-import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlStateAttribute;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.w3c.dom.Element;
-
-/**
- * Implements a state attribute in a read only mode. See
- * {@link TmfXmlStateAttribute} for the syntax of this attribute.
- *
- * In read-only mode, attributes that are requested but do not exist in the
- * state system will not be added.
- *
- * @author Geneviève Bastien
- */
-public class TmfXmlReadOnlyStateAttribute extends TmfXmlStateAttribute {
-
-    /**
-     * Constructor
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param attribute
-     *            The XML element corresponding to this attribute
-     * @param container
-     *            The state system container this state value belongs to
-     */
-    public TmfXmlReadOnlyStateAttribute(TmfXmlReadOnlyModelFactory modelFactory, Element attribute, IXmlStateSystemContainer container) {
-        super(modelFactory, attribute, container);
-    }
-
-    @Override
-    protected int getQuarkAbsoluteAndAdd(String... path) throws AttributeNotFoundException {
-        ITmfStateSystem ss = getStateSystem();
-        if (ss == null) {
-            throw new IllegalStateException("The state system hasn't been initialized yet"); //$NON-NLS-1$
-        }
-        return ss.getQuarkAbsolute(path);
-    }
-
-    @Override
-    protected int getQuarkRelativeAndAdd(int startNodeQuark, String... path) throws AttributeNotFoundException {
-        ITmfStateSystem ss = getStateSystem();
-        if (ss == null) {
-            throw new IllegalStateException("The state system hasn't been initialized yet"); //$NON-NLS-1$
-        }
-        return ss.getQuarkRelative(startNodeQuark, path);
-    }
-
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateValue.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readonly/TmfXmlReadOnlyStateValue.java
deleted file mode 100644 (file)
index cc0ad19..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model.readonly;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlStateValue;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.w3c.dom.Element;
-
-/**
- * Implements a state value is a read only mode. See {@link TmfXmlStateValue}
- * for the syntax of the state value.
- *
- * In read mode, a state value will typically be used to find a path to a value,
- * so the value is known and there is a path of attributes that should lead to
- * it.
- *
- * @author Geneviève Bastien
- */
-public class TmfXmlReadOnlyStateValue extends TmfXmlStateValue {
-
-    /**
-     * Constructor where the path to the value is a list of state attributes
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param node
-     *            The state value XML element
-     * @param container
-     *            The state system container this state value belongs to
-     * @param attributes
-     *            The attributes representing the path to this value
-     */
-    public TmfXmlReadOnlyStateValue(TmfXmlReadOnlyModelFactory modelFactory, Element node,
-            IXmlStateSystemContainer container, List<ITmfXmlStateAttribute> attributes) {
-        super(modelFactory, node, container, attributes, null);
-    }
-
-    /**
-     * Constructor where the path to the value is an event field
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param node
-     *            The state value XML element
-     * @param container
-     *            The state system container this state value belongs to
-     * @param eventField
-     *            The event field where to get the value
-     */
-    public TmfXmlReadOnlyStateValue(TmfXmlReadOnlyModelFactory modelFactory, Element node,
-            IXmlStateSystemContainer container, String eventField) {
-        super(modelFactory, node, container, Collections.EMPTY_LIST, eventField);
-    }
-
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readonly/package-info.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readonly/package-info.java
deleted file mode 100644 (file)
index 4452137..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *    Ericsson - Initial API and implementation
- *******************************************************************************/
-
-@org.eclipse.jdt.annotation.NonNullByDefault package org.eclipse.tracecompass.tmf.analysis.xml.core.model.readonly;
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteModelFactory.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteModelFactory.java
deleted file mode 100644 (file)
index 1cfe63c..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model.readwrite;
-
-import java.util.List;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlStateValue;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlAction;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlCondition;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlEventHandler;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlFsm;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlLocation;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlPatternEventHandler;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlPatternSegmentBuilder;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlState;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlStateChange;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlStateTransition;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlTransitionValidator;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlTimestampCondition;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.w3c.dom.Element;
-
-/**
- * Concrete factory for XML model elements in read write mode
- *
- * @author Geneviève Bastien
- */
-public class TmfXmlReadWriteModelFactory implements ITmfXmlModelFactory {
-
-    private static @Nullable ITmfXmlModelFactory fInstance = null;
-
-    /**
-     * Get the instance of this model creator
-     *
-     * @return The {@link TmfXmlReadWriteModelFactory} instance
-     */
-    public static synchronized ITmfXmlModelFactory getInstance() {
-        ITmfXmlModelFactory instance = fInstance;
-        if (instance == null) {
-            instance = new TmfXmlReadWriteModelFactory();
-            fInstance = instance;
-        }
-        return instance;
-    }
-
-    @Override
-    public ITmfXmlStateAttribute createStateAttribute(Element attribute, IXmlStateSystemContainer container) {
-        return new TmfXmlReadWriteStateAttribute(this, attribute, container);
-    }
-
-    @Override
-    public ITmfXmlStateValue createStateValue(Element node, IXmlStateSystemContainer container, List<ITmfXmlStateAttribute> attributes) {
-        return new TmfXmlReadWriteStateValue(this, node, container, attributes);
-    }
-
-    @Override
-    public ITmfXmlStateValue createStateValue(Element node, IXmlStateSystemContainer container, String eventField) {
-        return new TmfXmlReadWriteStateValue(this, node, container, eventField);
-    }
-
-    @Override
-    public TmfXmlCondition createCondition(Element node, IXmlStateSystemContainer container) {
-        return TmfXmlCondition.create(this, node, container);
-    }
-
-    @Override
-    public TmfXmlEventHandler createEventHandler(Element node, IXmlStateSystemContainer container) {
-        return new TmfXmlEventHandler(this, node, container);
-    }
-
-    @Override
-    public TmfXmlStateChange createStateChange(Element node, IXmlStateSystemContainer container) {
-        return new TmfXmlStateChange(this, node, container);
-    }
-
-    @Override
-    public TmfXmlLocation createLocation(Element node, IXmlStateSystemContainer container) {
-        return new TmfXmlLocation(this, node, container);
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public TmfXmlPatternEventHandler createPatternEventHandler(Element node, IXmlStateSystemContainer container) {
-        return new TmfXmlPatternEventHandler(this, node, container);
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public TmfXmlTransitionValidator createTransitionValidator(Element node, IXmlStateSystemContainer container) {
-        return new TmfXmlTransitionValidator(this, node, container);
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public TmfXmlAction createAction(Element node, IXmlStateSystemContainer container) {
-        return new TmfXmlAction(this, node, container);
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public TmfXmlFsm createFsm(Element node, IXmlStateSystemContainer container) {
-        return TmfXmlFsm.create(this, node, container);
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public @NonNull TmfXmlState createState(Element node, IXmlStateSystemContainer container, @Nullable TmfXmlState parent) {
-        return TmfXmlState.create(this, node, container, parent);
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public TmfXmlStateTransition createStateTransition(Element node, IXmlStateSystemContainer container) {
-        return new TmfXmlStateTransition(this, node, container);
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public TmfXmlTimestampCondition createTimestampsCondition(Element node, IXmlStateSystemContainer container) {
-        return new TmfXmlTimestampCondition(this, node, container);
-    }
-
-    /**
-     * @since 2.0
-     */
-    @Override
-    public TmfXmlPatternSegmentBuilder createPatternSegmentBuilder(Element node, IXmlStateSystemContainer container) {
-        return new TmfXmlPatternSegmentBuilder(this, node, container);
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateAttribute.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateAttribute.java
deleted file mode 100644 (file)
index 1841fd3..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model.readwrite;
-
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
-import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlStateAttribute;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.w3c.dom.Element;
-
-/**
- * Implements a state attribute in a read write mode. See
- * {@link TmfXmlStateAttribute} for the syntax of this attribute.
- *
- * In read-write mode, attributes that are requested but do not exist are added
- * to the state system.
- *
- * @author Geneviève Bastien
- */
-public class TmfXmlReadWriteStateAttribute extends TmfXmlStateAttribute {
-
-    /**
-     * Constructor
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param attribute
-     *            The XML element corresponding to this attribute
-     * @param container
-     *            The state system container this state value belongs to
-     */
-    public TmfXmlReadWriteStateAttribute(TmfXmlReadWriteModelFactory modelFactory, Element attribute, IXmlStateSystemContainer container) {
-        super(modelFactory, attribute, container);
-    }
-
-    @Override
-    protected @Nullable ITmfStateSystemBuilder getStateSystem() {
-        return (ITmfStateSystemBuilder) super.getStateSystem();
-    }
-
-    @Override
-    protected int getQuarkAbsoluteAndAdd(String... path) throws AttributeNotFoundException {
-        ITmfStateSystemBuilder ss = getStateSystem();
-        if (ss == null) {
-            throw new IllegalStateException("The state system hasn't been initialized yet"); //$NON-NLS-1$
-        }
-        return ss.getQuarkAbsoluteAndAdd(path);
-    }
-
-    @Override
-    protected int getQuarkRelativeAndAdd(int startNodeQuark, String... path) throws AttributeNotFoundException {
-        ITmfStateSystemBuilder ss = getStateSystem();
-        if (ss == null) {
-            throw new IllegalStateException("The state system hasn't been initialized yet"); //$NON-NLS-1$
-        }
-        return ss.getQuarkRelativeAndAdd(startNodeQuark, path);
-    }
-
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateValue.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readwrite/TmfXmlReadWriteStateValue.java
deleted file mode 100644 (file)
index a356417..0000000
+++ /dev/null
@@ -1,409 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.model.readwrite;
-
-import java.util.ArrayList;
-import java.util.List;
-
-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.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
-import org.eclipse.tracecompass.statesystem.core.StateSystemBuilderUtils;
-import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
-import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
-import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlScenarioInfo;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlStateValue;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.w3c.dom.Element;
-
-/**
- * Implements a state value in a read write mode. See {@link TmfXmlStateValue}
- * for the syntax of the state value.
- *
- * In read/write mode, a state value can be considered as an assignation where
- * the state value is assigned to the quark represented by the state attributes
- *
- * @author Geneviève Bastien
- */
-public class TmfXmlReadWriteStateValue extends TmfXmlStateValue {
-
-    private static final String ILLEGAL_STATE_EXCEPTION_MESSAGE = "The state system hasn't been initialized yet"; //$NON-NLS-1$
-
-    /**
-     * Constructor where the path to the value is a list of state attributes
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param node
-     *            The state value XML element
-     * @param container
-     *            The state system container this state value belongs to
-     * @param attributes
-     *            The attributes representing the path to this value
-     */
-    public TmfXmlReadWriteStateValue(TmfXmlReadWriteModelFactory modelFactory, Element node, IXmlStateSystemContainer container, List<ITmfXmlStateAttribute> attributes) {
-        this(modelFactory, node, container, attributes, null);
-    }
-
-    /**
-     * Constructor where the path to the value is an event field
-     *
-     * @param modelFactory
-     *            The factory used to create XML model elements
-     * @param node
-     *            The state value XML element
-     * @param container
-     *            The state system container this state value belongs to
-     * @param eventField
-     *            The event field where to get the value
-     */
-    public TmfXmlReadWriteStateValue(TmfXmlReadWriteModelFactory modelFactory, Element node, IXmlStateSystemContainer container, String eventField) {
-        this(modelFactory, node, container, new ArrayList<ITmfXmlStateAttribute>(), eventField);
-    }
-
-    private TmfXmlReadWriteStateValue(ITmfXmlModelFactory modelFactory, Element node, IXmlStateSystemContainer container, List<ITmfXmlStateAttribute> attributes, @Nullable String eventField) {
-        super(modelFactory, node, container, attributes, eventField);
-    }
-
-    @Override
-    protected @Nullable ITmfStateSystemBuilder getStateSystem() {
-        return (ITmfStateSystemBuilder) super.getStateSystem();
-    }
-
-    @Override
-    protected TmfXmlStateValueBase initializeStateValue(ITmfXmlModelFactory modelFactory, Element node) {
-        TmfXmlStateValueBase stateValueType = null;
-        /* Process the XML Element state value */
-        String type = node.getAttribute(TmfXmlStrings.TYPE);
-        String value = getSsContainer().getAttributeValue(node.getAttribute(TmfXmlStrings.VALUE));
-        if (value == null) {
-            throw new IllegalStateException();
-        }
-
-        switch (type) {
-        case TmfXmlStrings.TYPE_INT: {
-            /* Integer value */
-            ITmfStateValue stateValue = TmfStateValue.newValueInt(Integer.parseInt(value));
-            stateValueType = new TmfXmlStateValueTmf(stateValue);
-            break;
-        }
-        case TmfXmlStrings.TYPE_LONG: {
-            /* Long value */
-            ITmfStateValue stateValue = TmfStateValue.newValueLong(Long.parseLong(value));
-            stateValueType = new TmfXmlStateValueTmf(stateValue);
-            break;
-        }
-        case TmfXmlStrings.TYPE_STRING: {
-            /* String value */
-            ITmfStateValue stateValue = TmfStateValue.newValueString(value);
-            stateValueType = new TmfXmlStateValueTmf(stateValue);
-            break;
-        }
-        case TmfXmlStrings.TYPE_NULL: {
-            /* Null value */
-            ITmfStateValue stateValue = TmfStateValue.nullValue();
-            stateValueType = new TmfXmlStateValueTmf(stateValue);
-            break;
-        }
-        case TmfXmlStrings.EVENT_FIELD:
-            /* Event field */
-            stateValueType = new TmfXmlStateValueEventField(value);
-            break;
-        case TmfXmlStrings.TYPE_EVENT_NAME:
-            /* The value is the event name */
-            stateValueType = new TmfXmlStateValueEventName();
-            break;
-        case TmfXmlStrings.TYPE_DELETE:
-            /* Deletes the value of an attribute */
-            stateValueType = new TmfXmlStateValueDelete();
-            break;
-        case TmfXmlStrings.TYPE_QUERY:
-            /* Value is the result of a query */
-            List<@Nullable Element> children = XmlUtils.getChildElements(node);
-            List<ITmfXmlStateAttribute> childAttributes = new ArrayList<>();
-            for (Element child : children) {
-                if (child == null) {
-                    continue;
-                }
-                ITmfXmlStateAttribute queryAttribute = modelFactory.createStateAttribute(child, getSsContainer());
-                childAttributes.add(queryAttribute);
-            }
-            stateValueType = new TmfXmlStateValueQuery(childAttributes);
-            break;
-        default:
-            throw new IllegalArgumentException(String.format("TmfXmlStateValue constructor: unexpected element %s for stateValue type", type)); //$NON-NLS-1$
-        }
-        return stateValueType;
-    }
-
-    // ----------------------------------------------------------
-    // Internal state value classes for the different types
-    // ----------------------------------------------------------
-
-    /**
-     * Base class for all state value. Contain default methods to handle event,
-     * process or increment the value
-     */
-    protected abstract class TmfXmlStateValueTypeReadWrite extends TmfXmlStateValueBase {
-
-        @Override
-        public final void handleEvent(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
-            if (isIncrement()) {
-                incrementValue(event, quark, timestamp, scenarioInfo);
-            } else {
-                ITmfStateValue value = getValue(event, scenarioInfo);
-                processValue(quark, timestamp, value);
-            }
-        }
-
-        @Override
-        protected void processValue(int quark, long timestamp, ITmfStateValue value) throws AttributeNotFoundException, TimeRangeException, StateValueTypeException {
-            ITmfStateSystemBuilder ss = getStateSystem();
-            if (ss == null) {
-                throw new IllegalStateException(ILLEGAL_STATE_EXCEPTION_MESSAGE);
-            }
-            switch (getStackType()) {
-            case POP:
-                ss.popAttribute(timestamp, quark);
-                break;
-            case PUSH:
-                ss.pushAttribute(timestamp, value, quark);
-                break;
-            case NULL:
-            case PEEK:
-            default:
-                ss.modifyAttribute(timestamp, value, quark);
-                break;
-            }
-        }
-
-        @Override
-        protected void incrementValue(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
-            ITmfStateSystemBuilder ss = getStateSystem();
-            if (ss == null) {
-                throw new IllegalStateException(ILLEGAL_STATE_EXCEPTION_MESSAGE);
-            }
-            StateSystemBuilderUtils.incrementAttributeInt(ss, timestamp, quark, 1);
-        }
-    }
-
-    private static @Nullable ITmfStateValue incrementByType(int quark, ITmfStateSystem ss, ITmfStateValue stateValue) throws AttributeNotFoundException {
-        ITmfStateValue value = null;
-        switch (stateValue.getType()) {
-        case LONG: {
-            long incrementLong = stateValue.unboxLong();
-            ITmfStateValue currentState = ss.queryOngoingState(quark);
-            long currentValue = (currentState.isNull() ? 0 : currentState.unboxLong());
-            value = TmfStateValue.newValueLong(incrementLong + currentValue);
-            return value;
-        }
-        case INTEGER: {
-            int increment = stateValue.unboxInt();
-            ITmfStateValue currentState = ss.queryOngoingState(quark);
-            int currentValue = (currentState.isNull() ? 0 : currentState.unboxInt());
-            value = TmfStateValue.newValueInt(increment + currentValue);
-            return value;
-        }
-        case DOUBLE:
-        case NULL:
-        case STRING:
-        default:
-        }
-        return value;
-    }
-
-    /* This state value uses a constant value, defined in the XML */
-    private class TmfXmlStateValueTmf extends TmfXmlStateValueTypeReadWrite {
-
-        private final ITmfStateValue fValue;
-
-        public TmfXmlStateValueTmf(ITmfStateValue value) {
-            fValue = value;
-        }
-
-        @Override
-        public ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
-            return fValue;
-        }
-
-        @Override
-        public void incrementValue(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
-            ITmfStateSystem ss = getStateSystem();
-            if (ss == null) {
-                throw new IllegalStateException(ILLEGAL_STATE_EXCEPTION_MESSAGE);
-            }
-            ITmfStateValue value = incrementByType(quark, ss, fValue);
-            if (value != null) {
-                processValue(quark, timestamp, value);
-            } else {
-                Activator.logWarning("TmfXmlStateValue: The increment value is not a number type"); //$NON-NLS-1$
-            }
-        }
-
-        @Override
-        public String toString() {
-            return "Value=" + fValue; //$NON-NLS-1$
-        }
-
-    }
-
-    /* The state value uses the value of an event field */
-    private class TmfXmlStateValueEventField extends TmfXmlStateValueTypeReadWrite {
-
-        private final String fFieldName;
-
-        public TmfXmlStateValueEventField(String field) {
-            fFieldName = field;
-        }
-
-        @Override
-        public ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
-            if (event == null) {
-                Activator.logWarning("XML State value: requested an event field, but event is null"); //$NON-NLS-1$
-                return TmfStateValue.nullValue();
-            }
-            return getEventFieldValue(event, fFieldName);
-        }
-
-        @Override
-        public void incrementValue(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
-            ITmfStateSystem ss = getSsContainer().getStateSystem();
-            if (ss == null) {
-                throw new IllegalStateException(ILLEGAL_STATE_EXCEPTION_MESSAGE);
-            }
-            ITmfStateValue incrementValue = getValue(event, scenarioInfo);
-            ITmfStateValue value = incrementByType(quark, ss, incrementValue);
-            if (value != null) {
-                processValue(quark, timestamp, value);
-            } else {
-                Activator.logWarning(String.format("TmfXmlStateValue: The event field increment %s is not a number type but a %s", fFieldName, incrementValue.getType())); //$NON-NLS-1$
-            }
-        }
-
-        @Override
-        public String toString() {
-            return "Event Field=" + fFieldName; //$NON-NLS-1$
-        }
-    }
-
-    /* The state value is the event name */
-    private class TmfXmlStateValueEventName extends TmfXmlStateValueTypeReadWrite {
-
-        @Override
-        public @NonNull ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
-            if (event == null) {
-                Activator.logWarning("XML State value: request event name, but event is null"); //$NON-NLS-1$
-                return TmfStateValue.nullValue();
-            }
-            return TmfStateValue.newValueString(event.getName());
-        }
-
-        @Override
-        public String toString() {
-            return "Event name"; //$NON-NLS-1$
-        }
-    }
-
-    /* The state value deletes an attribute */
-    private class TmfXmlStateValueDelete extends TmfXmlStateValueTypeReadWrite {
-
-        @Override
-        public @NonNull ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
-            return TmfStateValue.nullValue();
-        }
-
-        @Override
-        protected void processValue(int quark, long timestamp, ITmfStateValue value) throws TimeRangeException, AttributeNotFoundException {
-            ITmfStateSystem ss = getStateSystem();
-            if (!(ss instanceof ITmfStateSystemBuilder)) {
-                throw new IllegalStateException("incrementValue should never be called when not building the state system"); //$NON-NLS-1$
-            }
-            ITmfStateSystemBuilder builder = (ITmfStateSystemBuilder) ss;
-            builder.removeAttribute(timestamp, quark);
-        }
-
-        @Override
-        public String toString() {
-            return "Delete"; //$NON-NLS-1$
-        }
-    }
-
-    /* The state value uses the result of a query */
-    private class TmfXmlStateValueQuery extends TmfXmlStateValueTypeReadWrite {
-
-        private final List<ITmfXmlStateAttribute> fQueryValue;
-
-        public TmfXmlStateValueQuery(List<ITmfXmlStateAttribute> childAttributes) {
-            fQueryValue = childAttributes;
-        }
-
-        @Override
-        public ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
-            /* Query the state system for the value */
-            ITmfStateValue value = TmfStateValue.nullValue();
-            int quarkQuery = IXmlStateSystemContainer.ROOT_QUARK;
-            ITmfStateSystem ss = getStateSystem();
-            if (ss == null) {
-                throw new IllegalStateException(ILLEGAL_STATE_EXCEPTION_MESSAGE);
-            }
-
-            for (ITmfXmlStateAttribute attribute : fQueryValue) {
-                quarkQuery = attribute.getAttributeQuark(event, quarkQuery, scenarioInfo);
-                if (quarkQuery == IXmlStateSystemContainer.ERROR_QUARK) {
-                    /* the query is not valid, we stop the state change */
-                    break;
-                }
-            }
-            /*
-             * the query can fail : for example, if a value is requested but has
-             * not been set yet
-             */
-            if (quarkQuery != IXmlStateSystemContainer.ERROR_QUARK) {
-                value = ss.queryOngoingState(quarkQuery);
-            }
-            return value;
-        }
-
-        @Override
-        public void incrementValue(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
-            ITmfStateSystem ss = getStateSystem();
-            if (ss == null) {
-                throw new IllegalStateException(ILLEGAL_STATE_EXCEPTION_MESSAGE);
-            }
-
-            ITmfStateValue incrementValue = getValue(event, scenarioInfo);
-            ITmfStateValue value = incrementByType(quark, ss, incrementValue);
-            if (value != null) {
-                processValue(quark, timestamp, value);
-            } else {
-                Activator.logWarning("TmfXmlStateValue: The query result increment is not a number type"); //$NON-NLS-1$
-            }
-        }
-
-        @Override
-        public String toString() {
-            return "Query=" + fQueryValue; //$NON-NLS-1$
-        }
-    }
-
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readwrite/package-info.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/model/readwrite/package-info.java
deleted file mode 100644 (file)
index a5ea3e2..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *    Ericsson - Initial API and implementation
- *******************************************************************************/
-
-@org.eclipse.jdt.annotation.NonNullByDefault package org.eclipse.tracecompass.tmf.analysis.xml.core.model.readwrite;
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/ITmfXmlTopLevelElement.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/ITmfXmlTopLevelElement.java
deleted file mode 100644 (file)
index 152c053..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.module;
-
-/**
- * Interface implemented by all classes representing XML top-level elements, for
- * example state providers and views
- *
- * @author Geneviève Bastien
- */
-public interface ITmfXmlTopLevelElement {
-
-    /**
-     * Get the requested value for an attribute. If the value is a pre-defined
-     * value, we return the string corresponding in the defined values map in
-     * the top-level XML element.
-     *
-     * @param name
-     *            the string to get
-     * @return the actual string value
-     */
-    String getAttributeValue(String name);
-
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/IXmlStateSystemContainer.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/IXmlStateSystemContainer.java
deleted file mode 100644 (file)
index af855e0..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.module;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlLocation;
-
-/**
- * Interface that all XML defined objects who provide, use or contain state
- * system must implement in order to use the state provider model elements in
- * {@link org.eclipse.tracecompass.tmf.analysis.xml.core.model} package
- *
- * @author Geneviève Bastien
- */
-public interface IXmlStateSystemContainer extends ITmfXmlTopLevelElement {
-
-    /** Root quark, to get values at the root of the state system */
-    int ROOT_QUARK = -1;
-    /**
-     * Error quark, value taken when a state system quark query is in error.
-     *
-     * FIXME: Originally in the code, the -1 was used for both root quark and
-     * return errors, so it has the same value as root quark, but maybe it can
-     * be changed to something else -2? A quark can never be negative
-     */
-    int ERROR_QUARK = -1;
-
-    /**
-     * Get the state system managed by this XML object
-     *
-     * @return The state system
-     */
-    ITmfStateSystem getStateSystem();
-
-    /**
-     * Get the list of locations defined in this top level XML element
-     *
-     * @return The list of {@link TmfXmlLocation}
-     */
-    @NonNull Iterable<@NonNull TmfXmlLocation> getLocations();
-
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/Messages.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/Messages.java
deleted file mode 100644 (file)
index 5624e90..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.module;
-
-import org.eclipse.osgi.util.NLS;
-
-/**
- * Externalized messages for the XML analysis module package
- *
- * @author Geneviève Bastien
- */
-public class Messages extends NLS {
-    private static final String BUNDLE_NAME = "org.eclipse.tracecompass.tmf.analysis.xml.core.module.messages"; //$NON-NLS-1$
-
-    /** Property name for file
-     * @since 2.0
-     */
-    public static String XmlModuleHelper_PropertyFile;
-
-    /** Property name for type
-     * @since 2.0
-     */
-    public static String XmlModuleHelper_PropertyType;
-
-    /** Error copying XML file to workspace folder */
-    public static String XmlUtils_ErrorCopyingFile;
-    /** XML parse error */
-    public static String XmlUtils_XmlParseError;
-    /** Error occurred while validating XML */
-    public static String XmlUtils_XmlValidateError;
-    /** XML validation error */
-    public static String XmlUtils_XmlValidationError;
-
-    static {
-        // initialize resource bundle
-        NLS.initializeMessages(BUNDLE_NAME, Messages.class);
-    }
-
-    private Messages() {
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/TmfAnalysisModuleHelperXml.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/TmfAnalysisModuleHelperXml.java
deleted file mode 100644 (file)
index c88030e..0000000
+++ /dev/null
@@ -1,236 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014, 2016 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.module;
-
-import java.io.File;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.common.core.NonNullUtils;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternAnalysis;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
-import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
-import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper;
-import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisManager;
-import org.eclipse.tracecompass.tmf.core.analysis.requirements.TmfAnalysisRequirement;
-import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
-import org.eclipse.tracecompass.tmf.core.project.model.ITmfPropertiesProvider;
-import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
-import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.osgi.framework.Bundle;
-import org.w3c.dom.Element;
-
-/**
- * Analysis module helpers for modules provided by XML files
- *
- * @author Geneviève Bastien
- * @since 2.0
- */
-public class TmfAnalysisModuleHelperXml implements IAnalysisModuleHelper, ITmfPropertiesProvider {
-
-    /**
-     * The types of analysis that can be XML-defined
-     */
-    public enum XmlAnalysisModuleType {
-        /** Analysis will be of type XmlStateSystemModule */
-        STATE_SYSTEM,
-
-        /**
-         * Analysis will be of type XmlPatternAnalysisModule
-         *
-         * @since 2.0
-         */
-        PATTERN
-    }
-
-    private final File fSourceFile;
-    private final Element fSourceElement;
-    private final XmlAnalysisModuleType fType;
-
-    /**
-     * Constructor
-     *
-     * @param xmlFile
-     *            The XML file containing the details of this analysis
-     * @param node
-     *            The XML node element
-     * @param type
-     *            The type of analysis
-     */
-    public TmfAnalysisModuleHelperXml(File xmlFile, Element node, XmlAnalysisModuleType type) {
-        fSourceFile = xmlFile;
-        fSourceElement = node;
-        fType = type;
-    }
-
-    @Override
-    public String getId() {
-        /*
-         * The attribute ID cannot be null because the XML has been validated
-         * and it is mandatory
-         */
-        return fSourceElement.getAttribute(TmfXmlStrings.ID);
-    }
-
-    @Override
-    public String getName() {
-        String name = null;
-        /* Label may be available in XML header */
-        List<Element> head = XmlUtils.getChildElements(fSourceElement, TmfXmlStrings.HEAD);
-        if (head.size() == 1) {
-            List<Element> labels = XmlUtils.getChildElements(head.get(0), TmfXmlStrings.LABEL);
-            if (!labels.isEmpty()) {
-                name = labels.get(0).getAttribute(TmfXmlStrings.VALUE);
-            }
-        }
-
-        if (name == null) {
-            name = getId();
-        }
-        return name;
-    }
-
-    @Override
-    public boolean isAutomatic() {
-        return false;
-    }
-
-    /**
-     * @since 1.0
-     */
-    @Override
-    public boolean appliesToExperiment() {
-        return false;
-    }
-
-    @Override
-    public String getHelpText() {
-        return ""; //$NON-NLS-1$
-    }
-
-    @Override
-    public String getHelpText(@NonNull ITmfTrace trace) {
-        return ""; //$NON-NLS-1$
-    }
-
-    @Override
-    public String getIcon() {
-        return null;
-    }
-
-    @Override
-    public Bundle getBundle() {
-        return Activator.getDefault().getBundle();
-    }
-
-    @Override
-    public boolean appliesToTraceType(Class<? extends ITmfTrace> traceClass) {
-        /* Trace types may be available in XML header */
-        List<Element> head = XmlUtils.getChildElements(fSourceElement, TmfXmlStrings.HEAD);
-        if (head.size() != 1) {
-            return true;
-        }
-        /*
-         * TODO: Test with custom trace types
-         */
-        List<Element> elements = XmlUtils.getChildElements(head.get(0), TmfXmlStrings.TRACETYPE);
-        if (elements.isEmpty()) {
-            return true;
-        }
-
-        for (Element element : elements) {
-            String traceTypeId = element.getAttribute(TmfXmlStrings.ID);
-            traceTypeId = TmfTraceType.buildCompatibilityTraceTypeId(traceTypeId);
-            TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
-            if ((helper != null) && helper.getTrace().getClass().isAssignableFrom(traceClass)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    @Override
-    public Iterable<Class<? extends ITmfTrace>> getValidTraceTypes() {
-        return Collections.EMPTY_SET;
-    }
-
-    @Override
-    public Iterable<TmfAnalysisRequirement> getAnalysisRequirements() {
-        return Collections.EMPTY_SET;
-    }
-
-    @Override
-    public IAnalysisModule newModule(ITmfTrace trace) throws TmfAnalysisException {
-        String analysisid = getId();
-        IAnalysisModule module = null;
-        switch (fType) {
-        case STATE_SYSTEM:
-            module = new XmlStateSystemModule();
-            XmlStateSystemModule ssModule = (XmlStateSystemModule) module;
-            module.setId(analysisid);
-            ssModule.setXmlFile(new Path(fSourceFile.getAbsolutePath()));
-
-            /*
-             * FIXME: There is no way to know if a module is automatic, so we
-             * default to true
-             */
-            ssModule.setAutomatic(true);
-
-            break;
-        case PATTERN:
-            module = new XmlPatternAnalysis();
-            module.setName(getName());
-            module.setId(analysisid);
-            XmlPatternAnalysis paModule = (XmlPatternAnalysis) module;
-            paModule.setXmlFile(new Path(fSourceFile.getAbsolutePath()));
-
-            /*
-             * FIXME: Maybe the pattern analysis should not be automatic.
-             */
-            paModule.setAutomatic(true);
-
-            break;
-        default:
-            break;
-
-        }
-        if (module != null) {
-            if (module.setTrace(trace)) {
-                TmfAnalysisManager.analysisModuleCreated(module);
-            } else {
-                /* The analysis does not apply to the trace, dispose of the module */
-                module.dispose();
-                module = null;
-            }
-        }
-
-        return module;
-    }
-
-    // ------------------------------------------------------------------------
-    // ITmfPropertiesProvider
-    // ------------------------------------------------------------------------
-
-    @Override
-    public @NonNull Map<@NonNull String, @NonNull String> getProperties() {
-        Map<@NonNull String, @NonNull String> properties = new HashMap<>();
-        properties.put(NonNullUtils.checkNotNull(Messages.XmlModuleHelper_PropertyFile), fSourceFile.getName());
-        properties.put(NonNullUtils.checkNotNull(Messages.XmlModuleHelper_PropertyType), fType.name());
-        return properties;
-    }
-
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/XmlAnalysisModuleSource.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/XmlAnalysisModuleSource.java
deleted file mode 100644 (file)
index e058e1b..0000000
+++ /dev/null
@@ -1,204 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014, 2016 École Polytechnique de Montréal and others
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.module;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.net.URL;
-import java.nio.channels.FileChannel;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.ISafeRunnable;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.SafeRunner;
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.TmfAnalysisModuleHelperXml.XmlAnalysisModuleType;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper;
-import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleSource;
-import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisManager;
-import org.osgi.framework.Bundle;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-/**
- * Analysis module source who creates helpers for the analysis modules described
- * in the imported XML files
- *
- * @author Geneviève Bastien
- * @since 2.0
- */
-public class XmlAnalysisModuleSource implements IAnalysisModuleSource {
-
-    /** Extension point ID */
-    private static final String TMF_XML_BUILTIN_ID = "org.eclipse.linuxtools.tmf.analysis.xml.core.files"; //$NON-NLS-1$
-    private static final String XML_FILE_ELEMENT = "xmlfile"; //$NON-NLS-1$
-
-    private static final String XML_FILE_ATTRIB = "file"; //$NON-NLS-1$
-
-    /*
-     * Legacy (Linux Tools) XML directory.
-     * TODO Remove once we feel the transition phase is over.
-     */
-    private static final IPath XML_DIRECTORY_LEGACY =
-            Activator.getDefault().getStateLocation().removeLastSegments(1)
-            .append("org.eclipse.linuxtools.tmf.analysis.xml.core") //$NON-NLS-1$
-            .append("xml_files"); //$NON-NLS-1$
-
-    private static List<@NonNull IAnalysisModuleHelper> fModules = null;
-
-    /**
-     * Constructor. It adds the new module listener to the analysis manager.
-     */
-    public XmlAnalysisModuleSource() {
-
-    }
-
-    @Override
-    public synchronized Iterable<IAnalysisModuleHelper> getAnalysisModules() {
-        List<@NonNull IAnalysisModuleHelper> modules = fModules;
-        if (modules == null) {
-            modules = new ArrayList<>();
-            fModules = modules;
-            populateBuiltinModules();
-            populateAnalysisModules();
-        }
-        return modules;
-    }
-
-    private static void processFile(File xmlFile) {
-        if (!XmlUtils.xmlValidate(xmlFile).isOK()) {
-            return;
-        }
-
-        try {
-            /* Load the XML File */
-            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
-            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
-            Document doc = dBuilder.parse(xmlFile);
-            doc.getDocumentElement().normalize();
-
-            /* get State Providers modules */
-            NodeList stateproviderNodes = doc.getElementsByTagName(TmfXmlStrings.STATE_PROVIDER);
-            for (int i = 0; i < stateproviderNodes.getLength(); i++) {
-                Element node = (Element) stateproviderNodes.item(i);
-
-                IAnalysisModuleHelper helper = new TmfAnalysisModuleHelperXml(xmlFile, node, XmlAnalysisModuleType.STATE_SYSTEM);
-                fModules.add(helper);
-            }
-
-            /* get pattern modules */
-            NodeList patternNodes = doc.getElementsByTagName(TmfXmlStrings.PATTERN);
-            for (int i = 0; i < patternNodes.getLength(); i++) {
-                Element node = (Element) patternNodes.item(i);
-
-                IAnalysisModuleHelper helper = new TmfAnalysisModuleHelperXml(xmlFile, node, XmlAnalysisModuleType.PATTERN);
-                fModules.add(helper);
-            }
-        } catch (ParserConfigurationException | SAXException | IOException e) {
-            Activator.logError("Error opening XML file", e); //$NON-NLS-1$
-        }
-    }
-
-    private static void populateBuiltinModules() {
-        /* Get the XML files advertised through the extension point */
-        IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(TMF_XML_BUILTIN_ID);
-        for (IConfigurationElement element : elements) {
-            if (element.getName().equals(XML_FILE_ELEMENT)) {
-                final String filename = element.getAttribute(XML_FILE_ATTRIB);
-                final String name = element.getContributor().getName();
-                // Run this in a safe runner in case there is an exception
-                // (IOException, FileNotFoundException, NPE, etc).
-                // This makes sure other extensions are not prevented from
-                // working if one is faulty.
-                SafeRunner.run(new ISafeRunnable() {
-
-                    @Override
-                    public void run() throws IOException {
-                        if (name != null) {
-                            Bundle bundle = Platform.getBundle(name);
-                            if (bundle != null) {
-                                URL xmlUrl = bundle.getResource(filename);
-                                if (xmlUrl == null) {
-                                    throw new FileNotFoundException(filename);
-                                }
-                                URL locatedURL = FileLocator.toFileURL(xmlUrl);
-                                processFile(new File(locatedURL.getFile()));
-                            }
-                        }
-                    }
-
-                    @Override
-                    public void handleException(Throwable exception) {
-                        // Handled sufficiently in SafeRunner
-                    }
-                });
-            }
-        }
-    }
-
-    private static void populateAnalysisModules() {
-        IPath pathToFiles = XmlUtils.getXmlFilesPath();
-        File folder = pathToFiles.toFile();
-        if (!(folder.isDirectory() && folder.exists())) {
-            return;
-        }
-        /*
-         * Transfer files from Linux Tools directory.
-         */
-        File oldFolder = XML_DIRECTORY_LEGACY.toFile();
-        final File[] oldAnalysisFiles = oldFolder.listFiles();
-        if (oldAnalysisFiles != null) {
-            for (File fromFile : oldAnalysisFiles) {
-                File toFile = pathToFiles.append(fromFile.getName()).toFile();
-                if (!toFile.exists() && !fromFile.isDirectory()) {
-                    try (FileInputStream fis = new FileInputStream(fromFile);
-                            FileOutputStream fos = new FileOutputStream(toFile);
-                            FileChannel source = fis.getChannel();
-                            FileChannel destination = fos.getChannel();) {
-                        destination.transferFrom(source, 0, source.size());
-                    } catch (IOException e) {
-                        String error = Messages.XmlUtils_ErrorCopyingFile;
-                        Activator.logError(error, e);
-                    }
-                }
-            }
-        }
-        Map<String, File> files = XmlUtils.listFiles();
-        for (File xmlFile : files.values()) {
-            processFile(xmlFile);
-        }
-    }
-
-    /**
-     * Notifies the main XML analysis module that the executable modules list
-     * may have changed and needs to be refreshed.
-     */
-    public static void notifyModuleChange() {
-        fModules = null;
-        TmfAnalysisManager.refreshModules();
-    }
-
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/XmlUtils.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/XmlUtils.java
deleted file mode 100644 (file)
index fbefde2..0000000
+++ /dev/null
@@ -1,374 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014, 2016 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.module;
-
-import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.net.URL;
-import java.nio.channels.FileChannel;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.XMLConstants;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-import javax.xml.validation.Validator;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-/**
- * Class containing some utilities for the XML plug-in packages: for example, it
- * manages the XML files and validates them
- *
- * @author Geneviève Bastien
- */
-public class XmlUtils {
-
-    /** Sub-directory of the plug-in where XML files are stored */
-    private static final String XML_DIRECTORY = "xml_files"; //$NON-NLS-1$
-
-    /** Name of the XSD schema file */
-    private static final String XSD = "xmlDefinition.xsd"; //$NON-NLS-1$
-
-    /**
-     * Extension for XML files
-     * @since 2.0
-     */
-    public static final String XML_EXTENSION = "xml"; //$NON-NLS-1$
-
-    /** Make this class non-instantiable */
-    private XmlUtils() {
-
-    }
-
-    /**
-     * Get the path where the XML files are stored. Create it if it does not
-     * exist
-     *
-     * @return path to XML files
-     */
-    public static IPath getXmlFilesPath() {
-        IPath path = Activator.getDefault().getStateLocation();
-        path = path.addTrailingSeparator().append(XML_DIRECTORY);
-
-        /* Check if directory exists, otherwise create it */
-        File dir = path.toFile();
-        if (!dir.exists() || !dir.isDirectory()) {
-            dir.mkdirs();
-        }
-
-        return path;
-    }
-
-    /**
-     * Validate the XML file input with the XSD schema
-     *
-     * @param xmlFile
-     *            XML file to validate
-     * @return True if the XML validates
-     */
-    public static IStatus xmlValidate(File xmlFile) {
-        URL url = XmlUtils.class.getResource(XSD);
-        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
-        Source xmlSource = new StreamSource(xmlFile);
-        try {
-            Schema schema = schemaFactory.newSchema(url);
-            Validator validator = schema.newValidator();
-            validator.validate(xmlSource);
-        } catch (SAXParseException e) {
-            String error = NLS.bind(Messages.XmlUtils_XmlParseError, e.getLineNumber(), e.getLocalizedMessage());
-            Activator.logError(error);
-            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, error, e);
-        } catch (SAXException e) {
-            String error = NLS.bind(Messages.XmlUtils_XmlValidationError, e.getLocalizedMessage());
-            Activator.logError(error);
-            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, error, e);
-        } catch (IOException e) {
-            String error = Messages.XmlUtils_XmlValidateError;
-            Activator.logError("IO exception occurred", e); //$NON-NLS-1$
-            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, error, e);
-        }
-        return Status.OK_STATUS;
-    }
-
-    /**
-     * Adds an XML file to the plugin's path. The XML file should have been
-     * validated using the {@link XmlUtils#xmlValidate(File)} method before
-     * calling this method.
-     *
-     * @param fromFile
-     *            The XML file to add
-     * @return Whether the file was successfully added
-     */
-    public static IStatus addXmlFile(File fromFile) {
-
-        /* Copy file to path */
-        File toFile = getXmlFilesPath().addTrailingSeparator().append(fromFile.getName()).toFile();
-
-        return copyXmlFile(fromFile, toFile);
-    }
-
-    /**
-     * List all files under the XML analysis files path. It returns a map where
-     * the key is the file name.
-     *
-     * @return A map with all the XML analysis files
-     * @since 2.0
-     */
-    public static synchronized @NonNull Map<String, File> listFiles() {
-        IPath pathToFiles = XmlUtils.getXmlFilesPath();
-        File folder = pathToFiles.toFile();
-
-        Map<String, File> fileMap = new HashMap<>();
-        if ((folder.isDirectory() && folder.exists())) {
-            File[] listOfFiles = folder.listFiles();
-            if (listOfFiles != null) {
-                for (File file : listOfFiles) {
-                    IPath path = new Path(file.getName());
-                    if (path.getFileExtension().equals(XML_EXTENSION)) {
-                        fileMap.put(file.getName(), file);
-                    }
-                }
-            } else {
-                Activator.logError("I/O error occured while accessing files in folder " + folder.getPath()); //$NON-NLS-1$
-            }
-        }
-        return Collections.unmodifiableMap(fileMap);
-    }
-
-    /**
-     * Delete an XML analysis file
-     *
-     * @param name
-     *            The XML file to delete
-     * @since 2.0
-     */
-    public static void deleteFile(String name) {
-        Map<String, File> files = listFiles();
-        File file = files.get(name);
-        if (file == null) {
-            return;
-        }
-        file.delete();
-    }
-
-    /**
-     * Export an XML analysis file to an external path
-     *
-     * @param from
-     *            The name of the file to export
-     * @param to
-     *            The full path of the file to write to
-     * @return Whether the file was successfully exported
-     * @since 2.0
-     */
-    public static IStatus exportXmlFile(String from, String to) {
-
-        /* Copy file to path */
-        File fromFile = getXmlFilesPath().addTrailingSeparator().append(from).toFile();
-
-        if (!fromFile.exists()) {
-            Activator.logError("Failed to find XML analysis file " + fromFile.getName()); //$NON-NLS-1$
-            return Status.CANCEL_STATUS;
-        }
-
-        File toFile = new File(to);
-
-        return copyXmlFile(fromFile, toFile);
-    }
-
-    private static IStatus copyXmlFile(File fromFile, File toFile) {
-        try {
-            if (!toFile.exists()) {
-                toFile.createNewFile();
-            }
-        } catch (IOException e) {
-            String error = Messages.XmlUtils_ErrorCopyingFile;
-            Activator.logError(error, e);
-            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, error, e);
-        }
-
-        try (FileInputStream fis = new FileInputStream(fromFile);
-                FileOutputStream fos = new FileOutputStream(toFile);
-                FileChannel source = fis.getChannel();
-                FileChannel destination = fos.getChannel();) {
-            destination.transferFrom(source, 0, source.size());
-        } catch (IOException e) {
-            String error = Messages.XmlUtils_ErrorCopyingFile;
-            Activator.logError(error, e);
-            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, error, e);
-        }
-        return Status.OK_STATUS;
-    }
-
-    /**
-     * Get the IDs of all the analysis described in a single file
-     *
-     * @param fileName
-     *            The file name
-     * @return The list of IDs
-     * @since 2.0
-     */
-    public static List<String> getAnalysisIdsFromFile(String fileName) {
-        List<String> ids = new ArrayList<>();
-        File file = getXmlFilesPath().addTrailingSeparator().append(fileName).toFile();
-        if (file.exists()) {
-            try {
-                /* Load the XML File */
-                DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
-                DocumentBuilder dBuilder;
-                dBuilder = dbFactory.newDocumentBuilder();
-                Document doc = dBuilder.parse(file);
-                doc.getDocumentElement().normalize();
-
-                /* get State Providers modules */
-                NodeList stateproviderNodes = doc.getElementsByTagName(TmfXmlStrings.STATE_PROVIDER);
-                for (int i = 0; i < stateproviderNodes.getLength(); i++) {
-                    ids.add(nullToEmptyString(((Element) stateproviderNodes.item(i)).getAttribute(TmfXmlStrings.ID)));
-                }
-
-                /* get patterns modules */
-                NodeList patternNodes = doc.getElementsByTagName(TmfXmlStrings.PATTERN);
-                for (int i = 0; i < patternNodes.getLength(); i++) {
-                    ids.add(nullToEmptyString(((Element) patternNodes.item(i)).getAttribute(TmfXmlStrings.ID)));
-                }
-            } catch (ParserConfigurationException | SAXException | IOException e) {
-                Activator.logError("Failed to get analyses IDs from " + fileName); //$NON-NLS-1$
-            }
-        }
-        return ids;
-    }
-
-    /**
-     * Get only the XML element children of an XML element.
-     *
-     * @param parent
-     *            The parent element to get children from
-     * @return The list of children Element of the parent
-     */
-    public static @NonNull List<@Nullable Element> getChildElements(Element parent) {
-        NodeList childNodes = parent.getChildNodes();
-        List<@Nullable Element> childElements = new ArrayList<>();
-        for (int index = 0; index < childNodes.getLength(); index++) {
-            if (childNodes.item(index).getNodeType() == Node.ELEMENT_NODE) {
-                childElements.add((Element) childNodes.item(index));
-            }
-        }
-        return childElements;
-    }
-
-    /**
-     * Get the XML children element of an XML element, but only those of a
-     * certain type
-     *
-     * @param parent
-     *            The parent element to get the children from
-     * @param elementTag
-     *            The tag of the elements to return
-     * @return The list of children {@link Element} of the parent
-     */
-    public static List<@NonNull Element> getChildElements(Element parent, String elementTag) {
-        /* get the state providers and find the corresponding one */
-        NodeList nodes = parent.getElementsByTagName(elementTag);
-        List<@NonNull Element> childElements = new ArrayList<>();
-
-        for (int i = 0; i < nodes.getLength(); i++) {
-            Element node = (Element) nodes.item(i);
-            if (node.getParentNode().equals(parent)) {
-                childElements.add(node);
-            }
-        }
-        return childElements;
-    }
-
-    /**
-     * Return the node element corresponding to the requested type in the file.
-     *
-     * TODO: Nothing prevents from having duplicate type -> id in a same file.
-     * That should not be allowed. If you want an element with the same ID as
-     * another one, it should be in a different file and we should check it at
-     * validation time.
-     *
-     * @param filePath
-     *            The absolute path to the XML file
-     * @param elementType
-     *            The type of top level element to search for
-     * @param elementId
-     *            The ID of the desired element
-     * @return The XML element or <code>null</code> if not found
-     */
-    public static Element getElementInFile(String filePath, @NonNull String elementType, @NonNull String elementId) {
-
-        if (filePath == null) {
-            return null;
-        }
-
-        IPath path = new Path(filePath);
-        File file = path.toFile();
-        if (file == null || !file.exists() || !file.isFile() || !xmlValidate(file).isOK()) {
-            return null;
-        }
-
-        try {
-            /* Load the XML File */
-            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
-            DocumentBuilder dBuilder;
-
-            dBuilder = dbFactory.newDocumentBuilder();
-            Document doc = dBuilder.parse(file);
-            doc.getDocumentElement().normalize();
-
-            /* get the state providers and find the corresponding one */
-            NodeList nodes = doc.getElementsByTagName(elementType);
-            Element foundNode = null;
-
-            for (int i = 0; i < nodes.getLength(); i++) {
-                Element node = (Element) nodes.item(i);
-                String id = node.getAttribute(TmfXmlStrings.ID);
-                if (id.equals(elementId)) {
-                    foundNode = node;
-                }
-            }
-            return foundNode;
-        } catch (ParserConfigurationException | SAXException | IOException e) {
-            return null;
-        }
-
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/messages.properties b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/messages.properties
deleted file mode 100644 (file)
index 9622a76..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-###############################################################################
-# Copyright (c) 2014 Ericsson
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Eclipse Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/epl-v10.html
-#
-# Contributors:
-#    Ericsson - Initial API and implementation
-###############################################################################
-XmlModuleHelper_PropertyFile=Source XML File
-XmlModuleHelper_PropertyType=Type of analysis
-XmlUtils_ErrorCopyingFile=An error occurred while copying the XML file to the TMF directory. The file was not imported.
-XmlUtils_XmlParseError=XML Parsing error at line {0}: {1}
-XmlUtils_XmlValidateError=An error occurred while validating the XML file.
-XmlUtils_XmlValidationError=Error validating XML file {0}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/xmlCommon.xsd b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/xmlCommon.xsd
deleted file mode 100644 (file)
index 453a219..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!-- ***************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Florian Wininger - Initial API and implementation
- *************************************************************************** -->
-<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
-       attributeFormDefault="unqualified" elementFormDefault="qualified">
-
-       <xs:complexType name="definedValue">
-               <xs:annotation>
-                       <xs:documentation>Maps a string (usually a human-readable value used by the XML elements) to another string (a value in the system, which can be converted to an integer, long by the a stateValue element or used as-is).</xs:documentation></xs:annotation>
-               <xs:attribute name="name" type="xs:string" use="required" >
-                       <xs:annotation>
-                               <xs:documentation>The human-readable string to identify this value. This is what will be manipulated by the XML and shown to the end-user (if applicable).</xs:documentation></xs:annotation></xs:attribute>
-               <xs:attribute name="value" type="xs:string" use="required" >
-                       <xs:annotation>
-                               <xs:documentation>A system value the 'name' maps to. It will usually not be shown to the end user.</xs:documentation></xs:annotation></xs:attribute>
-               <xs:attribute name="color" type="xs:string" use="optional" >
-                       <xs:annotation>
-                               <xs:documentation>Optional color attribute to this mapping. This attribute is used in XML-defined views to represent this mapping.</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="location">
-               <xs:annotation>
-                       <xs:documentation>Define a path in a state system, that can then be used as a shortcut in other XML elements.</xs:documentation></xs:annotation>
-               <xs:sequence>
-                       <xs:element maxOccurs="unbounded" minOccurs="0" name="stateAttribute" type="stateAttribute" >
-                               <xs:annotation>
-                                       <xs:documentation>Define each element of the path represented by this location. For instance, if location "abc" has path "a/b/c", there would be a sequence of 3 stateAttribute elements of type constant.</xs:documentation></xs:annotation></xs:element>
-               </xs:sequence>
-               <xs:attribute name="id" type="xs:string" use="required" >
-                       <xs:annotation>
-                               <xs:documentation>The identifier of this location, used inside the XML element in the scope of which it is defined.</xs:documentation></xs:annotation></xs:attribute>
-               <xs:anyAttribute />
-       </xs:complexType>
-
-</xs:schema>
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/xmlDefinition.xsd b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/xmlDefinition.xsd
deleted file mode 100644 (file)
index 492ddc1..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!-- ***************************************************************************
- * Copyright (c) 2014, 2015 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Florian Wininger - Initial API and implementation
- *************************************************************************** -->
-<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
-       attributeFormDefault="unqualified" elementFormDefault="qualified">
-
-       <xs:include schemaLocation="xmlCommon.xsd" />
-       <xs:include schemaLocation="xmlStateProvider.xsd" />
-       <xs:include schemaLocation="xmlPatternStateProvider.xsd" />
-       <xs:include schemaLocation="xmlView.xsd" />
-       <xs:element name="tmfxml">
-               <xs:complexType>
-                       <xs:choice maxOccurs="unbounded">
-                               <xs:element maxOccurs="unbounded" minOccurs="0" name="timeGraphView" type="timeGraphView" >
-                                       <xs:annotation>
-                                               <xs:documentation>Define a new time graph view.</xs:documentation></xs:annotation></xs:element>
-                               <xs:element maxOccurs="unbounded" minOccurs="0" name="xyView" type="xyView" >
-                                       <xs:annotation>
-                                               <xs:documentation>Define a new XY chart view.</xs:documentation></xs:annotation></xs:element>
-                               <xs:element maxOccurs="unbounded" minOccurs="0" name="stateProvider" type="stateProvider" >
-                                       <xs:annotation>
-                                               <xs:documentation>Define a new state provider</xs:documentation></xs:annotation></xs:element>
-                               <xs:element maxOccurs="unbounded" minOccurs="0" name="pattern" type="pattern" >
-                                       <xs:annotation>
-                                               <xs:documentation>Define a new pattern analysis</xs:documentation></xs:annotation></xs:element>
-                       </xs:choice>
-               </xs:complexType>
-       </xs:element>
-
-</xs:schema>
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/xmlPatternStateProvider.xsd b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/xmlPatternStateProvider.xsd
deleted file mode 100644 (file)
index 042fa19..0000000
+++ /dev/null
@@ -1,460 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!-- ***************************************************************************
- * Copyright (c) 2016 École Polytechnique de Montréal and others
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *************************************************************************** -->
-<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
-       attributeFormDefault="unqualified" elementFormDefault="qualified">
-       <xs:complexType name="pattern">
-               <xs:annotation>
-                       <xs:documentation>Declares a pattern provider which defines one or several sequences of trace data that one would want to locate within the trace. Each pattern provider defined in XML will become an analysis in Trace Compass.</xs:documentation></xs:annotation>
-               <xs:sequence maxOccurs="1" minOccurs="1">
-                       <xs:element maxOccurs="1" minOccurs="0" name="head" type="headPattern" >
-                               <xs:annotation>
-                                       <xs:documentation>Provides meta-information on this pattern provider, like labels and applicable trace types.</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="unbounded" minOccurs="0" name="storedField" type="storedField" >
-                               <xs:annotation>
-                                       <xs:documentation>Defines a data from the trace event that will be stored in the database with the specified name. It is a way to save and update the value of a field of the trace events each time it will be seen. For instance, it can be used to save the value of the field 'fd' each time it will be seen.</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="unbounded" minOccurs="0" name="definedValue" type="definedValue" >
-                               <xs:annotation>
-                                       <xs:documentation>Defines a value that maps a string used in the pattern state provider to a numbered value.</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="unbounded" minOccurs="0" name="location" type="location" >
-                               <xs:annotation>
-                                       <xs:documentation>Declares shortcuts to frequently used attribute/data locations. For instance, if a path to an often-used attribute is CPUs/{event.some_field}/Threads/Status, it may be a good idea to put this path in a location and then use the location name in the event handlers.</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="1" minOccurs="1" name="patternHandler" type="patternHandler" >
-                               <xs:annotation>
-                                       <xs:documentation>Describes the pattern behavior. It defines all the entities; i.e., all the transitions, actions and state machines that describe the pattern.</xs:documentation></xs:annotation></xs:element>
-               </xs:sequence>
-               <xs:attribute name="id" type="xs:string" use="required" >
-                       <xs:annotation>
-                               <xs:documentation>The unique ID of this pattern provider. It will be used to identify the analysis that will be built from this pattern provider.</xs:documentation></xs:annotation></xs:attribute>
-               <xs:attribute name="version" type="xs:integer" use="required" >
-                       <xs:annotation>
-                               <xs:documentation>The version ID of this pattern provider. Whenever the pattern provider changes so that the resulting state system is different from previous versions, this version number should be bumped.</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="headPattern">
-               <xs:annotation>
-                       <xs:documentation>Declares the meta-information that can be defined for an XML pattern provider.</xs:documentation></xs:annotation>
-               <xs:sequence>
-                       <xs:element maxOccurs="unbounded" minOccurs="0" name="traceType">
-                               <xs:annotation>
-                                       <xs:documentation>Indicates that the pattern provider applies to a given trace type.</xs:documentation></xs:annotation>
-                               <xs:complexType>
-                                       <xs:attribute name="id" use="required" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The ID of the trace type, as declared in a org.eclipse.linuxtools.tmf.core.tracetype extension point or a custom trace parser. For example: "org.eclipse.linuxtools.lttng2.kernel.tracetype" or "org.eclipse.linuxtools.lttng2.ust.tracetype" for respectively LTTng Kernel and LTTng UST traces.</xs:documentation></xs:annotation></xs:attribute>
-                               </xs:complexType>
-                       </xs:element>
-                       <xs:element maxOccurs="1" minOccurs="0" name="label">
-                               <xs:annotation>
-                                       <xs:documentation>Adds a label to the pattern provider. If provided, this text will be the name of the analysis that the user will see in Trace Compass.</xs:documentation></xs:annotation>
-                               <xs:complexType>
-                                       <xs:attribute name="value" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The text to name this pattern provider (and the analysis it will generate).</xs:documentation></xs:annotation></xs:attribute>
-                               </xs:complexType>
-                       </xs:element>
-               </xs:sequence>
-       </xs:complexType>
-
-       <xs:complexType name="storedField">
-               <xs:annotation>
-                       <xs:documentation>Declares an event data that will be saved in the database each time it will be seen. It is used to save fields that could appear often in the events stream. The data saved could be added to the pattern segment as fields when they will be generated.</xs:documentation></xs:annotation>
-               <xs:attribute name="id" type="xs:string" use="required">
-                       <xs:annotation>
-                               <xs:documentation>The id of the data in the incoming events.</xs:documentation></xs:annotation></xs:attribute>
-               <xs:attribute name="alias" type="xs:string" use="optional">
-                       <xs:annotation>
-                               <xs:documentation>The alias that the event data will have in the database.</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="patternHandler">
-               <xs:annotation>
-                       <xs:documentation>Declares the entities necessary to describe the pattern behavior.</xs:documentation></xs:annotation>
-               <xs:sequence maxOccurs="unbounded" minOccurs="1">
-                       <xs:choice maxOccurs="unbounded" minOccurs="0">
-                               <xs:element maxOccurs="unbounded" minOccurs="0" name="test" type="test" >
-                                       <xs:annotation>
-                                               <xs:documentation>Defines a condition that could be used in the FSMs as transition to trigger state changes into them.</xs:documentation></xs:annotation></xs:element>
-                               <xs:element maxOccurs="unbounded" minOccurs="0" name="action" type="action">
-                                       <xs:annotation>
-                                               <xs:documentation>Defines an action that could be executed when leaving a state of an FSM.</xs:documentation></xs:annotation></xs:element>
-                       </xs:choice>
-                       <xs:element maxOccurs="unbounded" minOccurs="1" name="fsm" type="state">
-                               <xs:annotation>
-                                       <xs:documentation>Defines a finite state machine that will describe the behavior or a part of the behavior of a pattern. The FSM uses the transitions described to modify its behavior and can execute actions. Each pattern could have one or several FSMs to describe its behavior.</xs:documentation></xs:annotation></xs:element>
-               </xs:sequence>
-               <xs:attribute name="initial" type="xs:string" use="optional">
-                       <xs:annotation>
-                                       <xs:documentation>Lists the state machines (FSMs) that will start directly at the beginning of the analysis. For instance, if the pattern need to start with both FSM A and B, the value of this attribute will be "A:B"</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="test">
-               <xs:annotation>
-                                       <xs:documentation>Defines a test condition that will be validated in a fsm.".</xs:documentation></xs:annotation>
-               <xs:sequence>
-                       <xs:element maxOccurs="1" minOccurs="0" name="if" type="patternSingleCondition">
-                               <xs:annotation>
-                                       <xs:documentation>Defines a condition element, in the form "if (some_path == value)".</xs:documentation></xs:annotation></xs:element>
-               </xs:sequence>
-               <xs:attribute name="id" type="xs:string" use="required">
-                       <xs:annotation>
-                               <xs:documentation>The id of this test. The id will be used as reference to this test.</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="patternSingleCondition">
-               <xs:choice maxOccurs="1" minOccurs="1">
-                       <xs:element name="condition" type="patternCondition">
-                               <xs:annotation>
-                                       <xs:documentation>Defines a condition element to validate.</xs:documentation></xs:annotation></xs:element>
-                       <xs:element name="not" type="patternSingleCondition" >
-                               <xs:annotation>
-                                       <xs:documentation>Negates the result of the following condition, allowing statements of the form "if (!cond)".</xs:documentation></xs:annotation></xs:element>
-                       <xs:element name="and" type="patternMultipleCondition" >
-                               <xs:annotation>
-                                       <xs:documentation>ANDs 2 conditional statements, allowing statements of the form "if (condA AND condB)"</xs:documentation></xs:annotation></xs:element>
-                       <xs:element name="or" type="patternMultipleCondition" >
-                               <xs:annotation>
-                                       <xs:documentation>ORs 2 conditional statements, allowing statements of the form "if (condA OR condB)"</xs:documentation></xs:annotation></xs:element>
-               </xs:choice>
-       </xs:complexType>
-
-       <xs:complexType name="patternMultipleCondition">
-               <xs:annotation>
-                       <xs:documentation>Allows the composition of more than one conditional statements.</xs:documentation></xs:annotation>
-               <xs:sequence maxOccurs="unbounded" minOccurs="1">
-                       <xs:element maxOccurs="1" minOccurs="0" name="condition" type="patternCondition">
-                               <xs:annotation>
-                                       <xs:documentation>Defines a condition element.</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="1" minOccurs="0" name="or" type="patternMultipleCondition" >
-                               <xs:annotation>
-                                       <xs:documentation>ORs 2 conditional statements, allowing statements of the form "if (condA OR condB)"</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="1" minOccurs="0" name="and" type="patternMultipleCondition" >
-                               <xs:annotation>
-                                       <xs:documentation>ANDs 2 conditional statements, allowing statements of the form "if (condA AND condB)"</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="1" minOccurs="0" name="not" type="patternSingleCondition" >
-                               <xs:annotation>
-                                       <xs:documentation>Negates the result of the following condition, allowing statements of the form "if (!cond)".</xs:documentation></xs:annotation></xs:element>
-               </xs:sequence>
-               <xs:anyAttribute />
-       </xs:complexType>
-
-       <xs:complexType name="patternCondition">
-               <xs:choice maxOccurs="1" minOccurs="1">
-                       <xs:sequence maxOccurs="1" minOccurs="1">
-                               <xs:choice maxOccurs="1">
-                                       <xs:sequence>
-                                               <xs:choice maxOccurs="1" minOccurs="1">
-                                                       <xs:element maxOccurs="unbounded" minOccurs="1" name="stateAttribute" type="stateAttribute" >
-                                                               <xs:annotation>
-                                                                       <xs:documentation>Compares the current value of an attribute of the state system.</xs:documentation></xs:annotation></xs:element>
-                                                       <xs:element maxOccurs="1" minOccurs="1" name="field" type="eventField" >
-                                                               <xs:annotation>
-                                                                       <xs:documentation>Compares the value of an event field.</xs:documentation></xs:annotation></xs:element>
-                                               </xs:choice>
-                                               <xs:element maxOccurs="1" minOccurs="1" name="stateValue" type="stateValue" >
-                                                       <xs:annotation>
-                                                               <xs:documentation>Defines the value to compare to.</xs:documentation></xs:annotation></xs:element>
-                                       </xs:sequence>
-                                       <xs:sequence>
-                                               <xs:element maxOccurs="2" minOccurs="2" name="stateValue" type="stateValue"/>
-                                       </xs:sequence>
-                               </xs:choice>
-                       </xs:sequence>
-
-                       <xs:sequence maxOccurs="1" minOccurs="1">
-                               <xs:element maxOccurs="1" minOccurs="1" name="timerange">
-                               <xs:annotation>
-                                       <xs:documentation>Defines a condition element, in a form like "if (x &lt; value &lt; y)".</xs:documentation></xs:annotation>
-                                       <xs:complexType>
-                                               <xs:choice>
-                                                       <xs:element name="in" type="timeRangeSingleCondition">
-                                                               <xs:annotation>
-                                                                       <xs:documentation>Defines a condition element, in the form "if (x &lt; value &lt; y)".</xs:documentation></xs:annotation></xs:element>
-                                                       <xs:element name="out" type="timeRangeSingleCondition">
-                                                               <xs:annotation>
-                                                                       <xs:documentation>Defines a condition element, in the form "if (value &lt; x || value &gt; y)".</xs:documentation></xs:annotation></xs:element>
-                                               </xs:choice>
-                                               <xs:attribute name="unit" default="ns">
-                                                       <xs:annotation>
-                                                               <xs:documentation>The unit of the timing values used for the condition.</xs:documentation></xs:annotation>
-                                                       <xs:simpleType>
-                                                               <xs:restriction base="xs:string">
-                                                                       <xs:enumeration value="ns">
-                                                                               <xs:annotation>
-                                                                                       <xs:documentation>nanosecond</xs:documentation></xs:annotation></xs:enumeration>
-                                                                       <xs:enumeration value="us">
-                                                                               <xs:annotation>
-                                                                                       <xs:documentation>microsecond</xs:documentation></xs:annotation></xs:enumeration>
-                                                                       <xs:enumeration value="ms">
-                                                                               <xs:annotation>
-                                                                                       <xs:documentation>millisecond</xs:documentation></xs:annotation></xs:enumeration>
-                                                                       <xs:enumeration value="s">
-                                                                               <xs:annotation>
-                                                                                       <xs:documentation>second</xs:documentation></xs:annotation></xs:enumeration>
-                                                               </xs:restriction>
-                                                       </xs:simpleType>
-                                               </xs:attribute>
-                                       </xs:complexType>
-                               </xs:element>
-                       </xs:sequence>
-
-                       <xs:sequence maxOccurs="1" minOccurs="1">
-                               <xs:element maxOccurs="1" minOccurs="1" name="elapsedTime">
-                                       <xs:complexType>
-                                               <xs:choice>
-                                                       <xs:element maxOccurs="1" minOccurs="1" name="less" type="elapsedTimeSingleCondition">
-                                                               <xs:annotation>
-                                                                       <xs:documentation>Defines a condition element, in the form "if (value &lt; x)".</xs:documentation></xs:annotation></xs:element>
-                                                       <xs:element maxOccurs="1" minOccurs="1" name="equal" type="elapsedTimeSingleCondition">
-                                                               <xs:annotation>
-                                                                       <xs:documentation>Defines a condition element, in the form "if (value == x)".</xs:documentation></xs:annotation></xs:element>
-                                                       <xs:element maxOccurs="1" minOccurs="1" name="more" type="elapsedTimeSingleCondition">
-                                                               <xs:annotation>
-                                                                       <xs:documentation>Defines a condition element, in the form "if (value &gt; x)".</xs:documentation></xs:annotation></xs:element>
-                                               </xs:choice>
-                                               <xs:attribute name="unit" default="ns">
-                                                       <xs:annotation>
-                                                               <xs:documentation>The unit of the timing values used for the condition.</xs:documentation></xs:annotation>
-                                                       <xs:simpleType>
-                                                               <xs:restriction base="xs:string">
-                                                                       <xs:enumeration value="ns">
-                                                                               <xs:annotation>
-                                                                                       <xs:documentation>nanosecond</xs:documentation></xs:annotation></xs:enumeration>
-                                                                       <xs:enumeration value="us">
-                                                                               <xs:annotation>
-                                                                                       <xs:documentation>microsecond</xs:documentation></xs:annotation></xs:enumeration>
-                                                                       <xs:enumeration value="ms">
-                                                                               <xs:annotation>
-                                                                                       <xs:documentation>millisecond</xs:documentation></xs:annotation></xs:enumeration>
-                                                                       <xs:enumeration value="s">
-                                                                               <xs:annotation>
-                                                                                       <xs:documentation>second</xs:documentation></xs:annotation></xs:enumeration>
-                                                               </xs:restriction>
-                                                       </xs:simpleType>
-                                               </xs:attribute>
-                                       </xs:complexType>
-                               </xs:element>
-                       </xs:sequence>
-
-               </xs:choice>
-       </xs:complexType>
-
-       <xs:complexType name="timeRangeSingleCondition">
-               <xs:annotation>
-                       <xs:documentation>Defines a timerange condition.</xs:documentation></xs:annotation>
-               <xs:attribute name="begin" type="xs:long" use="required">
-                       <xs:annotation>
-                               <xs:documentation>The timestamp of the beginning of the range.</xs:documentation></xs:annotation></xs:attribute>
-               <xs:attribute name="end" type="xs:long" use="required">
-                       <xs:annotation>
-                               <xs:documentation>The timestamp of the end of the range.</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="elapsedTimeSingleCondition">
-               <xs:annotation>
-                       <xs:documentation>Defines an elapsed time condition.</xs:documentation></xs:annotation>
-               <xs:attribute name="since" type="xs:string" use="required">
-                       <xs:annotation>
-                               <xs:documentation>The starting point from where the condition will be evaluated.</xs:documentation></xs:annotation></xs:attribute>
-               <xs:attribute name="value" type="xs:long" use="required">
-                       <xs:annotation>
-                               <xs:documentation>The value used for the comparison.</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="action">
-               <xs:annotation>
-                       <xs:documentation>Define an action that could be executed. Three kind of action are actually supported : state changes, generation of pattern segments and start of a new instance of an FSM.</xs:documentation></xs:annotation>
-               <xs:sequence maxOccurs="unbounded" minOccurs="1">
-                       <xs:choice>
-                               <xs:element maxOccurs="unbounded" minOccurs="0" name="stateChange" type="stateChange">
-                                       <xs:annotation>
-                                               <xs:documentation>Defines how the database is modified by the data provided by the event aspects and the values already stored in the database. A data may cause more than one state change.</xs:documentation></xs:annotation></xs:element>
-                               <xs:element maxOccurs="unbounded" minOccurs="0" name="segment" type="segment">
-                                       <xs:annotation>
-                                               <xs:documentation>Defines a pattern segment that will be generated. The generated segment has content.</xs:documentation></xs:annotation></xs:element>
-                               <xs:element maxOccurs="1" minOccurs="0" name="fsmScheduleAction" type="fsmScheduleAction">
-                                       <xs:annotation>
-                                               <xs:documentation>Declares an FSM that will be scheduled to start.</xs:documentation></xs:annotation></xs:element>
-                               <xs:element maxOccurs="unbounded" minOccurs="0" name="action" type="action">
-                                       <xs:annotation>
-                                               <xs:documentation>Declares an action that will be executed. With this, an action could call another one using its ID.</xs:documentation></xs:annotation></xs:element>
-                       </xs:choice>
-               </xs:sequence>
-               <xs:attribute name="id" type="xs:string" use="required">
-                       <xs:annotation>
-                               <xs:documentation>The ID of the action. This ID is used to reference to this action when needed.</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="fsmScheduleAction">
-               <xs:annotation>
-                       <xs:documentation>Defines an action to start a new instance of an FSM.</xs:documentation></xs:annotation>
-               <xs:attribute name="id" type="xs:string" use="required">
-                       <xs:annotation>
-                               <xs:documentation>The ID of the FSM to start.</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="segment">
-               <xs:annotation>
-                       <xs:documentation>Describes a pattern segment that could be generated by the pattern. A pattern segment is an output of the pattern. It is a segment that would be generated by an FSM in the pattern. Its start will be the start timestamp of the scenario and its end will be the timestamp of the current event. This type of segment has a name and it is possible to add fields.</xs:documentation></xs:annotation>
-               <xs:sequence maxOccurs="1" minOccurs="1">
-                       <xs:element name="segType" >
-                               <xs:annotation>
-                                               <xs:documentation>The XML description of the segment type.</xs:documentation></xs:annotation>
-                               <xs:complexType>
-                                       <xs:sequence maxOccurs="1" minOccurs="0">
-                                               <xs:element maxOccurs="1" name="segName">
-                                                       <xs:annotation>
-                                                               <xs:documentation>Defines the name of the segment. This name could be a value queried from the database or from the event aspects or could be a constant.</xs:documentation></xs:annotation>
-                                                       <xs:complexType>
-                                                               <xs:sequence>
-                                                                       <xs:element maxOccurs="1" minOccurs="1" name="stateValue" type="stateValue">
-                                                                               <xs:annotation>
-                                                                                       <xs:documentation>The value of the segment name.</xs:documentation></xs:annotation></xs:element>
-                                                               </xs:sequence>
-                                                       </xs:complexType>
-                                               </xs:element>
-                                       </xs:sequence>
-                                       <xs:attribute name="segName" type="xs:string" use="optional">
-                                               <xs:annotation>
-                                                       <xs:documentation>The value of the segment name.</xs:documentation></xs:annotation></xs:attribute>
-                               </xs:complexType>
-                       </xs:element>
-                       <xs:element minOccurs="0" name="segContent">
-                               <xs:annotation>
-                                       <xs:documentation>Describes the content of the segment.</xs:documentation></xs:annotation>
-                               <xs:complexType>
-                                       <xs:sequence maxOccurs="1" minOccurs="1">
-                                               <xs:element maxOccurs="unbounded" minOccurs="1" name="segField" type="segField">
-                                                       <xs:annotation>
-                                                               <xs:documentation>Defines a field for the segment.</xs:documentation></xs:annotation></xs:element>
-                                       </xs:sequence>
-                               </xs:complexType>
-                       </xs:element>
-               </xs:sequence>
-       </xs:complexType>
-
-       <xs:complexType name="segField">
-               <xs:annotation>
-                       <xs:documentation>Describes a field for a pattern segment. The value of the field could be a constant or the result of a query to the database or the value of an event aspect.</xs:documentation></xs:annotation>
-               <xs:sequence maxOccurs="1" minOccurs="0">
-                       <xs:annotation>
-                                       <xs:documentation>Defines the value of the field, if it is a data from the ongoing event or if the value is stored in the database.</xs:documentation></xs:annotation>
-                       <xs:element maxOccurs="1" minOccurs="0" name="stateValue" type="stateValue" />
-               </xs:sequence>
-               <xs:attribute name="name" type="xs:string" use="required">
-                       <xs:annotation>
-                               <xs:documentation>Declares the name of the field.</xs:documentation></xs:annotation></xs:attribute>
-               <xs:attribute name="type" use="required">
-                       <xs:annotation>
-                               <xs:documentation>The type of this field value.</xs:documentation></xs:annotation>
-                       <xs:simpleType>
-                               <xs:restriction base="xs:string">
-                                       <xs:enumeration value="null" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The value is a null value.</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="int" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The value is a constant of type integer.</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="long" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The value is a constant of type long.</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="string" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The value is a constant of type string.</xs:documentation></xs:annotation></xs:enumeration>
-                               </xs:restriction>
-                       </xs:simpleType>
-               </xs:attribute>
-               <xs:attribute name="value" type="xs:string" use="optional">
-                       <xs:annotation>
-                               <xs:documentation>Declares the value of the field, if the value is a constant.</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="initialState">
-               <xs:sequence>
-                       <xs:element maxOccurs="unbounded" minOccurs="1" name="transition" type="transition">
-                               <xs:annotation>
-                                       <xs:documentation>Declares a transition for the state.</xs:documentation></xs:annotation></xs:element>
-               </xs:sequence>
-       </xs:complexType>
-
-       <xs:complexType name="finalState">
-               <xs:attribute name="id" type="xs:string" use="required">
-                       <xs:annotation>
-                               <xs:documentation>The id of the state. This name is used to reference to this state when needed.</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="state">
-               <xs:annotation>
-                                       <xs:documentation>Declares a state. Two types of states are actually supported : atomic state and complex state. An atomic state is state without sub-state and complex state is a full state with sub-state. An atomic state is a complex state but with less capacity.</xs:documentation></xs:annotation>
-               <xs:sequence maxOccurs="1">
-                       <xs:element maxOccurs="1" minOccurs="0" name="onentry" type="handlers">
-                               <xs:annotation>
-                                       <xs:documentation>Declares a list of actions to execute when entering the complex state.</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="1" minOccurs="0" name="onexit" type="handlers">
-                               <xs:annotation>
-                                       <xs:documentation>Declares a list of actions to execute when exiting the complex state.</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="unbounded" minOccurs="0" name="precondition" type="transition">
-                               <xs:annotation>
-                                       <xs:documentation>Declares a precondition for this fsm. At least one of the preconditions needs to be validated before being able to activate process the fsm. A precondition is a special transition with no target or action. It should contains only conditions that needs to be validated. Only used for fsm.</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="1" minOccurs="0" name="initial" type="initialState">
-                               <xs:annotation>
-                                       <xs:documentation>Declares the default initial state of this complex state. Must not be specified for an atomic state</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="unbounded" minOccurs="0" name="state" type="state">
-                               <xs:annotation>
-                                       <xs:documentation>Declares an state as children of this declared state state.</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="1" minOccurs="0" name="final" type="finalState">
-                               <xs:annotation>
-                                       <xs:documentation>Declares the default final state of this complex state.</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="unbounded" minOccurs="0" name="transition" type="transition">
-                               <xs:annotation>
-                                       <xs:documentation>Declares a transition for the state.</xs:documentation></xs:annotation></xs:element>
-               </xs:sequence>
-               <xs:attribute name="id" type="xs:string" use="required">
-                       <xs:annotation>
-                               <xs:documentation>The id of the state. This name is used to reference to this state when needed.</xs:documentation></xs:annotation></xs:attribute>
-               <xs:attribute name="initial" type="xs:string" use="optional">
-                       <xs:annotation>
-                               <xs:documentation>The id of the initial state of the complex state. MUST NOT be specified in conjunction with the 'initial' element.</xs:documentation></xs:annotation></xs:attribute>
-               <xs:attribute name="automatic" type="xs:string" use="optional">
-                       <xs:annotation>
-                               <xs:documentation>When reaching this state, this attribute specifies whether or not the state will use the ongoing event or will wait for the next event before starting to analyze its transitions. MUST NOT be specified if the complex state is an fsm.</xs:documentation></xs:annotation></xs:attribute>
-               <xs:attribute name="multiple" type="xs:boolean" use="optional" default="true">
-                       <xs:annotation>
-                               <xs:documentation>ONLY USE for fsm. Specifies if this FSM allows multiple instance or only one instance. If not specified, this attribute will be set to 'true' by default.</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="transition">
-               <xs:annotation>
-                       <xs:documentation>Describes a transition of this state. The transition describes how the event data can change the state of the FSM and trigger an action.</xs:documentation></xs:annotation>
-               <xs:attribute name="event" type="xs:string" use="optional">
-                       <xs:annotation>
-                               <xs:documentation>The event name to be validated.</xs:documentation></xs:annotation></xs:attribute>
-               <xs:attribute name="cond" type="xs:string" use="optional">
-                       <xs:annotation>
-                               <xs:documentation>The ID of the test to be validated.</xs:documentation></xs:annotation></xs:attribute>
-               <xs:attribute name="target" type="xs:string" use="optional">
-                       <xs:annotation>
-                               <xs:documentation>The name of the state that the FSM will reach if the 'cond' condition is validated.</xs:documentation></xs:annotation></xs:attribute>
-               <xs:attribute name="action" type="xs:string" use="optional">
-                       <xs:annotation>
-                               <xs:documentation>The list of IDs of the actions that would be executed if the conditions are validated. If action A and B need to be executed, the value will be 'A:B'.</xs:documentation></xs:annotation></xs:attribute>
-               <xs:attribute name="saveStoredFields" type="xs:string" use="optional">
-                       <xs:annotation>
-                               <xs:documentation>The action that specifies that the defined fields need to be checked and saved into the database if they are found in the event data. If not specify, the value will be false by default. This action let the user decide when he wants to save the special fields.</xs:documentation></xs:annotation></xs:attribute>
-               <xs:attribute name="clearStoredFields" type="xs:string" use="optional">
-                       <xs:annotation>
-                               <xs:documentation>The action that specifies that the defined fields need to be all cleared from the database. If not specify, the value will be false by default. This action let the user decide when he wants to clear the special fields.</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="handlers">
-               <xs:attribute name="action" type="xs:string" use="required">
-                       <xs:annotation>
-                               <xs:documentation>The list of IDs of the actions that would be executed. If action A and B need to be executed, the value should be 'A:B'.</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-</xs:schema>
\ No newline at end of file
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/xmlStateProvider.xsd b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/xmlStateProvider.xsd
deleted file mode 100644 (file)
index 8703857..0000000
+++ /dev/null
@@ -1,337 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!-- ***************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal and others
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Florian Wininger - Initial API and implementation
- *************************************************************************** -->
-<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
-       attributeFormDefault="unqualified" elementFormDefault="qualified">
-
-       <xs:complexType name="stateProvider">
-               <xs:annotation>
-                       <xs:documentation>Declares a data-driven state provider which defines how events change the state of attributes of the system. Each state provider defined in XML will become an analysis in TMF.</xs:documentation></xs:annotation>
-               <xs:sequence maxOccurs="1" minOccurs="1">
-                       <xs:element maxOccurs="1" minOccurs="0" name="head" type="headProvider" >
-                               <xs:annotation>
-                                       <xs:documentation>Provide meta-information on this state provider, like labels and applicable trace types.</xs:documentation></xs:annotation></xs:element>
-                       <xs:sequence maxOccurs="unbounded" minOccurs="1">
-                               <xs:choice maxOccurs="unbounded" minOccurs="0">
-                                       <xs:element maxOccurs="unbounded" minOccurs="0" name="definedValue" type="definedValue" >
-                                               <xs:annotation>
-                                                       <xs:documentation>Define a value that maps a string used in the state provider to a numbered value.</xs:documentation></xs:annotation></xs:element>
-                                       <xs:element maxOccurs="unbounded" minOccurs="0" name="location" type="location" >
-                                               <xs:annotation>
-                                                       <xs:documentation>Declare shortcuts to frequently used attribute/data locations. For instance, if a path to an often-used attribute is CPUs/{event.some_field}/Threads/Status, it may be a good idea to put this path in a location and then use the location name in the event handlers.</xs:documentation></xs:annotation></xs:element>
-                               </xs:choice>
-                               <xs:element maxOccurs="unbounded" minOccurs="1" name="eventHandler" type="eventHandler" >
-                                       <xs:annotation>
-                                               <xs:documentation>Define how a given event will modify the state system being built. For each event in the trace that causes a state change, a event handler should be defined.</xs:documentation></xs:annotation></xs:element>
-                       </xs:sequence>
-               </xs:sequence>
-               <xs:attribute name="id" type="xs:string" use="required" >
-                       <xs:annotation>
-                               <xs:documentation>The unique ID of this state provider. It will be used to identify the analysis that will be built from this state provider.</xs:documentation></xs:annotation></xs:attribute>
-               <xs:attribute name="version" type="xs:integer" use="required" >
-                       <xs:annotation>
-                               <xs:documentation>The version ID of this state provider. Whenever the state provider changes so that the resulting state system is different from previous versions, this version number should be bumped.</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="headProvider">
-               <xs:annotation>
-                       <xs:documentation>Declares the meta-information that can be defined for an XML state provider.</xs:documentation></xs:annotation>
-               <xs:sequence>
-                       <xs:element maxOccurs="unbounded" minOccurs="0" name="traceType">
-                               <xs:annotation>
-                                       <xs:documentation>Indicate that the state provider applies to a given trace type.</xs:documentation></xs:annotation>
-                               <xs:complexType>
-                                       <xs:attribute name="id" use="required" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The ID of the trace type, as declared in a org.eclipse.linuxtools.tmf.core.tracetype extension point or a custom trace parser. For example: "org.eclipse.linuxtools.lttng2.kernel.tracetype" or "org.eclipse.linuxtools.lttng2.ust.tracetype" for respectively LTTng Kernel and LTTng UST traces.</xs:documentation></xs:annotation></xs:attribute>
-                               </xs:complexType>
-                       </xs:element>
-                       <xs:element maxOccurs="1" minOccurs="0" name="label">
-                               <xs:annotation>
-                                       <xs:documentation>Add a label to the state provider. If provided, this text will be the name of the analysis that the user will see in TMF.</xs:documentation></xs:annotation>
-                               <xs:complexType>
-                                       <xs:attribute name="value" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The text to name this state provider (and the analysis it will generate).</xs:documentation></xs:annotation></xs:attribute>
-                               </xs:complexType>
-                       </xs:element>
-               </xs:sequence>
-       </xs:complexType>
-
-       <xs:complexType name="eventHandler">
-               <xs:annotation>
-                       <xs:documentation>Define how an event modifies the state of the system. There should be one event handler for each event causing a state change.</xs:documentation></xs:annotation>
-               <xs:sequence>
-                       <xs:element maxOccurs="unbounded" minOccurs="1" name="stateChange" type="stateChange" >
-                               <xs:annotation>
-                                       <xs:documentation>Define how the state system is modified by the event. An event may cause more than one state change.</xs:documentation></xs:annotation></xs:element>
-               </xs:sequence>
-               <xs:attribute name="eventName" type="xs:string" use="required" >
-                       <xs:annotation>
-                               <xs:documentation>Name of the event that causes a state change.</xs:documentation></xs:annotation></xs:attribute>
-               <xs:anyAttribute />
-       </xs:complexType>
-
-       <xs:complexType name="stateChange">
-               <xs:annotation>
-                       <xs:documentation>Define a change of state in the state system being built.</xs:documentation></xs:annotation>
-               <xs:choice maxOccurs="1" minOccurs="1">
-                       <xs:sequence maxOccurs="1" minOccurs="1">
-                               <xs:annotation>
-                                       <xs:documentation>Describe a single attribute assignation. Simply put: a state change where path/to/attribute=value.</xs:documentation></xs:annotation>
-                               <xs:element maxOccurs="unbounded" minOccurs="1" name="stateAttribute" type="stateAttribute" >
-                                       <xs:annotation>
-                                               <xs:documentation>Explain how to reach an attribute in the state system. It describes the path/to/attribute.</xs:documentation></xs:annotation></xs:element>
-                               <xs:element maxOccurs="1" minOccurs="1" name="stateValue" type="stateValue" >
-                                       <xs:annotation>
-                                               <xs:documentation>Explain how to obtain the value of the state attribute to modify.</xs:documentation></xs:annotation></xs:element>
-                       </xs:sequence>
-                       <xs:sequence maxOccurs="1" minOccurs="1">
-                               <xs:annotation>
-                                       <xs:documentation>Describe a conditional state change, where different path conditions may lead to different state changes.</xs:documentation></xs:annotation>
-                               <xs:element maxOccurs="1" minOccurs="1" name="if" type="conditionSingle" >
-                                       <xs:annotation>
-                                               <xs:documentation>Define the condition to verify.</xs:documentation></xs:annotation></xs:element>
-                               <xs:element maxOccurs="1" minOccurs="1" name="then" type="stateChange" >
-                                       <xs:annotation>
-                                               <xs:documentation>Define the state change to use if the previous condition is true.</xs:documentation></xs:annotation></xs:element>
-                               <xs:element maxOccurs="1" minOccurs="0" name="else" type="stateChange" >
-                                       <xs:annotation>
-                                               <xs:documentation>Optionally define the state change to use if the condition is false.</xs:documentation></xs:annotation></xs:element>
-                       </xs:sequence>
-               </xs:choice>
-       </xs:complexType>
-
-       <xs:complexType name="condition">
-               <xs:annotation>
-                       <xs:documentation>Define a conditional statement. Conditions may use values of the state system or from the event being handled. This element defines a statement in the form of "if (some_path == value)".</xs:documentation></xs:annotation>
-               <xs:choice>
-                       <xs:sequence>
-                               <xs:choice maxOccurs="1" minOccurs="1">
-                                       <xs:element maxOccurs="unbounded" minOccurs="1" name="stateAttribute" type="stateAttribute" >
-                                               <xs:annotation>
-                                                       <xs:documentation>Compare the current value of an attribute of the state system.</xs:documentation></xs:annotation></xs:element>
-                                       <xs:element maxOccurs="1" minOccurs="1" name="field" type="eventField" >
-                                               <xs:annotation>
-                                                       <xs:documentation>Compare the value of an event field.</xs:documentation></xs:annotation></xs:element>
-                               </xs:choice>
-                               <xs:element maxOccurs="1" minOccurs="1" name="stateValue" type="stateValue" >
-                                       <xs:annotation>
-                                               <xs:documentation>Define the value to compare to.</xs:documentation></xs:annotation></xs:element>
-                       </xs:sequence>
-                       <xs:sequence>
-                               <xs:element maxOccurs="2" minOccurs="2" name="stateValue" type="stateValue"/>
-                       </xs:sequence>
-               </xs:choice>
-
-               <xs:attribute name="operator" default="eq">
-                       <xs:annotation>
-                               <xs:documentation>Indicate that a comparison operation will be performed with the value</xs:documentation></xs:annotation>
-                       <xs:simpleType>
-                               <xs:restriction base="xs:string">
-                                       <xs:enumeration value="eq">
-                                               <xs:annotation>
-                                                       <xs:documentation>The operation type is to check if two values are equal</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="ne">
-                                               <xs:annotation>
-                                                       <xs:documentation>The operation type is to check if two values are not equal</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="ge">
-                                               <xs:annotation>
-                                                       <xs:documentation>The operation type is to check if the first value is greater than or equal the second one</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="gt">
-                                               <xs:annotation>
-                                                       <xs:documentation>The operation type is to check if the first value is greater than the second one</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="le">
-                                               <xs:annotation>
-                                                       <xs:documentation>The operation type is to check if the first value is smaller than or equal the second one</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="lt">
-                                               <xs:annotation>
-                                                       <xs:documentation>The operation type is to check if the first value is smaller than the second one</xs:documentation></xs:annotation></xs:enumeration>
-                               </xs:restriction>
-                       </xs:simpleType>
-               </xs:attribute>
-
-       </xs:complexType>
-
-       <xs:complexType name="conditionSingle">
-               <xs:annotation>
-                       <xs:documentation>Define a conditional statement with only one child. From this element, a condition may be composed of other conditional elements to create more complex conditional statements.</xs:documentation></xs:annotation>
-               <xs:choice maxOccurs="1" minOccurs="1">
-                       <xs:element name="condition" type="condition" >
-                               <xs:annotation>
-                                       <xs:documentation>Define a condition element, in the form "if (some_path == value)".</xs:documentation></xs:annotation></xs:element>
-                       <xs:element name="not" type="conditionSingle" >
-                               <xs:annotation>
-                                       <xs:documentation>Negate the result of the following condition, allowing statements of the form "if (!cond)".</xs:documentation></xs:annotation></xs:element>
-                       <xs:element name="and" type="conditionMultiple" >
-                               <xs:annotation>
-                                       <xs:documentation>ANDs 2 conditional statements, allowing statements of the form "if (condA AND condB)"</xs:documentation></xs:annotation></xs:element>
-                       <xs:element name="or" type="conditionMultiple" >
-                               <xs:annotation>
-                                       <xs:documentation>ORs 2 conditional statements, allowing statements of the form "if (condA OR condB)"</xs:documentation></xs:annotation></xs:element>
-               </xs:choice>
-               <xs:anyAttribute />
-       </xs:complexType>
-
-       <xs:complexType name="conditionMultiple">
-               <xs:annotation>
-                       <xs:documentation>Allows the composition of more than one conditional statements.</xs:documentation></xs:annotation>
-               <xs:sequence maxOccurs="unbounded" minOccurs="1">
-                       <xs:element maxOccurs="1" minOccurs="0" name="condition" type="condition" >
-                               <xs:annotation>
-                                       <xs:documentation>Define a condition element, in the form "if (some_path == value)".</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="1" minOccurs="0" name="or" type="conditionMultiple" >
-                               <xs:annotation>
-                                       <xs:documentation>ORs 2 conditional statements, allowing statements of the form "if (condA OR condB)"</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="1" minOccurs="0" name="and" type="conditionMultiple" >
-                               <xs:annotation>
-                                       <xs:documentation>ANDs 2 conditional statements, allowing statements of the form "if (condA AND condB)"</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="1" minOccurs="0" name="not" type="conditionSingle" >
-                               <xs:annotation>
-                                       <xs:documentation>Negate the result of the following condition, allowing statements of the form "if (!cond)".</xs:documentation></xs:annotation></xs:element>
-               </xs:sequence>
-               <xs:anyAttribute />
-       </xs:complexType>
-
-       <xs:complexType name="stateAttribute">
-               <xs:annotation>
-                       <xs:documentation>Define a path to an attribute of the state system.</xs:documentation></xs:annotation>
-               <xs:sequence>
-                       <xs:element maxOccurs="unbounded" minOccurs="0" name="stateAttribute" type="stateAttribute" >
-                               <xs:annotation>
-                                       <xs:documentation>If the type is a "query", those stateAttribute elements describe the elements of the query.</xs:documentation></xs:annotation></xs:element>
-               </xs:sequence>
-               <xs:attribute name="type" use="required">
-                       <xs:annotation>
-                               <xs:documentation>The type of path to this attribute. The meaning of those paths type will depend on the context where the stateAttribute is being used. Not all types will make sense everywhere.</xs:documentation></xs:annotation>
-                       <xs:simpleType>
-                               <xs:restriction base="xs:string">
-                                       <xs:enumeration value="null" >
-                                               <xs:annotation>
-                                                       <xs:documentation>This type does not change the current attribute. Whatever attribute was the reference attribute at a given time, it will be returned as is.</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="constant" >
-                                               <xs:annotation>
-                                                       <xs:documentation>This type identifies the state system attribute by a constant string. For instance, if the first level attribute of the state system is "Threads", then a constant type with "Threads" value should be used.</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="eventField" >
-                                               <xs:annotation>
-                                                       <xs:documentation>This type identifies the attribute by the value of an event field. Note that the event field corresponds to the attribute name, not its value. For example, if the event has a field called "current_cpu" with a value of "2", "2" would be the attribute name we want.</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="eventName" >
-                                               <xs:annotation>
-                                                       <xs:documentation>This type identifies the attribute as the name of an event.</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="location" >
-                                               <xs:annotation>
-                                                       <xs:documentation>This type indicates that the path to the attribute is at the specified location. Location simply avoids having to write full path to an attribute each time it is being used, but the location itself is a sequence of stateAttribute elements. For example, if we previously defined a location named "CurrentThead" for path "CPUs/{current_cpu}/CurrentThread", we can use a stateAttribute of type location with "CurrentThread" value.</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="query" >
-                                               <xs:annotation>
-                                                       <xs:documentation>This type indicates that the path to the attribute is the result of a query. If this type is selected, a sequence of stateAttribute elements needs to be specified for this state attribute. The result of the query is the attribute name of the current element. For example, if the attribute we want is the PID of the current process on CPU 0, that PID can be found through the query "CPUs/0/CurrentThread". The value of this attribute would be, for example, 1234, the attribute we are looking for.</xs:documentation></xs:annotation></xs:enumeration>
-                               </xs:restriction>
-                       </xs:simpleType>
-               </xs:attribute>
-               <xs:attribute name="value" type="xs:string" >
-                       <xs:annotation>
-                               <xs:documentation>The value of this state attribute. A value should be specified only if the type is "constant", "eventField" or "location".</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="stateValue">
-               <xs:annotation>
-                       <xs:documentation>Define a value, that can be assigned to an attribute of the state system.</xs:documentation></xs:annotation>
-               <xs:sequence>
-                       <xs:annotation>
-                               <xs:documentation>For a "query" value type, a sequence of stateAttributes will define the query whose result is the value.</xs:documentation></xs:annotation>
-                       <xs:element maxOccurs="unbounded" minOccurs="0" name="stateAttribute" type="stateAttribute" ></xs:element>
-               </xs:sequence>
-               <xs:attribute name="type" use="required">
-                       <xs:annotation>
-                               <xs:documentation>The type of this state value. It will describe how to obtain to value and/or what to do with it.</xs:documentation></xs:annotation>
-                       <xs:simpleType>
-                               <xs:restriction base="xs:string">
-                                       <xs:enumeration value="null" >
-                                               <xs:annotation>
-                                                       <xs:documentation>Indicate that the value is a null value.</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="int" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The value is a constant of type integer.</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="long" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The value is a constant of type long</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="string" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The value is a constant of type string</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="eventField" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The value is the content of an event field. The "value" attribute is the field name. To convert this field to a certain type, attribute "forcedType" may be used.</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="eventName" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The value is the name of the event.</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="delete" >
-                                               <xs:annotation>
-                                                       <xs:documentation>Indicate that the attribute the value is to be applied to should be deleted.</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="query" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The value is the result of a query to the state system. If this type is selected, a sequence of stateAttributes must be defined in this stateValue element.</xs:documentation></xs:annotation></xs:enumeration>
-                               </xs:restriction>
-                       </xs:simpleType>
-               </xs:attribute>
-               <xs:attribute name="increment" type="xs:boolean" >
-                       <xs:annotation>
-                               <xs:documentation>Indicate that the current value will be added to any previously available value.</xs:documentation></xs:annotation></xs:attribute>
-               <xs:attribute name="stack">
-                       <xs:annotation>
-                               <xs:documentation>Indicate that a stack operation will be performed with the value</xs:documentation></xs:annotation>
-                       <xs:simpleType>
-                               <xs:restriction base="xs:string">
-                                       <xs:enumeration value="pop">
-                                               <xs:annotation>
-                                                       <xs:documentation>The value will be popped from the stack</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="push">
-                                               <xs:annotation>
-                                                       <xs:documentation>The value will be pushed on a stack</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="peek">
-                                               <xs:annotation>
-                                                       <xs:documentation>The value will be peeked from the top of the stack, but it will stay there</xs:documentation></xs:annotation></xs:enumeration>
-                               </xs:restriction>
-                       </xs:simpleType>
-               </xs:attribute>
-               <xs:attribute name="forcedType">
-                       <xs:annotation>
-                               <xs:documentation>Indicate the desired type for the state value. If the value is not already of this type, a conversion will be attempted. The forcedType is used to convert values of event fields.</xs:documentation></xs:annotation>
-                       <xs:simpleType>
-                               <xs:restriction base="xs:string">
-                                       <xs:enumeration value="int" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The value should be an integer</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="long" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The value should be a long</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="string" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The value should be a string</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="double" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The value should be a double</xs:documentation></xs:annotation></xs:enumeration>
-                               </xs:restriction>
-                       </xs:simpleType>
-               </xs:attribute>
-               <xs:attribute name="value" type="xs:string" >
-                       <xs:annotation>
-                               <xs:documentation>Indicate what the value is. A value should be specified only if the type is int, long, string or event_field. See the documentation on types for information on what to put for value.</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="eventField">
-               <xs:annotation>
-                       <xs:documentation>This element is used in conditions where the value of an event field is compared to something else. It is not the same as the stateAttribute's type eventField, where the eventField is used as the name for an attribute to the state system.</xs:documentation></xs:annotation>
-               <xs:attribute name="name" type="xs:string" use="required" >
-                       <xs:annotation>
-                               <xs:documentation>Indicate which field to use.</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-</xs:schema>
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/xmlView.xsd b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/xmlView.xsd
deleted file mode 100644 (file)
index 1931843..0000000
+++ /dev/null
@@ -1,178 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!-- ***************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Florian Wininger - Initial API and implementation
- *************************************************************************** -->
-<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
-       attributeFormDefault="unqualified" elementFormDefault="qualified">
-
-       <xs:complexType name="timeGraphView">
-               <xs:annotation>
-                       <xs:documentation>Declares a data-driven time graph view, which defines how the view will display the results of an analysis. For now, only state system analysis are supported by this view.</xs:documentation></xs:annotation>
-               <xs:sequence>
-                       <xs:element maxOccurs="1" minOccurs="0" name="head" type="headOutput" >
-                               <xs:annotation>
-                                       <xs:documentation>Provider meta-information on this view, like labels and analysis it applies to.</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="unbounded" minOccurs="0" name="definedValue" type="definedValue" >
-                               <xs:annotation>
-                                       <xs:documentation>Define a mapping between a human-readable text and the value used in the analysis. The "definedValue"'s optional "color" attribute is the color with which this value will be displayed.</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="unbounded" minOccurs="0" name="entry" type="viewEntry" >
-                               <xs:annotation>
-                                       <xs:documentation>Define how to determine the entries (lines) to show on the time graph view. An entry may have children entry elements defined as children, where children are sub-elements of this one (for example, child attributes in the state system). A parent/child relationship may be defined for entries of the same level. See the viewEntry element documentation for more details.</xs:documentation></xs:annotation></xs:element>
-               </xs:sequence>
-               <xs:attribute name="id" type="xs:string" use="required" >
-                       <xs:annotation>
-                               <xs:documentation>The unique identifier of this view element. It will be used by the framework to identify this view.</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="xyView">
-               <xs:annotation>
-                       <xs:documentation>Declares a data-driven XY chart view, which defines how the view will display the results of an analysis. For now, only state system analyses are supported by this view.</xs:documentation></xs:annotation>
-               <xs:sequence>
-                       <xs:element maxOccurs="1" minOccurs="0" name="head" type="headOutput" >
-                               <xs:annotation>
-                                       <xs:documentation>Provider meta-information on this view, like labels and analyses it applies to.</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="1" minOccurs="1" name="entry" type="xyViewEntry" >
-                               <xs:annotation>
-                                       <xs:documentation>Define how to determine the entries (series) to show on the XY view. See the xyViewEntry element documentation for more details.</xs:documentation></xs:annotation></xs:element>
-               </xs:sequence>
-               <xs:attribute name="id" type="xs:string" use="required" >
-                       <xs:annotation>
-                               <xs:documentation>The unique identifier of this view element. It will be used by the framework to identify this view.</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="headOutput">
-               <xs:annotation>
-                       <xs:documentation>Declares the meta-information that can be defined for an XML time graph view.</xs:documentation></xs:annotation>
-               <xs:sequence>
-                       <xs:element maxOccurs="unbounded" minOccurs="0" name="analysis">
-                               <xs:annotation>
-                                       <xs:documentation>Indicate that the view applies to the analysis identified with the given ID. To have a view apply to an XML-defined state system analysis, you'd use the state provider ID in the "stateProvider" element.</xs:documentation></xs:annotation>
-                               <xs:complexType>
-                                       <xs:attribute name="id" type="xs:string" use="required" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The ID of the analysis this view applies to.</xs:documentation></xs:annotation></xs:attribute>
-                                       <xs:attribute name="ssid" type="xs:string" use="optional" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The ID of the state system this view applies to. The attribute is used only if the analysis contains more than one state system.</xs:documentation></xs:annotation></xs:attribute>
-                               </xs:complexType>
-                       </xs:element>
-                       <xs:element maxOccurs="1" minOccurs="0" name="label">
-                               <xs:annotation>
-                                       <xs:documentation>Add a label to the time graph view. If provided, this text will be displayed to the user to identify this view, otherwise, the view's ID will be used.</xs:documentation></xs:annotation>
-                               <xs:complexType>
-                                       <xs:attribute name="value" use="required" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The text used as a name for this time graph view.</xs:documentation></xs:annotation></xs:attribute>
-                               </xs:complexType>
-                       </xs:element>
-               </xs:sequence>
-       </xs:complexType>
-
-       <xs:complexType name="viewEntry">
-               <xs:annotation>
-                       <xs:documentation>Define a path to entries in the view. If this element is at the top level, the base path to reach the entry is the root of the state system. Otherwise, it will use the parent element's corresponding attribute as the base. Each view entry element corresponds to a time graph view entry that will actually be displayed.</xs:documentation></xs:annotation>
-               <xs:sequence>
-                       <xs:element maxOccurs="1" minOccurs="0" name="display" type="viewStateAttribute" >
-                               <xs:annotation>
-                                       <xs:documentation>Indicate the attribute whose value will be displayed in the time graph (the value that changes over time). If this element is not specified, no entry will be created for this element, and all other elements will be ignored.</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="1" minOccurs="0" name="id" type="viewStateAttribute" >
-                               <xs:annotation>
-                                       <xs:documentation>Specify which attribute to use as ID for this entry. This ID will be used in the ID column in the view, and will also be used to build the tree if a parent element is specified. If this element is not present, the display attribute's name will be used as ID.</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="1" minOccurs="0" name="parent" type="viewStateAttribute" >
-                               <xs:annotation>
-                                       <xs:documentation>Specify how to find the parent's ID of this entry. By default, the parent/child hierarchy is the same as defined in the timeGraphView element of the XML file. This element will add to this default parent/child relationship so that elements at the same XML-defined level can still have a relationship.</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="1" minOccurs="0" name="name" type="viewStateAttribute" >
-                               <xs:annotation>
-                                       <xs:documentation>Specify how to find the name of this entry. Typically, the name will be human-readable. If not specified, the display attribute's name will be used as the name.</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="unbounded" minOccurs="0" name="entry" type="viewEntry" >
-                               <xs:annotation>
-                                       <xs:documentation>Define child entries for this entry. Child entries will be shown as children of this entry (with or without additional parent/child relationship defined through the viewEntry element's "parent" element).</xs:documentation></xs:annotation></xs:element>
-               </xs:sequence>
-               <xs:attribute name="path" type="xs:string" use="required" >
-                       <xs:annotation>
-                               <xs:documentation>The path of the entry in the state system. Wildcards '*' may be used. For example, to display entries from all CPUs, the path could be "CPUs/*" and one entry will be created for each sub-attribute of the "CPUs" attribute. Each entry will be used as the base for all child elements, unless specified otherwise.</xs:documentation></xs:annotation></xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="xyViewEntry">
-               <xs:annotation>
-                       <xs:documentation>Define a path to entries in the view. If this element is at the top level, the base path to reach the entry is the root of the state system. Otherwise, it will use the parent element's corresponding attribute as the base. Each XY view entry element corresponds to a series in the resulting view.</xs:documentation></xs:annotation>
-               <xs:sequence>
-                       <xs:element maxOccurs="1" minOccurs="0" name="display" type="viewStateAttribute" >
-                               <xs:annotation>
-                                       <xs:documentation>Indicate the attribute whose value will be displayed in the time graph (the value that changes over time). If this element is not specified, no entry will be created for this element, and all other elements will be ignored.</xs:documentation></xs:annotation></xs:element>
-                       <xs:element maxOccurs="1" minOccurs="0" name="name" type="viewStateAttribute" >
-                               <xs:annotation>
-                                       <xs:documentation>Specify how to find the name of this entry. Typically, the name will be human-readable. If not specified, the display attribute's name will be used as the name.</xs:documentation></xs:annotation></xs:element>
-               </xs:sequence>
-               <xs:attribute name="path" type="xs:string" use="required" >
-                       <xs:annotation>
-                               <xs:documentation>The path of the entry in the state system. Wildcards '*' may be used. For example, to display entries from all CPUs, the path could be "CPUs/*" and one series will be created for each sub-attribute of the "CPUs" attribute. Each entry will be used as the base for all child elements, unless specified otherwise.</xs:documentation></xs:annotation></xs:attribute>
-               <xs:attribute name="displayType" use="optional" default="absolute" >
-                       <xs:annotation>
-                               <xs:documentation>Indicate how to display the value, compared with preceding values.</xs:documentation></xs:annotation>
-                       <xs:simpleType>
-                               <xs:restriction base="xs:string">
-                                       <xs:enumeration value="absolute" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The value is shown as is.</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="delta" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The value is the difference between the value at current timestamp and the value at the preceding timestamp.</xs:documentation></xs:annotation></xs:enumeration>
-                               </xs:restriction>
-                       </xs:simpleType>
-               </xs:attribute>
-       </xs:complexType>
-
-       <xs:complexType name="viewStateAttribute">
-               <xs:sequence>
-                       <xs:element maxOccurs="unbounded" minOccurs="0" name="stateAttribute" type="viewStateAttribute" >
-                               <xs:annotation>
-                                       <xs:documentation>If the type is a "query", those stateAttribute elements describe the  elements of the query.</xs:documentation></xs:annotation></xs:element>
-               </xs:sequence>
-               <xs:attribute name="type" use="required">
-                       <xs:annotation>
-                               <xs:documentation>The type of path to this attribute. The value of the other attributes will depend on the selected type.</xs:documentation></xs:annotation>
-                       <xs:simpleType>
-                               <xs:restriction base="xs:string">
-                                       <xs:enumeration value="constant" >
-                                               <xs:annotation>
-                                                       <xs:documentation>This type identifies the state system attribute by a constant string. For instance, if the state system attribute to display is "Status", it would be a constant type with value "Status".</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="location" >
-                                               <xs:annotation>
-                                                       <xs:documentation>This type indicates that the path to the attribute is at the specified location. A location avoids having to write the full path to an attribute every time it is being used. The location itself is a sequence of stateAttribute elements. For example, if we previously defined a location named "Procname" for path "Threads/tid/Procname", we can use a stateAttribute of type location with "Procname" value.</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="query" >
-                                               <xs:annotation>
-                                                       <xs:documentation>This type indicates that the path to the attribute is the result of a query. If this type is selected, a sequence of stateAttribute elements needs to be specified for this viewStateAttribute. The result of the query is the attribute name of the current element. For example, if the attribute we want is the PID of the current process on CPU 0, that PID can be found through the query "CPUs/0/CurrentThread". The value of this attribute would be for example 1234, which is the attribute we are looking for.</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="self" >
-                                               <xs:annotation>
-                                                       <xs:documentation>This type indicates that the requested attribute is the attribute itself. For this attribute, the reference is always relative (setting it to absolute will be ignored).</xs:documentation></xs:annotation></xs:enumeration>
-                               </xs:restriction>
-                       </xs:simpleType>
-               </xs:attribute>
-               <xs:attribute name="value" type="xs:string" >
-                       <xs:annotation>
-                               <xs:documentation>The value of this state attribute. A value should be specified if the type is "constant" or "location".</xs:documentation></xs:annotation></xs:attribute>
-               <xs:attribute name="reference" use="optional" default="relative">
-                       <xs:annotation>
-                               <xs:documentation>Specify which state system attribute to use as the base to reach this path. It is either absolute or relative. By default, it is relative to the current entry.</xs:documentation></xs:annotation>
-                       <xs:simpleType>
-                               <xs:restriction base="xs:string">
-                                       <xs:enumeration value="relative" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The path will be calculated starting from the entry under which this viewStateAttribute element is defined.</xs:documentation></xs:annotation></xs:enumeration>
-                                       <xs:enumeration value="absolute" >
-                                               <xs:annotation>
-                                                       <xs:documentation>The path will be calculated starting from the root of the state system. That means that if the entry itself is one of "CPUs/*", we could reach another attribute from the root of the state system, like "Threads/tid".</xs:documentation></xs:annotation></xs:enumeration>
-                               </xs:restriction>
-                       </xs:simpleType>
-               </xs:attribute>
-       </xs:complexType>
-</xs:schema>
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/segment/TmfXmlPatternSegment.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/segment/TmfXmlPatternSegment.java
deleted file mode 100644 (file)
index f32406a..0000000
+++ /dev/null
@@ -1,236 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Ecole Polytechnique de Montreal, Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- ******************************************************************************/
-package org.eclipse.tracecompass.tmf.analysis.xml.core.segment;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.segmentstore.core.ISegment;
-import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
-import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
-import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
-
-/**
- * This class implements an XML Pattern Segment. This type of segment has
- * content and a default timestamp, which is the start time of the segment.
- *
- * @author Jean-Christian Kouame
- * @since 2.0
- *
- */
-public class TmfXmlPatternSegment implements ISegment {
-
-    /**
-     * The serial version UID
-     */
-    private static final long serialVersionUID = 3556323761465412078L;
-
-    /* 'Byte' equivalent for state values types */
-    private static final byte TYPE_NULL = -1;
-    private static final byte TYPE_INTEGER = 0;
-    private static final byte TYPE_STRING = 1;
-    private static final byte TYPE_LONG = 2;
-
-    private final int fScale;
-    private final long fStart;
-    private final long fEnd;
-    private final String fSegmentName;
-    private transient Map<@NonNull String, @NonNull ITmfStateValue> fContent;
-
-    /**
-     * Constructs an XML pattern segment
-     *
-     * @param start
-     *            Start time of the pattern segment
-     * @param end
-     *            End time of the pattern segment
-     * @param scale
-     *            Scale of the pattern segment
-     * @param segmentName
-     *            Name of the pattern segment
-     * @param fields
-     *            Fields of the pattern segment
-     */
-    public TmfXmlPatternSegment(long start, long end, int scale, String segmentName, @NonNull Map<@NonNull String, @NonNull ITmfStateValue> fields) {
-        fStart = start;
-        fEnd = end;
-        fScale = scale;
-        fSegmentName = segmentName;
-        fContent = Collections.unmodifiableMap(fields);
-    }
-
-    /**
-     * Get the start timestamp of the segment
-     *
-     * @return The start timestamp
-     */
-    public @NonNull ITmfTimestamp getTimestampStart() {
-        return TmfTimestamp.create(fStart, fScale);
-    }
-
-    /**
-     * Get the end timestamp of this segment
-     *
-     * @return The end timestamp
-     */
-    public @NonNull ITmfTimestamp getTimestampEnd() {
-        return TmfTimestamp.create(fEnd, fScale);
-    }
-
-    /**
-     * Get the content of the pattern segment
-     * @return The content
-     */
-    public Map<@NonNull String, @NonNull ITmfStateValue> getContent() {
-        return fContent;
-    }
-
-    /**
-     * Get the name of pattern segment
-     * @return The name
-     */
-    public String getName() {
-        return fSegmentName;
-    }
-
-    /**
-     * Get the timestamp scale of the pattern segment
-     * @return The timestamp scale
-     */
-    public int getScale() {
-        return fScale;
-    }
-
-    @Override
-    public int compareTo(@NonNull ISegment o) {
-        int ret = ISegment.super.compareTo(o);
-        if (ret != 0) {
-            return ret;
-        }
-        return toString().compareTo(o.toString());
-    }
-
-    @Override
-    public long getStart() {
-        return fStart;
-    }
-
-    @Override
-    public long getEnd() {
-        return fEnd;
-    }
-
-    @Override
-    public String toString() {
-        return new StringBuilder(getClass().getSimpleName())
-                .append(", [fTimestampStart=").append(getTimestampStart()) //$NON-NLS-1$
-                .append(", fTimestampEnd=").append(getTimestampEnd()) //$NON-NLS-1$
-                .append(", duration= ").append(getLength()) //$NON-NLS-1$
-                .append(", fName=").append(getName()) //$NON-NLS-1$
-                .append(", fContent=").append(getContent()) //$NON-NLS-1$
-                .append("]").toString(); //$NON-NLS-1$
-    }
-
-    private void writeObject(ObjectOutputStream out) throws IOException {
-        out.defaultWriteObject();
-
-        // Write the number of fields
-        out.writeInt(fContent.size());
-
-        // Write the fields
-        for (Map.Entry<String, ITmfStateValue> entry : fContent.entrySet()) {
-            out.writeInt(entry.getKey().length());
-            out.writeBytes(entry.getKey());
-            final ITmfStateValue value = entry.getValue();
-            final byte type = getByteFromType(value.getType());
-            out.writeByte(type);
-            switch (type) {
-            case TYPE_NULL:
-                break;
-            case TYPE_INTEGER:
-                out.writeInt(value.unboxInt());
-                break;
-            case TYPE_LONG:
-                out.writeLong(value.unboxLong());
-                break;
-            case TYPE_STRING:
-                final @NonNull String string = value.unboxStr();
-                out.writeInt(string.length());
-                out.writeBytes(string);
-                break;
-            default:
-                throw new IOException("Write object failed : Invalid data"); //$NON-NLS-1$
-            }
-        }
-    }
-
-    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
-        in.defaultReadObject();
-        int contentSize = in.readInt();
-
-        final Map<@NonNull String, @NonNull ITmfStateValue> content = new HashMap<>();
-        for (int i = 0; i < contentSize; i++) {
-            int length = in.readInt();
-            byte[] bytes = new byte[length];
-            in.read(bytes, 0, length);
-            String name = new String(bytes).intern();
-
-            Byte type = in.readByte();
-            ITmfStateValue value;
-            switch (type) {
-            case TYPE_NULL:
-                value = TmfStateValue.nullValue();
-                break;
-            case TYPE_INTEGER:
-                value = TmfStateValue.newValueInt(in.readInt());
-                break;
-            case TYPE_LONG:
-                value = TmfStateValue.newValueLong(in.readLong());
-                break;
-            case TYPE_STRING:
-                length = in.readInt();
-                bytes = new byte[length];
-                in.read(bytes, 0, length);
-                value = TmfStateValue.newValueString(new String(bytes).intern());
-                break;
-            default:
-                throw new IOException("Read object failed : Invalid data"); //$NON-NLS-1$
-            }
-            content.put(name, value);
-        }
-        fContent = content;
-    }
-
-    /**
-     * Here we determine how state values "types" are written in the 8-bit field
-     * that indicates the value type in the file.
-     */
-    private static byte getByteFromType(ITmfStateValue.Type type) {
-        switch (type) {
-        case NULL:
-            return TYPE_NULL;
-        case INTEGER:
-            return TYPE_INTEGER;
-        case STRING:
-            return TYPE_STRING;
-        case LONG:
-            return TYPE_LONG;
-        case DOUBLE:
-        default:
-            /* Should not happen if the switch is fully covered */
-            throw new IllegalStateException("Data type " + type + " not supported"); //$NON-NLS-1$ //$NON-NLS-2$
-        }
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/stateprovider/TmfXmlStrings.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/stateprovider/TmfXmlStrings.java
deleted file mode 100644 (file)
index b40d714..0000000
+++ /dev/null
@@ -1,328 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 Ecole Polytechnique
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Florian Wininger - Initial implementation
- ******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-
-/**
- * This file defines all name in the XML Structure for the State Provider
- *
- * @author Florian Wininger
- * @noimplement This interface only contains static defines
- */
-@SuppressWarnings({ "javadoc", "nls" })
-@NonNullByDefault
-public interface TmfXmlStrings {
-
-    /* XML generic Element attribute names */
-    String VALUE = "value";
-    String NAME = "name";
-    String VERSION = "version";
-    String TYPE = "type";
-
-    /* XML header element */
-    String HEAD = "head";
-    String TRACETYPE = "traceType";
-    String ID = "id";
-    String LABEL = "label";
-    String ANALYSIS = "analysis";
-
-    /* XML String */
-    String NULL = "";
-    String WILDCARD = "*";
-    String VARIABLE_PREFIX = "$";
-    String COLOR = "color";
-    String COLOR_PREFIX = "#";
-
-    /* XML Element Name */
-    String STATE_PROVIDER = "stateProvider";
-    String DEFINED_VALUE = "definedValue";
-    String LOCATION = "location";
-    String EVENT_HANDLER = "eventHandler";
-    String STATE_ATTRIBUTE = "stateAttribute";
-    String STATE_VALUE = "stateValue";
-    String STATE_CHANGE = "stateChange";
-    String ELEMENT_FIELD = "field";
-
-    /* XML Condition strings */
-    String IF = "if";
-    String CONDITION = "condition";
-    String THEN = "then";
-    String ELSE = "else";
-
-    /* XML event handler strings */
-    String HANDLER_EVENT_NAME = "eventName";
-
-    /* XML constant for Type of Attribute and Value */
-    String TYPE_NULL = "null";
-    String TYPE_CONSTANT = "constant";
-    String EVENT_FIELD = "eventField";
-    String TYPE_LOCATION = "location";
-    String TYPE_QUERY = "query";
-    String TYPE_SELF = "self";
-    String TYPE_INT = "int";
-    String TYPE_LONG = "long";
-    /** @since 2.0 */
-    String TYPE_DOUBLE = "double";
-    String TYPE_STRING = "string";
-    String TYPE_EVENT_NAME = "eventName";
-    String TYPE_DELETE = "delete";
-    String INCREMENT = "increment";
-    String FORCED_TYPE = "forcedType";
-    String ATTRIBUTE_STACK = "stack";
-    String STACK_POP = "pop";
-    String STACK_PUSH = "push";
-    String STACK_PEEK = "peek";
-    String CPU = "cpu";
-
-    String TIMESTAMP = "timestamp";
-
-    /* Operator type */
-    String NOT = "not";
-    String AND = "and";
-    String OR = "or";
-
-    String OPERATOR = "operator";
-
-    /* Comparison/Condition operator types */
-    String EQ = "eq";
-    String NE = "ne";
-    String GE = "ge";
-    String GT = "gt";
-    String LE = "le";
-    String LT = "lt";
-
-    /* XML pattern elements */
-    /**
-     * @since 2.0
-     */
-    String PATTERN = "pattern";
-
-    /**
-     * @since 2.0
-     */
-    String STORED_FIELD = "storedField";
-
-    /**
-     * @since 2.0
-     */
-    String STORED_FIELDS = "storedFields";
-
-    /**
-     * @since 2.0
-     */
-    String PATTERN_HANDLER = "patternHandler";
-
-    /* XML synthetic event elements */
-    /**
-     * @since 2.0
-     */
-    String SEGMENT_NAME = "segName";
-    /**
-     * @since 2.0
-     */
-    String SEGMENT = "segment";
-    /**
-     * @since 2.0
-     */
-    String SEGMENT_TYPE = "segType";
-    /**
-     * @since 2.0
-     */
-    String SEGMENT_CONTENT = "segContent";
-    /**
-     * @since 2.0
-     */
-    String SEGMENT_FIELD = "segField";
-
-    /**
-     * @since 2.0
-     */
-    String INITIAL = "initial";
-    /**
-     * @since 2.0
-     */
-    String TEST = "test";
-    /**
-     * @since 2.0
-     */
-    String ACTION = "action";
-    /**
-     * @since 2.0
-     */
-    String FSM = "fsm";
-    /**
-     * @since 2.0
-     */
-    String STATE = "state";
-    /**
-     * @since 2.0
-     */
-    String EVENT_INFO = "eventInfo";
-    /**
-     * @since 2.0
-     */
-    String TIME_INFO = "timeInfo";
-    /**
-     * @since 2.0
-     */
-    String EVENT = "event";
-    /**
-     * @since 2.0
-     */
-    String CONSTANT_PREFIX = "#";
-    /**
-     * @since 2.0
-     */
-    String FSM_SCHEDULE_ACTION = "fsmScheduleAction";
-    /**
-     * @since 2.0
-     */
-    String MULTIPLE = "multiple";
-    /**
-     * @since 2.0
-     */
-    String PRECONDITION = "precondition";
-    /**
-     * @since 2.0
-     */
-    String COND = "cond";
-    /**
-     * @since 2.0
-     */
-    String FINAL = "final";
-    /**
-     * @since 2.0
-     */
-    String ABANDON_STATE = "abandonState";
-    /**
-     * @since 2.0
-     */
-    String STATE_TABLE = "stateTable";
-    /**
-     * @since 2.0
-     */
-    String STATE_DEFINITION = "stateDefinition";
-    /**
-     * @since 2.0
-     */
-    String EMPTY_STRING = "";
-    /**
-     * @since 2.0
-     */
-    String TRANSITION = "transition";
-    /**
-     * @since 2.0
-     */
-    String TARGET = "target";
-    /**
-     * @since 2.0
-     */
-    String SAVE_STORED_FIELDS = "saveStoredFields";
-    /**
-     * @since 2.0
-     */
-    String CLEAR_STORED_FIELDS = "clearStoredFields";
-    /**
-     * @since 2.0
-     */
-    String TIME_RANGE = "timerange";
-    /**
-     * @since 2.0
-     */
-    String ELAPSED_TIME = "elapsedTime";
-    /**
-     * @since 2.0
-     */
-    String NS = "ns";
-    /**
-     * @since 2.0
-     */
-    String US = "us";
-    /**
-     * @since 2.0
-     */
-    String MS = "ms";
-    /**
-     * @since 2.0
-     */
-    String S = "s";
-    /**
-     * @since 2.0
-     */
-    String UNIT = "unit";
-    /**
-     * @since 2.0
-     */
-    String IN = "in";
-    /**
-     * @since 2.0
-     */
-    String OUT = "out";
-    /**
-     * @since 2.0
-     */
-    String BEGIN = "begin";
-    /**
-     * @since 2.0
-     */
-    String END = "end";
-    /**
-     * @since 2.0
-     */
-    String LESS = "less";
-    /**
-     * @since 2.0
-     */
-    String EQUAL = "equal";
-    /**
-     * @since 2.0
-     */
-    String MORE = "more";
-    /**
-     * @since 2.0
-     */
-    String SINCE = "since";
-    /**
-     * @since 2.0
-     */
-    String ARG = "arg";
-    /**
-     * @since 2.0
-     */
-    String SCENARIOS = "scenarios";
-    /**
-     * @since 2.0
-     */
-    String ONENTRY = "onentry";
-    /**
-     * @since 2.0
-     */
-    String ONEXIT = "onexit";
-    /**
-     * @since 2.0
-     */
-    String OR_SEPARATOR = "\\|";
-    /**
-     * @since 2.0
-     */
-    String AND_SEPARATOR = ":";
-    /**
-     * @since 2.0
-     */
-    String ALIAS = "alias";
-    /**
-     * @since 2.0
-     */
-    String ABANDON = "abandon";
-}
\ No newline at end of file
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/stateprovider/XmlStateProvider.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/stateprovider/XmlStateProvider.java
deleted file mode 100644 (file)
index 5dc864a..0000000
+++ /dev/null
@@ -1,188 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014, 2015 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Florian Wininger - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlEventHandler;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlLocation;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.readwrite.TmfXmlReadWriteModelFactory;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
-/**
- * This is the state change input plug-in for TMF's state system which handles
- * the XML Format
- *
- * @author Florian Wininger
- */
-public class XmlStateProvider extends AbstractTmfStateProvider implements IXmlStateSystemContainer {
-
-    private final IPath fFilePath;
-    private final @NonNull String fStateId;
-
-    /** List of all Event Handlers */
-    private final List<TmfXmlEventHandler> fEventHandlers = new ArrayList<>();
-
-    /** List of all Locations */
-    private final @NonNull Set<@NonNull TmfXmlLocation> fLocations;
-
-    /** Map for defined values */
-    private final Map<String, String> fDefinedValues = new HashMap<>();
-
-    // ------------------------------------------------------------------------
-    // Constructor
-    // ------------------------------------------------------------------------
-
-    /**
-     * Instantiate a new state provider plug-in.
-     *
-     * @param trace
-     *            The trace
-     * @param stateid
-     *            The state system id, corresponding to the analysis_id
-     *            attribute of the state provider element of the XML file
-     * @param file
-     *            Path to the XML file containing the state provider definition
-     */
-    public XmlStateProvider(@NonNull ITmfTrace trace, @NonNull String stateid, IPath file) {
-        super(trace, stateid);
-        fStateId = stateid;
-        fFilePath = file;
-        Element doc = XmlUtils.getElementInFile(fFilePath.makeAbsolute().toOSString(), TmfXmlStrings.STATE_PROVIDER, fStateId);
-        if (doc == null) {
-            fLocations = new HashSet<>();
-            return;
-        }
-
-        ITmfXmlModelFactory modelFactory = TmfXmlReadWriteModelFactory.getInstance();
-        /* parser for defined Values */
-        NodeList definedStateNodes = doc.getElementsByTagName(TmfXmlStrings.DEFINED_VALUE);
-        for (int i = 0; i < definedStateNodes.getLength(); i++) {
-            Element element = (Element) definedStateNodes.item(i);
-            fDefinedValues.put(element.getAttribute(TmfXmlStrings.NAME), element.getAttribute(TmfXmlStrings.VALUE));
-        }
-
-        /* parser for the locations */
-        List<Element> childElements = XmlUtils.getChildElements(doc, TmfXmlStrings.LOCATION);
-        Set<@NonNull TmfXmlLocation> locations = new HashSet<>();
-        for (Element element : childElements) {
-            if (element == null) {
-                continue;
-            }
-            TmfXmlLocation location = modelFactory.createLocation(element, this);
-            locations.add(location);
-        }
-        fLocations = Collections.unmodifiableSet(locations);
-
-        /* parser for the event handlers */
-        childElements = XmlUtils.getChildElements(doc, TmfXmlStrings.EVENT_HANDLER);
-        for (Element element : childElements) {
-            if (element == null) {
-                continue;
-            }
-            TmfXmlEventHandler handler = modelFactory.createEventHandler(element, this);
-            fEventHandlers.add(handler);
-        }
-    }
-
-    /**
-     * Get the state id of the state provider
-     *
-     * @return The state id of the state provider
-     */
-    @NonNull
-    public String getStateId() {
-        return fStateId;
-    }
-
-    // ------------------------------------------------------------------------
-    // IStateChangeInput
-    // ------------------------------------------------------------------------
-
-    @Override
-    public int getVersion() {
-        Element ssNode = XmlUtils.getElementInFile(fFilePath.makeAbsolute().toOSString(), TmfXmlStrings.STATE_PROVIDER, fStateId);
-        if (ssNode != null) {
-            return Integer.parseInt(ssNode.getAttribute(TmfXmlStrings.VERSION));
-        }
-        /*
-         * The version attribute is mandatory and XML files that don't validate
-         * with the XSD are ignored, so this should never happen
-         */
-        throw new IllegalStateException("The state provider XML node should have a version attribute"); //$NON-NLS-1$
-    }
-
-    @Override
-    public XmlStateProvider getNewInstance() {
-        return new XmlStateProvider(this.getTrace(), getStateId(), fFilePath);
-    }
-
-    @Override
-    protected void eventHandle(ITmfEvent event) {
-        for (TmfXmlEventHandler eventHandler : fEventHandlers) {
-            eventHandler.handleEvent(event);
-        }
-    }
-
-    @Override
-    public ITmfStateSystem getStateSystem() {
-        return getStateSystemBuilder();
-    }
-
-    // ------------------------------------------------------------------------
-    // Operations
-    // ------------------------------------------------------------------------
-
-    @Override
-    public Iterable<TmfXmlLocation> getLocations() {
-        return fLocations;
-    }
-
-    /**
-     * Get the defined value associated with a constant
-     *
-     * @param constant
-     *            The constant defining this value
-     * @return The actual value corresponding to this constant
-     */
-    public String getDefinedValue(String constant) {
-        return fDefinedValues.get(constant);
-    }
-
-    @Override
-    public String getAttributeValue(String name) {
-        String attribute = name;
-        if (attribute.startsWith(TmfXmlStrings.VARIABLE_PREFIX)) {
-            /* search the attribute in the map without the fist character $ */
-            attribute = getDefinedValue(attribute.substring(1));
-        }
-        return attribute;
-    }
-
-}
\ No newline at end of file
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/stateprovider/XmlStateSystemModule.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/stateprovider/XmlStateSystemModule.java
deleted file mode 100644 (file)
index 86bad86..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014, 2015 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider;
-
-import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
-
-import java.util.List;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
-import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
-import org.w3c.dom.Element;
-
-/**
- * Analysis module for the data-driven state systems, defined in XML.
- *
- * @author Geneviève Bastien
- */
-public class XmlStateSystemModule extends TmfStateSystemAnalysisModule {
-
-    private @Nullable IPath fXmlFile;
-
-    @Override
-    protected StateSystemBackendType getBackendType() {
-        return StateSystemBackendType.FULL;
-    }
-
-    @Override
-    @NonNull
-    protected ITmfStateProvider createStateProvider() {
-        return new XmlStateProvider(checkNotNull(getTrace()), getId(), fXmlFile);
-    }
-
-    @Override
-    public String getName() {
-        String id = getId();
-        IPath xmlFile = fXmlFile;
-        if (xmlFile == null) {
-            return id;
-        }
-        Element doc = XmlUtils.getElementInFile(xmlFile.makeAbsolute().toString(), TmfXmlStrings.STATE_PROVIDER, id);
-        /* Label may be available in XML header */
-        List<Element> head = XmlUtils.getChildElements(doc, TmfXmlStrings.HEAD);
-        String name = null;
-        if (head.size() == 1) {
-            List<Element> labels = XmlUtils.getChildElements(head.get(0), TmfXmlStrings.LABEL);
-            if (!labels.isEmpty()) {
-                name = labels.get(0).getAttribute(TmfXmlStrings.VALUE);
-            }
-        }
-        return (name == null) ? id : name;
-    }
-
-    /**
-     * Sets the file path of the XML file containing the state provider
-     *
-     * @param file
-     *            The absolute path to the XML file
-     */
-    public void setXmlFile(IPath file) {
-        fXmlFile = file;
-    }
-
-    /**
-     * Get the path to the XML file containing this state provider definition.
-     *
-     * @return XML file path
-     */
-    public IPath getXmlFile() {
-        return fXmlFile;
-    }
-
-}
index 5f16b858dff9b230efbda5c2c79a90fd10977c0d..9935cf67aa3d13ef46547fc02d545c4c991726d6 100644 (file)
@@ -24,8 +24,7 @@ Export-Package: org.eclipse.tracecompass.internal.tmf.analysis.xml.ui;x-friends:
  org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module;x-internal:=true,
  org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views;x-internal:=true,
  org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency;x-internal:=true,
- org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.xychart;x-internal:=true,
- org.eclipse.tracecompass.tmf.analysis.xml.ui.module,
- org.eclipse.tracecompass.tmf.analysis.xml.ui.views.timegraph
+ org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.timegraph;x-internal:=true,
+ org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.xychart;x-internal:=true
 Import-Package: com.google.common.collect,
  org.eclipse.ui.views.properties
index 6a834b93b37a4ff57ccbc01a50f08f8805001441..9be72622593b97fe1eed6a4d08487d2bda75661e 100644 (file)
@@ -4,7 +4,7 @@
    <extension
          point="org.eclipse.linuxtools.tmf.core.analysis">
       <listener
-            class="org.eclipse.tracecompass.tmf.analysis.xml.ui.module.TmfXmlAnalysisOutputSource">
+            class="org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module.TmfXmlAnalysisOutputSource">
       </listener>
    </extension>
    <extension
@@ -65,7 +65,7 @@
       <view
             allowMultiple="false"
             category="org.eclipse.linuxtools.lttng2.ui.views.category"
-            class="org.eclipse.tracecompass.tmf.analysis.xml.ui.views.timegraph.XmlTimeGraphView"
+            class="org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.timegraph.XmlTimeGraphView"
             id="org.eclipse.linuxtools.tmf.analysis.xml.ui.views.timegraph"
             name="%xmltimegraph.view.name"
             restorable="true">
index acc28f97b2d9da1012d7d9fa6f63b00bbafc47cd..ff17095369fce86910f626c22c30c39b42f2bf73 100644 (file)
@@ -39,9 +39,9 @@ import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.List;
 import org.eclipse.swt.widgets.Shell;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlAnalysisModuleSource;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.Activator;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlAnalysisModuleSource;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
 import org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement;
 import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement;
 import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectModelElement;
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/module/TmfXmlAnalysisOutputSource.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/module/TmfXmlAnalysisOutputSource.java
new file mode 100644 (file)
index 0000000..406bf05
--- /dev/null
@@ -0,0 +1,202 @@
+/*******************************************************************************
+ * Copyright (c) 2016 École Polytechnique de Montréal and others
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternAnalysis;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.Activator;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternDensityView;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternLatencyTableView;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternScatterGraphView;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternStatisticsView;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.timegraph.XmlTimeGraphView;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.xychart.XmlXYView;
+import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
+import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisOutput;
+import org.eclipse.tracecompass.tmf.core.analysis.ITmfNewAnalysisModuleListener;
+import org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * This class searches all XML files to find outputs applicable to the newly
+ * created analysis
+ *
+ * @author Geneviève Bastien
+ */
+public class TmfXmlAnalysisOutputSource implements ITmfNewAnalysisModuleListener {
+
+    /** String separating data elements for the output properties */
+    public static final @NonNull String DATA_SEPARATOR = ";;;"; //$NON-NLS-1$
+
+    /**
+     * Enum to match the name of a view's XML element to its view ID.
+     */
+    public static enum ViewType {
+        /**
+         * Time graph view element
+         */
+        TIME_GRAPH_VIEW(TmfXmlUiStrings.TIME_GRAPH_VIEW, XmlTimeGraphView.ID),
+        /**
+         * XY chart view element
+         */
+        XY_VIEW(TmfXmlUiStrings.XY_VIEW, XmlXYView.ID);
+
+        private final @NonNull String fXmlElem;
+        private final String fViewId;
+
+        private ViewType(@NonNull String xmlElem, String viewId) {
+            fXmlElem = xmlElem;
+            fViewId = viewId;
+        }
+
+        /**
+         * Get the XML element corresponding to this view type
+         *
+         * @return The XML element corresponding to this type
+         */
+        public @NonNull String getXmlElem() {
+            return fXmlElem;
+        }
+
+        private String getViewId() {
+            return fViewId;
+        }
+    }
+
+    /**
+     * Enum for latency view type.
+     *
+     * @author Jean-Christian Kouame
+     */
+    public static enum LatencyViewType {
+
+        /**
+         * Latency Table View type
+         */
+        LATENCY_TABLE(PatternLatencyTableView.ID, Messages.TmfXmlAnalysisOutputSource_LatencyTable),
+
+        /**
+         * Latency Scatter View type
+         */
+        SCATTER_GRAPH(PatternScatterGraphView.ID, Messages.TmfXmlAnalysisOutputSource_ScatterGraphTitle),
+
+        /**
+         * Latency Density View type
+         */
+        DENSITY_VIEW(PatternDensityView.ID, Messages.TmfXmlAnalysisOutputSource_DensityChartTitle),
+
+        /**
+         * Latency Statistic View type
+         */
+        STATISTIC_VIEW(PatternStatisticsView.ID, Messages.TmfXmlAnalysisOutputSource_LatencyStatisticsTitle);
+
+        private @NonNull String fLatencyViewId;
+        private String fLatencyViewLabel;
+
+        private LatencyViewType(@NonNull String viewId, String label) {
+            fLatencyViewId = viewId;
+            fLatencyViewLabel = label;
+        }
+
+        /**
+         * Get the ID of the latency view
+         *
+         * @return The ID
+         */
+        public String getViewId() {
+            return fLatencyViewId;
+        }
+
+        /**
+         * Get the label of the view
+         *
+         * @return The label
+         */
+        public String getLabel() {
+            return fLatencyViewLabel;
+        }
+    }
+
+    @Override
+    public void moduleCreated(IAnalysisModule module) {
+        Map<String, File> files = XmlUtils.listFiles();
+        for (File xmlFile : files.values()) {
+            if (!XmlUtils.xmlValidate(xmlFile).isOK()) {
+                continue;
+            }
+
+            try {
+                /* Load the XML File */
+                DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+                DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+                Document doc = dBuilder.parse(xmlFile);
+                doc.getDocumentElement().normalize();
+
+                /* get state provider views if the analysis has state systems */
+                if (module instanceof ITmfAnalysisModuleWithStateSystems) {
+                    for (ViewType viewType : ViewType.values()) {
+                        NodeList ssViewNodes = doc.getElementsByTagName(viewType.getXmlElem());
+                        for (int i = 0; i < ssViewNodes.getLength(); i++) {
+                            Element node = (Element) ssViewNodes.item(i);
+
+                            /* Check if analysis is the right one */
+                            List<Element> headNodes = XmlUtils.getChildElements(node, TmfXmlStrings.HEAD);
+                            if (headNodes.size() != 1) {
+                                continue;
+                            }
+
+                            List<Element> analysisNodes = XmlUtils.getChildElements(headNodes.get(0), TmfXmlStrings.ANALYSIS);
+                            for (Element analysis : analysisNodes) {
+                                String analysisId = analysis.getAttribute(TmfXmlStrings.ID);
+                                if (analysisId.equals(module.getId())) {
+                                    String viewId = viewType.getViewId();
+                                    IAnalysisOutput output = new TmfXmlViewOutput(viewId, viewType);
+                                    output.setOutputProperty(TmfXmlUiStrings.XML_OUTPUT_DATA, node.getAttribute(TmfXmlStrings.ID) + DATA_SEPARATOR + xmlFile.getAbsolutePath(), false);
+                                    module.registerOutput(output);
+                                }
+                            }
+                        }
+                    }
+                }
+
+                // Add the latency views for pattern analysis
+                if (module instanceof XmlPatternAnalysis) {
+                    for (LatencyViewType viewType : LatencyViewType.values()) {
+                        IAnalysisOutput output = new TmfXmlLatencyViewOutput(viewType.getViewId(), viewType.getLabel());
+                        output.setOutputProperty(TmfXmlUiStrings.XML_LATENCY_OUTPUT_DATA, module.getId() + DATA_SEPARATOR + viewType.getLabel(), false);
+                        module.registerOutput(output);
+                    }
+                }
+
+            } catch (ParserConfigurationException | SAXException | IOException e) {
+                Activator.logError("Error opening XML file", e); //$NON-NLS-1$
+            }
+        }
+    }
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/module/TmfXmlLatencyViewOutput.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/module/TmfXmlLatencyViewOutput.java
new file mode 100644 (file)
index 0000000..c2e30a4
--- /dev/null
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module;
+
+import org.eclipse.tracecompass.tmf.ui.analysis.TmfAnalysisViewOutput;
+
+/**
+ * Class overriding the default analysis view output for XML pattern analysis
+ * latency views
+ *
+ * @author Jean-Christian Kouame
+ */
+public class TmfXmlLatencyViewOutput extends TmfAnalysisViewOutput {
+
+    private String fLabel;
+
+    /**
+     * @param viewid
+     *            The ID of the view
+     * @param label
+     *            The label of view
+     */
+    public TmfXmlLatencyViewOutput(String viewid, String label) {
+        super(viewid);
+        fLabel = label;
+    }
+
+    @Override
+    public String getName() {
+        return fLabel;
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/module/TmfXmlViewOutput.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/module/TmfXmlViewOutput.java
new file mode 100644 (file)
index 0000000..cd9b880
--- /dev/null
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module.TmfXmlAnalysisOutputSource.ViewType;
+import org.eclipse.tracecompass.tmf.ui.analysis.TmfAnalysisViewOutput;
+import org.w3c.dom.Element;
+
+/**
+ * Class overriding the default analysis view output for XML views. These views
+ * may have labels defined in the XML element and those label will be used as
+ * the name of the view
+ *
+ * @author Geneviève Bastien
+ *
+ *         TODO: We shouldn't have to do a new class here, we should be able to
+ *         set the name in the parent instead
+ */
+public class TmfXmlViewOutput extends TmfAnalysisViewOutput {
+
+    private String fLabel = null;
+    private final @NonNull ViewType fViewType;
+
+    /**
+     * Constructor
+     *
+     * @param viewid
+     *            id of the view to display as output
+     */
+    public TmfXmlViewOutput(String viewid) {
+        this(viewid, ViewType.TIME_GRAPH_VIEW);
+    }
+
+    /**
+     * Constructor
+     *
+     * @param viewid
+     *            id of the view to display as output
+     * @param viewType
+     *            type of view this output is for
+     */
+    public TmfXmlViewOutput(String viewid, @NonNull ViewType viewType) {
+        super(viewid);
+        fViewType = viewType;
+    }
+
+    @Override
+    public String getName() {
+        if (fLabel == null) {
+            return super.getName();
+        }
+        return fLabel;
+    }
+
+    @Override
+    public void setOutputProperty(@NonNull String key, String value, boolean immediate) {
+        super.setOutputProperty(key, value, immediate);
+        /* Find the label of the view */
+        if (key.equals(TmfXmlUiStrings.XML_OUTPUT_DATA)) {
+            String[] idFile = value.split(TmfXmlAnalysisOutputSource.DATA_SEPARATOR);
+            String viewId = (idFile.length > 0) ? idFile[0] : null;
+            String filePath = (idFile.length > 1) ? idFile[1] : null;
+            if ((viewId == null) || (filePath == null)) {
+                return;
+            }
+            Element viewElement = XmlUtils.getElementInFile(filePath, fViewType.getXmlElem(), viewId);
+            if (viewElement == null) {
+                return;
+            }
+            List<Element> heads = XmlUtils.getChildElements(viewElement, TmfXmlStrings.HEAD);
+            if (heads.size() != 1) {
+                return;
+            }
+            Element headElement = heads.get(0);
+            List<Element> label = XmlUtils.getChildElements(headElement, TmfXmlStrings.LABEL);
+            if (label.isEmpty()) {
+                return;
+            }
+            Element labelElement = label.get(0);
+            fLabel = labelElement.getAttribute(TmfXmlStrings.VALUE);
+        }
+    }
+}
index 84bd4b52b2905006dee8474eab9b93cf767a7609..864ebdce5b2efe637dc1ae1047ae90e7a50cdf60 100644 (file)
@@ -11,7 +11,7 @@ package org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jface.dialogs.IDialogSettings;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.Activator;
-import org.eclipse.tracecompass.tmf.analysis.xml.ui.module.TmfXmlAnalysisOutputSource;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module.TmfXmlAnalysisOutputSource;
 
 /**
  * Abstract class to manage information about a view for an XML analysis
index 402d405f06dda0243eff58649572e06e76fe9ff2..c225b41250faaf06acc68cb95a6caa99134c69a6 100644 (file)
@@ -10,7 +10,7 @@ package org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views;
 
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.jface.dialogs.IDialogSettings;
-import org.eclipse.tracecompass.tmf.analysis.xml.ui.module.TmfXmlAnalysisOutputSource;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module.TmfXmlAnalysisOutputSource;
 
 /**
  * Class that manages information about a latency view for pattern analysis: its
index 191a6ad35ae543bef2092ce6a176a68dfd3a0cf7..2ae9d6d2dafcfaeafb9faca9df4b3ac5215b910d 100644 (file)
@@ -19,9 +19,9 @@ import java.util.Set;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.jface.dialogs.IDialogSettings;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.analysis.xml.ui.module.TmfXmlAnalysisOutputSource;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module.TmfXmlAnalysisOutputSource;
 import org.w3c.dom.Element;
 
 /**
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/timegraph/Messages.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/timegraph/Messages.java
new file mode 100644 (file)
index 0000000..d9550f8
--- /dev/null
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.timegraph;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Message for the XML state system view
+ *
+ * @author Geneviève Bastien
+ */
+@SuppressWarnings("javadoc")
+public class Messages extends NLS {
+    private static final String BUNDLE_NAME = "org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.timegraph.messages"; //$NON-NLS-1$
+
+    public static String XmlPresentationProvider_MultipleStates;
+
+    /* Default text messages */
+    public static String XmlTimeGraphView_ColumnId;
+    public static String XmlTimeGraphView_ColumnName;
+    public static String XmlTimeGraphView_ColumnParentId;
+    public static String XmlTimeGraphView_DefaultTitle;
+
+    /* Text and tooltips of the view */
+    public static String XmlTimeGraphView_NextText;
+    public static String XmlTimeGraphView_NextTooltip;
+    public static String XmlTimeGraphView_PreviousInterval;
+    public static String XmlTimeGraphView_PreviousText;
+
+    /* Errors and warnings messages */
+    public static String XmlTimeGraphView_UselessEndPath;
+    static {
+        // initialize resource bundle
+        NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+    }
+
+    private Messages() {
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/timegraph/XmlEntry.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/timegraph/XmlEntry.java
new file mode 100644 (file)
index 0000000..b5783c9
--- /dev/null
@@ -0,0 +1,286 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2016 École Polytechnique de Montréal and others.
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Florian Wininger - Initial API and implementation
+ *   Geneviève Bastien - Review of the initial implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.timegraph;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlLocation;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readonly.TmfXmlReadOnlyModelFactory;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
+import org.eclipse.tracecompass.statesystem.core.StateSystemUtils;
+import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
+import org.w3c.dom.Element;
+
+/**
+ * An XML-defined entry, or row, to display in the XML state system view
+ *
+ * @author Florian Wininger
+ */
+public class XmlEntry extends TimeGraphEntry implements IXmlStateSystemContainer {
+
+    private static final String EMPTY_STRING = ""; //$NON-NLS-1$
+
+    /** Type of resource */
+    public static enum EntryDisplayType {
+        /** Entries without events to display (filler rows, etc.) */
+        NULL,
+        /** Entries with time events */
+        DISPLAY
+    }
+
+    private final ITmfTrace fTrace;
+    private final EntryDisplayType fType;
+    private final int fBaseQuark;
+    private final int fDisplayQuark;
+    private final String fParentId;
+    private final String fId;
+    private final @NonNull ITmfStateSystem fSs;
+    private final Element fElement;
+
+    /**
+     * Constructor
+     *
+     * @param baseQuark
+     *            The quark matching this entry, or <code>-1</code> if no quark
+     * @param displayQuark
+     *            The quark containing the value to display. It was needed by
+     *            the caller to get the start and end time of this entry, so we
+     *            receive it as parameter from him.
+     * @param trace
+     *            The trace on which we are working (FIXME: is this parameter
+     *            useful?)
+     * @param name
+     *            The name of this entry. It will be overridden if a "name" XML
+     *            tag is specified in the entryElement. It will also be used as
+     *            the ID of this entry if no "id" XML tag is specified. It
+     *            typically is the attribute name corresponding the the base
+     *            quark.
+     * @param startTime
+     *            The start time of this entry lifetime
+     * @param endTime
+     *            The end time of this entry
+     * @param type
+     *            The display type of this entry
+     * @param ss
+     *            The state system this entry belongs to
+     * @param entryElement
+     *            The XML element describing this entry. This element will be
+     *            used to determine, if available, the parent, ID, name and
+     *            other display option of this entry
+     */
+    public XmlEntry(int baseQuark, int displayQuark, ITmfTrace trace, String name, long startTime, long endTime, EntryDisplayType type, @NonNull ITmfStateSystem ss, Element entryElement) {
+        super(name, startTime, endTime);
+        fTrace = trace;
+        fType = type;
+        fBaseQuark = baseQuark;
+        fDisplayQuark = displayQuark;
+        fSs = ss;
+        fElement = entryElement;
+
+        /* Get the parent if specified */
+        List<Element> elements = XmlUtils.getChildElements(fElement, TmfXmlUiStrings.PARENT_ELEMENT);
+        if (elements.size() > 0) {
+            fParentId = getFirstValue(elements.get(0));
+        } else {
+            fParentId = EMPTY_STRING;
+        }
+
+        /* Get the name of this entry */
+        elements = XmlUtils.getChildElements(fElement, TmfXmlUiStrings.NAME_ELEMENT);
+        if (elements.size() > 0) {
+            String nameFromSs = getFirstValue(elements.get(0));
+            if (!nameFromSs.isEmpty()) {
+                setName(nameFromSs);
+            }
+        }
+
+        /* Get the id of this entry */
+        elements = XmlUtils.getChildElements(fElement, TmfXmlUiStrings.ID_ELEMENT);
+        if (elements.size() > 0) {
+            fId = getFirstValue(elements.get(0));
+        } else {
+            fId = name;
+        }
+
+    }
+
+    /**
+     * Constructor
+     *
+     * @param baseQuark
+     *            The quark matching this entry, or <code>-1</code> if no quark
+     * @param trace
+     *            The trace on which we are working
+     * @param name
+     *            The exec_name of this entry
+     * @param ss
+     *            The state system this entry belongs to
+     */
+    public XmlEntry(int baseQuark, ITmfTrace trace, String name, @NonNull ITmfStateSystem ss) {
+        super(name, ss.getStartTime(), ss.getCurrentEndTime());
+        fTrace = trace;
+        fType = EntryDisplayType.NULL;
+        fBaseQuark = baseQuark;
+        fDisplayQuark = baseQuark;
+        fSs = ss;
+        fElement = null;
+        fParentId = EMPTY_STRING;
+        fId = name;
+    }
+
+    /** Return the state value of the first interval with a non-null value */
+    private String getFirstValue(Element stateAttribute) {
+        if (stateAttribute == null) {
+            throw new IllegalArgumentException();
+        }
+
+        ITmfXmlModelFactory factory = TmfXmlReadOnlyModelFactory.getInstance();
+        ITmfXmlStateAttribute display = factory.createStateAttribute(stateAttribute, this);
+        int quark = display.getAttributeQuark(fBaseQuark, null);
+        if (quark != IXmlStateSystemContainer.ERROR_QUARK) {
+            ITmfStateInterval firstInterval = StateSystemUtils.queryUntilNonNullValue(fSs, quark, getStartTime(), getEndTime());
+            if (firstInterval != null) {
+                return firstInterval.getStateValue().toString();
+            }
+        }
+        return EMPTY_STRING;
+    }
+
+    /**
+     * Get the trace this entry was taken from
+     *
+     * @return the entry's trace
+     */
+    public ITmfTrace getTrace() {
+        return fTrace;
+    }
+
+    /**
+     * Get the entry Type of this entry. Uses the inner EntryDisplayType enum.
+     *
+     * @return The entry type
+     */
+    public EntryDisplayType getType() {
+        return fType;
+    }
+
+    /**
+     * Get the quark from which to get the time event intervals for this entry.
+     *
+     * @return The attribute quark containing the intervals to display
+     */
+    public int getDisplayQuark() {
+        return fDisplayQuark;
+    }
+
+    /**
+     * Get this entry's ID
+     *
+     * @return The id of the entry.
+     */
+    public String getId() {
+        return fId;
+    }
+
+    /**
+     * Return the entry's parent ID. It corresponds to another entry's ID
+     * received from the {@link #getId()} method.
+     *
+     * @return The parent ID of this entry
+     */
+    public String getParentId() {
+        return fParentId;
+    }
+
+    @Override
+    public boolean hasTimeEvents() {
+        if (fType == EntryDisplayType.NULL) {
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * Add a child to this entry of type XmlEntry
+     *
+     * @param entry
+     *            The entry to add
+     */
+    public void addChild(XmlEntry entry) {
+        int index;
+        for (index = 0; index < getChildren().size(); index++) {
+            XmlEntry other = (XmlEntry) getChildren().get(index);
+            if (entry.getType().compareTo(other.getType()) < 0) {
+                break;
+            } else if (entry.getType().equals(other.getType())) {
+                if (entry.getName().compareTo(other.getName()) < 0) {
+                    break;
+                }
+            }
+        }
+
+        entry.setParent(this);
+        addChild(index, entry);
+    }
+
+    /**
+     * Return the state system this entry is associated to
+     *
+     * @return The state system, or <code>null</code> if the state system can't
+     *         be found.
+     */
+    @Override
+    @NonNull
+    public ITmfStateSystem getStateSystem() {
+        return fSs;
+    }
+
+    @Override
+    public String getAttributeValue(String name) {
+        return name;
+    }
+
+    @Override
+    public Iterable<TmfXmlLocation> getLocations() {
+        return Collections.EMPTY_SET;
+    }
+
+    @Override
+    public Iterator<@NonNull ITimeEvent> getTimeEventsIterator() {
+        return super.getTimeEventsIterator();
+    }
+
+    @Override
+    public boolean matches(@NonNull Pattern pattern) {
+        if (pattern.matcher(getName()).find()) {
+            return true;
+        }
+        if (pattern.matcher(fId).find()) {
+            return true;
+        }
+        return pattern.matcher(fParentId).find();
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/timegraph/XmlPresentationProvider.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/timegraph/XmlPresentationProvider.java
new file mode 100644 (file)
index 0000000..ac8eb75
--- /dev/null
@@ -0,0 +1,212 @@
+/*******************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Florian Wininger - Initial API and implementation
+ *   Geneviève Bastien - Review of the initial implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.timegraph;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.timegraph.XmlEntry.EntryDisplayType;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent;
+import org.w3c.dom.Element;
+
+/**
+ * Presentation provider for the XML view, based on the generic TMF presentation
+ * provider.
+ *
+ * TODO: This should support colors/states defined for each entry element in the
+ * XML element. Also, event values may not be integers only (for instance, this
+ * wouldn't support yet the callstack view)
+ *
+ * @author Florian Wininger
+ */
+public class XmlPresentationProvider extends TimeGraphPresentationProvider {
+
+    private List<StateItem> stateValues = new ArrayList<>();
+    /*
+     * Maps the value of an event with the corresponding index in the
+     * stateValues list
+     */
+    private Map<Integer, Integer> stateIndex = new HashMap<>();
+
+    @Override
+    public int getStateTableIndex(ITimeEvent event) {
+        if (event instanceof TimeEvent && ((TimeEvent) event).hasValue()) {
+            TimeEvent tcEvent = (TimeEvent) event;
+
+            XmlEntry entry = (XmlEntry) event.getEntry();
+            int value = tcEvent.getValue();
+
+            if (entry.getType() == EntryDisplayType.DISPLAY) {
+                // Draw state only if state is already known
+                Integer index = stateIndex.get(value);
+                if (index != null) {
+                    return index;
+                }
+            }
+        }
+        return INVISIBLE;
+    }
+
+    @Override
+    public StateItem[] getStateTable() {
+        return stateValues.toArray(new StateItem[stateValues.size()]);
+    }
+
+    @Override
+    public String getEventName(ITimeEvent event) {
+        if (event instanceof TimeEvent && ((TimeEvent) event).hasValue()) {
+            TimeEvent tcEvent = (TimeEvent) event;
+
+            XmlEntry entry = (XmlEntry) event.getEntry();
+            int value = tcEvent.getValue();
+
+            if (entry.getType() == EntryDisplayType.DISPLAY) {
+                Integer index = stateIndex.get(value);
+                if (index != null) {
+                    String rgb = stateValues.get(index.intValue()).getStateString();
+                    return rgb;
+                }
+            }
+            return null;
+        }
+        return Messages.XmlPresentationProvider_MultipleStates;
+    }
+
+    @Override
+    public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event, long hoverTime) {
+        /*
+         * TODO: Add the XML elements to support adding extra information in the
+         * tooltips and implement this
+         */
+        return Collections.EMPTY_MAP;
+    }
+
+    @Override
+    public void postDrawEvent(ITimeEvent event, Rectangle bounds, GC gc) {
+        /*
+         * TODO Add the XML elements to support texts in intervals and implement
+         * this
+         */
+    }
+
+    @Override
+    public void postDrawEntry(ITimeGraphEntry entry, Rectangle bounds, GC gc) {
+    }
+
+    /**
+     * Loads the states from a {@link TmfXmlUiStrings#TIME_GRAPH_VIEW} XML
+     * element
+     *
+     * @param viewElement
+     *            The XML view element
+     */
+    public void loadNewStates(@NonNull Element viewElement) {
+        stateValues.clear();
+        stateIndex.clear();
+        List<Element> states = XmlUtils.getChildElements(viewElement, TmfXmlStrings.DEFINED_VALUE);
+
+        for (Element state : states) {
+            int value = Integer.parseInt(state.getAttribute(TmfXmlStrings.VALUE));
+            String name = state.getAttribute(TmfXmlStrings.NAME);
+            String color = state.getAttribute(TmfXmlStrings.COLOR);
+
+            // FIXME Allow this case
+            if (value < 0) {
+                return;
+            }
+
+            final RGB colorRGB = (color.startsWith(TmfXmlStrings.COLOR_PREFIX)) ? parseColor(color) : calcColor(value);
+
+            StateItem item = new StateItem(colorRGB, name);
+
+            Integer index = stateIndex.get(value);
+            if (index == null) {
+                /* Add the new state value */
+                stateIndex.put(value, stateValues.size());
+                stateValues.add(item);
+            } else {
+                /* Override a previous state value */
+                stateValues.set(index, item);
+            }
+        }
+        Display.getDefault().asyncExec(new Runnable() {
+            @Override
+            public void run() {
+                fireColorSettingsChanged();
+            }
+        });
+    }
+
+    private static RGB parseColor(String color) {
+        RGB colorRGB;
+        Integer hex = Integer.parseInt(color.substring(1), 16);
+        int hex1 = hex.intValue() % 256;
+        int hex2 = (hex.intValue() / 256) % 256;
+        int hex3 = (hex.intValue() / (256 * 256)) % 256;
+        colorRGB = new RGB(hex3, hex2, hex1);
+        return colorRGB;
+    }
+
+    private static RGB calcColor(int value) {
+        int x = (value * 97) % 1530;
+        int r = 0, g = 0, b = 0;
+        if (x >= 0 && x < 255) {
+            r = 255;
+            g = x;
+            b = 0;
+        }
+        if (x >= 255 && x < 510) {
+            r = 510 - x;
+            g = 255;
+            b = 0;
+        }
+        if (x >= 510 && x < 765) {
+            r = 0;
+            g = 255;
+            b = x - 510;
+        }
+        if (x >= 765 && x < 1020) {
+            r = 0;
+            g = 1020 - x;
+            b = 255;
+        }
+        if (x >= 1020 && x < 1275) {
+            r = x - 1020;
+            g = 0;
+            b = 255;
+        }
+        if (x >= 1275 && x <= 1530) {
+            r = 255;
+            g = 0;
+            b = 1530 - x;
+        }
+        return new RGB(r, g, b);
+    }
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java
new file mode 100644 (file)
index 0000000..106e85e
--- /dev/null
@@ -0,0 +1,568 @@
+/*******************************************************************************
+ * Copyright (c) 2014, 2016 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Florian Wininger - Initial API and implementation
+ *   Geneviève Bastien - Review of the initial implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.timegraph;
+
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readonly.TmfXmlReadOnlyModelFactory;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.Activator;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.XmlViewInfo;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.timegraph.XmlEntry.EntryDisplayType;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
+import org.eclipse.tracecompass.statesystem.core.StateSystemUtils;
+import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
+import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
+import org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
+import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider2;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
+import org.w3c.dom.Element;
+
+import com.google.common.collect.Iterables;
+
+/**
+ * This view displays state system data in a time graph view. It uses an XML
+ * {@link TmfXmlUiStrings#TIME_GRAPH_VIEW} element from an XML file. This
+ * element defines which entries from the state system will be shown and also
+ * gives additional information on the presentation of the view (states, colors,
+ * etc)
+ *
+ * @author Florian Wininger
+ */
+public class XmlTimeGraphView extends AbstractTimeGraphView {
+
+    /** View ID. */
+    public static final @NonNull String ID = "org.eclipse.linuxtools.tmf.analysis.xml.ui.views.timegraph"; //$NON-NLS-1$
+
+    private static final String[] DEFAULT_COLUMN_NAMES = new String[] {
+            Messages.XmlTimeGraphView_ColumnName,
+            Messages.XmlTimeGraphView_ColumnId,
+            Messages.XmlTimeGraphView_ColumnParentId,
+    };
+
+    private static final String[] DEFAULT_FILTER_COLUMN_NAMES = new String[] {
+            Messages.XmlTimeGraphView_ColumnName,
+            Messages.XmlTimeGraphView_ColumnId
+    };
+
+    /** The relative weight of the sash */
+    private static final int[] fWeight = { 1, 2 };
+
+    private static final String EMPTY_STRING = ""; //$NON-NLS-1$
+    private static final @NonNull String SPLIT_STRING = "/"; //$NON-NLS-1$
+
+    private final @NonNull XmlViewInfo fViewInfo = new XmlViewInfo(ID);
+    private final ITmfXmlModelFactory fFactory;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Default constructor
+     */
+    public XmlTimeGraphView() {
+        super(ID, new XmlPresentationProvider());
+        setWeight(fWeight);
+        setTreeColumns(DEFAULT_COLUMN_NAMES);
+        setTreeLabelProvider(new XmlTreeLabelProvider());
+        setFilterColumns(DEFAULT_FILTER_COLUMN_NAMES);
+        setFilterLabelProvider(new XmlTreeLabelProvider());
+        setEntryComparator(new XmlEntryComparator());
+        this.addPartPropertyListener(new IPropertyChangeListener() {
+            @Override
+            public void propertyChange(PropertyChangeEvent event) {
+                if (event.getProperty().equals(TmfXmlUiStrings.XML_OUTPUT_DATA)) {
+                    Object newValue = event.getNewValue();
+                    if (newValue instanceof String) {
+                        String data = (String) newValue;
+                        fViewInfo.setViewData(data);
+                        loadNewXmlView();
+                    }
+                }
+            }
+        });
+
+        fFactory = TmfXmlReadOnlyModelFactory.getInstance();
+    }
+
+    private void loadNewXmlView() {
+        rebuild();
+    }
+
+    private void setViewTitle(final String title) {
+        Display.getDefault().asyncExec(new Runnable() {
+            @Override
+            public void run() {
+                setPartName(title);
+            }
+        });
+
+    }
+
+    @Override
+    protected String getNextText() {
+        return Messages.XmlTimeGraphView_NextText;
+    }
+
+    @Override
+    protected String getNextTooltip() {
+        return Messages.XmlTimeGraphView_NextTooltip;
+    }
+
+    @Override
+    protected String getPrevText() {
+        return Messages.XmlTimeGraphView_PreviousText;
+    }
+
+    @Override
+    protected String getPrevTooltip() {
+        return Messages.XmlTimeGraphView_PreviousInterval;
+    }
+
+    /**
+     * Default label provider, it shows name, id and parent columns
+     *
+     * TODO: There should be a way to define columns in the XML
+     */
+    private static class XmlTreeLabelProvider extends TreeLabelProvider {
+
+        @Override
+        public String getColumnText(Object element, int columnIndex) {
+            XmlEntry entry = (XmlEntry) element;
+
+            if (DEFAULT_COLUMN_NAMES[columnIndex].equals(Messages.XmlTimeGraphView_ColumnName)) {
+                return entry.getName();
+            } else if (DEFAULT_COLUMN_NAMES[columnIndex].equals(Messages.XmlTimeGraphView_ColumnId)) {
+                return entry.getId();
+            } else if (DEFAULT_COLUMN_NAMES[columnIndex].equals(Messages.XmlTimeGraphView_ColumnParentId)) {
+                return entry.getParentId();
+            }
+            return EMPTY_STRING;
+        }
+
+    }
+
+    private static class XmlEntryComparator implements Comparator<ITimeGraphEntry> {
+
+        @Override
+        public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) {
+
+            int result = 0;
+
+            if ((o1 instanceof XmlEntry) && (o2 instanceof XmlEntry)) {
+                XmlEntry entry1 = (XmlEntry) o1;
+                XmlEntry entry2 = (XmlEntry) o2;
+                result = entry1.getTrace().getStartTime().compareTo(entry2.getTrace().getStartTime());
+                if (result == 0) {
+                    result = entry1.getTrace().getName().compareTo(entry2.getTrace().getName());
+                }
+                if (result == 0) {
+                    result = entry1.getName().compareTo(entry2.getName());
+                }
+            }
+
+            if (result == 0) {
+                result = o1.getStartTime() < o2.getStartTime() ? -1 : o1.getStartTime() > o2.getStartTime() ? 1 : 0;
+            }
+
+            return result;
+        }
+    }
+
+    // ------------------------------------------------------------------------
+    // Internal
+    // ------------------------------------------------------------------------
+
+    @Override
+    protected void buildEntryList(ITmfTrace trace, ITmfTrace parentTrace, IProgressMonitor monitor) {
+
+        /*
+         * Get the view element from the XML file. If the element can't be
+         * found, return.
+         */
+        Element viewElement = fViewInfo.getViewElement(TmfXmlUiStrings.TIME_GRAPH_VIEW);
+        if (viewElement == null) {
+            return;
+        }
+        ITimeGraphPresentationProvider2 pres = this.getPresentationProvider();
+        if (pres instanceof XmlPresentationProvider) {
+            /*
+             * TODO: Each entry of a line could have their own states/color.
+             * That will require an update to the presentation provider
+             */
+            ((XmlPresentationProvider) pres).loadNewStates(viewElement);
+        }
+
+        String title = fViewInfo.getViewTitle(viewElement);
+        if (title == null) {
+            title = Messages.XmlTimeGraphView_DefaultTitle;
+        }
+        setViewTitle(title);
+        Set<String> analysisIds = fViewInfo.getViewAnalysisIds(viewElement);
+
+        List<Element> entries = XmlUtils.getChildElements(viewElement, TmfXmlUiStrings.ENTRY_ELEMENT);
+        Set<XmlEntry> entryList = new TreeSet<>(getEntryComparator());
+        if (monitor.isCanceled()) {
+            return;
+        }
+
+        Set<@NonNull ITmfAnalysisModuleWithStateSystems> stateSystemModules = new HashSet<>();
+        if (analysisIds.isEmpty()) {
+            /*
+             * No analysis specified, take all state system analysis modules
+             */
+            Iterables.addAll(stateSystemModules, TmfTraceUtils.getAnalysisModulesOfClass(trace, ITmfAnalysisModuleWithStateSystems.class));
+        } else {
+            for (String moduleId : analysisIds) {
+                moduleId = checkNotNull(moduleId);
+                ITmfAnalysisModuleWithStateSystems module = TmfTraceUtils.getAnalysisModuleOfClass(trace, ITmfAnalysisModuleWithStateSystems.class, moduleId);
+                if (module != null) {
+                    stateSystemModules.add(module);
+                }
+            }
+        }
+
+        for (ITmfAnalysisModuleWithStateSystems module : stateSystemModules) {
+            IStatus status = module.schedule();
+            if (!status.isOK()) {
+                return;
+            }
+            if (!module.waitForInitialization()) {
+                return;
+            }
+            for (ITmfStateSystem ssq : module.getStateSystems()) {
+                ssq.waitUntilBuilt();
+
+                long startTime = ssq.getStartTime();
+                long endTime = ssq.getCurrentEndTime();
+                XmlEntry groupEntry = new XmlEntry(-1, trace, trace.getName(), ssq);
+                entryList.add(groupEntry);
+                setStartTime(Math.min(getStartTime(), startTime));
+                setEndTime(Math.max(getEndTime(), endTime));
+
+                /* Add children entry of this entry for each line */
+                for (Element entry : entries) {
+                    buildEntry(entry, groupEntry, -1);
+                }
+            }
+        }
+
+        addToEntryList(parentTrace, new ArrayList<TimeGraphEntry>(entryList));
+
+        if (parentTrace.equals(getTrace())) {
+            refresh();
+        }
+        for (XmlEntry traceEntry : entryList) {
+            if (monitor.isCanceled()) {
+                return;
+            }
+            long startTime = traceEntry.getStateSystem().getStartTime();
+            long endTime = traceEntry.getStateSystem().getCurrentEndTime() + 1;
+            buildStatusEvent(traceEntry, monitor, startTime, endTime);
+        }
+    }
+
+    private void buildEntry(Element entryElement, XmlEntry parentEntry, int baseQuark) {
+        /* Get the attribute string to display */
+        String path = entryElement.getAttribute(TmfXmlUiStrings.PATH);
+        if (path.isEmpty()) {
+            path = TmfXmlStrings.WILDCARD;
+        }
+
+        /*
+         * Make sure the XML element has either a display attribute or entries,
+         * otherwise issue a warning
+         */
+
+        List<Element> displayElements = XmlUtils.getChildElements(entryElement, TmfXmlUiStrings.DISPLAY_ELEMENT);
+        List<Element> entryElements = XmlUtils.getChildElements(entryElement, TmfXmlUiStrings.ENTRY_ELEMENT);
+
+        if (displayElements.isEmpty() && entryElements.isEmpty()) {
+            Activator.logWarning(String.format("XML view: entry for %s should have either a display element or entry elements", path)); //$NON-NLS-1$
+            return;
+        }
+
+        ITmfStateSystem ss = parentEntry.getStateSystem();
+
+        /* Get the list of quarks to process with this path */
+        String[] paths = path.split(SPLIT_STRING);
+        int i = 0;
+        List<Integer> quarks = Collections.singletonList(baseQuark);
+
+        try {
+            while (i < paths.length) {
+                List<Integer> subQuarks = new LinkedList<>();
+                /* Replace * by .* to have a regex string */
+                String name = paths[i].replaceAll("\\*", ".*"); //$NON-NLS-1$ //$NON-NLS-2$
+                for (int relativeQuark : quarks) {
+                    for (int quark : ss.getSubAttributes(relativeQuark, false, name)) {
+                        subQuarks.add(quark);
+                    }
+                }
+                quarks = subQuarks;
+                i++;
+            }
+
+            /* Process each quark */
+            XmlEntry currentEntry = parentEntry;
+            Element displayElement = null;
+            Map<String, XmlEntry> entryMap = new HashMap<>();
+            if (!displayElements.isEmpty()) {
+                displayElement = displayElements.get(0);
+            }
+            for (int quark : quarks) {
+                currentEntry = parentEntry;
+                /* Process the current entry, if specified */
+                if (displayElement != null) {
+                    currentEntry = processEntry(entryElement, displayElement, parentEntry, quark, ss);
+                    entryMap.put(currentEntry.getId(), currentEntry);
+                }
+                /* Process the children entry of this entry */
+                for (Element subEntryEl : entryElements) {
+                    buildEntry(subEntryEl, currentEntry, quark);
+                }
+            }
+            if (!entryMap.isEmpty()) {
+                buildTree(entryMap, parentEntry);
+            }
+        } catch (AttributeNotFoundException e) {
+        }
+    }
+
+    private XmlEntry processEntry(@NonNull Element entryElement, @NonNull Element displayEl,
+            @NonNull XmlEntry parentEntry, int quark, ITmfStateSystem ss) {
+        /*
+         * Get the start time and end time of this entry from the display
+         * attribute
+         */
+        ITmfXmlStateAttribute display = fFactory.createStateAttribute(displayEl, parentEntry);
+        int displayQuark = display.getAttributeQuark(quark, null);
+        if (displayQuark == IXmlStateSystemContainer.ERROR_QUARK) {
+            return new XmlEntry(quark, parentEntry.getTrace(),
+                    String.format("Unknown display quark for %s", ss.getAttributeName(quark)), ss); //$NON-NLS-1$
+        }
+
+        long entryStart = ss.getStartTime();
+        long entryEnd = ss.getCurrentEndTime();
+
+        try {
+
+            ITmfStateInterval oneInterval = ss.querySingleState(entryStart, displayQuark);
+
+            /* The entry start is the first non-null interval */
+            while (oneInterval.getStateValue().isNull()) {
+                long ts = oneInterval.getEndTime() + 1;
+                if (ts > ss.getCurrentEndTime()) {
+                    break;
+                }
+                oneInterval = ss.querySingleState(ts, displayQuark);
+            }
+            entryStart = oneInterval.getStartTime();
+
+            /* The entry end is the last non-null interval */
+            oneInterval = ss.querySingleState(entryEnd, displayQuark);
+            while (oneInterval.getStateValue().isNull()) {
+                long ts = oneInterval.getStartTime() - 1;
+                if (ts < ss.getStartTime()) {
+                    break;
+                }
+                oneInterval = ss.querySingleState(ts, displayQuark);
+            }
+            entryEnd = oneInterval.getEndTime();
+
+        } catch (AttributeNotFoundException | StateSystemDisposedException e) {
+        }
+
+        return new XmlEntry(quark, displayQuark, parentEntry.getTrace(), ss.getAttributeName(quark),
+                entryStart, entryEnd, EntryDisplayType.DISPLAY, ss, entryElement);
+    }
+
+    private void buildStatusEvent(XmlEntry traceEntry, @NonNull IProgressMonitor monitor, long start, long end) {
+        long resolution = (end - start) / getDisplayWidth();
+        long startTime = Math.max(start, traceEntry.getStartTime());
+        long endTime = Math.min(end + 1, traceEntry.getEndTime());
+        List<ITimeEvent> eventList = getEventList(traceEntry, startTime, endTime, resolution, monitor);
+        if (monitor.isCanceled()) {
+            return;
+        }
+        traceEntry.setEventList(eventList);
+        redraw();
+
+        for (ITimeGraphEntry entry : traceEntry.getChildren()) {
+            if (monitor.isCanceled()) {
+                return;
+            }
+            XmlEntry xmlEntry = (XmlEntry) entry;
+            buildStatusEvent(xmlEntry, monitor, start, end);
+        }
+    }
+
+    /** Build a tree using getParentId() and getId() */
+    private static void buildTree(Map<String, XmlEntry> entryMap, XmlEntry rootEntry) {
+        for (XmlEntry entry : entryMap.values()) {
+            boolean root = true;
+            if (!entry.getParentId().isEmpty()) {
+                XmlEntry parent = entryMap.get(entry.getParentId());
+                /*
+                 * Associate the parent entry only if their time overlap. A
+                 * child entry may start before its parent, for example at the
+                 * beginning of the trace if a parent has not yet appeared in
+                 * the state system. We just want to make sure that the entry
+                 * didn't start after the parent ended or ended before the
+                 * parent started.
+                 */
+                if (parent != null &&
+                        !(entry.getStartTime() > parent.getEndTime() ||
+                                entry.getEndTime() < parent.getStartTime())) {
+                    parent.addChild(entry);
+                    root = false;
+                }
+            }
+            if (root) {
+                rootEntry.addChild(entry);
+            }
+        }
+    }
+
+    @Override
+    protected List<ITimeEvent> getEventList(TimeGraphEntry entry, long startTime, long endTime, long resolution, IProgressMonitor monitor) {
+        if (!(entry instanceof XmlEntry)) {
+            return Collections.EMPTY_LIST;
+        }
+        XmlEntry xmlEntry = (XmlEntry) entry;
+        ITmfStateSystem ssq = xmlEntry.getStateSystem();
+        final long realStart = Math.max(startTime, entry.getStartTime());
+        final long realEnd = Math.min(endTime, entry.getEndTime());
+        if (realEnd <= realStart) {
+            return null;
+        }
+        List<ITimeEvent> eventList = null;
+        int quark = xmlEntry.getDisplayQuark();
+
+        try {
+            if (xmlEntry.getType() == EntryDisplayType.DISPLAY) {
+
+                List<ITmfStateInterval> statusIntervals = StateSystemUtils.queryHistoryRange(ssq, quark, realStart, realEnd - 1, resolution, monitor);
+                eventList = new ArrayList<>(statusIntervals.size());
+                long lastEndTime = -1;
+                for (ITmfStateInterval statusInterval : statusIntervals) {
+                    if (monitor.isCanceled()) {
+                        return null;
+                    }
+                    int status = statusInterval.getStateValue().unboxInt();
+                    long time = statusInterval.getStartTime();
+                    long duration = statusInterval.getEndTime() - time + 1;
+                    if (!statusInterval.getStateValue().isNull()) {
+                        if (lastEndTime != time && lastEndTime != -1) {
+                            eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime));
+                        }
+                        eventList.add(new TimeEvent(entry, time, duration, status));
+                    } else if (lastEndTime == -1 || time + duration >= endTime) {
+                        // add null event if it intersects the start or end time
+                        eventList.add(new NullTimeEvent(entry, time, duration));
+                    }
+                    lastEndTime = time + duration;
+                }
+            }
+        } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException | StateSystemDisposedException e) {
+            /* Ignored */
+        }
+        return eventList;
+    }
+
+    @Override
+    protected List<ILinkEvent> getLinkList(long startTime, long endTime, long resolution, IProgressMonitor monitor) {
+        /* TODO: not implemented yet, need XML to go along */
+        return Collections.EMPTY_LIST;
+    }
+
+    /**
+     * This method will pre-filter the traces that contain analysis modules
+     * supported by this view, whether they are from a trace or an experiment.
+     */
+    @Override
+    protected Iterable<ITmfTrace> getTracesToBuild(ITmfTrace trace) {
+        /*
+         * Get the view element from the XML file. If the element can't be
+         * found, return.
+         */
+        Element viewElement = fViewInfo.getViewElement(TmfXmlUiStrings.TIME_GRAPH_VIEW);
+        if (viewElement == null) {
+            return super.getTracesToBuild(trace);
+        }
+
+        Set<String> analysisIds = fViewInfo.getViewAnalysisIds(viewElement);
+        Set<ITmfTrace> traces = new HashSet<>();
+
+        for (ITmfTrace aTrace : TmfTraceManager.getTraceSetWithExperiment(trace)) {
+            if (aTrace == null) {
+                continue;
+            }
+            if ((analysisIds.isEmpty() && TmfTraceUtils.getAnalysisModulesOfClass(aTrace, ITmfAnalysisModuleWithStateSystems.class).iterator().hasNext())) {
+                /*
+                 * No analysis ID specified, so this trace will be built only if
+                 * it has state system modules
+                 */
+                traces.add(aTrace);
+            } else {
+                /* Build this trace only if it has one the requested modules */
+                for (String moduleId : analysisIds) {
+                    if (TmfTraceUtils.getAnalysisModuleOfClass(aTrace, ITmfAnalysisModuleWithStateSystems.class, NonNullUtils.checkNotNull(moduleId)) != null) {
+                        traces.add(aTrace);
+                    }
+                }
+            }
+        }
+        if (traces.isEmpty()) {
+            return super.getTracesToBuild(trace);
+        }
+        return traces;
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/timegraph/messages.properties b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/internal/tmf/analysis/xml/ui/views/timegraph/messages.properties
new file mode 100644 (file)
index 0000000..b978928
--- /dev/null
@@ -0,0 +1,21 @@
+###############################################################################
+# Copyright (c) 2015 Ericsson
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+#     Ericsson - Initial API and implementation
+###############################################################################
+XmlPresentationProvider_MultipleStates=(multiple)
+XmlTimeGraphView_ColumnId=ID
+XmlTimeGraphView_ColumnName=Name
+XmlTimeGraphView_ColumnParentId=ParentID
+XmlTimeGraphView_DefaultTitle=Xml State Provider
+XmlTimeGraphView_NextText=Next Interval
+XmlTimeGraphView_NextTooltip=Select next interval in time graph
+XmlTimeGraphView_PreviousInterval=Select previous interval in time graph
+XmlTimeGraphView_PreviousText=Previous Interval
+XmlTimeGraphView_UselessEndPath=There should be an XML <entry > for path {0} in the view's XML otherwise the last level is useless
index 2fb3339e8a94efbedd413c9adc8a338f71d839fc..438422b219e43ccd5c3f33182537118314c4becb 100644 (file)
@@ -26,6 +26,13 @@ import org.eclipse.core.runtime.IStatus;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlLocation;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.readonly.TmfXmlReadOnlyModelFactory;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.Activator;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.XmlViewInfo;
@@ -35,13 +42,6 @@ import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedE
 import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
 import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlLocation;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.readonly.TmfXmlReadOnlyModelFactory;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
 import org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/module/TmfXmlAnalysisOutputSource.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/module/TmfXmlAnalysisOutputSource.java
deleted file mode 100644 (file)
index c216127..0000000
+++ /dev/null
@@ -1,205 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 École Polytechnique de Montréal and others
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.ui.module;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternAnalysis;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.Activator;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.module.Messages;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternDensityView;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternLatencyTableView;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternScatterGraphView;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.latency.PatternStatisticsView;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.xychart.XmlXYView;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.analysis.xml.ui.views.timegraph.XmlTimeGraphView;
-import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
-import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisOutput;
-import org.eclipse.tracecompass.tmf.core.analysis.ITmfNewAnalysisModuleListener;
-import org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-/**
- * This class searches all XML files to find outputs applicable to the newly
- * created analysis
- *
- * @author Geneviève Bastien
- */
-public class TmfXmlAnalysisOutputSource implements ITmfNewAnalysisModuleListener {
-
-    /** String separating data elements for the output properties */
-    public static final @NonNull String DATA_SEPARATOR = ";;;"; //$NON-NLS-1$
-
-    /**
-     * Enum to match the name of a view's XML element to its view ID.
-     */
-    public static enum ViewType {
-        /**
-         * Time graph view element
-         */
-        TIME_GRAPH_VIEW(TmfXmlUiStrings.TIME_GRAPH_VIEW, XmlTimeGraphView.ID),
-        /**
-         * XY chart view element
-         */
-        XY_VIEW(TmfXmlUiStrings.XY_VIEW, XmlXYView.ID);
-
-        private final @NonNull String fXmlElem;
-        private final String fViewId;
-
-        private ViewType(@NonNull String xmlElem, String viewId) {
-            fXmlElem = xmlElem;
-            fViewId = viewId;
-        }
-
-        /**
-         * Get the XML element corresponding to this view type
-         *
-         * @return The XML element corresponding to this type
-         */
-        public @NonNull String getXmlElem() {
-            return fXmlElem;
-        }
-
-        private String getViewId() {
-            return fViewId;
-        }
-    }
-
-    /**
-     * Enum for latency view type.
-     *
-     * @author Jean-Christian Kouame
-     * @since 2.0
-     *
-     */
-    public static enum LatencyViewType {
-
-        /**
-         * Latency Table View type
-         */
-        LATENCY_TABLE(PatternLatencyTableView.ID, Messages.TmfXmlAnalysisOutputSource_LatencyTable),
-
-        /**
-         * Latency Scatter View type
-         */
-        SCATTER_GRAPH(PatternScatterGraphView.ID, Messages.TmfXmlAnalysisOutputSource_ScatterGraphTitle),
-
-        /**
-         * Latency Density View type
-         */
-        DENSITY_VIEW(PatternDensityView.ID, Messages.TmfXmlAnalysisOutputSource_DensityChartTitle),
-
-        /**
-         * Latency Statistic View type
-         */
-        STATISTIC_VIEW(PatternStatisticsView.ID, Messages.TmfXmlAnalysisOutputSource_LatencyStatisticsTitle);
-
-        private @NonNull String fLatencyViewId;
-        private String fLatencyViewLabel;
-
-        private LatencyViewType(@NonNull String viewId, String label) {
-            fLatencyViewId = viewId;
-            fLatencyViewLabel = label;
-        }
-
-        /**
-         * Get the ID of the latency view
-         *
-         * @return The ID
-         */
-        public String getViewId() {
-            return fLatencyViewId;
-        }
-
-        /**
-         * Get the label of the view
-         *
-         * @return The label
-         */
-        public String getLabel() {
-            return fLatencyViewLabel;
-        }
-    }
-
-    @Override
-    public void moduleCreated(IAnalysisModule module) {
-        Map<String, File> files = XmlUtils.listFiles();
-        for (File xmlFile : files.values()) {
-            if (!XmlUtils.xmlValidate(xmlFile).isOK()) {
-                continue;
-            }
-
-            try {
-                /* Load the XML File */
-                DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
-                DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
-                Document doc = dBuilder.parse(xmlFile);
-                doc.getDocumentElement().normalize();
-
-                /* get state provider views if the analysis has state systems */
-                if (module instanceof ITmfAnalysisModuleWithStateSystems) {
-                    for (ViewType viewType : ViewType.values()) {
-                        NodeList ssViewNodes = doc.getElementsByTagName(viewType.getXmlElem());
-                        for (int i = 0; i < ssViewNodes.getLength(); i++) {
-                            Element node = (Element) ssViewNodes.item(i);
-
-                            /* Check if analysis is the right one */
-                            List<Element> headNodes = XmlUtils.getChildElements(node, TmfXmlStrings.HEAD);
-                            if (headNodes.size() != 1) {
-                                continue;
-                            }
-
-                            List<Element> analysisNodes = XmlUtils.getChildElements(headNodes.get(0), TmfXmlStrings.ANALYSIS);
-                            for (Element analysis : analysisNodes) {
-                                String analysisId = analysis.getAttribute(TmfXmlStrings.ID);
-                                if (analysisId.equals(module.getId())) {
-                                    String viewId = viewType.getViewId();
-                                    IAnalysisOutput output = new TmfXmlViewOutput(viewId, viewType);
-                                    output.setOutputProperty(TmfXmlUiStrings.XML_OUTPUT_DATA, node.getAttribute(TmfXmlStrings.ID) + DATA_SEPARATOR + xmlFile.getAbsolutePath(), false);
-                                    module.registerOutput(output);
-                                }
-                            }
-                        }
-                    }
-                }
-
-                // Add the latency views for pattern analysis
-                if (module instanceof XmlPatternAnalysis) {
-                    for (LatencyViewType viewType : LatencyViewType.values()) {
-                        IAnalysisOutput output = new TmfXmlLatencyViewOutput(viewType.getViewId(), viewType.getLabel());
-                        output.setOutputProperty(TmfXmlUiStrings.XML_LATENCY_OUTPUT_DATA, module.getId() + DATA_SEPARATOR + viewType.getLabel(), false);
-                        module.registerOutput(output);
-                    }
-                }
-
-            } catch (ParserConfigurationException | SAXException | IOException e) {
-                Activator.logError("Error opening XML file", e); //$NON-NLS-1$
-            }
-        }
-    }
-
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/module/TmfXmlLatencyViewOutput.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/module/TmfXmlLatencyViewOutput.java
deleted file mode 100644 (file)
index f563cb5..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2016 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *******************************************************************************/
-package org.eclipse.tracecompass.tmf.analysis.xml.ui.module;
-
-import org.eclipse.tracecompass.tmf.ui.analysis.TmfAnalysisViewOutput;
-
-/**
- * Class overriding the default analysis view output for XML pattern analysis
- * latency views
- *
- * @author Jean-Christian Kouame
- * @since 2.0
- *
- */
-public class TmfXmlLatencyViewOutput extends TmfAnalysisViewOutput {
-
-    private String fLabel;
-
-    /**
-     * @param viewid
-     *            The ID of the view
-     * @param label
-     *            The label of view
-     */
-    public TmfXmlLatencyViewOutput(String viewid, String label) {
-        super(viewid);
-        fLabel = label;
-    }
-
-    @Override
-    public String getName() {
-        return fLabel;
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/module/TmfXmlViewOutput.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/module/TmfXmlViewOutput.java
deleted file mode 100644 (file)
index 504e431..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.ui.module;
-
-import java.util.List;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.analysis.xml.ui.module.TmfXmlAnalysisOutputSource.ViewType;
-import org.eclipse.tracecompass.tmf.ui.analysis.TmfAnalysisViewOutput;
-import org.w3c.dom.Element;
-
-/**
- * Class overriding the default analysis view output for XML views. These views
- * may have labels defined in the XML element and those label will be used as
- * the name of the view
- *
- * @author Geneviève Bastien
- *
- *         TODO: We shouldn't have to do a new class here, we should be able to
- *         set the name in the parent instead
- */
-public class TmfXmlViewOutput extends TmfAnalysisViewOutput {
-
-    private String fLabel = null;
-    private final @NonNull ViewType fViewType;
-
-    /**
-     * Constructor
-     *
-     * @param viewid
-     *            id of the view to display as output
-     */
-    public TmfXmlViewOutput(String viewid) {
-        this(viewid, ViewType.TIME_GRAPH_VIEW);
-    }
-
-    /**
-     * Constructor
-     *
-     * @param viewid
-     *            id of the view to display as output
-     * @param viewType
-     *            type of view this output is for
-     */
-    public TmfXmlViewOutput(String viewid, @NonNull ViewType viewType) {
-        super(viewid);
-        fViewType = viewType;
-    }
-
-    @Override
-    public String getName() {
-        if (fLabel == null) {
-            return super.getName();
-        }
-        return fLabel;
-    }
-
-    @Override
-    public void setOutputProperty(@NonNull String key, String value, boolean immediate) {
-        super.setOutputProperty(key, value, immediate);
-        /* Find the label of the view */
-        if (key.equals(TmfXmlUiStrings.XML_OUTPUT_DATA)) {
-            String[] idFile = value.split(TmfXmlAnalysisOutputSource.DATA_SEPARATOR);
-            String viewId = (idFile.length > 0) ? idFile[0] : null;
-            String filePath = (idFile.length > 1) ? idFile[1] : null;
-            if ((viewId == null) || (filePath == null)) {
-                return;
-            }
-            Element viewElement = XmlUtils.getElementInFile(filePath, fViewType.getXmlElem(), viewId);
-            if (viewElement == null) {
-                return;
-            }
-            List<Element> heads = XmlUtils.getChildElements(viewElement, TmfXmlStrings.HEAD);
-            if (heads.size() != 1) {
-                return;
-            }
-            Element headElement = heads.get(0);
-            List<Element> label = XmlUtils.getChildElements(headElement, TmfXmlStrings.LABEL);
-            if (label.isEmpty()) {
-                return;
-            }
-            Element labelElement = label.get(0);
-            fLabel = labelElement.getAttribute(TmfXmlStrings.VALUE);
-        }
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/Messages.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/Messages.java
deleted file mode 100644 (file)
index f7e3bfd..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.ui.views.timegraph;
-
-import org.eclipse.osgi.util.NLS;
-
-/**
- * Message for the XML state system view
- *
- * @author Geneviève Bastien
- */
-@SuppressWarnings("javadoc")
-public class Messages extends NLS {
-    private static final String BUNDLE_NAME = "org.eclipse.tracecompass.tmf.analysis.xml.ui.views.timegraph.messages"; //$NON-NLS-1$
-
-    public static String XmlPresentationProvider_MultipleStates;
-
-    /* Default text messages */
-    public static String XmlTimeGraphView_ColumnId;
-    public static String XmlTimeGraphView_ColumnName;
-    public static String XmlTimeGraphView_ColumnParentId;
-    public static String XmlTimeGraphView_DefaultTitle;
-
-    /* Text and tooltips of the view */
-    public static String XmlTimeGraphView_NextText;
-    public static String XmlTimeGraphView_NextTooltip;
-    public static String XmlTimeGraphView_PreviousInterval;
-    public static String XmlTimeGraphView_PreviousText;
-
-    /* Errors and warnings messages */
-    public static String XmlTimeGraphView_UselessEndPath;
-    static {
-        // initialize resource bundle
-        NLS.initializeMessages(BUNDLE_NAME, Messages.class);
-    }
-
-    private Messages() {
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlEntry.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlEntry.java
deleted file mode 100644 (file)
index 58fe923..0000000
+++ /dev/null
@@ -1,286 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014, 2016 École Polytechnique de Montréal and others.
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Florian Wininger - Initial API and implementation
- *   Geneviève Bastien - Review of the initial implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.ui.views.timegraph;
-
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.regex.Pattern;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings;
-import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.statesystem.core.StateSystemUtils;
-import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlLocation;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.readonly.TmfXmlReadOnlyModelFactory;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
-import org.w3c.dom.Element;
-
-/**
- * An XML-defined entry, or row, to display in the XML state system view
- *
- * @author Florian Wininger
- */
-public class XmlEntry extends TimeGraphEntry implements IXmlStateSystemContainer {
-
-    private static final String EMPTY_STRING = ""; //$NON-NLS-1$
-
-    /** Type of resource */
-    public static enum EntryDisplayType {
-        /** Entries without events to display (filler rows, etc.) */
-        NULL,
-        /** Entries with time events */
-        DISPLAY
-    }
-
-    private final ITmfTrace fTrace;
-    private final EntryDisplayType fType;
-    private final int fBaseQuark;
-    private final int fDisplayQuark;
-    private final String fParentId;
-    private final String fId;
-    private final @NonNull ITmfStateSystem fSs;
-    private final Element fElement;
-
-    /**
-     * Constructor
-     *
-     * @param baseQuark
-     *            The quark matching this entry, or <code>-1</code> if no quark
-     * @param displayQuark
-     *            The quark containing the value to display. It was needed by
-     *            the caller to get the start and end time of this entry, so we
-     *            receive it as parameter from him.
-     * @param trace
-     *            The trace on which we are working (FIXME: is this parameter
-     *            useful?)
-     * @param name
-     *            The name of this entry. It will be overridden if a "name" XML
-     *            tag is specified in the entryElement. It will also be used as
-     *            the ID of this entry if no "id" XML tag is specified. It
-     *            typically is the attribute name corresponding the the base
-     *            quark.
-     * @param startTime
-     *            The start time of this entry lifetime
-     * @param endTime
-     *            The end time of this entry
-     * @param type
-     *            The display type of this entry
-     * @param ss
-     *            The state system this entry belongs to
-     * @param entryElement
-     *            The XML element describing this entry. This element will be
-     *            used to determine, if available, the parent, ID, name and
-     *            other display option of this entry
-     */
-    public XmlEntry(int baseQuark, int displayQuark, ITmfTrace trace, String name, long startTime, long endTime, EntryDisplayType type, @NonNull ITmfStateSystem ss, Element entryElement) {
-        super(name, startTime, endTime);
-        fTrace = trace;
-        fType = type;
-        fBaseQuark = baseQuark;
-        fDisplayQuark = displayQuark;
-        fSs = ss;
-        fElement = entryElement;
-
-        /* Get the parent if specified */
-        List<Element> elements = XmlUtils.getChildElements(fElement, TmfXmlUiStrings.PARENT_ELEMENT);
-        if (elements.size() > 0) {
-            fParentId = getFirstValue(elements.get(0));
-        } else {
-            fParentId = EMPTY_STRING;
-        }
-
-        /* Get the name of this entry */
-        elements = XmlUtils.getChildElements(fElement, TmfXmlUiStrings.NAME_ELEMENT);
-        if (elements.size() > 0) {
-            String nameFromSs = getFirstValue(elements.get(0));
-            if (!nameFromSs.isEmpty()) {
-                setName(nameFromSs);
-            }
-        }
-
-        /* Get the id of this entry */
-        elements = XmlUtils.getChildElements(fElement, TmfXmlUiStrings.ID_ELEMENT);
-        if (elements.size() > 0) {
-            fId = getFirstValue(elements.get(0));
-        } else {
-            fId = name;
-        }
-
-    }
-
-    /**
-     * Constructor
-     *
-     * @param baseQuark
-     *            The quark matching this entry, or <code>-1</code> if no quark
-     * @param trace
-     *            The trace on which we are working
-     * @param name
-     *            The exec_name of this entry
-     * @param ss
-     *            The state system this entry belongs to
-     */
-    public XmlEntry(int baseQuark, ITmfTrace trace, String name, @NonNull ITmfStateSystem ss) {
-        super(name, ss.getStartTime(), ss.getCurrentEndTime());
-        fTrace = trace;
-        fType = EntryDisplayType.NULL;
-        fBaseQuark = baseQuark;
-        fDisplayQuark = baseQuark;
-        fSs = ss;
-        fElement = null;
-        fParentId = EMPTY_STRING;
-        fId = name;
-    }
-
-    /** Return the state value of the first interval with a non-null value */
-    private String getFirstValue(Element stateAttribute) {
-        if (stateAttribute == null) {
-            throw new IllegalArgumentException();
-        }
-
-        ITmfXmlModelFactory factory = TmfXmlReadOnlyModelFactory.getInstance();
-        ITmfXmlStateAttribute display = factory.createStateAttribute(stateAttribute, this);
-        int quark = display.getAttributeQuark(fBaseQuark, null);
-        if (quark != IXmlStateSystemContainer.ERROR_QUARK) {
-            ITmfStateInterval firstInterval = StateSystemUtils.queryUntilNonNullValue(fSs, quark, getStartTime(), getEndTime());
-            if (firstInterval != null) {
-                return firstInterval.getStateValue().toString();
-            }
-        }
-        return EMPTY_STRING;
-    }
-
-    /**
-     * Get the trace this entry was taken from
-     *
-     * @return the entry's trace
-     */
-    public ITmfTrace getTrace() {
-        return fTrace;
-    }
-
-    /**
-     * Get the entry Type of this entry. Uses the inner EntryDisplayType enum.
-     *
-     * @return The entry type
-     */
-    public EntryDisplayType getType() {
-        return fType;
-    }
-
-    /**
-     * Get the quark from which to get the time event intervals for this entry.
-     *
-     * @return The attribute quark containing the intervals to display
-     */
-    public int getDisplayQuark() {
-        return fDisplayQuark;
-    }
-
-    /**
-     * Get this entry's ID
-     *
-     * @return The id of the entry.
-     */
-    public String getId() {
-        return fId;
-    }
-
-    /**
-     * Return the entry's parent ID. It corresponds to another entry's ID
-     * received from the {@link #getId()} method.
-     *
-     * @return The parent ID of this entry
-     */
-    public String getParentId() {
-        return fParentId;
-    }
-
-    @Override
-    public boolean hasTimeEvents() {
-        if (fType == EntryDisplayType.NULL) {
-            return false;
-        }
-        return true;
-    }
-
-    /**
-     * Add a child to this entry of type XmlEntry
-     *
-     * @param entry
-     *            The entry to add
-     */
-    public void addChild(XmlEntry entry) {
-        int index;
-        for (index = 0; index < getChildren().size(); index++) {
-            XmlEntry other = (XmlEntry) getChildren().get(index);
-            if (entry.getType().compareTo(other.getType()) < 0) {
-                break;
-            } else if (entry.getType().equals(other.getType())) {
-                if (entry.getName().compareTo(other.getName()) < 0) {
-                    break;
-                }
-            }
-        }
-
-        entry.setParent(this);
-        addChild(index, entry);
-    }
-
-    /**
-     * Return the state system this entry is associated to
-     *
-     * @return The state system, or <code>null</code> if the state system can't
-     *         be found.
-     */
-    @Override
-    @NonNull
-    public ITmfStateSystem getStateSystem() {
-        return fSs;
-    }
-
-    @Override
-    public String getAttributeValue(String name) {
-        return name;
-    }
-
-    @Override
-    public Iterable<TmfXmlLocation> getLocations() {
-        return Collections.EMPTY_SET;
-    }
-
-    @Override
-    public Iterator<@NonNull ITimeEvent> getTimeEventsIterator() {
-        return super.getTimeEventsIterator();
-    }
-
-    @Override
-    public boolean matches(@NonNull Pattern pattern) {
-        if (pattern.matcher(getName()).find()) {
-            return true;
-        }
-        if (pattern.matcher(fId).find()) {
-            return true;
-        }
-        return pattern.matcher(fParentId).find();
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlPresentationProvider.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlPresentationProvider.java
deleted file mode 100644 (file)
index cd7a8b2..0000000
+++ /dev/null
@@ -1,212 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Florian Wininger - Initial API and implementation
- *   Geneviève Bastien - Review of the initial implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.ui.views.timegraph;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.analysis.xml.ui.views.timegraph.XmlEntry.EntryDisplayType;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphPresentationProvider;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent;
-import org.w3c.dom.Element;
-
-/**
- * Presentation provider for the XML view, based on the generic TMF presentation
- * provider.
- *
- * TODO: This should support colors/states defined for each entry element in the
- * XML element. Also, event values may not be integers only (for instance, this
- * wouldn't support yet the callstack view)
- *
- * @author Florian Wininger
- */
-public class XmlPresentationProvider extends TimeGraphPresentationProvider {
-
-    private List<StateItem> stateValues = new ArrayList<>();
-    /*
-     * Maps the value of an event with the corresponding index in the
-     * stateValues list
-     */
-    private Map<Integer, Integer> stateIndex = new HashMap<>();
-
-    @Override
-    public int getStateTableIndex(ITimeEvent event) {
-        if (event instanceof TimeEvent && ((TimeEvent) event).hasValue()) {
-            TimeEvent tcEvent = (TimeEvent) event;
-
-            XmlEntry entry = (XmlEntry) event.getEntry();
-            int value = tcEvent.getValue();
-
-            if (entry.getType() == EntryDisplayType.DISPLAY) {
-                // Draw state only if state is already known
-                Integer index = stateIndex.get(value);
-                if (index != null) {
-                    return index;
-                }
-            }
-        }
-        return INVISIBLE;
-    }
-
-    @Override
-    public StateItem[] getStateTable() {
-        return stateValues.toArray(new StateItem[stateValues.size()]);
-    }
-
-    @Override
-    public String getEventName(ITimeEvent event) {
-        if (event instanceof TimeEvent && ((TimeEvent) event).hasValue()) {
-            TimeEvent tcEvent = (TimeEvent) event;
-
-            XmlEntry entry = (XmlEntry) event.getEntry();
-            int value = tcEvent.getValue();
-
-            if (entry.getType() == EntryDisplayType.DISPLAY) {
-                Integer index = stateIndex.get(value);
-                if (index != null) {
-                    String rgb = stateValues.get(index.intValue()).getStateString();
-                    return rgb;
-                }
-            }
-            return null;
-        }
-        return Messages.XmlPresentationProvider_MultipleStates;
-    }
-
-    @Override
-    public Map<String, String> getEventHoverToolTipInfo(ITimeEvent event, long hoverTime) {
-        /*
-         * TODO: Add the XML elements to support adding extra information in the
-         * tooltips and implement this
-         */
-        return Collections.EMPTY_MAP;
-    }
-
-    @Override
-    public void postDrawEvent(ITimeEvent event, Rectangle bounds, GC gc) {
-        /*
-         * TODO Add the XML elements to support texts in intervals and implement
-         * this
-         */
-    }
-
-    @Override
-    public void postDrawEntry(ITimeGraphEntry entry, Rectangle bounds, GC gc) {
-    }
-
-    /**
-     * Loads the states from a {@link TmfXmlUiStrings#TIME_GRAPH_VIEW} XML
-     * element
-     *
-     * @param viewElement
-     *            The XML view element
-     */
-    public void loadNewStates(@NonNull Element viewElement) {
-        stateValues.clear();
-        stateIndex.clear();
-        List<Element> states = XmlUtils.getChildElements(viewElement, TmfXmlStrings.DEFINED_VALUE);
-
-        for (Element state : states) {
-            int value = Integer.parseInt(state.getAttribute(TmfXmlStrings.VALUE));
-            String name = state.getAttribute(TmfXmlStrings.NAME);
-            String color = state.getAttribute(TmfXmlStrings.COLOR);
-
-            // FIXME Allow this case
-            if (value < 0) {
-                return;
-            }
-
-            final RGB colorRGB = (color.startsWith(TmfXmlStrings.COLOR_PREFIX)) ? parseColor(color) : calcColor(value);
-
-            StateItem item = new StateItem(colorRGB, name);
-
-            Integer index = stateIndex.get(value);
-            if (index == null) {
-                /* Add the new state value */
-                stateIndex.put(value, stateValues.size());
-                stateValues.add(item);
-            } else {
-                /* Override a previous state value */
-                stateValues.set(index, item);
-            }
-        }
-        Display.getDefault().asyncExec(new Runnable() {
-            @Override
-            public void run() {
-                fireColorSettingsChanged();
-            }
-        });
-    }
-
-    private static RGB parseColor(String color) {
-        RGB colorRGB;
-        Integer hex = Integer.parseInt(color.substring(1), 16);
-        int hex1 = hex.intValue() % 256;
-        int hex2 = (hex.intValue() / 256) % 256;
-        int hex3 = (hex.intValue() / (256 * 256)) % 256;
-        colorRGB = new RGB(hex3, hex2, hex1);
-        return colorRGB;
-    }
-
-    private static RGB calcColor(int value) {
-        int x = (value * 97) % 1530;
-        int r = 0, g = 0, b = 0;
-        if (x >= 0 && x < 255) {
-            r = 255;
-            g = x;
-            b = 0;
-        }
-        if (x >= 255 && x < 510) {
-            r = 510 - x;
-            g = 255;
-            b = 0;
-        }
-        if (x >= 510 && x < 765) {
-            r = 0;
-            g = 255;
-            b = x - 510;
-        }
-        if (x >= 765 && x < 1020) {
-            r = 0;
-            g = 1020 - x;
-            b = 255;
-        }
-        if (x >= 1020 && x < 1275) {
-            r = x - 1020;
-            g = 0;
-            b = 255;
-        }
-        if (x >= 1275 && x <= 1530) {
-            r = 255;
-            g = 0;
-            b = 1530 - x;
-        }
-        return new RGB(r, g, b);
-    }
-
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java
deleted file mode 100644 (file)
index b8af05b..0000000
+++ /dev/null
@@ -1,568 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014, 2016 École Polytechnique de Montréal
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *   Florian Wininger - Initial API and implementation
- *   Geneviève Bastien - Review of the initial implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.analysis.xml.ui.views.timegraph;
-
-import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.tracecompass.common.core.NonNullUtils;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.Activator;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings;
-import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.XmlViewInfo;
-import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.statesystem.core.StateSystemUtils;
-import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
-import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.model.readonly.TmfXmlReadOnlyModelFactory;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
-import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.tracecompass.tmf.analysis.xml.ui.views.timegraph.XmlEntry.EntryDisplayType;
-import org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems;
-import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
-import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
-import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
-import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider2;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent;
-import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry;
-import org.w3c.dom.Element;
-
-import com.google.common.collect.Iterables;
-
-/**
- * This view displays state system data in a time graph view. It uses an XML
- * {@link TmfXmlUiStrings#TIME_GRAPH_VIEW} element from an XML file. This
- * element defines which entries from the state system will be shown and also
- * gives additional information on the presentation of the view (states, colors,
- * etc)
- *
- * @author Florian Wininger
- */
-public class XmlTimeGraphView extends AbstractTimeGraphView {
-
-    /** View ID. */
-    public static final @NonNull String ID = "org.eclipse.linuxtools.tmf.analysis.xml.ui.views.timegraph"; //$NON-NLS-1$
-
-    private static final String[] DEFAULT_COLUMN_NAMES = new String[] {
-            Messages.XmlTimeGraphView_ColumnName,
-            Messages.XmlTimeGraphView_ColumnId,
-            Messages.XmlTimeGraphView_ColumnParentId,
-    };
-
-    private static final String[] DEFAULT_FILTER_COLUMN_NAMES = new String[] {
-            Messages.XmlTimeGraphView_ColumnName,
-            Messages.XmlTimeGraphView_ColumnId
-    };
-
-    /** The relative weight of the sash */
-    private static final int[] fWeight = { 1, 2 };
-
-    private static final String EMPTY_STRING = ""; //$NON-NLS-1$
-    private static final @NonNull String SPLIT_STRING = "/"; //$NON-NLS-1$
-
-    private final @NonNull XmlViewInfo fViewInfo = new XmlViewInfo(ID);
-    private final ITmfXmlModelFactory fFactory;
-
-    // ------------------------------------------------------------------------
-    // Constructors
-    // ------------------------------------------------------------------------
-
-    /**
-     * Default constructor
-     */
-    public XmlTimeGraphView() {
-        super(ID, new XmlPresentationProvider());
-        setWeight(fWeight);
-        setTreeColumns(DEFAULT_COLUMN_NAMES);
-        setTreeLabelProvider(new XmlTreeLabelProvider());
-        setFilterColumns(DEFAULT_FILTER_COLUMN_NAMES);
-        setFilterLabelProvider(new XmlTreeLabelProvider());
-        setEntryComparator(new XmlEntryComparator());
-        this.addPartPropertyListener(new IPropertyChangeListener() {
-            @Override
-            public void propertyChange(PropertyChangeEvent event) {
-                if (event.getProperty().equals(TmfXmlUiStrings.XML_OUTPUT_DATA)) {
-                    Object newValue = event.getNewValue();
-                    if (newValue instanceof String) {
-                        String data = (String) newValue;
-                        fViewInfo.setViewData(data);
-                        loadNewXmlView();
-                    }
-                }
-            }
-        });
-
-        fFactory = TmfXmlReadOnlyModelFactory.getInstance();
-    }
-
-    private void loadNewXmlView() {
-        rebuild();
-    }
-
-    private void setViewTitle(final String title) {
-        Display.getDefault().asyncExec(new Runnable() {
-            @Override
-            public void run() {
-                setPartName(title);
-            }
-        });
-
-    }
-
-    @Override
-    protected String getNextText() {
-        return Messages.XmlTimeGraphView_NextText;
-    }
-
-    @Override
-    protected String getNextTooltip() {
-        return Messages.XmlTimeGraphView_NextTooltip;
-    }
-
-    @Override
-    protected String getPrevText() {
-        return Messages.XmlTimeGraphView_PreviousText;
-    }
-
-    @Override
-    protected String getPrevTooltip() {
-        return Messages.XmlTimeGraphView_PreviousInterval;
-    }
-
-    /**
-     * Default label provider, it shows name, id and parent columns
-     *
-     * TODO: There should be a way to define columns in the XML
-     */
-    private static class XmlTreeLabelProvider extends TreeLabelProvider {
-
-        @Override
-        public String getColumnText(Object element, int columnIndex) {
-            XmlEntry entry = (XmlEntry) element;
-
-            if (DEFAULT_COLUMN_NAMES[columnIndex].equals(Messages.XmlTimeGraphView_ColumnName)) {
-                return entry.getName();
-            } else if (DEFAULT_COLUMN_NAMES[columnIndex].equals(Messages.XmlTimeGraphView_ColumnId)) {
-                return entry.getId();
-            } else if (DEFAULT_COLUMN_NAMES[columnIndex].equals(Messages.XmlTimeGraphView_ColumnParentId)) {
-                return entry.getParentId();
-            }
-            return EMPTY_STRING;
-        }
-
-    }
-
-    private static class XmlEntryComparator implements Comparator<ITimeGraphEntry> {
-
-        @Override
-        public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) {
-
-            int result = 0;
-
-            if ((o1 instanceof XmlEntry) && (o2 instanceof XmlEntry)) {
-                XmlEntry entry1 = (XmlEntry) o1;
-                XmlEntry entry2 = (XmlEntry) o2;
-                result = entry1.getTrace().getStartTime().compareTo(entry2.getTrace().getStartTime());
-                if (result == 0) {
-                    result = entry1.getTrace().getName().compareTo(entry2.getTrace().getName());
-                }
-                if (result == 0) {
-                    result = entry1.getName().compareTo(entry2.getName());
-                }
-            }
-
-            if (result == 0) {
-                result = o1.getStartTime() < o2.getStartTime() ? -1 : o1.getStartTime() > o2.getStartTime() ? 1 : 0;
-            }
-
-            return result;
-        }
-    }
-
-    // ------------------------------------------------------------------------
-    // Internal
-    // ------------------------------------------------------------------------
-
-    @Override
-    protected void buildEntryList(ITmfTrace trace, ITmfTrace parentTrace, IProgressMonitor monitor) {
-
-        /*
-         * Get the view element from the XML file. If the element can't be
-         * found, return.
-         */
-        Element viewElement = fViewInfo.getViewElement(TmfXmlUiStrings.TIME_GRAPH_VIEW);
-        if (viewElement == null) {
-            return;
-        }
-        ITimeGraphPresentationProvider2 pres = this.getPresentationProvider();
-        if (pres instanceof XmlPresentationProvider) {
-            /*
-             * TODO: Each entry of a line could have their own states/color.
-             * That will require an update to the presentation provider
-             */
-            ((XmlPresentationProvider) pres).loadNewStates(viewElement);
-        }
-
-        String title = fViewInfo.getViewTitle(viewElement);
-        if (title == null) {
-            title = Messages.XmlTimeGraphView_DefaultTitle;
-        }
-        setViewTitle(title);
-        Set<String> analysisIds = fViewInfo.getViewAnalysisIds(viewElement);
-
-        List<Element> entries = XmlUtils.getChildElements(viewElement, TmfXmlUiStrings.ENTRY_ELEMENT);
-        Set<XmlEntry> entryList = new TreeSet<>(getEntryComparator());
-        if (monitor.isCanceled()) {
-            return;
-        }
-
-        Set<@NonNull ITmfAnalysisModuleWithStateSystems> stateSystemModules = new HashSet<>();
-        if (analysisIds.isEmpty()) {
-            /*
-             * No analysis specified, take all state system analysis modules
-             */
-            Iterables.addAll(stateSystemModules, TmfTraceUtils.getAnalysisModulesOfClass(trace, ITmfAnalysisModuleWithStateSystems.class));
-        } else {
-            for (String moduleId : analysisIds) {
-                moduleId = checkNotNull(moduleId);
-                ITmfAnalysisModuleWithStateSystems module = TmfTraceUtils.getAnalysisModuleOfClass(trace, ITmfAnalysisModuleWithStateSystems.class, moduleId);
-                if (module != null) {
-                    stateSystemModules.add(module);
-                }
-            }
-        }
-
-        for (ITmfAnalysisModuleWithStateSystems module : stateSystemModules) {
-            IStatus status = module.schedule();
-            if (!status.isOK()) {
-                return;
-            }
-            if (!module.waitForInitialization()) {
-                return;
-            }
-            for (ITmfStateSystem ssq : module.getStateSystems()) {
-                ssq.waitUntilBuilt();
-
-                long startTime = ssq.getStartTime();
-                long endTime = ssq.getCurrentEndTime();
-                XmlEntry groupEntry = new XmlEntry(-1, trace, trace.getName(), ssq);
-                entryList.add(groupEntry);
-                setStartTime(Math.min(getStartTime(), startTime));
-                setEndTime(Math.max(getEndTime(), endTime));
-
-                /* Add children entry of this entry for each line */
-                for (Element entry : entries) {
-                    buildEntry(entry, groupEntry, -1);
-                }
-            }
-        }
-
-        addToEntryList(parentTrace, new ArrayList<TimeGraphEntry>(entryList));
-
-        if (parentTrace.equals(getTrace())) {
-            refresh();
-        }
-        for (XmlEntry traceEntry : entryList) {
-            if (monitor.isCanceled()) {
-                return;
-            }
-            long startTime = traceEntry.getStateSystem().getStartTime();
-            long endTime = traceEntry.getStateSystem().getCurrentEndTime() + 1;
-            buildStatusEvent(traceEntry, monitor, startTime, endTime);
-        }
-    }
-
-    private void buildEntry(Element entryElement, XmlEntry parentEntry, int baseQuark) {
-        /* Get the attribute string to display */
-        String path = entryElement.getAttribute(TmfXmlUiStrings.PATH);
-        if (path.isEmpty()) {
-            path = TmfXmlStrings.WILDCARD;
-        }
-
-        /*
-         * Make sure the XML element has either a display attribute or entries,
-         * otherwise issue a warning
-         */
-
-        List<Element> displayElements = XmlUtils.getChildElements(entryElement, TmfXmlUiStrings.DISPLAY_ELEMENT);
-        List<Element> entryElements = XmlUtils.getChildElements(entryElement, TmfXmlUiStrings.ENTRY_ELEMENT);
-
-        if (displayElements.isEmpty() && entryElements.isEmpty()) {
-            Activator.logWarning(String.format("XML view: entry for %s should have either a display element or entry elements", path)); //$NON-NLS-1$
-            return;
-        }
-
-        ITmfStateSystem ss = parentEntry.getStateSystem();
-
-        /* Get the list of quarks to process with this path */
-        String[] paths = path.split(SPLIT_STRING);
-        int i = 0;
-        List<Integer> quarks = Collections.singletonList(baseQuark);
-
-        try {
-            while (i < paths.length) {
-                List<Integer> subQuarks = new LinkedList<>();
-                /* Replace * by .* to have a regex string */
-                String name = paths[i].replaceAll("\\*", ".*"); //$NON-NLS-1$ //$NON-NLS-2$
-                for (int relativeQuark : quarks) {
-                    for (int quark : ss.getSubAttributes(relativeQuark, false, name)) {
-                        subQuarks.add(quark);
-                    }
-                }
-                quarks = subQuarks;
-                i++;
-            }
-
-            /* Process each quark */
-            XmlEntry currentEntry = parentEntry;
-            Element displayElement = null;
-            Map<String, XmlEntry> entryMap = new HashMap<>();
-            if (!displayElements.isEmpty()) {
-                displayElement = displayElements.get(0);
-            }
-            for (int quark : quarks) {
-                currentEntry = parentEntry;
-                /* Process the current entry, if specified */
-                if (displayElement != null) {
-                    currentEntry = processEntry(entryElement, displayElement, parentEntry, quark, ss);
-                    entryMap.put(currentEntry.getId(), currentEntry);
-                }
-                /* Process the children entry of this entry */
-                for (Element subEntryEl : entryElements) {
-                    buildEntry(subEntryEl, currentEntry, quark);
-                }
-            }
-            if (!entryMap.isEmpty()) {
-                buildTree(entryMap, parentEntry);
-            }
-        } catch (AttributeNotFoundException e) {
-        }
-    }
-
-    private XmlEntry processEntry(@NonNull Element entryElement, @NonNull Element displayEl,
-            @NonNull XmlEntry parentEntry, int quark, ITmfStateSystem ss) {
-        /*
-         * Get the start time and end time of this entry from the display
-         * attribute
-         */
-        ITmfXmlStateAttribute display = fFactory.createStateAttribute(displayEl, parentEntry);
-        int displayQuark = display.getAttributeQuark(quark, null);
-        if (displayQuark == IXmlStateSystemContainer.ERROR_QUARK) {
-            return new XmlEntry(quark, parentEntry.getTrace(),
-                    String.format("Unknown display quark for %s", ss.getAttributeName(quark)), ss); //$NON-NLS-1$
-        }
-
-        long entryStart = ss.getStartTime();
-        long entryEnd = ss.getCurrentEndTime();
-
-        try {
-
-            ITmfStateInterval oneInterval = ss.querySingleState(entryStart, displayQuark);
-
-            /* The entry start is the first non-null interval */
-            while (oneInterval.getStateValue().isNull()) {
-                long ts = oneInterval.getEndTime() + 1;
-                if (ts > ss.getCurrentEndTime()) {
-                    break;
-                }
-                oneInterval = ss.querySingleState(ts, displayQuark);
-            }
-            entryStart = oneInterval.getStartTime();
-
-            /* The entry end is the last non-null interval */
-            oneInterval = ss.querySingleState(entryEnd, displayQuark);
-            while (oneInterval.getStateValue().isNull()) {
-                long ts = oneInterval.getStartTime() - 1;
-                if (ts < ss.getStartTime()) {
-                    break;
-                }
-                oneInterval = ss.querySingleState(ts, displayQuark);
-            }
-            entryEnd = oneInterval.getEndTime();
-
-        } catch (AttributeNotFoundException | StateSystemDisposedException e) {
-        }
-
-        return new XmlEntry(quark, displayQuark, parentEntry.getTrace(), ss.getAttributeName(quark),
-                entryStart, entryEnd, EntryDisplayType.DISPLAY, ss, entryElement);
-    }
-
-    private void buildStatusEvent(XmlEntry traceEntry, @NonNull IProgressMonitor monitor, long start, long end) {
-        long resolution = (end - start) / getDisplayWidth();
-        long startTime = Math.max(start, traceEntry.getStartTime());
-        long endTime = Math.min(end + 1, traceEntry.getEndTime());
-        List<ITimeEvent> eventList = getEventList(traceEntry, startTime, endTime, resolution, monitor);
-        if (monitor.isCanceled()) {
-            return;
-        }
-        traceEntry.setEventList(eventList);
-        redraw();
-
-        for (ITimeGraphEntry entry : traceEntry.getChildren()) {
-            if (monitor.isCanceled()) {
-                return;
-            }
-            XmlEntry xmlEntry = (XmlEntry) entry;
-            buildStatusEvent(xmlEntry, monitor, start, end);
-        }
-    }
-
-    /** Build a tree using getParentId() and getId() */
-    private static void buildTree(Map<String, XmlEntry> entryMap, XmlEntry rootEntry) {
-        for (XmlEntry entry : entryMap.values()) {
-            boolean root = true;
-            if (!entry.getParentId().isEmpty()) {
-                XmlEntry parent = entryMap.get(entry.getParentId());
-                /*
-                 * Associate the parent entry only if their time overlap. A
-                 * child entry may start before its parent, for example at the
-                 * beginning of the trace if a parent has not yet appeared in
-                 * the state system. We just want to make sure that the entry
-                 * didn't start after the parent ended or ended before the
-                 * parent started.
-                 */
-                if (parent != null &&
-                        !(entry.getStartTime() > parent.getEndTime() ||
-                                entry.getEndTime() < parent.getStartTime())) {
-                    parent.addChild(entry);
-                    root = false;
-                }
-            }
-            if (root) {
-                rootEntry.addChild(entry);
-            }
-        }
-    }
-
-    @Override
-    protected List<ITimeEvent> getEventList(TimeGraphEntry entry, long startTime, long endTime, long resolution, IProgressMonitor monitor) {
-        if (!(entry instanceof XmlEntry)) {
-            return Collections.EMPTY_LIST;
-        }
-        XmlEntry xmlEntry = (XmlEntry) entry;
-        ITmfStateSystem ssq = xmlEntry.getStateSystem();
-        final long realStart = Math.max(startTime, entry.getStartTime());
-        final long realEnd = Math.min(endTime, entry.getEndTime());
-        if (realEnd <= realStart) {
-            return null;
-        }
-        List<ITimeEvent> eventList = null;
-        int quark = xmlEntry.getDisplayQuark();
-
-        try {
-            if (xmlEntry.getType() == EntryDisplayType.DISPLAY) {
-
-                List<ITmfStateInterval> statusIntervals = StateSystemUtils.queryHistoryRange(ssq, quark, realStart, realEnd - 1, resolution, monitor);
-                eventList = new ArrayList<>(statusIntervals.size());
-                long lastEndTime = -1;
-                for (ITmfStateInterval statusInterval : statusIntervals) {
-                    if (monitor.isCanceled()) {
-                        return null;
-                    }
-                    int status = statusInterval.getStateValue().unboxInt();
-                    long time = statusInterval.getStartTime();
-                    long duration = statusInterval.getEndTime() - time + 1;
-                    if (!statusInterval.getStateValue().isNull()) {
-                        if (lastEndTime != time && lastEndTime != -1) {
-                            eventList.add(new TimeEvent(entry, lastEndTime, time - lastEndTime));
-                        }
-                        eventList.add(new TimeEvent(entry, time, duration, status));
-                    } else if (lastEndTime == -1 || time + duration >= endTime) {
-                        // add null event if it intersects the start or end time
-                        eventList.add(new NullTimeEvent(entry, time, duration));
-                    }
-                    lastEndTime = time + duration;
-                }
-            }
-        } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException | StateSystemDisposedException e) {
-            /* Ignored */
-        }
-        return eventList;
-    }
-
-    @Override
-    protected List<ILinkEvent> getLinkList(long startTime, long endTime, long resolution, IProgressMonitor monitor) {
-        /* TODO: not implemented yet, need XML to go along */
-        return Collections.EMPTY_LIST;
-    }
-
-    /**
-     * This method will pre-filter the traces that contain analysis modules
-     * supported by this view, whether they are from a trace or an experiment.
-     */
-    @Override
-    protected Iterable<ITmfTrace> getTracesToBuild(ITmfTrace trace) {
-        /*
-         * Get the view element from the XML file. If the element can't be
-         * found, return.
-         */
-        Element viewElement = fViewInfo.getViewElement(TmfXmlUiStrings.TIME_GRAPH_VIEW);
-        if (viewElement == null) {
-            return super.getTracesToBuild(trace);
-        }
-
-        Set<String> analysisIds = fViewInfo.getViewAnalysisIds(viewElement);
-        Set<ITmfTrace> traces = new HashSet<>();
-
-        for (ITmfTrace aTrace : TmfTraceManager.getTraceSetWithExperiment(trace)) {
-            if (aTrace == null) {
-                continue;
-            }
-            if ((analysisIds.isEmpty() && TmfTraceUtils.getAnalysisModulesOfClass(aTrace, ITmfAnalysisModuleWithStateSystems.class).iterator().hasNext())) {
-                /*
-                 * No analysis ID specified, so this trace will be built only if
-                 * it has state system modules
-                 */
-                traces.add(aTrace);
-            } else {
-                /* Build this trace only if it has one the requested modules */
-                for (String moduleId : analysisIds) {
-                    if (TmfTraceUtils.getAnalysisModuleOfClass(aTrace, ITmfAnalysisModuleWithStateSystems.class, NonNullUtils.checkNotNull(moduleId)) != null) {
-                        traces.add(aTrace);
-                    }
-                }
-            }
-        }
-        if (traces.isEmpty()) {
-            return super.getTracesToBuild(trace);
-        }
-        return traces;
-    }
-}
diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/messages.properties b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/messages.properties
deleted file mode 100644 (file)
index b978928..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-###############################################################################
-# Copyright (c) 2015 Ericsson
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Eclipse Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/epl-v10.html
-#
-# Contributors:
-#     Ericsson - Initial API and implementation
-###############################################################################
-XmlPresentationProvider_MultipleStates=(multiple)
-XmlTimeGraphView_ColumnId=ID
-XmlTimeGraphView_ColumnName=Name
-XmlTimeGraphView_ColumnParentId=ParentID
-XmlTimeGraphView_DefaultTitle=Xml State Provider
-XmlTimeGraphView_NextText=Next Interval
-XmlTimeGraphView_NextTooltip=Select next interval in time graph
-XmlTimeGraphView_PreviousInterval=Select previous interval in time graph
-XmlTimeGraphView_PreviousText=Previous Interval
-XmlTimeGraphView_UselessEndPath=There should be an XML <entry > for path {0} in the view's XML otherwise the last level is useless
This page took 0.246492 seconds and 5 git commands to generate.