Commit | Line | Data |
---|---|---|
6151d86c | 1 | /******************************************************************************* |
53f17e49 | 2 | * Copyright (c) 2010, 2016 Ericsson |
6151d86c PT |
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 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.core.parsers.custom; |
6151d86c | 14 | |
ca5b04ad | 15 | import org.eclipse.jdt.annotation.NonNull; |
2bdf0193 AM |
16 | import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; |
17 | import org.eclipse.tracecompass.tmf.core.event.TmfEvent; | |
18 | import org.eclipse.tracecompass.tmf.core.event.TmfEventType; | |
f5cc6ed1 | 19 | import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag; |
2bdf0193 AM |
20 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; |
21 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
6151d86c | 22 | |
a0a88f65 AM |
23 | /** |
24 | * Trace event for custom XML traces. | |
25 | * | |
26 | * @author Patrick Tassé | |
27 | */ | |
6151d86c PT |
28 | public class CustomXmlEvent extends CustomEvent { |
29 | ||
efeeb733 GB |
30 | private String fLastExtraFieldName = null; |
31 | ||
a0a88f65 AM |
32 | /** |
33 | * Constructor defining only the trace definition | |
34 | * | |
35 | * @param definition | |
36 | * Trace definition | |
37 | */ | |
6151d86c PT |
38 | public CustomXmlEvent(CustomXmlTraceDefinition definition) { |
39 | super(definition); | |
6151d86c PT |
40 | } |
41 | ||
a0a88f65 AM |
42 | /** |
43 | * Build a custom trace event from an existing TmfEvent. | |
44 | * | |
45 | * @param definition | |
46 | * Trace definition | |
47 | * @param other | |
48 | * Other TmfEvent to copy | |
49 | */ | |
ca5b04ad | 50 | public CustomXmlEvent(CustomXmlTraceDefinition definition, @NonNull TmfEvent other) { |
6151d86c PT |
51 | super(definition, other); |
52 | } | |
53 | ||
a0a88f65 AM |
54 | /** |
55 | * Full constructor | |
56 | * | |
57 | * @param definition | |
58 | * Trace definition | |
59 | * @param parentTrace | |
60 | * Parent trace object | |
61 | * @param timestamp | |
62 | * Timestamp of the event | |
a0a88f65 AM |
63 | * @param type |
64 | * Event type | |
a0a88f65 | 65 | */ |
e1de2fd4 AM |
66 | public CustomXmlEvent(CustomXmlTraceDefinition definition, |
67 | ITmfTrace parentTrace, ITmfTimestamp timestamp, TmfEventType type) { | |
68 | super(definition, parentTrace, timestamp, type); | |
6151d86c PT |
69 | } |
70 | ||
71 | @Override | |
72 | public void setContent(ITmfEventField content) { | |
73 | super.setContent(content); | |
74 | } | |
75 | ||
a0a88f65 AM |
76 | /** |
77 | * Parse an entry. | |
78 | * | |
79 | * @param value Value | |
80 | * @param name Name | |
81 | * @param inputAction Input action | |
82 | * @param inputFormat Input format | |
f5cc6ed1 | 83 | * @deprecated Use {@link #parseInput(String, Tag, String, int, String)} instead. |
a0a88f65 | 84 | */ |
f5cc6ed1 | 85 | @Deprecated |
6151d86c | 86 | public void parseInput(String value, String name, int inputAction, String inputFormat) { |
f5cc6ed1 PT |
87 | } |
88 | ||
89 | /** | |
90 | * Parse an entry. | |
91 | * | |
92 | * @param value Value | |
93 | * @param inputTag Input tag | |
94 | * @param inputName Input name | |
95 | * @param inputAction Input action | |
96 | * @param inputFormat Input format | |
97 | * @since 2.1 | |
98 | */ | |
99 | public void parseInput(String value, Tag inputTag, String inputName, int inputAction, String inputFormat) { | |
6151d86c PT |
100 | if (value.length() == 0) { |
101 | return; | |
102 | } | |
f5cc6ed1 | 103 | Object key = (inputTag.equals(Tag.OTHER) ? inputName : inputTag); |
efeeb733 GB |
104 | if (key.equals(Tag.EXTRA_FIELD_NAME)) { |
105 | // If tag extra field name, save the extra field name for | |
106 | // the next extra field value and add the field to the map | |
107 | fLastExtraFieldName = value; | |
108 | if (!fData.containsKey(value)) { | |
109 | fData.put(value, null); | |
110 | } | |
111 | return; | |
112 | } else if (key.equals(Tag.EXTRA_FIELD_VALUE)) { | |
113 | // If tag extra field value, use the extra field name as key | |
114 | if (fLastExtraFieldName == null) { | |
115 | return; | |
116 | } | |
117 | key = fLastExtraFieldName; | |
118 | } | |
6151d86c | 119 | if (inputAction == CustomTraceDefinition.ACTION_SET) { |
f5cc6ed1 PT |
120 | fData.put(key, value); |
121 | if (key.equals(Tag.TIMESTAMP)) { | |
122 | fData.put(Key.TIMESTAMP_INPUT_FORMAT, inputFormat); | |
6151d86c PT |
123 | } |
124 | } else if (inputAction == CustomTraceDefinition.ACTION_APPEND) { | |
f5cc6ed1 | 125 | String s = fData.get(key); |
6151d86c | 126 | if (s != null) { |
f5cc6ed1 | 127 | fData.put(key, s + value); |
6151d86c | 128 | } else { |
f5cc6ed1 | 129 | fData.put(key, value); |
6151d86c | 130 | } |
f5cc6ed1 PT |
131 | if (key.equals(Tag.TIMESTAMP)) { |
132 | String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT); | |
6151d86c | 133 | if (timeStampInputFormat != null) { |
f5cc6ed1 | 134 | fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + inputFormat); |
6151d86c | 135 | } else { |
f5cc6ed1 | 136 | fData.put(Key.TIMESTAMP_INPUT_FORMAT, inputFormat); |
6151d86c PT |
137 | } |
138 | } | |
139 | } else if (inputAction == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) { | |
f5cc6ed1 | 140 | String s = fData.get(key); |
6151d86c | 141 | if (s != null) { |
efeeb733 | 142 | fData.put(key, s + CustomTraceDefinition.SEPARATOR + value); |
6151d86c | 143 | } else { |
f5cc6ed1 | 144 | fData.put(key, value); |
6151d86c | 145 | } |
f5cc6ed1 PT |
146 | if (key.equals(Tag.TIMESTAMP)) { |
147 | String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT); | |
6151d86c | 148 | if (timeStampInputFormat != null) { |
f5cc6ed1 | 149 | fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + " | " + inputFormat); //$NON-NLS-1$ |
6151d86c | 150 | } else { |
f5cc6ed1 | 151 | fData.put(Key.TIMESTAMP_INPUT_FORMAT, inputFormat); |
6151d86c PT |
152 | } |
153 | } | |
154 | } | |
155 | } | |
156 | ||
157 | } |