Commit | Line | Data |
---|---|---|
c3c5c786 FC |
1 | /*******************************************************************************\r |
2 | * Copyright (c) 2010 Ericsson\r | |
3 | * \r | |
4 | * All rights reserved. This program and the accompanying materials are\r | |
5 | * made available under the terms of the Eclipse Public License v1.0 which\r | |
6 | * accompanies this distribution, and is available at\r | |
7 | * http://www.eclipse.org/legal/epl-v10.html\r | |
8 | * \r | |
9 | * Contributors:\r | |
10 | * Patrick Tasse - Initial API and implementation\r | |
11 | *******************************************************************************/\r | |
12 | \r | |
13 | package org.eclipse.linuxtools.tmf.ui.parsers.custom;\r | |
14 | \r | |
15 | import java.text.ParseException;\r | |
16 | import java.text.SimpleDateFormat;\r | |
17 | import java.util.Date;\r | |
18 | import java.util.HashMap;\r | |
19 | import java.util.Map;\r | |
20 | \r | |
4df4581d | 21 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;\r |
6c13869b | 22 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent;\r |
5d3e8747 | 23 | import org.eclipse.linuxtools.tmf.core.event.TmfEventField;\r |
6c13869b FC |
24 | import org.eclipse.linuxtools.tmf.core.event.TmfEventType;\r |
25 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;\r | |
26 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r | |
c3c5c786 FC |
27 | import org.eclipse.linuxtools.tmf.ui.parsers.custom.CustomTraceDefinition.OutputColumn;\r |
28 | \r | |
29 | public class CustomEvent extends TmfEvent {\r | |
30 | \r | |
3b38ea61 FC |
31 | protected static final String TIMESTAMP_INPUT_FORMAT_KEY = "CE_TS_I_F"; //$NON-NLS-1$\r |
32 | protected static final String NO_MESSAGE = ""; //$NON-NLS-1$\r | |
c3c5c786 FC |
33 | public static final byte TIMESTAMP_SCALE = -3;\r |
34 | \r | |
35 | protected CustomTraceDefinition fDefinition;\r | |
36 | protected Map<String, String> fData;\r | |
5d3e8747 | 37 | private TmfEventField[] fColumnData;\r |
c3c5c786 | 38 | \r |
4bf17f4a | 39 | public CustomEvent(CustomTraceDefinition definition) {\r |
40 | fDefinition = definition;\r | |
41 | fData = new HashMap<String, String>();\r | |
42 | }\r | |
43 | \r | |
c3c5c786 FC |
44 | public CustomEvent(CustomTraceDefinition definition, TmfEvent other) {\r |
45 | super(other);\r | |
46 | fDefinition = definition;\r | |
47 | fData = new HashMap<String, String>();\r | |
48 | }\r | |
49 | \r | |
c64aa527 | 50 | public CustomEvent(CustomTraceDefinition definition, ITmfTrace<?> parentTrace, ITmfTimestamp timestamp, String source, TmfEventType type, String reference) {\r |
4bf17f4a | 51 | super(parentTrace, timestamp, source, type, reference);\r |
c3c5c786 FC |
52 | fDefinition = definition;\r |
53 | fData = new HashMap<String, String>();\r | |
54 | }\r | |
55 | \r | |
c3c5c786 | 56 | @Override\r |
4df4581d | 57 | public ITmfTimestamp getTimestamp() {\r |
c3c5c786 FC |
58 | if (fData != null) processData();\r |
59 | return super.getTimestamp();\r | |
60 | }\r | |
61 | \r | |
5d3e8747 | 62 | public TmfEventField[] extractItemFields() {\r |
c3c5c786 FC |
63 | if (fData != null) processData();\r |
64 | return fColumnData;\r | |
65 | }\r | |
66 | \r | |
67 | private void processData() {\r | |
68 | String timeStampString = fData.get(CustomTraceDefinition.TAG_TIMESTAMP);\r | |
69 | String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);\r | |
70 | Date date = null;\r | |
71 | if (timeStampInputFormat != null && timeStampString != null) {\r | |
72 | SimpleDateFormat dateFormat = new SimpleDateFormat(timeStampInputFormat);\r | |
73 | try {\r | |
74 | date = dateFormat.parse(timeStampString);\r | |
ce970a71 | 75 | fTimestamp = new TmfTimestamp(date.getTime(), TIMESTAMP_SCALE);\r |
c3c5c786 | 76 | } catch (ParseException e) {\r |
ce970a71 | 77 | fTimestamp = TmfTimestamp.Zero;\r |
c3c5c786 FC |
78 | }\r |
79 | } else {\r | |
ce970a71 | 80 | fTimestamp = TmfTimestamp.Zero;\r |
c3c5c786 FC |
81 | }\r |
82 | \r | |
83 | int i = 0;\r | |
5d3e8747 | 84 | fColumnData = new TmfEventField[fDefinition.outputs.size()];\r |
c3c5c786 FC |
85 | for (OutputColumn outputColumn : fDefinition.outputs) {\r |
86 | String value = fData.get(outputColumn.name);\r | |
87 | if (outputColumn.name.equals(CustomTraceDefinition.TAG_TIMESTAMP) && date != null) {\r | |
88 | SimpleDateFormat dateFormat = new SimpleDateFormat(fDefinition.timeStampOutputFormat);\r | |
4c564a2d | 89 | fColumnData[i++] = new TmfEventField(outputColumn.name, dateFormat.format(date));\r |
c3c5c786 | 90 | } else {\r |
4c564a2d | 91 | fColumnData[i++] = new TmfEventField(outputColumn.name, (value != null ? value : "")); //$NON-NLS-1$\r |
c3c5c786 FC |
92 | }\r |
93 | }\r | |
c3c5c786 FC |
94 | fData = null;\r |
95 | }\r | |
96 | }\r |