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
.event
.TmfEvent
;
19 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventContent
;
20 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventField
;
21 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventReference
;
22 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventSource
;
23 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventType
;
24 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
25 import org
.eclipse
.linuxtools
.tmf
.parser
.ITmfEventParser
;
26 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
;
27 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfContext
;
28 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfLocation
;
29 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfTraceStub
;
31 public class TmfUml2SDTestTrace
implements ITmfEventParser
{
34 @SuppressWarnings({ "unchecked", "nls" })
35 public TmfEvent
parseNextEvent(ITmfTrace eventStream
, TmfContext context
) throws IOException
{
36 if (! (eventStream
instanceof TmfTraceStub
)) {
40 // Highly inefficient...
41 RandomAccessFile stream
= ((TmfTraceStub
) eventStream
).getStream();
43 String name
= eventStream
.getName();
44 name
= name
.substring(name
.lastIndexOf('/') + 1);
48 location
= ((TmfLocation
<Long
>) (context
.getLocation())).getLocation();
49 stream
.seek(location
);
52 long ts
= stream
.readLong();
53 String source
= stream
.readUTF();
54 String type
= stream
.readUTF();
55 String reference
= stream
.readUTF();
56 String sender
= stream
.readUTF();
57 String receiver
= stream
.readUTF();
58 String signal
= stream
.readUTF();
60 TmfEventReference tmfReference
= new TmfEventReference(reference
);
61 TmfEventSource tmfSource
= new TmfEventSource(source
);
62 String
[] labels
= {"sender", "receiver", "signal"};
64 TmfEventType tmfEventType
= new TmfEventType(type
, labels
);
65 TmfEvent tmfEvent
= new TmfEvent(new TmfTimestamp(ts
, (byte)-9), tmfSource
, tmfEventType
, tmfReference
);
69 content
+= "," + receiver
;
70 content
+= "," + signal
;
73 TmfEventContent tmfContent
= new TmfEventContent(tmfEvent
, content
) {
75 public void parseContent() {
76 String raw
= (String
) fRawContent
;
77 int i
= raw
.indexOf(",");
78 String sender
= raw
.substring(1, i
);
79 int k
= raw
.indexOf(",", i
+1);
80 String receiver
= raw
.substring(i
+1, k
);
81 i
= raw
.indexOf(",", k
+1);
82 String signal
= raw
.substring(k
+1, raw
.length() - 1);
83 fFields
= new Object
[3];
84 fFields
[0] = new TmfEventField(this, "sender", sender
);
85 fFields
[1] = new TmfEventField(this, "receiver", receiver
);;
86 fFields
[2] = new TmfEventField(this, "signal", signal
);;
89 tmfEvent
.setContent(tmfContent
);
92 } catch (EOFException e
) {