Made BigBang/BigCrunch/Zero ITmfTimestamp:s
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / parsers / custom / CustomEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2010 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 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.parsers.custom;
14
15 import java.text.ParseException;
16 import java.text.SimpleDateFormat;
17 import java.util.Date;
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
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.trace.ITmfTrace;
27 import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;
28
29 public class CustomEvent extends TmfEvent {
30
31 protected static final String TIMESTAMP_INPUT_FORMAT_KEY = "CE_TS_I_F"; //$NON-NLS-1$
32 protected static final String NO_MESSAGE = ""; //$NON-NLS-1$
33 public static final byte TIMESTAMP_SCALE = -3;
34
35 protected CustomTraceDefinition fDefinition;
36 protected Map<String, String> fData;
37 private TmfEventField[] fColumnData;
38
39 public CustomEvent(CustomTraceDefinition definition) {
40 fDefinition = definition;
41 fData = new HashMap<String, String>();
42 }
43
44 public CustomEvent(CustomTraceDefinition definition, TmfEvent other) {
45 super(other);
46 fDefinition = definition;
47 fData = new HashMap<String, String>();
48 }
49
50 public CustomEvent(CustomTraceDefinition definition, ITmfTrace<?> parentTrace, ITmfTimestamp timestamp, String source, TmfEventType type, String reference) {
51 super(parentTrace, timestamp, source, type, reference);
52 fDefinition = definition;
53 fData = new HashMap<String, String>();
54 }
55
56 @Override
57 public ITmfTimestamp getTimestamp() {
58 if (fData != null) processData();
59 return super.getTimestamp();
60 }
61
62 public TmfEventField[] extractItemFields() {
63 if (fData != null) processData();
64 return fColumnData;
65 }
66
67 private void processData() {
68 String timeStampString = fData.get(CustomTraceDefinition.TAG_TIMESTAMP);
69 String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
70 Date date = null;
71 if (timeStampInputFormat != null && timeStampString != null) {
72 SimpleDateFormat dateFormat = new SimpleDateFormat(timeStampInputFormat);
73 try {
74 date = dateFormat.parse(timeStampString);
75 fTimestamp = new TmfTimestamp(date.getTime(), TIMESTAMP_SCALE);
76 } catch (ParseException e) {
77 fTimestamp = TmfTimestamp.Zero;
78 }
79 } else {
80 fTimestamp = TmfTimestamp.Zero;
81 }
82
83 int i = 0;
84 fColumnData = new TmfEventField[fDefinition.outputs.size()];
85 for (OutputColumn outputColumn : fDefinition.outputs) {
86 String value = fData.get(outputColumn.name);
87 if (outputColumn.name.equals(CustomTraceDefinition.TAG_TIMESTAMP) && date != null) {
88 SimpleDateFormat dateFormat = new SimpleDateFormat(fDefinition.timeStampOutputFormat);
89 fColumnData[i++] = new TmfEventField(getContent(), outputColumn.name, dateFormat.format(date));
90 } else {
91 fColumnData[i++] = new TmfEventField(getContent(), outputColumn.name, (value != null ? value : "")); //$NON-NLS-1$
92 }
93 }
94 fData = null;
95 }
96 }
This page took 0.041005 seconds and 6 git commands to generate.