analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui.tests / widgetStubs / org / eclipse / tracecompass / tmf / ui / tests / uml2sd / trace / TmfUml2SDTestTrace.java
CommitLineData
73005152 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2011, 2014 Ericsson
64636df8 3 *
73005152
BH
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
64636df8 8 *
73005152
BH
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
2bdf0193 12package org.eclipse.tracecompass.tmf.ui.tests.uml2sd.trace;
73005152
BH
13
14import java.io.EOFException;
15import java.io.IOException;
16import java.io.RandomAccessFile;
17
2bdf0193
AM
18import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
19import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
20import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
21import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
22import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
23import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
24import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
25import org.eclipse.tracecompass.tmf.core.trace.ITmfEventParser;
26import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
27import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub;
73005152 28
64636df8
BH
29/**
30 * Parser implementation for Uml2SD Test Traces.
31 *
32 */
6256d8ad 33public class TmfUml2SDTestTrace implements ITmfEventParser {
64636df8 34
6256d8ad 35 ITmfTrace fEventStream;
7e6347b0 36
64636df8
BH
37 /**
38 * Default Constructor
39 */
7e6347b0
FC
40 public TmfUml2SDTestTrace() {
41 }
42
64636df8
BH
43 /**
44 * Constructor
45 * @param eventStream ITmfTrace implementation
46 */
6256d8ad 47 public TmfUml2SDTestTrace(ITmfTrace eventStream) {
7e6347b0
FC
48 fEventStream = eventStream;
49 }
50
64636df8
BH
51 /**
52 * @param eventStream ITmfTrace implementation to set
53 */
6256d8ad 54 public void setTrace(ITmfTrace eventStream) {
7e6347b0
FC
55 fEventStream = eventStream;
56 }
57
73005152 58 @Override
2771b032 59 public ITmfEvent parseEvent(ITmfContext context) {
7e6347b0 60 if (! (fEventStream instanceof TmfTraceStub)) {
73005152
BH
61 return null;
62 }
63
64 // Highly inefficient...
7e6347b0 65 RandomAccessFile stream = ((TmfTraceStub) fEventStream).getStream();
73005152 66
1f2f091b
BH
67// String name = eventStream.getName();
68// name = name.substring(name.lastIndexOf('/') + 1);
73005152
BH
69
70 long location = 0;
64636df8 71 if (context != null) {
5976d44a 72 location = (Long) context.getLocation().getLocationInfo();
64636df8 73 }
73005152
BH
74
75 try {
7e6347b0
FC
76 stream.seek(location);
77
73005152 78 long ts = stream.readLong();
e1de2fd4 79 stream.readUTF(); /* Previously source, now unused */
73005152 80 String type = stream.readUTF();
e1de2fd4 81 stream.readUTF(); /* Previously reference, now unused */
73005152
BH
82 String sender = stream.readUTF();
83 String receiver = stream.readUTF();
84 String signal = stream.readUTF();
85
73005152
BH
86 String[] labels = {"sender", "receiver", "signal"};
87
e600c338 88 TmfEventType tmfEventType = new TmfEventType(type, TmfEventField.makeRoot(labels));
73005152
BH
89
90 String content = "[";
91 content += sender;
92 content += "," + receiver;
93 content += "," + signal;
94 content += "]";
95
4c564a2d
FC
96 // Pre-parse the content
97 TmfEventField[] fields = new TmfEventField[3];
214cc822
AM
98 fields[0] = new TmfEventField("sender", sender, null);
99 fields[1] = new TmfEventField("receiver", receiver, null);
100 fields[2] = new TmfEventField("signal", signal, null);
64636df8 101
a4115405 102 ITmfEventField tmfContent = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, content, fields);
e1de2fd4 103 ITmfEvent tmfEvent = new TmfEvent(fEventStream, ITmfContext.UNKNOWN_RANK, new TmfTimestamp(ts, -9), tmfEventType, tmfContent);
73005152
BH
104
105 return tmfEvent;
7e6347b0
FC
106 } catch (final EOFException e) {
107 } catch (final IOException e) {
73005152
BH
108 }
109 return null;
110 }
111
112}
This page took 0.097105 seconds and 5 git commands to generate.