| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2010, 2014 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.linuxtools.tmf.core.parsers.custom; |
| 14 | |
| 15 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; |
| 16 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent; |
| 17 | import org.eclipse.linuxtools.tmf.core.event.TmfEventType; |
| 18 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
| 19 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
| 20 | |
| 21 | /** |
| 22 | * Trace event for custom XML traces. |
| 23 | * |
| 24 | * @author Patrick Tassé |
| 25 | * @since 3.0 |
| 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 | setType(new CustomXmlEventType(definition)); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Build a custom trace event from an existing TmfEvent. |
| 42 | * |
| 43 | * @param definition |
| 44 | * Trace definition |
| 45 | * @param other |
| 46 | * Other TmfEvent to copy |
| 47 | */ |
| 48 | public CustomXmlEvent(CustomXmlTraceDefinition definition, TmfEvent other) { |
| 49 | super(definition, other); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Full constructor |
| 54 | * |
| 55 | * @param definition |
| 56 | * Trace definition |
| 57 | * @param parentTrace |
| 58 | * Parent trace object |
| 59 | * @param timestamp |
| 60 | * Timestamp of the event |
| 61 | * @param source |
| 62 | * Source of the event |
| 63 | * @param type |
| 64 | * Event type |
| 65 | * @param reference |
| 66 | * Reference of the event |
| 67 | */ |
| 68 | public CustomXmlEvent(CustomXmlTraceDefinition definition, ITmfTrace parentTrace, ITmfTimestamp timestamp, String source, TmfEventType type, String reference) { |
| 69 | super(definition, parentTrace, timestamp, source, type, reference); |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public void setContent(ITmfEventField content) { |
| 74 | super.setContent(content); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Parse an entry. |
| 79 | * |
| 80 | * @param value Value |
| 81 | * @param name Name |
| 82 | * @param inputAction Input action |
| 83 | * @param inputFormat Input format |
| 84 | */ |
| 85 | public void parseInput(String value, String name, int inputAction, String inputFormat) { |
| 86 | if (value.length() == 0) { |
| 87 | return; |
| 88 | } |
| 89 | if (inputAction == CustomTraceDefinition.ACTION_SET) { |
| 90 | fData.put(name, value); |
| 91 | if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { |
| 92 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat); |
| 93 | } |
| 94 | } else if (inputAction == CustomTraceDefinition.ACTION_APPEND) { |
| 95 | String s = fData.get(name); |
| 96 | if (s != null) { |
| 97 | fData.put(name, s + value); |
| 98 | } else { |
| 99 | fData.put(name, value); |
| 100 | } |
| 101 | if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { |
| 102 | String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY); |
| 103 | if (timeStampInputFormat != null) { |
| 104 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + inputFormat); |
| 105 | } else { |
| 106 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat); |
| 107 | } |
| 108 | } |
| 109 | } else if (inputAction == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) { |
| 110 | String s = fData.get(name); |
| 111 | if (s != null) { |
| 112 | fData.put(name, s + " | " + value); //$NON-NLS-1$ |
| 113 | } else { |
| 114 | fData.put(name, value); |
| 115 | } |
| 116 | if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { |
| 117 | String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY); |
| 118 | if (timeStampInputFormat != null) { |
| 119 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + inputFormat); //$NON-NLS-1$ |
| 120 | } else { |
| 121 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat); |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | } |