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
.Date
;
18 import java
.util
.HashMap
;
21 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEvent
;
22 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventReference
;
23 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventSource
;
24 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventType
;
25 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.parsers
.custom
.CustomTraceDefinition
.OutputColumn
;
28 public class CustomEvent
extends TmfEvent
{
30 protected static final String TIMESTAMP_INPUT_FORMAT_KEY
= "CE_TS_I_F"; //$NON-NLS-1$
31 protected static final String NO_MESSAGE
= ""; //$NON-NLS-1$
32 public static final byte TIMESTAMP_SCALE
= -3;
34 protected CustomTraceDefinition fDefinition
;
35 protected Map
<String
, String
> fData
;
36 private String
[] fColumnData
;
38 public CustomEvent(CustomTraceDefinition definition
, TmfEvent other
) {
40 fDefinition
= definition
;
41 fData
= new HashMap
<String
, String
>();
44 public CustomEvent(CustomTraceDefinition definition
, TmfTimestamp timestamp
, TmfEventSource source
, TmfEventType type
, TmfEventReference reference
) {
45 super(timestamp
, source
, type
, reference
);
46 fDefinition
= definition
;
47 fData
= new HashMap
<String
, String
>();
50 public CustomEvent(CustomTraceDefinition definition
, TmfTimestamp originalTS
, TmfTimestamp effectiveTS
, TmfEventSource source
, TmfEventType type
, TmfEventReference reference
) {
51 super(originalTS
, effectiveTS
, source
, type
, reference
);
52 fDefinition
= definition
;
53 fData
= new HashMap
<String
, String
>();
57 public TmfTimestamp
getTimestamp() {
58 if (fData
!= null) processData();
59 return super.getTimestamp();
63 public TmfTimestamp
getOriginalTimestamp() {
64 if (fData
!= null) processData();
65 return super.getOriginalTimestamp();
68 public String
[] extractItemFields() {
69 if (fData
!= null) processData();
73 private void processData() {
74 String timeStampString
= fData
.get(CustomTraceDefinition
.TAG_TIMESTAMP
);
75 String timeStampInputFormat
= fData
.get(TIMESTAMP_INPUT_FORMAT_KEY
);
77 if (timeStampInputFormat
!= null && timeStampString
!= null) {
78 SimpleDateFormat dateFormat
= new SimpleDateFormat(timeStampInputFormat
);
80 date
= dateFormat
.parse(timeStampString
);
81 fOriginalTimestamp
= fEffectiveTimestamp
= new TmfTimestamp(date
.getTime(), TIMESTAMP_SCALE
);
82 } catch (ParseException e
) {
83 fOriginalTimestamp
= fEffectiveTimestamp
= TmfTimestamp
.Zero
;
86 fOriginalTimestamp
= fEffectiveTimestamp
= TmfTimestamp
.Zero
;
90 fColumnData
= new String
[fDefinition
.outputs
.size()];
91 for (OutputColumn outputColumn
: fDefinition
.outputs
) {
92 String value
= fData
.get(outputColumn
.name
);
93 if (outputColumn
.name
.equals(CustomTraceDefinition
.TAG_TIMESTAMP
) && date
!= null) {
94 SimpleDateFormat dateFormat
= new SimpleDateFormat(fDefinition
.timeStampOutputFormat
);
95 fColumnData
[i
++] = dateFormat
.format(date
);
97 fColumnData
[i
++] = (value
!= null ? value
: ""); //$NON-NLS-1$