Remove the generic location (replace by Comparable)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core.tests / stubs / org / eclipse / linuxtools / tmf / tests / stubs / trace / TmfEventParserStub.java
1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.tests.stubs.trace;
14
15 import java.io.EOFException;
16 import java.io.IOException;
17 import java.io.RandomAccessFile;
18 import java.util.Vector;
19
20 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
21 import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
22 import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
23 import org.eclipse.linuxtools.tmf.core.event.TmfEventType;
24 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
25 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
26 import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
27 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
28
29 /**
30 * <b><u>TmfEventParserStub</u></b>
31 * <p>
32 * TODO: Implement me. Please.
33 */
34 @SuppressWarnings({"nls","javadoc"})
35 public class TmfEventParserStub implements ITmfEventParser {
36
37 // ------------------------------------------------------------------------
38 // Attributes
39 // ------------------------------------------------------------------------
40
41 private static final int NB_TYPES = 10;
42 private final TmfEventType[] fTypes;
43 private final ITmfTrace fEventStream;
44
45 // ------------------------------------------------------------------------
46 // Constructors
47 // ------------------------------------------------------------------------
48
49 public TmfEventParserStub(final ITmfTrace eventStream) {
50 fEventStream = eventStream;
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;
56 fields.add(field);
57 }
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);
61 }
62 }
63
64 // ------------------------------------------------------------------------
65 // Operators
66 // ------------------------------------------------------------------------
67
68 static final String typePrefix = "Type-";
69 @Override
70 public TmfEvent parseEvent(final ITmfContext context) {
71
72 if (! (fEventStream instanceof TmfTraceStub)) {
73 return null;
74 }
75
76 // Highly inefficient...
77 final RandomAccessFile stream = ((TmfTraceStub) fEventStream).getStream();
78 // String name = eventStream.getName();
79 // name = name.substring(name.lastIndexOf('/') + 1);
80
81 // no need to use synchronized since it's already cover by the calling method
82
83 long location = 0;
84 if (context != null && context.getLocation() != null) {
85 location = (Long) context.getLocation().getLocationData();
86 try {
87 stream.seek(location);
88
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();
97 }
98
99 final StringBuffer content = new StringBuffer("[");
100 if (typeIndex > 0) {
101 content.append(fields[0]);
102 }
103 for (int i = 1; i < typeIndex; i++) {
104 content.append(", ").append(fields[i]);
105 }
106 content.append("]");
107
108 final TmfEventField root = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, content.toString());
109 final TmfEvent event = new TmfEvent(fEventStream,
110 new TmfTimestamp(ts, -3, 0), // millisecs
111 source, fTypes[typeIndex], root, reference.toString());
112 return event;
113 } catch (final EOFException e) {
114 } catch (final IOException e) {
115 }
116 }
117 return null;
118 }
119
120 }
This page took 0.040725 seconds and 5 git commands to generate.