fcf8dfbf3583f05e1e53e37d2572d58a9dbe86fb
1 /*******************************************************************************
2 * Copyright (c) 2009 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 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
;
15 import java
.io
.EOFException
;
16 import java
.io
.IOException
;
17 import java
.io
.RandomAccessFile
;
18 import java
.util
.Vector
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventField
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventType
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.parser
.ITmfEventParser
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfLocation
;
32 * <b><u>TmfEventParserStub</u></b>
34 * TODO: Implement me. Please.
36 @SuppressWarnings("nls")
37 public class TmfEventParserStub
implements ITmfEventParser
<TmfEvent
> {
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
43 private static final int NB_TYPES
= 10;
44 private final TmfEventType
[] fTypes
;
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
50 public TmfEventParserStub() {
51 fTypes
= new TmfEventType
[NB_TYPES
];
52 for (int i
= 0; i
< NB_TYPES
; i
++) {
53 final Vector
<String
> fields
= new Vector
<String
>();
54 for (int j
= 1; j
<= i
; j
++) {
55 final String field
= "Fmt-" + i
+ "-Fld-" + j
;
58 final String
[] fieldArray
= new String
[i
];
59 final ITmfEventField rootField
= TmfEventField
.makeRoot(fields
.toArray(fieldArray
));
60 fTypes
[i
] = new TmfEventType("UnitTest", "Type-" + i
, rootField
);
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
68 static final String typePrefix
= "Type-";
70 @SuppressWarnings("unchecked")
71 public ITmfEvent
parseNextEvent(final ITmfTrace
<TmfEvent
> eventStream
, final ITmfContext context
) throws IOException
{
73 if (! (eventStream
instanceof TmfTraceStub
))
76 // Highly inefficient...
77 final RandomAccessFile stream
= ((TmfTraceStub
) eventStream
).getStream();
78 // String name = eventStream.getName();
79 // name = name.substring(name.lastIndexOf('/') + 1);
81 // no need to use synchronized since it's already cover by the calling method
85 location
= ((TmfLocation
<Long
>) (context
.getLocation())).getLocation();
86 stream
.seek(location
);
89 final long ts
= stream
.readLong();
90 final String source
= stream
.readUTF();
91 final String type
= stream
.readUTF();
92 final Integer reference
= stream
.readInt();
93 final int typeIndex
= Integer
.parseInt(type
.substring(typePrefix
.length()));
94 final String
[] fields
= new String
[typeIndex
];
95 for (int i
= 0; i
< typeIndex
; i
++)
96 fields
[i
] = stream
.readUTF();
98 final StringBuffer content
= new StringBuffer("[");
100 content
.append(fields
[0]);
101 for (int i
= 1; i
< typeIndex
; i
++)
102 content
.append(", ").append(fields
[i
]);
105 final TmfEventField root
= new TmfEventField(ITmfEventField
.ROOT_FIELD_ID
, content
.toString());
106 final ITmfEvent event
= new TmfEvent(eventStream
,
107 new TmfTimestamp(ts
, -3, 0), // millisecs
108 source
, fTypes
[typeIndex
], root
, reference
.toString());
110 } catch (final EOFException e
) {
This page took 0.037121 seconds and 4 git commands to generate.