custom.parsers: bug 494697 Define event names in custom parsers
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / parsers / custom / CustomXmlEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2016 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.tracecompass.tmf.core.parsers.custom;
14
15 import org.eclipse.jdt.annotation.NonNull;
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;
19 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
20 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
21
22 /**
23 * Trace event for custom XML traces.
24 *
25 * @author Patrick Tassé
26 */
27 public class CustomXmlEvent extends CustomEvent {
28
29 /**
30 * Constructor defining only the trace definition
31 *
32 * @param definition
33 * Trace definition
34 */
35 public CustomXmlEvent(CustomXmlTraceDefinition definition) {
36 super(definition);
37 }
38
39 /**
40 * Build a custom trace event from an existing TmfEvent.
41 *
42 * @param definition
43 * Trace definition
44 * @param other
45 * Other TmfEvent to copy
46 */
47 public CustomXmlEvent(CustomXmlTraceDefinition definition, @NonNull TmfEvent other) {
48 super(definition, other);
49 }
50
51 /**
52 * Full constructor
53 *
54 * @param definition
55 * Trace definition
56 * @param parentTrace
57 * Parent trace object
58 * @param timestamp
59 * Timestamp of the event
60 * @param type
61 * Event type
62 */
63 public CustomXmlEvent(CustomXmlTraceDefinition definition,
64 ITmfTrace parentTrace, ITmfTimestamp timestamp, TmfEventType type) {
65 super(definition, parentTrace, timestamp, type);
66 }
67
68 @Override
69 public void setContent(ITmfEventField content) {
70 super.setContent(content);
71 }
72
73 /**
74 * Parse an entry.
75 *
76 * @param value Value
77 * @param name Name
78 * @param inputAction Input action
79 * @param inputFormat Input format
80 */
81 public void parseInput(String value, String name, int inputAction, String inputFormat) {
82 if (value.length() == 0) {
83 return;
84 }
85 if (inputAction == CustomTraceDefinition.ACTION_SET) {
86 fData.put(name, value);
87 if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
88 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat);
89 }
90 } else if (inputAction == CustomTraceDefinition.ACTION_APPEND) {
91 String s = fData.get(name);
92 if (s != null) {
93 fData.put(name, s + value);
94 } else {
95 fData.put(name, value);
96 }
97 if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
98 String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
99 if (timeStampInputFormat != null) {
100 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + inputFormat);
101 } else {
102 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat);
103 }
104 }
105 } else if (inputAction == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
106 String s = fData.get(name);
107 if (s != null) {
108 fData.put(name, s + " | " + value); //$NON-NLS-1$
109 } else {
110 fData.put(name, value);
111 }
112 if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
113 String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
114 if (timeStampInputFormat != null) {
115 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + inputFormat); //$NON-NLS-1$
116 } else {
117 fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat);
118 }
119 }
120 }
121 }
122
123 }
This page took 0.036665 seconds and 5 git commands to generate.