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
.TmfEvent
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventContent
;
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
.parser
.ITmfEventParser
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfContext
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLocation
;
27 import org
.eclipse
.linuxtools
.tmf
.stubs
.trace
.TmfTraceStub
;
29 public class TmfUml2SDTestTrace
implements ITmfEventParser
{
32 @SuppressWarnings({ "unchecked", "nls" })
33 public TmfEvent
parseNextEvent(ITmfTrace
<?
> eventStream
, TmfContext context
) throws IOException
{
34 if (! (eventStream
instanceof TmfTraceStub
)) {
38 // Highly inefficient...
39 RandomAccessFile stream
= ((TmfTraceStub
) eventStream
).getStream();
41 String name
= eventStream
.getName();
42 name
= name
.substring(name
.lastIndexOf('/') + 1);
46 location
= ((TmfLocation
<Long
>) (context
.getLocation())).getLocation();
47 stream
.seek(location
);
50 long ts
= stream
.readLong();
51 String source
= stream
.readUTF();
52 String type
= stream
.readUTF();
53 String reference
= stream
.readUTF();
54 String sender
= stream
.readUTF();
55 String receiver
= stream
.readUTF();
56 String signal
= stream
.readUTF();
58 String
[] labels
= {"sender", "receiver", "signal"};
60 TmfEventType tmfEventType
= new TmfEventType(type
, labels
);
61 TmfEvent tmfEvent
= new TmfEvent(new TmfTimestamp(ts
, (byte)-9), source
, tmfEventType
, reference
);
65 content
+= "," + receiver
;
66 content
+= "," + signal
;
69 TmfEventContent tmfContent
= new TmfEventContent(tmfEvent
, content
) {
71 public void parseContent() {
72 String raw
= (String
) fRawContent
;
73 int i
= raw
.indexOf(",");
74 String sender
= raw
.substring(1, i
);
75 int k
= raw
.indexOf(",", i
+1);
76 String receiver
= raw
.substring(i
+1, k
);
77 i
= raw
.indexOf(",", k
+1);
78 String signal
= raw
.substring(k
+1, raw
.length() - 1);
79 fFields
= new Object
[3];
80 fFields
[0] = new TmfEventField(this, "sender", sender
);
81 fFields
[1] = new TmfEventField(this, "receiver", receiver
);;
82 fFields
[2] = new TmfEventField(this, "signal", signal
);;
85 tmfEvent
.setContent(tmfContent
);
88 } catch (EOFException e
) {