tmf: Update copyright headers in tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.tests / widgetStubs / org / eclipse / linuxtools / tmf / ui / tests / uml2sd / trace / TmfUml2SDTestTrace.java
index a01011d02839dc52a69ba112cdfa23fcdb188490..bdfc326678875eead8c2c36f8ec6d3eca9787875 100644 (file)
@@ -1,11 +1,11 @@
 /*******************************************************************************
- * Copyright (c) 2011 Ericsson
- * 
+ * Copyright (c) 2011, 2013 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:
  *   Bernd Hufmann - Initial API and implementation
  *******************************************************************************/
@@ -15,38 +15,67 @@ import java.io.EOFException;
 import java.io.IOException;
 import java.io.RandomAccessFile;
 
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.TmfEventContent;
 import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
 import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.parser.ITmfEventParser;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
-import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
-import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
-import org.eclipse.linuxtools.tmf.stubs.trace.TmfTraceStub;
+import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
 
+/**
+ * Parser implementation for Uml2SD Test Traces.
+ *
+ */
 public class TmfUml2SDTestTrace implements ITmfEventParser {
-    
+
+    ITmfTrace fEventStream;
+
+    /**
+     * Default Constructor
+     */
+    public TmfUml2SDTestTrace() {
+    }
+
+    /**
+     * Constructor
+     * @param eventStream ITmfTrace implementation
+     */
+    public TmfUml2SDTestTrace(ITmfTrace eventStream) {
+        fEventStream = eventStream;
+    }
+
+    /**
+     * @param eventStream ITmfTrace implementation to set
+     */
+    public void setTrace(ITmfTrace eventStream) {
+        fEventStream = eventStream;
+    }
+
     @Override
-    @SuppressWarnings({ "unchecked", "nls" })    
-    public TmfEvent parseNextEvent(ITmfTrace<?> eventStream, TmfContext context) throws IOException {
-        if (! (eventStream instanceof TmfTraceStub)) {
+    @SuppressWarnings({ "nls" })
+    public ITmfEvent parseEvent(ITmfContext context) {
+        if (! (fEventStream instanceof TmfTraceStub)) {
             return null;
         }
 
         // Highly inefficient...
-        RandomAccessFile stream = ((TmfTraceStub) eventStream).getStream();
+        RandomAccessFile stream = ((TmfTraceStub) fEventStream).getStream();
 
-        String name = eventStream.getName();
-        name = name.substring(name.lastIndexOf('/') + 1);
+//        String name = eventStream.getName();
+//        name = name.substring(name.lastIndexOf('/') + 1);
 
         long location = 0;
-        if (context != null)
-            location = ((TmfLocation<Long>) (context.getLocation())).getLocation();
-        stream.seek(location);
+        if (context != null) {
+            location = (Long) context.getLocation().getLocationInfo();
+        }
 
         try {
+            stream.seek(location);
+
             long ts        = stream.readLong();
             String source  = stream.readUTF();
             String type    = stream.readUTF();
@@ -57,8 +86,7 @@ public class TmfUml2SDTestTrace implements ITmfEventParser {
 
             String[] labels = {"sender", "receiver", "signal"};
 
-            TmfEventType tmfEventType = new TmfEventType("UnitTest", type, labels);
-            TmfEvent tmfEvent = new TmfEvent(new TmfTimestamp(ts, (byte)-9), source, tmfEventType, reference);
+            TmfEventType tmfEventType = new TmfEventType("UnitTest", type, TmfEventField.makeRoot(labels));
 
             String content = "[";
             content += sender;
@@ -66,26 +94,18 @@ public class TmfUml2SDTestTrace implements ITmfEventParser {
             content += "," + signal;
             content += "]";
 
-            TmfEventContent tmfContent = new TmfEventContent(tmfEvent, content) {
-                @Override
-                public void parseContent() {
-                    String raw = (String) fRawContent;
-                    int i = raw.indexOf(",");
-                    String sender = raw.substring(1, i);
-                    int k = raw.indexOf(",", i+1);
-                    String receiver = raw.substring(i+1, k);
-                    i = raw.indexOf(",", k+1);
-                    String signal = raw.substring(k+1, raw.length() - 1);
-                    fFields = new Object[3];
-                    fFields[0] = new TmfEventField(this, "sender", sender);
-                    fFields[1] = new TmfEventField(this, "receiver", receiver);;
-                    fFields[2] = new TmfEventField(this, "signal", signal);;
-                }
-            };
-            tmfEvent.setContent(tmfContent);
+            // Pre-parse the content
+            TmfEventField[] fields = new TmfEventField[3];
+            fields[0] = new TmfEventField("sender", sender);
+            fields[1] = new TmfEventField("receiver", receiver);
+            fields[2] = new TmfEventField("signal", signal);
+
+            ITmfEventField tmfContent = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, content, fields);
+            ITmfEvent tmfEvent = new TmfEvent(fEventStream, new TmfTimestamp(ts, -9), source, tmfEventType, tmfContent, reference);
 
             return tmfEvent;
-        } catch (EOFException e) {
+        } catch (final EOFException e) {
+        } catch (final IOException e) {
         }
         return null;
     }
This page took 0.025104 seconds and 5 git commands to generate.