Refactor TmfTrace and dependencies - move parseEvent to ITmfEventParser
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.tests / widgetStubs / org / eclipse / linuxtools / tmf / ui / tests / uml2sd / trace / TmfUml2SDTestTrace.java
1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.linuxtools.tmf.ui.tests.uml2sd.trace;
13
14 import java.io.EOFException;
15 import java.io.IOException;
16 import java.io.RandomAccessFile;
17
18 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
19 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
20 import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
21 import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
22 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
23 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
24 import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
25 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
26 import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
27 import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
28
29 public class TmfUml2SDTestTrace implements ITmfEventParser<TmfEvent> {
30
31 ITmfTrace<TmfEvent> fEventStream;
32
33 public TmfUml2SDTestTrace() {
34 }
35
36 public TmfUml2SDTestTrace(ITmfTrace<TmfEvent> eventStream) {
37 fEventStream = eventStream;
38 }
39
40 public void setTrace(ITmfTrace<TmfEvent> eventStream) {
41 fEventStream = eventStream;
42 }
43
44 @Override
45 @SuppressWarnings({ "unchecked", "nls" })
46 public TmfEvent parseEvent(ITmfContext context) {
47 if (! (fEventStream instanceof TmfTraceStub)) {
48 return null;
49 }
50
51 // Highly inefficient...
52 RandomAccessFile stream = ((TmfTraceStub) fEventStream).getStream();
53
54 // String name = eventStream.getName();
55 // name = name.substring(name.lastIndexOf('/') + 1);
56
57 long location = 0;
58 if (context != null)
59 location = ((TmfLocation<Long>) (context.getLocation())).getLocation();
60
61 try {
62 stream.seek(location);
63
64 long ts = stream.readLong();
65 String source = stream.readUTF();
66 String type = stream.readUTF();
67 String reference = stream.readUTF();
68 String sender = stream.readUTF();
69 String receiver = stream.readUTF();
70 String signal = stream.readUTF();
71
72 String[] labels = {"sender", "receiver", "signal"};
73
74 TmfEventType tmfEventType = new TmfEventType("UnitTest", type, TmfEventField.makeRoot(labels));
75
76 String content = "[";
77 content += sender;
78 content += "," + receiver;
79 content += "," + signal;
80 content += "]";
81
82 // Pre-parse the content
83 TmfEventField[] fields = new TmfEventField[3];
84 fields[0] = new TmfEventField("sender", sender);
85 fields[1] = new TmfEventField("receiver", receiver);
86 fields[2] = new TmfEventField("signal", signal);
87
88 ITmfEventField tmfContent = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, content, fields);
89 TmfEvent tmfEvent = new TmfEvent(fEventStream, new TmfTimestamp(ts, -9), source, tmfEventType, tmfContent, reference);
90
91 return tmfEvent;
92 } catch (final EOFException e) {
93 } catch (final IOException e) {
94 }
95 return null;
96 }
97
98 }
This page took 0.033072 seconds and 6 git commands to generate.