1 /*******************************************************************************
2 * Copyright (c) 2010 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 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
;
15 import java
.text
.ParseException
;
16 import java
.text
.SimpleDateFormat
;
17 import java
.util
.Arrays
;
18 import java
.util
.Date
;
19 import java
.util
.HashMap
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventField
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventType
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTraceDefinition
.OutputColumn
;
30 public class CustomEvent
extends TmfEvent
{
32 protected static final String TIMESTAMP_INPUT_FORMAT_KEY
= "CE_TS_I_F"; //$NON-NLS-1$
33 protected static final String NO_MESSAGE
= ""; //$NON-NLS-1$
34 public static final byte TIMESTAMP_SCALE
= -3;
36 protected CustomTraceDefinition fDefinition
;
37 protected Map
<String
, String
> fData
;
38 private TmfEventField
[] fColumnData
;
40 public CustomEvent(CustomTraceDefinition definition
) {
41 fDefinition
= definition
;
42 fData
= new HashMap
<String
, String
>();
45 public CustomEvent(CustomTraceDefinition definition
, TmfEvent other
) {
47 fDefinition
= definition
;
48 fData
= new HashMap
<String
, String
>();
51 public CustomEvent(CustomTraceDefinition definition
, ITmfTrace
<?
> parentTrace
, ITmfTimestamp timestamp
, String source
, TmfEventType type
, String reference
) {
52 super(parentTrace
, timestamp
, source
, type
, reference
);
53 fDefinition
= definition
;
54 fData
= new HashMap
<String
, String
>();
58 public ITmfTimestamp
getTimestamp() {
59 if (fData
!= null) processData();
60 return super.getTimestamp();
63 public TmfEventField
[] extractItemFields() {
64 if (fData
!= null) processData();
68 private void processData() {
69 String timeStampString
= fData
.get(CustomTraceDefinition
.TAG_TIMESTAMP
);
70 String timeStampInputFormat
= fData
.get(TIMESTAMP_INPUT_FORMAT_KEY
);
72 if (timeStampInputFormat
!= null && timeStampString
!= null) {
73 SimpleDateFormat dateFormat
= new SimpleDateFormat(timeStampInputFormat
);
75 date
= dateFormat
.parse(timeStampString
);
76 fTimestamp
= new TmfTimestamp(date
.getTime(), TIMESTAMP_SCALE
);
77 } catch (ParseException e
) {
78 fTimestamp
= TmfTimestamp
.Zero
;
81 fTimestamp
= TmfTimestamp
.Zero
;
85 fColumnData
= new TmfEventField
[fDefinition
.outputs
.size()];
86 for (OutputColumn outputColumn
: fDefinition
.outputs
) {
87 String value
= fData
.get(outputColumn
.name
);
88 if (outputColumn
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
) && date
!= null) {
89 SimpleDateFormat dateFormat
= new SimpleDateFormat(fDefinition
.timeStampOutputFormat
);
90 fColumnData
[i
++] = new TmfEventField(outputColumn
.name
, dateFormat
.format(date
));
92 fColumnData
[i
++] = new TmfEventField(outputColumn
.name
, (value
!= null ? value
: "")); //$NON-NLS-1$