1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.tmf
.ui
.tests
.uml2sd
.trace
;
14 import java
.io
.EOFException
;
15 import java
.io
.IOException
;
16 import java
.io
.RandomAccessFile
;
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
.tests
.stubs
.trace
.TmfTraceStub
;
29 * Parser implementation for Uml2SD Test Traces.
32 public class TmfUml2SDTestTrace
implements ITmfEventParser
{
34 ITmfTrace fEventStream
;
39 public TmfUml2SDTestTrace() {
44 * @param eventStream ITmfTrace implementation
46 public TmfUml2SDTestTrace(ITmfTrace eventStream
) {
47 fEventStream
= eventStream
;
51 * @param eventStream ITmfTrace implementation to set
53 public void setTrace(ITmfTrace eventStream
) {
54 fEventStream
= eventStream
;
58 @SuppressWarnings({ "nls" })
59 public TmfEvent
parseEvent(ITmfContext context
) {
60 if (! (fEventStream
instanceof TmfTraceStub
)) {
64 // Highly inefficient...
65 RandomAccessFile stream
= ((TmfTraceStub
) fEventStream
).getStream();
67 // String name = eventStream.getName();
68 // name = name.substring(name.lastIndexOf('/') + 1);
71 if (context
!= null) {
72 location
= (Long
) context
.getLocation().getLocationInfo();
76 stream
.seek(location
);
78 long ts
= stream
.readLong();
79 String source
= stream
.readUTF();
80 String type
= stream
.readUTF();
81 String reference
= stream
.readUTF();
82 String sender
= stream
.readUTF();
83 String receiver
= stream
.readUTF();
84 String signal
= stream
.readUTF();
86 String
[] labels
= {"sender", "receiver", "signal"};
88 TmfEventType tmfEventType
= new TmfEventType("UnitTest", type
, TmfEventField
.makeRoot(labels
));
92 content
+= "," + receiver
;
93 content
+= "," + signal
;
96 // Pre-parse the content
97 TmfEventField
[] fields
= new TmfEventField
[3];
98 fields
[0] = new TmfEventField("sender", sender
);
99 fields
[1] = new TmfEventField("receiver", receiver
);
100 fields
[2] = new TmfEventField("signal", signal
);
102 ITmfEventField tmfContent
= new TmfEventField(ITmfEventField
.ROOT_FIELD_ID
, content
, fields
);
103 TmfEvent tmfEvent
= new TmfEvent(fEventStream
, new TmfTimestamp(ts
, -9), source
, tmfEventType
, tmfContent
, reference
);
106 } catch (final EOFException e
) {
107 } catch (final IOException e
) {