| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2010, 2013 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.internal.tmf.ui.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 | */ |
| 26 | public class CustomXmlEvent extends CustomEvent { |
| 27 | |
| 28 | /** |
| 29 | * Constructor defining only the trace definition |
| 30 | * |
| 31 | * @param definition |
| 32 | * Trace definition |
| 33 | */ |
| 34 | public CustomXmlEvent(CustomXmlTraceDefinition definition) { |
| 35 | super(definition); |
| 36 | setType(new CustomXmlEventType(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, 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 source |
| 61 | * Source of the event |
| 62 | * @param type |
| 63 | * Event type |
| 64 | * @param reference |
| 65 | * Reference of the event |
| 66 | */ |
| 67 | public CustomXmlEvent(CustomXmlTraceDefinition definition, ITmfTrace parentTrace, ITmfTimestamp timestamp, String source, TmfEventType type, String reference) { |
| 68 | super(definition, parentTrace, timestamp, source, type, reference); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public void setContent(ITmfEventField content) { |
| 73 | super.setContent(content); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Parse an entry. |
| 78 | * |
| 79 | * @param value Value |
| 80 | * @param name Name |
| 81 | * @param inputAction Input action |
| 82 | * @param inputFormat Input format |
| 83 | */ |
| 84 | public void parseInput(String value, String name, int inputAction, String inputFormat) { |
| 85 | if (value.length() == 0) { |
| 86 | return; |
| 87 | } |
| 88 | if (inputAction == CustomTraceDefinition.ACTION_SET) { |
| 89 | fData.put(name, value); |
| 90 | if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { |
| 91 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat); |
| 92 | } |
| 93 | } else if (inputAction == CustomTraceDefinition.ACTION_APPEND) { |
| 94 | String s = fData.get(name); |
| 95 | if (s != null) { |
| 96 | fData.put(name, s + value); |
| 97 | } else { |
| 98 | fData.put(name, value); |
| 99 | } |
| 100 | if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { |
| 101 | String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY); |
| 102 | if (timeStampInputFormat != null) { |
| 103 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + inputFormat); |
| 104 | } else { |
| 105 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat); |
| 106 | } |
| 107 | } |
| 108 | } else if (inputAction == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) { |
| 109 | String s = fData.get(name); |
| 110 | if (s != null) { |
| 111 | fData.put(name, s + " | " + value); //$NON-NLS-1$ |
| 112 | } else { |
| 113 | fData.put(name, value); |
| 114 | } |
| 115 | if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { |
| 116 | String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY); |
| 117 | if (timeStampInputFormat != null) { |
| 118 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + inputFormat); //$NON-NLS-1$ |
| 119 | } else { |
| 120 | fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | } |