tmf.xml: Add mapping group to XML description
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.analysis.xml.core / src / org / eclipse / tracecompass / internal / tmf / analysis / xml / core / pattern / stateprovider / XmlPatternStateProvider.java
index 3712dad1e27e762b75bbffe5fc242e68fe1a990e..b0c3c597b2e4ae66f4051c0fd52d3a69653f835c 100644 (file)
@@ -20,6 +20,7 @@ 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.TmfXmlMapEntry;
 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;
@@ -52,6 +53,8 @@ public class XmlPatternStateProvider extends AbstractTmfStateProvider implements
     /** List of all Locations */
     private final @NonNull Set<@NonNull TmfXmlLocation> fLocations;
 
+    private final @NonNull Map<@NonNull String, @NonNull Set<@NonNull TmfXmlMapEntry>> fMappingGroups;
+
     /** Map for stored values */
     private final @NonNull Map<@NonNull String, @NonNull String> fStoredFields = new HashMap<>();
 
@@ -82,6 +85,7 @@ public class XmlPatternStateProvider extends AbstractTmfStateProvider implements
         Element doc = XmlUtils.getElementInFile(pathString, TmfXmlStrings.PATTERN, fStateId);
         if (doc == null) {
             fLocations = new HashSet<>();
+            fMappingGroups = new HashMap<>();
             Activator.logError("Failed to find a pattern in " + pathString); //$NON-NLS-1$
             return;
         }
@@ -115,6 +119,31 @@ public class XmlPatternStateProvider extends AbstractTmfStateProvider implements
         }
         fLocations = Collections.unmodifiableSet(locations);
 
+        /* parser for the mapping groups */
+        final @NonNull Map<@NonNull String, @NonNull Set<@NonNull TmfXmlMapEntry>> mapGroups = new HashMap<>();
+        NodeList mapNodes = doc.getElementsByTagName(TmfXmlStrings.MAPPING_GROUP);
+        for (int i = 0; i < mapNodes.getLength(); i++) {
+            Element map = (Element) mapNodes.item(i);
+            String id = map.getAttribute(TmfXmlStrings.ID);
+
+            Set<@NonNull TmfXmlMapEntry> entrySet = mapGroups.get(id);
+            if (entrySet == null) {
+                entrySet = new HashSet<>();
+                mapGroups.put(id, entrySet);
+            }
+
+            NodeList entryNodes = map.getElementsByTagName(TmfXmlStrings.ENTRY);
+            for (int j = 0; j < entryNodes.getLength(); j++) {
+                Element entryElement = (Element) entryNodes.item(j);
+                if (entryElement == null) {
+                    continue;
+                }
+                TmfXmlMapEntry entry = modelFactory.createMapEntry(entryElement, this);
+                entrySet.add(entry);
+            }
+        }
+        fMappingGroups = Collections.unmodifiableMap(mapGroups);
+
         /* parser for the event handlers */
         NodeList nodes = doc.getElementsByTagName(TmfXmlStrings.PATTERN_HANDLER);
         fHandler = modelFactory.createPatternEventHandler(NonNullUtils.checkNotNull((Element) nodes.item(0)), this);
@@ -209,4 +238,15 @@ public class XmlPatternStateProvider extends AbstractTmfStateProvider implements
     public @NonNull TmfXmlScenarioHistoryBuilder getHistoryBuilder() {
         return fHistoryBuilder;
     }
+
+    /**
+     * Get the list of state value handlers defined in this top level element
+     *
+     * @param id
+     *            The mapping group id
+     * @return The set of {@link TmfXmlMapEntry}
+     */
+    public @Nullable Set<@NonNull TmfXmlMapEntry> getMappingGroup(@NonNull String id) {
+        return fMappingGroups.get(id);
+    }
 }
\ No newline at end of file
This page took 0.026034 seconds and 5 git commands to generate.