tmf: Add support for custom event type by text line or XML element
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / parsers / custom / CustomXmlTrace.java
index 8af0cc739abd72bccb62aef67672ce3ac72b2dc2..cca70ea65a108efeda0f1560913eb071ee406e90 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2015 Ericsson
+ * Copyright (c) 2010, 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
@@ -13,6 +13,8 @@
 
 package org.eclipse.tracecompass.tmf.core.parsers.custom;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
@@ -31,6 +33,7 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.tracecompass.internal.tmf.core.Activator;
 import org.eclipse.tracecompass.internal.tmf.core.parsers.custom.CustomEventAspects;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile;
@@ -72,10 +75,10 @@ public class CustomXmlTrace extends TmfTrace implements ITmfPersistentlyIndexabl
     private static final int CONFIDENCE = 100;
 
     private final CustomXmlTraceDefinition fDefinition;
-    private final CustomXmlEventType fEventType;
+    private final ITmfEventField fRootField;
     private final CustomXmlInputElement fRecordInputElement;
     private BufferedRandomAccessFile fFile;
-    private final String fTraceTypeId;
+    private final @NonNull String fTraceTypeId;
 
     private static final char SEPARATOR = ':';
     private static final String CUSTOM_XML_TRACE_TYPE_PREFIX = "custom.xml.trace" + SEPARATOR; //$NON-NLS-1$
@@ -90,7 +93,7 @@ public class CustomXmlTrace extends TmfTrace implements ITmfPersistentlyIndexabl
      */
     public CustomXmlTrace(final CustomXmlTraceDefinition definition) {
         fDefinition = definition;
-        fEventType = new CustomXmlEventType(fDefinition);
+        fRootField = CustomEventType.getRootField(definition);
         fRecordInputElement = getRecordInputElement(fDefinition.rootInputElement);
         fTraceTypeId = buildTraceTypeId(definition.categoryName, definition.definitionName);
         setCacheSize(DEFAULT_CACHE_SIZE);
@@ -156,7 +159,7 @@ public class CustomXmlTrace extends TmfTrace implements ITmfPersistentlyIndexabl
     }
 
     @Override
-    public Iterable<ITmfEventAspect> getEventAspects() {
+    public Iterable<ITmfEventAspect<?>> getEventAspects() {
         return CustomEventAspects.generateAspects(fDefinition);
     }
 
@@ -506,13 +509,18 @@ public class CustomXmlTrace extends TmfTrace implements ITmfPersistentlyIndexabl
      * @return The extracted event
      */
     public CustomXmlEvent extractEvent(final Element element, final CustomXmlInputElement inputElement) {
-        final CustomXmlEvent event = new CustomXmlEvent(fDefinition, this, TmfTimestamp.ZERO, fEventType);
+        CustomXmlEventType eventType = new CustomXmlEventType(checkNotNull(fDefinition.definitionName), fRootField);
+        final CustomXmlEvent event = new CustomXmlEvent(fDefinition, this, TmfTimestamp.ZERO, eventType);
         event.setContent(new CustomEventContent(event, new StringBuffer()));
         parseElement(element, event, inputElement);
         return event;
     }
 
     private void parseElement(final Element element, final CustomXmlEvent event, final CustomXmlInputElement inputElement) {
+        String eventType = inputElement.getEventType();
+        if (eventType != null && event.getType() instanceof CustomEventType) {
+            ((CustomEventType) event.getType()).setName(eventType);
+        }
         if (inputElement.getInputName() != null && !inputElement.getInputName().equals(CustomXmlTraceDefinition.TAG_IGNORE)) {
             event.parseInput(parseElement(element, new StringBuffer()).toString(), inputElement.getInputName(), inputElement.getInputAction(), inputElement.getInputFormat());
         }
This page took 0.026415 seconds and 5 git commands to generate.