tmf: Bug 497038: Custom parser field names conflict with built-in tags
authorPatrick Tasse <patrick.tasse@gmail.com>
Wed, 29 Jun 2016 20:58:08 +0000 (16:58 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Wed, 20 Jul 2016 21:20:47 +0000 (17:20 -0400)
A new Tag enum is added as part of the custom parser definition model.

The 'tag' attribute is added to the XML definition.

For backward compatibility if the 'tag' attribute is not present when
loading a definition from XML, the Tag is determined from the 'name'
attribute.

In the internal payload data map of the custom event, the map's key is
changed from a String to an Object that can either be the Tag, a String,
or an enum constant, to ensure there is no conflict of keys.

If the tag is OTHER, the wizards should ensure that the user-entered
name does not conflict with one of the built-in tag labels.

Change-Id: If9bf65fb32d646cda4f24f28bf41941f1f5c85f6
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/76257
Reviewed-by: Hudson CI
21 files changed:
tmf/org.eclipse.tracecompass.tmf.core.tests/testfiles/txt/testTxtDefinition.xml
tmf/org.eclipse.tracecompass.tmf.core.tests/testfiles/xml/testDefinition.xml
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomEvent.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTraceDefinition.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtEvent.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTraceDefinition.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlEvent.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlInputAttribute.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlInputElement.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTrace.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTraceDefinition.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/Messages.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/messages.properties
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/parsers/custom/TestCustomTxtWizard.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/parsers/custom/TestCustomXmlWizard.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomTxtParserInputWizardPage.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomTxtParserOutputWizardPage.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomXmlParserInputWizardPage.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomXmlParserOutputWizardPage.java

index 25de0059188d8e62b66c1d1cd34d0f0a0970c11d..c21f6da13e567b26f0ddedc5165747e584a7d93e 100644 (file)
@@ -5,31 +5,31 @@
 <InputLine>
 <Cardinality max="2147483647" min="0"/>
 <RegEx>(\S*\s\S*) (.*\S)</RegEx>
-<InputData action="0" format="dd/MM/yyyy HH:mm:ss:SSS" name="Time Stamp"/>
-<InputData action="0" format="" name="Message"/>
+<InputData action="0" format="dd/MM/yyyy HH:mm:ss:SSS" name="Timestamp" tag="TIMESTAMP"/>
+<InputData action="0" format="" name="Message" tag="MESSAGE"/>
 <InputLine>
 <Cardinality max="2147483647" min="0"/>
 <RegEx>(.*\S)</RegEx>
-<InputData action="2" name="Message"/>
+<InputData action="2" tag="MESSAGE"/>
 </InputLine>
 </InputLine>
-<OutputColumn name="Time Stamp"/>
-<OutputColumn name="Message"/>
+<OutputColumn name="Time Stamp" tag="TIMESTAMP"/>
+<OutputColumn name="Message" tag="MESSAGE"/>
 </Definition>
 <Definition name="testtxtevname">
 <TimeStampOutputFormat>dd/MM/yyyy HH:mm:ss:SSS</TimeStampOutputFormat>
 <InputLine>
 <Cardinality max="2147483647" min="0"/>
 <RegEx>(\d*) (.*\S)</RegEx>
-<InputData action="0" format="Tn" name="Time Stamp"/>
-<InputData action="0" format="" name="Event type"/>
+<InputData action="0" format="Tn" name="Timestamp" tag="TIMESTAMP"/>
+<InputData action="0" name="Event type" tag="EVENT_TYPE"/>
 <InputLine>
 <Cardinality max="2147483647" min="0"/>
 <RegEx>(.*\S)</RegEx>
-<InputData action="2" name="Message"/>
+<InputData action="2" name="Message" tag="MESSAGE"/>
 </InputLine>
 </InputLine>
-<OutputColumn name="Time Stamp"/>
-<OutputColumn name="Event type"/>
+<OutputColumn name="Timestamp" tag="TIMESTAMP"/>
+<OutputColumn name="Event type" tag="EVENT_TYPE"/>
 </Definition>
 </CustomTxtTraceDefinitionList>
index f2ac3a6e537ccf7e7fc83a1735ae0502973a8210..3eddce1677299f1f5f3d08d525e540fd531d46f0 100644 (file)
@@ -4,26 +4,26 @@
 <TimeStampOutputFormat>HH:mm:ss:SSS</TimeStampOutputFormat>
 <InputElement name="trace">
 <InputElement logentry="true" name="element">
-<InputData action="0" format="" name="Message"/>
+<InputData action="0" name="Message" tag="MESSAGE"/>
 <Attribute name="time">
-<InputData action="0" format="dd/MM/yyyy HH:mm:ss:SSS" name="Time Stamp"/>
+<InputData action="0" format="dd/MM/yyyy HH:mm:ss:SSS" name="Timestamp" tag="TIMESTAMP"/>
 </Attribute>
 </InputElement>
 </InputElement>
-<OutputColumn name="Time Stamp"/>
-<OutputColumn name="Message"/>
+<OutputColumn name="Timestamp" tag="TIMESTAMP"/>
+<OutputColumn name="Message" tag="MESSAGE"/>
 </Definition>
 <Definition name="xmlevname">
 <TimeStampOutputFormat>HH:mm:ss:SSS</TimeStampOutputFormat>
 <InputElement name="trace">
 <InputElement logentry="true" name="element">
-<InputData action="0" format="" name="Event type"/>
+<InputData action="0" name="Event type" tag="EVENT_TYPE"/>
 <Attribute name="time">
-<InputData action="0" format="Tn" name="Time Stamp"/>
+<InputData action="0" format="Tn" name="Timestamp" tag="TIMESTAMP"/>
 </Attribute>
 </InputElement>
 </InputElement>
-<OutputColumn name="Time Stamp"/>
-<OutputColumn name="Event type"/>
+<OutputColumn name="Timestamp" tag="TIMESTAMP"/>
+<OutputColumn name="Event type" tag="EVENT_TYPE"/>
 </Definition>
 </CustomXMLTraceDefinitionList>
index e0e41ef6a2aca8e2a065b3b1cc8ba369723c5123..ef57420953934855c06785a72f47e9fefce65185 100644 (file)
@@ -24,6 +24,7 @@ import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
 import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
 import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat;
@@ -37,7 +38,16 @@ import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
  */
 public class CustomEvent extends TmfEvent {
 
-    /** Input format key */
+    /** Payload data map key
+     * @since 2.1*/
+    protected enum Key {
+        /** Timestamp input format */
+        TIMESTAMP_INPUT_FORMAT
+    }
+
+    /** Input format key
+     * @deprecated Use {@link Key#TIMESTAMP_INPUT_FORMAT} instead. */
+    @Deprecated
     protected static final String TIMESTAMP_INPUT_FORMAT_KEY = "CE_TS_I_F"; //$NON-NLS-1$
 
     /** Empty message */
@@ -55,8 +65,12 @@ public class CustomEvent extends TmfEvent {
     /** The trace to which this event belongs */
     protected CustomTraceDefinition fDefinition;
 
-    /** The payload data of this event, <field name, value> */
-    protected Map<String, String> fData;
+    /**
+     * The payload data of this event, where the key is one of: the {@link Tag},
+     * the field name string if the tag is {@link Tag#OTHER}, or
+     * {@link Key#TIMESTAMP_INPUT_FORMAT}.
+     */
+    protected Map<Object, String> fData;
 
     private TmfEventField[] fColumnData;
 
@@ -224,8 +238,8 @@ public class CustomEvent extends TmfEvent {
     }
 
     private void processData() {
-        String timestampString = fData.get(CustomTraceDefinition.TAG_TIMESTAMP);
-        String timestampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
+        String timestampString = fData.get(Tag.TIMESTAMP);
+        String timestampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT);
         ITmfTimestamp timestamp = null;
         if (timestampInputFormat != null && timestampString != null) {
             TmfTimestampFormat timestampFormat = new TmfTimestampFormat(timestampInputFormat);
@@ -241,7 +255,7 @@ public class CustomEvent extends TmfEvent {
         }
 
         // Update the custom event type of this event if set
-        String eventName = fData.get(CustomTraceDefinition.TAG_EVENT_TYPE);
+        String eventName = fData.get(Tag.EVENT_TYPE);
         ITmfEventType type = getType();
         if (eventName != null && type instanceof CustomEventType) {
             ((CustomEventType) type).setName(eventName);
@@ -250,8 +264,9 @@ public class CustomEvent extends TmfEvent {
         int i = 0;
         fColumnData = new TmfEventField[fDefinition.outputs.size()];
         for (OutputColumn outputColumn : fDefinition.outputs) {
-            String value = fData.get(outputColumn.name);
-            if (outputColumn.name.equals(CustomTraceDefinition.TAG_TIMESTAMP) && timestamp != null) {
+            Object key = (outputColumn.tag.equals(Tag.OTHER) ? outputColumn.name : outputColumn.tag);
+            String value = fData.get(key);
+            if (outputColumn.tag.equals(Tag.TIMESTAMP) && timestamp != null) {
                 TmfTimestampFormat timestampFormat = new TmfTimestampFormat(fDefinition.timeStampOutputFormat);
                 fColumnData[i++] = new TmfEventField(outputColumn.name, timestampFormat.format(timestamp.getValue()), null);
             } else {
index d2b9935b591c6c63048079ac92cd0323c428ccb8..71469277707843f2d784f379bf42dc0ebd7ad09e 100644 (file)
 
 package org.eclipse.tracecompass.tmf.core.parsers.custom;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
 import java.io.ByteArrayInputStream;
 import java.text.SimpleDateFormat;
+import java.util.AbstractMap.SimpleEntry;
 import java.util.List;
+import java.util.Map.Entry;
 
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
+import org.w3c.dom.Element;
 import org.xml.sax.EntityResolver;
 import org.xml.sax.ErrorHandler;
 import org.xml.sax.InputSource;
@@ -40,19 +46,82 @@ public abstract class CustomTraceDefinition {
     /** "append with separator" action */
     public static final int ACTION_APPEND_WITH_SEPARATOR = 2;
 
-    /** Timestamp tag */
+    /**
+     * Input tag
+     *
+     * @since 2.1
+     */
+    public enum Tag {
+        /** Ignore */
+        IGNORE(Messages.CustomXmlTraceDefinition_ignoreTag),
+        /** Timestamp */
+        TIMESTAMP(TmfBaseAspects.getTimestampAspect().getName()),
+        /** Event type */
+        EVENT_TYPE(TmfBaseAspects.getEventTypeAspect().getName()),
+        /** Message */
+        MESSAGE(Messages.CustomTraceDefinition_messageTag),
+        /** Other */
+        OTHER(Messages.CustomTraceDefinition_otherTag);
+
+        private final String fLabel;
+
+        private Tag(String label) {
+            fLabel = label;
+        }
+
+        @Override
+        public String toString() {
+            return fLabel;
+        }
+
+        /**
+         * Get a tag from its label (toString).
+         *
+         * @param label
+         *            the label
+         * @return the corresponding tag, or null
+         */
+        public static Tag fromLabel(String label) {
+            for (Tag tag : Tag.values()) {
+                if (tag.toString().equals(label)) {
+                    return tag;
+                }
+            }
+            return null;
+        }
+
+        /**
+         * Get a tag from its name (identifier).
+         *
+         * @param name
+         *            the name
+         * @return the corresponding tag, or null
+         */
+        public static Tag fromName(String name) {
+            for (Tag tag : Tag.values()) {
+                if (tag.name().equals(name)) {
+                    return tag;
+                }
+            }
+            return null;
+        }
+    }
+
+    /** Timestamp tag
+     * @deprecated Use {@link Tag#TIMESTAMP} instead. */
+    @Deprecated
     public static final String TAG_TIMESTAMP = Messages.CustomTraceDefinition_timestampTag;
 
-    /** Message tag */
+    /** Message tag
+     * @deprecated Use {@link Tag#MESSAGE} instead. */
+    @Deprecated
     public static final String TAG_MESSAGE = Messages.CustomTraceDefinition_messageTag;
 
-    /** "Other" tag */
+    /** "Other" tag
+     * @deprecated Use {@link Tag#OTHER} instead. */
+    @Deprecated
     public static final String TAG_OTHER = Messages.CustomTraceDefinition_otherTag;
 
-    /** Event type tag
-     * @since 2.1*/
-    public static final String TAG_EVENT_TYPE = Messages.CustomTraceDefinition_eventTypeTag;
-
     /** Category of this trace definition */
     public String categoryName;
 
@@ -70,22 +139,48 @@ public abstract class CustomTraceDefinition {
      */
     public static class OutputColumn {
 
+        /** Tag of this input
+         * @since 2.1*/
+        public @NonNull Tag tag;
+
         /** Name of this column */
         public @NonNull String name;
 
         /**
          * Default constructor (empty)
+         * @deprecated Use {@link OutputColumn#OutputColumn(Tag, String)}
+         *             instead.
          */
+        @Deprecated
         public OutputColumn() {
-            this(""); //$NON-NLS-1$
+            this(Tag.IGNORE, ""); //$NON-NLS-1$
         }
 
         /**
          * Constructor
          *
-         * @param name Name of this output column
+         * @param name
+         *            Name of this output column
+         * @deprecated Use {@link OutputColumn#OutputColumn(Tag, String)}
+         *             instead.
          */
+        @Deprecated
         public OutputColumn(@NonNull String name) {
+            this.tag = Tag.OTHER;
+            this.name = name;
+        }
+
+        /**
+         * Constructor
+         *
+         * @param tag
+         *            Tag of this output column
+         * @param name
+         *            Name of this output column
+         * @since 2.1
+         */
+        public OutputColumn(@NonNull Tag tag, @NonNull String name) {
+            this.tag = tag;
             this.name = name;
         }
 
@@ -157,4 +252,39 @@ public abstract class CustomTraceDefinition {
             }
         };
     }
+
+    /**
+     * Extract the tag and name from an XML element
+     *
+     * @param element
+     *            the XML element
+     * @param tagAttribute
+     *            the tag attribute
+     * @param nameAttribute
+     *            the name attribute
+     * @return an entry where the key is the tag and the value is the name
+     * @since 2.1
+     */
+    protected static Entry<@NonNull Tag, @NonNull String> extractTagAndName(Element element, String tagAttribute, String nameAttribute) {
+        Tag tag = Tag.fromName(element.getAttribute(tagAttribute));
+        String name = element.getAttribute(nameAttribute);
+        if (tag == null) {
+            // Backward compatibility
+            if (name.equals(Messages.CustomTraceDefinition_timestampTag)) {
+                tag = Tag.TIMESTAMP;
+                name = checkNotNull(Tag.TIMESTAMP.toString());
+            } else if (name.equals(Messages.CustomTraceDefinition_messageTag)) {
+                tag = Tag.MESSAGE;
+                name = checkNotNull(Tag.MESSAGE.toString());
+            } else if (name.equals(Messages.CustomXmlTraceDefinition_ignoreTag)) {
+                tag = Tag.IGNORE;
+                name = checkNotNull(Tag.IGNORE.toString());
+            } else {
+                tag = Tag.OTHER;
+            }
+        } else if (name.isEmpty()) {
+            name = checkNotNull(tag.toString());
+        }
+        return new SimpleEntry<>(tag, name);
+    }
 }
index d555f2028894a4d532a4a0f3258a18659d527aa3..4ea2fd5376bbb355f5e5eb1d95bd733c4de9255b 100644 (file)
@@ -18,6 +18,7 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
 import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
 import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputData;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputLine;
 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
@@ -84,7 +85,7 @@ public class CustomTxtEvent extends CustomEvent {
      */
     public void processGroups(InputLine input, Matcher matcher) {
         if (input.eventType != null) {
-            fData.put(CustomTraceDefinition.TAG_EVENT_TYPE, input.eventType);
+            fData.put(Tag.EVENT_TYPE, input.eventType);
         }
         if (input.columns == null) {
             return;
@@ -96,40 +97,40 @@ public class CustomTxtEvent extends CustomEvent {
                 if (value.length() == 0) {
                     continue;
                 }
-                String name = column.name;
+                Object key = (column.tag.equals(Tag.OTHER) ? column.name : column.tag);
                 if (column.action == CustomTraceDefinition.ACTION_SET) {
-                    fData.put(name, value);
-                    if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
-                        fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
+                    fData.put(key, value);
+                    if (key.equals(Tag.TIMESTAMP)) {
+                        fData.put(Key.TIMESTAMP_INPUT_FORMAT, column.format);
                     }
                 } else if (column.action == CustomTraceDefinition.ACTION_APPEND) {
-                    String s = fData.get(name);
+                    String s = fData.get(key);
                     if (s != null) {
-                        fData.put(name, s + value);
+                        fData.put(key, s + value);
                     } else {
-                        fData.put(name, value);
+                        fData.put(key, value);
                     }
-                    if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
-                        String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
+                    if (key.equals(Tag.TIMESTAMP)) {
+                        String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT);
                         if (timeStampInputFormat != null) {
-                            fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + column.format);
+                            fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + column.format);
                         } else {
-                            fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
+                            fData.put(Key.TIMESTAMP_INPUT_FORMAT, column.format);
                         }
                     }
                 } else if (column.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
-                    String s = fData.get(name);
+                    String s = fData.get(key);
                     if (s != null) {
-                        fData.put(name, s + " | " + value); //$NON-NLS-1$
+                        fData.put(key, s + " | " + value); //$NON-NLS-1$
                     } else {
-                        fData.put(name, value);
+                        fData.put(key, value);
                     }
-                    if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
-                        String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
+                    if (key.equals(Tag.TIMESTAMP)) {
+                        String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT);
                         if (timeStampInputFormat != null) {
-                            fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + column.format); //$NON-NLS-1$
+                            fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + " | " + column.format); //$NON-NLS-1$
                         } else {
-                            fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format);
+                            fData.put(Key.TIMESTAMP_INPUT_FORMAT, column.format);
                         }
                     }
                 }
index f7e3df49fdd1d665ce04611310b591192eb77079..4364a23b3ee634b0714f6cb87e6d20eeb44217f8 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Arrays;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 import java.util.TreeSet;
 import java.util.regex.Pattern;
@@ -41,6 +42,7 @@ import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
 import org.eclipse.core.runtime.Platform;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.tracecompass.internal.tmf.core.Activator;
 import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
 import org.w3c.dom.Document;
@@ -100,6 +102,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
     private static final String CUSTOM_TXT_TRACE_DEFINITION_ROOT_ELEMENT = Messages.CustomTxtTraceDefinition_definitionRootElement;
     private static final String DEFINITION_ELEMENT = Messages.CustomTxtTraceDefinition_definition;
     private static final String CATEGORY_ATTRIBUTE = Messages.CustomTxtTraceDefinition_category;
+    private static final String TAG_ATTRIBUTE = Messages.CustomTxtTraceDefinition_tag;
     private static final String NAME_ATTRIBUTE = Messages.CustomTxtTraceDefinition_name;
     private static final String TIME_STAMP_OUTPUT_FORMAT_ELEMENT = Messages.CustomTxtTraceDefinition_timestampOutputFormat;
     private static final String INPUT_LINE_ELEMENT = Messages.CustomTxtTraceDefinition_inputLine;
@@ -365,7 +368,11 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
      */
     public static class InputData {
 
-        /** Name of this column */
+        /** Tag of this input
+         * @since 2.1*/
+        public Tag tag;
+
+        /** Name of this input for "Other" tag */
         public String name;
 
         /** Action id */
@@ -408,6 +415,20 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
             this.name = name;
             this.action = action;
         }
+
+        /**
+         * Constructor
+         *
+         * @param tag
+         *            Tag
+         * @param action
+         *            Action
+         * @since 2.1
+         */
+        public InputData(Tag tag, int action) {
+            this.tag = tag;
+            this.action = action;
+        }
     }
 
     /**
@@ -532,6 +553,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
                 for (OutputColumn output : outputs) {
                     Element outputColumnElement = doc.createElement(OUTPUT_COLUMN_ELEMENT);
                     definitionElement.appendChild(outputColumnElement);
+                    outputColumnElement.setAttribute(TAG_ATTRIBUTE, output.tag.name());
                     outputColumnElement.setAttribute(NAME_ATTRIBUTE, output.name);
                 }
             }
@@ -578,6 +600,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
             for (InputData inputData : inputLine.columns) {
                 Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT);
                 inputLineElement.appendChild(inputDataElement);
+                inputDataElement.setAttribute(TAG_ATTRIBUTE, inputData.tag.name());
                 inputDataElement.setAttribute(NAME_ATTRIBUTE, inputData.name);
                 inputDataElement.setAttribute(ACTION_ATTRIBUTE, Integer.toString(inputData.action));
                 if (inputData.format != null) {
@@ -811,8 +834,8 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
                 }
             } else if (nodeName.equals(OUTPUT_COLUMN_ELEMENT)) {
                 Element outputColumnElement = (Element) node;
-                OutputColumn outputColumn = new OutputColumn();
-                outputColumn.name = outputColumnElement.getAttribute(NAME_ATTRIBUTE);
+                Entry<@NonNull Tag, @NonNull String> entry = extractTagAndName(outputColumnElement, TAG_ATTRIBUTE, NAME_ATTRIBUTE);
+                OutputColumn outputColumn = new OutputColumn(entry.getKey(), entry.getValue());
                 def.outputs.add(outputColumn);
             }
         }
@@ -843,7 +866,9 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
             } else if (nodeName.equals(INPUT_DATA_ELEMENT)) {
                 Element inputDataElement = (Element) node;
                 InputData inputData = new InputData();
-                inputData.name = inputDataElement.getAttribute(NAME_ATTRIBUTE);
+                Entry<@NonNull Tag, @NonNull String> entry = extractTagAndName(inputDataElement, TAG_ATTRIBUTE, NAME_ATTRIBUTE);
+                inputData.tag = checkNotNull(entry.getKey());
+                inputData.name = checkNotNull(entry.getValue());
                 inputData.action = Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE));
                 inputData.format = inputDataElement.getAttribute(FORMAT_ATTRIBUTE);
                 inputLine.addColumn(inputData);
index ba862b54849d4e030a3b06d4e75d019e6363c688..3322554f3e0454779110767df7856f49b7f04000 100644 (file)
@@ -16,6 +16,7 @@ import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
 import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
 import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 
@@ -77,44 +78,60 @@ public class CustomXmlEvent extends CustomEvent {
      * @param name Name
      * @param inputAction Input action
      * @param inputFormat Input format
+     * @deprecated Use {@link #parseInput(String, Tag, String, int, String)} instead.
      */
+    @Deprecated
     public void parseInput(String value, String name, int inputAction, String inputFormat) {
+    }
+
+    /**
+     * Parse an entry.
+     *
+     * @param value Value
+     * @param inputTag Input tag
+     * @param inputName Input name
+     * @param inputAction Input action
+     * @param inputFormat Input format
+     * @since 2.1
+     */
+    public void parseInput(String value, Tag inputTag, String inputName, int inputAction, String inputFormat) {
         if (value.length() == 0) {
             return;
         }
+        Object key = (inputTag.equals(Tag.OTHER) ? inputName : inputTag);
         if (inputAction == CustomTraceDefinition.ACTION_SET) {
-            fData.put(name, value);
-            if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
-                fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat);
+            fData.put(key, value);
+            if (key.equals(Tag.TIMESTAMP)) {
+                fData.put(Key.TIMESTAMP_INPUT_FORMAT, inputFormat);
             }
         } else if (inputAction == CustomTraceDefinition.ACTION_APPEND) {
-            String s = fData.get(name);
+            String s = fData.get(key);
             if (s != null) {
-                fData.put(name, s + value);
+                fData.put(key, s + value);
             } else {
-                fData.put(name, value);
+                fData.put(key, value);
             }
-            if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
-                String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
+            if (key.equals(Tag.TIMESTAMP)) {
+                String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT);
                 if (timeStampInputFormat != null) {
-                    fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + inputFormat);
+                    fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + inputFormat);
                 } else {
-                    fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat);
+                    fData.put(Key.TIMESTAMP_INPUT_FORMAT, inputFormat);
                 }
             }
         } else if (inputAction == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
-            String s = fData.get(name);
+            String s = fData.get(key);
             if (s != null) {
-                fData.put(name, s + " | " + value); //$NON-NLS-1$
+                fData.put(key, s + " | " + value); //$NON-NLS-1$
             } else {
-                fData.put(name, value);
+                fData.put(key, value);
             }
-            if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
-                String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY);
+            if (key.equals(Tag.TIMESTAMP)) {
+                String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT);
                 if (timeStampInputFormat != null) {
-                    fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + inputFormat); //$NON-NLS-1$
+                    fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + " | " + inputFormat); //$NON-NLS-1$
                 } else {
-                    fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat);
+                    fData.put(Key.TIMESTAMP_INPUT_FORMAT, inputFormat);
                 }
             }
         }
index 5040c3df3bfd8ac354d31a514598fe2fad4c2d6a..5bbb8848a8e3116844dcf5f3031cb38f48264c2f 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014 Ericsson
+ * Copyright (c) 2014, 2016 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -12,6 +12,8 @@
  *******************************************************************************/
 package org.eclipse.tracecompass.tmf.core.parsers.custom;
 
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
+
 /**
  * Wrapper for XML element attributes
  */
@@ -20,6 +22,9 @@ public final class CustomXmlInputAttribute {
     /** Name of the XML attribute */
     private final String fAttributeName;
 
+    /** Input tag */
+    private final Tag fInputTag;
+
     /** Input name */
     private final String fInputName;
 
@@ -40,10 +45,39 @@ public final class CustomXmlInputAttribute {
      *            Input action
      * @param inputFormat
      *            Input format
+     * @deprecated Use
+     *             {@link #CustomXmlInputAttribute(String, Tag, String, int, String)}
+     *             instead.
      */
+    @Deprecated
     public CustomXmlInputAttribute(String attributeName, String inputName,
             int inputAction, String inputFormat) {
         fAttributeName = attributeName;
+        fInputTag = Tag.IGNORE;
+        fInputName = inputName;
+        fInputAction = inputAction;
+        fInputFormat = inputFormat;
+    }
+
+    /**
+     * Constructor
+     *
+     * @param attributeName
+     *            Name of the XML attribute
+     * @param inputTag
+     *            Input tag
+     * @param inputName
+     *            Input name
+     * @param inputAction
+     *            Input action
+     * @param inputFormat
+     *            Input format
+     * @since 2.1
+     */
+    public CustomXmlInputAttribute(String attributeName, Tag inputTag,
+            String inputName, int inputAction, String inputFormat) {
+        fAttributeName = attributeName;
+        fInputTag = inputTag;
         fInputName = inputName;
         fInputAction = inputAction;
         fInputFormat = inputFormat;
@@ -56,6 +90,14 @@ public final class CustomXmlInputAttribute {
         return fAttributeName;
     }
 
+    /**
+     * @return the inputTag
+     * @since 2.1
+     */
+    public Tag getInputTag() {
+        return fInputTag;
+    }
+
     /**
      * @return the inputName
      */
index 75d4b82c7d0135e7c1498310a9dc8e080e2a66fa..20921013387937d3c94975715637713e9ff879af 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014 Ericsson
+ * Copyright (c) 2014, 2016 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -16,6 +16,8 @@ package org.eclipse.tracecompass.tmf.core.parsers.custom;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
+
 /**
  * Wrapper for input XML elements
  */
@@ -27,6 +29,9 @@ public final class CustomXmlInputElement {
     /** Indicates if this is a log entry */
     private boolean fLogEntry;
 
+    /** Tag of the input element */
+    private Tag fInputTag;
+
     /** Name of the input element */
     private String fInputName;
 
@@ -65,14 +70,18 @@ public final class CustomXmlInputElement {
      * @param logEntry
      *            If this element is a log entry
      * @param inputName
-     *            Name of the the input
+     *            Name of the input
      * @param inputAction
      *            Input action
      * @param inputFormat
      *            Input format
      * @param attributes
      *            XML attributes of this element
+     * @deprecated Use
+     *             {@link #CustomXmlInputElement(String, boolean, Tag, String, int, String, List)}
+     *             instead.
      */
+    @Deprecated
     public CustomXmlInputElement(String elementName, boolean logEntry,
             String inputName, int inputAction, String inputFormat,
             List<CustomXmlInputAttribute> attributes) {
@@ -84,6 +93,37 @@ public final class CustomXmlInputElement {
         fAttributes = attributes;
     }
 
+    /**
+     * Constructor
+     *
+     * @param elementName
+     *            Element name
+     * @param logEntry
+     *            If this element is a log entry
+     * @param inputTag
+     *            Tag of the input
+     * @param inputName
+     *            Name of the input
+     * @param inputAction
+     *            Input action
+     * @param inputFormat
+     *            Input format
+     * @param attributes
+     *            XML attributes of this element
+     * @since 2.1
+     */
+    public CustomXmlInputElement(String elementName, boolean logEntry, Tag inputTag,
+            String inputName, int inputAction, String inputFormat,
+            List<CustomXmlInputAttribute> attributes) {
+        fElementName = elementName;
+        fLogEntry = logEntry;
+        fInputTag = inputTag;
+        fInputName = inputName;
+        fInputAction = inputAction;
+        fInputFormat = inputFormat;
+        fAttributes = attributes;
+    }
+
     /**
      * Add a XML attribute to the element
      *
@@ -193,6 +233,23 @@ public final class CustomXmlInputElement {
         fLogEntry = logEntry;
     }
 
+    /**
+     * @return the inputTag
+     * @since 2.1
+     */
+    public Tag getInputTag() {
+        return fInputTag;
+    }
+
+    /**
+     * @param inputTag
+     *            the inputTag to set
+     * @since 2.1
+     */
+    public void setInputTag(Tag inputTag) {
+        fInputTag = inputTag;
+    }
+
     /**
      * @return the inputName
      */
index cca70ea65a108efeda0f1560913eb071ee406e90..e562fd880e6f232d9669e073e17fc10654222ded 100644 (file)
@@ -37,6 +37,7 @@ import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
 import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
 import org.eclipse.tracecompass.tmf.core.signal.TmfTraceRangeUpdatedSignal;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
@@ -521,12 +522,12 @@ public class CustomXmlTrace extends TmfTrace implements ITmfPersistentlyIndexabl
         if (eventType != null && event.getType() instanceof CustomEventType) {
             ((CustomEventType) event.getType()).setName(eventType);
         }
-        if (inputElement.getInputName() != null && !inputElement.getInputName().equals(CustomXmlTraceDefinition.TAG_IGNORE)) {
-            event.parseInput(parseElement(element, new StringBuffer()).toString(), inputElement.getInputName(), inputElement.getInputAction(), inputElement.getInputFormat());
+        if (!inputElement.getInputTag().equals(Tag.IGNORE)) {
+            event.parseInput(parseElement(element, new StringBuffer()).toString(), inputElement.getInputTag(), inputElement.getInputName(), inputElement.getInputAction(), inputElement.getInputFormat());
         }
         if (inputElement.getAttributes() != null) {
             for (final CustomXmlInputAttribute attribute : inputElement.getAttributes()) {
-                event.parseInput(element.getAttribute(attribute.getAttributeName()), attribute.getInputName(), attribute.getInputAction(), attribute.getInputFormat());
+                event.parseInput(element.getAttribute(attribute.getAttributeName()), attribute.getInputTag(), attribute.getInputName(), attribute.getInputAction(), attribute.getInputFormat());
             }
         }
         final NodeList childNodes = element.getChildNodes();
index 2f3496f54a339dda55e5269d59a5947dec498db8..6fc26120c84935436e917455b19893c4c2f7d10a 100644 (file)
@@ -24,6 +24,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Comparator;
 import java.util.List;
+import java.util.Map.Entry;
 import java.util.Set;
 import java.util.TreeSet;
 
@@ -39,6 +40,7 @@ import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
 import org.eclipse.core.runtime.Platform;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.tracecompass.internal.tmf.core.Activator;
 import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
 import org.w3c.dom.Document;
@@ -58,7 +60,9 @@ import org.xml.sax.SAXParseException;
  */
 public class CustomXmlTraceDefinition extends CustomTraceDefinition {
 
-    /** "ignore" tag */
+    /** Ignore tag
+     * @deprecated Use {@link Tag#IGNORE} instead. */
+    @Deprecated
     public static final String TAG_IGNORE = Messages.CustomXmlTraceDefinition_ignoreTag;
 
     /**
@@ -104,6 +108,7 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
     private static final String CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT = Messages.CustomXmlTraceDefinition_definitionRootElement;
     private static final String DEFINITION_ELEMENT = Messages.CustomXmlTraceDefinition_definition;
     private static final String CATEGORY_ATTRIBUTE = Messages.CustomXmlTraceDefinition_category;
+    private static final String TAG_ATTRIBUTE = Messages.CustomXmlTraceDefinition_tag;
     private static final String NAME_ATTRIBUTE = Messages.CustomXmlTraceDefinition_name;
     private static final String LOG_ENTRY_ATTRIBUTE = Messages.CustomXmlTraceDefinition_logEntry;
     private static final String EVENT_TYPE_ATTRIBUTE = Messages.CustomXmlTraceDefinition_eventType;
@@ -202,6 +207,7 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
                 for (OutputColumn output : outputs) {
                     Element outputColumnElement = doc.createElement(OUTPUT_COLUMN_ELEMENT);
                     definitionElement.appendChild(outputColumnElement);
+                    outputColumnElement.setAttribute(TAG_ATTRIBUTE, output.tag.name());
                     outputColumnElement.setAttribute(NAME_ATTRIBUTE, output.name);
                 }
             }
@@ -241,10 +247,12 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
         if (inputElement.getParentElement() != null) {
             Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT);
             inputElementElement.appendChild(inputDataElement);
+            inputDataElement.setAttribute(TAG_ATTRIBUTE, inputElement.getInputTag().name());
             inputDataElement.setAttribute(NAME_ATTRIBUTE, inputElement.getInputName());
             inputDataElement.setAttribute(ACTION_ATTRIBUTE, Integer.toString(inputElement.getInputAction()));
-            if (inputElement.getInputFormat() != null) {
-                inputDataElement.setAttribute(FORMAT_ATTRIBUTE, inputElement.getInputFormat());
+            String inputFormat = inputElement.getInputFormat();
+            if (inputFormat != null && !inputFormat.isEmpty()) {
+                inputDataElement.setAttribute(FORMAT_ATTRIBUTE, inputFormat);
             }
         }
 
@@ -255,10 +263,12 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
                 inputAttributeElement.setAttribute(NAME_ATTRIBUTE, attribute.getAttributeName());
                 Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT);
                 inputAttributeElement.appendChild(inputDataElement);
+                inputDataElement.setAttribute(TAG_ATTRIBUTE, attribute.getInputTag().name());
                 inputDataElement.setAttribute(NAME_ATTRIBUTE, attribute.getInputName());
                 inputDataElement.setAttribute(ACTION_ATTRIBUTE, Integer.toString(attribute.getInputAction()));
-                if (attribute.getInputFormat() != null) {
-                    inputDataElement.setAttribute(FORMAT_ATTRIBUTE, attribute.getInputFormat());
+                String inputFormat = attribute.getInputFormat();
+                if (inputFormat != null && !inputFormat.isEmpty()) {
+                    inputDataElement.setAttribute(FORMAT_ATTRIBUTE, inputFormat);
                 }
             }
         }
@@ -525,8 +535,8 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
                 }
             } else if (nodeName.equals(OUTPUT_COLUMN_ELEMENT)) {
                 Element outputColumnElement = (Element) node;
-                OutputColumn outputColumn = new OutputColumn();
-                outputColumn.name = outputColumnElement.getAttribute(NAME_ATTRIBUTE);
+                Entry<@NonNull Tag, @NonNull String> entry = extractTagAndName(outputColumnElement, TAG_ATTRIBUTE, NAME_ATTRIBUTE);
+                OutputColumn outputColumn = new OutputColumn(entry.getKey(), entry.getValue());
                 def.outputs.add(outputColumn);
             }
         }
@@ -545,28 +555,28 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
             String nodeName = node.getNodeName();
             if (nodeName.equals(INPUT_DATA_ELEMENT)) {
                 Element inputDataElement = (Element) node;
-                inputElement.setInputName(inputDataElement.getAttribute(NAME_ATTRIBUTE));
+                Entry<@NonNull Tag, @NonNull String> entry = extractTagAndName(inputDataElement, TAG_ATTRIBUTE, NAME_ATTRIBUTE);
+                inputElement.setInputTag(entry.getKey());
+                inputElement.setInputName(entry.getValue());
                 inputElement.setInputAction(Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE)));
                 inputElement.setInputFormat(inputDataElement.getAttribute(FORMAT_ATTRIBUTE));
             } else if (nodeName.equals(ATTRIBUTE_ELEMENT)) {
                 Element attributeElement = (Element) node;
 
                 String attributeName = attributeElement.getAttribute(NAME_ATTRIBUTE);
-                String inputName = null;
-                int inputAction = 0;
-                String inputFormat = null;
                 NodeList attributeNodeList = attributeElement.getChildNodes();
                 for (int j = 0; j < attributeNodeList.getLength(); j++) {
                     Node attributeNode = attributeNodeList.item(j);
                     String attributeNodeName = attributeNode.getNodeName();
                     if (attributeNodeName.equals(INPUT_DATA_ELEMENT)) {
                         Element inputDataElement = (Element) attributeNode;
-                        inputName = inputDataElement.getAttribute(NAME_ATTRIBUTE);
-                        inputAction = Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE));
-                        inputFormat = inputDataElement.getAttribute(FORMAT_ATTRIBUTE);
+                        Entry<@NonNull Tag, @NonNull String> entry = extractTagAndName(inputDataElement, TAG_ATTRIBUTE, NAME_ATTRIBUTE);
+                        int action = Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE));
+                        String format = inputDataElement.getAttribute(FORMAT_ATTRIBUTE);
+                        inputElement.addAttribute(new CustomXmlInputAttribute(attributeName, entry.getKey(), entry.getValue(), action, format));
+                        break;
                     }
                 }
-                inputElement.addAttribute(new CustomXmlInputAttribute(attributeName, inputName, inputAction, inputFormat));
             } else if (nodeName.equals(INPUT_ELEMENT_ELEMENT)) {
                 Element childInputElementElement = (Element) node;
                 CustomXmlInputElement childInputElement = extractInputElement(childInputElementElement);
index ec9b0a3face6c3f73648276cdbc312e4d6c4532b..494a952601bf0c6edf697d6c80ab01cf48e04b0c 100644 (file)
@@ -41,6 +41,8 @@ public class Messages extends NLS {
     public static String CustomTxtTraceDefinition_name;
     public static String CustomTxtTraceDefinition_outputColumn;
     public static String CustomTxtTraceDefinition_regEx;
+    /** @since 2.1 */
+    public static String CustomTxtTraceDefinition_tag;
     public static String CustomTxtTraceDefinition_timestampOutputFormat;
     public static String CustomXmlTraceDefinition_action;
     public static String CustomXmlTraceDefinition_attribute;
@@ -56,6 +58,8 @@ public class Messages extends NLS {
     public static String CustomXmlTraceDefinition_logEntry;
     public static String CustomXmlTraceDefinition_name;
     public static String CustomXmlTraceDefinition_outputColumn;
+    /** @since 2.1 */
+    public static String CustomXmlTraceDefinition_tag;
     public static String CustomXmlTraceDefinition_timestampOutputFormat;
 
     static {
index ca8da7d6bd8a796b708be2341f16873b2a7efa60..5820a308454b567ba25793bec36500bfed17c435 100644 (file)
@@ -30,6 +30,7 @@ CustomTxtTraceDefinition_min=min
 CustomTxtTraceDefinition_name=name
 CustomTxtTraceDefinition_outputColumn=OutputColumn
 CustomTxtTraceDefinition_regEx=RegEx
+CustomTxtTraceDefinition_tag=tag
 CustomTxtTraceDefinition_timestampOutputFormat=TimeStampOutputFormat
 CustomXmlTraceDefinition_action=action
 CustomXmlTraceDefinition_attribute=Attribute
@@ -44,4 +45,5 @@ CustomXmlTraceDefinition_inputElement=InputElement
 CustomXmlTraceDefinition_logEntry=logentry
 CustomXmlTraceDefinition_name=name
 CustomXmlTraceDefinition_outputColumn=OutputColumn
+CustomXmlTraceDefinition_tag=tag
 CustomXmlTraceDefinition_timestampOutputFormat=TimeStampOutputFormat
index f524162df6c0a27499b10b821e842bf0e14a0860..29741d6d0b26a7a56090ab9e5c11f28705256ea4 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014, 2015 Ericsson
+ * Copyright (c) 2014, 2016 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -75,16 +75,16 @@ public class TestCustomTxtWizard extends AbstractCustomParserWizard {
             "<InputLine>\n" +
             "<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
             "<RegEx>\\s*(\\d\\d)\\s(.*\\S)</RegEx>\n" +
-            "<InputData action=\"0\" format=\"ss\" name=\"Time Stamp\"/>\n" +
-            "<InputData action=\"0\" name=\"Message\"/>\n" +
+            "<InputData action=\"0\" format=\"ss\" name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" +
+            "<InputData action=\"0\" name=\"Message\" tag=\"MESSAGE\"/>\n" +
             "</InputLine>\n" +
             "<InputLine>\n" +
             "<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
             "<RegEx>([^0-9]*)</RegEx>\n" +
-            "<InputData action=\"2\" name=\"Message\"/>\n" +
+            "<InputData action=\"2\" name=\"Message\" tag=\"MESSAGE\"/>\n" +
             "</InputLine>\n" +
-            "<OutputColumn name=\"Time Stamp\"/>\n" +
-            "<OutputColumn name=\"Message\"/>\n";
+            "<OutputColumn name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" +
+            "<OutputColumn name=\"Message\" tag=\"MESSAGE\"/>\n";
 
     /**
      * Test to create a custom txt trace and compare the xml
@@ -127,7 +127,7 @@ public class TestCustomTxtWizard extends AbstractCustomParserWizard {
         fBot.textWithLabel("Time Stamp format:").setText("ss");
 
         // Fill Group 1 as time stamp
-        fBot.comboBox(1).setSelection("Time Stamp");
+        fBot.comboBox(1).setSelection("Timestamp");
         fBot.textWithLabel("format:").setText("ss");
         // Click on the New group button
         fBot.button(8).click();
@@ -192,22 +192,22 @@ public class TestCustomTxtWizard extends AbstractCustomParserWizard {
                     "<InputLine>\n" +
                     "<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
                     "<RegEx>\\s*(\\d*)\\s(.*)</RegEx>\n" +
-                    "<InputData action=\"0\" format=\"sss\" name=\"Time Stamp\"/>\n" +
-                    "<InputData action=\"0\" name=\"Message\"/>\n" +
+                    "<InputData action=\"0\" format=\"sss\" name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" +
+                    "<InputData action=\"0\" name=\"Message\" tag=\"MESSAGE\"/>\n" +
                     "</InputLine>\n" +
-                    "<OutputColumn name=\"Time Stamp\"/>\n" +
-                    "<OutputColumn name=\"Message\"/>\n" +
+                    "<OutputColumn name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" +
+                    "<OutputColumn name=\"Message\" tag=\"MESSAGE\"/>\n" +
                     "</Definition>\n" +
                     "<Definition name=\"dmesg\">\n" +
                     "<TimeStampOutputFormat>sssssss.ssssss</TimeStampOutputFormat>\n" +
                     "<InputLine>\n" +
                     "<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
                     "<RegEx>^[([0-9]*\\.[0.9]*)]\\s(.*)</RegEx>\n" +
-                    "<InputData action=\"0\" format=\"sssss.sssss\" name=\"Time Stamp\"/>\n" +
-                    "<InputData action=\"0\" name=\"Message\"/>\n" +
+                    "<InputData action=\"0\" format=\"sssss.sssss\" name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" +
+                    "<InputData action=\"0\" name=\"Message\" tag=\"MESSAGE\"/>\n" +
                     "</InputLine>\n" +
-                    "<OutputColumn name=\"Time Stamp\"/>\n" +
-                    "<OutputColumn name=\"Message\"/>\n" +
+                    "<OutputColumn name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" +
+                    "<OutputColumn name=\"Message\" tag=\"MESSAGE\"/>\n" +
                     "</Definition>\n" +
                     "</CustomTxtTraceDefinitionList>";
             fw.write(xmlContent);
@@ -243,7 +243,7 @@ public class TestCustomTxtWizard extends AbstractCustomParserWizard {
         fBot.textWithLabel("Time Stamp format:").setText("ss");
 
         // update time stamp format
-        fBot.comboBox(1).setSelection("Time Stamp");
+        fBot.comboBox(1).setSelection("Timestamp");
         fBot.textWithLabel("format:").setText("ss");
         fBot.button(2).click();
         SWTBotTreeItem[] treeItems = fBot.tree().getAllItems();
index a48a6a0414a2b6b127b74d690367d76e668c3421..a8f443cebfda9b6a9c1a2b952d0a3dbdf852ca2e 100644 (file)
@@ -50,17 +50,17 @@ public class TestCustomXmlWizard extends AbstractCustomParserWizard {
             "<TimeStampOutputFormat>ss</TimeStampOutputFormat>\n" +
             "<InputElement name=\"trace\">\n" +
             "<InputElement logentry=\"true\" name=\"event\">\n" +
-            "<InputData action=\"0\" format=\"\" name=\"Ignore\"/>\n" +
+            "<InputData action=\"0\" name=\"Ignore\" tag=\"IGNORE\"/>\n" +
             "<Attribute name=\"msg\">\n" +
-            "<InputData action=\"0\" name=\"msg\"/>\n" +
+            "<InputData action=\"0\" name=\"msg\" tag=\"OTHER\"/>\n" +
             "</Attribute>\n" +
             "<Attribute name=\"time\">\n" +
-            "<InputData action=\"0\" name=\"time\"/>\n" +
+            "<InputData action=\"0\" name=\"time\" tag=\"OTHER\"/>\n" +
             "</Attribute>\n" +
             "</InputElement>\n" +
             "</InputElement>\n" +
-            "<OutputColumn name=\"msg\"/>\n" +
-            "<OutputColumn name=\"time\"/>\n";
+            "<OutputColumn name=\"msg\" tag=\"OTHER\"/>\n" +
+            "<OutputColumn name=\"time\" tag=\"OTHER\"/>\n";
 
     /**
      * Test to create a custom XML trace and compare the XML generated
index 0244c82c2c642d52c9aad8e50ab5d46e02955a1e..7aa2c6499b3f34a11c9cbc5c933d46dd899bf864 100644 (file)
@@ -239,11 +239,13 @@ public class Messages extends NLS {
     public static String CustomXmlParserInputWizardPage_elementMissingTimestampFmtError;
     public static String CustomXmlParserInputWizardPage_elementInvalidTimestampFmtError;
     public static String CustomXmlParserInputWizardPage_elementDuplicateNameError;
+    public static String CustomXmlParserInputWizardPage_elementReservedInputNameError;
     public static String CustomXmlParserInputWizardPage_attributeMissingNameError;
     public static String CustomXmlParserInputWizardPage_attributeMissingInputNameError;
     public static String CustomXmlParserInputWizardPage_attributeMissingTimestampFmtError;
     public static String CustomXmlParserInputWizardPage_attributeInvalidTimestampFmtError;
     public static String CustomXmlParserInputWizardPage_attributeDuplicateNameError;
+    public static String CustomXmlParserInputWizardPage_attributeReservedInputNameError;
     public static String CustomXmlParserInputWizardPage_addAttribute;
     public static String CustomXmlParserInputWizardPage_addChildElement;
     public static String CustomXmlParserInputWizardPage_addDocumentEleemnt;
index 96ccf2059d5abda49c0e36f15f127229f1176611..736fdf19c258616ea321db8303eb62b8d63f9d5b 100644 (file)
@@ -239,11 +239,13 @@ CustomXmlParserInputWizardPage_elementMissingInputNameError=Enter a name for the
 CustomXmlParserInputWizardPage_elementMissingTimestampFmtError=Enter the input format for the Time Stamp (Element {0}).
 CustomXmlParserInputWizardPage_elementInvalidTimestampFmtError=Enter a valid output format for the Time Stamp field (Element {0}).
 CustomXmlParserInputWizardPage_elementDuplicateNameError=Duplicate element names (Element {0}).
+CustomXmlParserInputWizardPage_elementReservedInputNameError=Cannot use reserved name for the input (Element {0}).
 CustomXmlParserInputWizardPage_attributeMissingNameError=Enter a name for the attribute (Attribute {0}: ?).
 CustomXmlParserInputWizardPage_attributeMissingInputNameError=Enter a name for the input (Attribute {0}).
 CustomXmlParserInputWizardPage_attributeMissingTimestampFmtError=Enter the input format for the Time Stamp (Attribute {0}).
 CustomXmlParserInputWizardPage_attributeInvalidTimestampFmtError=Enter a valid input format for the Time Stamp (Attribute {0}).
 CustomXmlParserInputWizardPage_attributeDuplicateNameError=Duplicate attribute names (Attribute {0}).
+CustomXmlParserInputWizardPage_attributeReservedInputNameError=Cannot use reserved name for the input (Attribute {0}).
 CustomXmlParserInputWizardPage_addAttribute=Add attribute
 CustomXmlParserInputWizardPage_addChildElement=Add child element
 CustomXmlParserInputWizardPage_addDocumentEleemnt=Add document element
index 1d8284ceb82de91cbbdf0661211adfaebe31e5ba..3b646a44a9787df1c15fe0280e97cc1649cd1b3e 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
+ * Copyright (c) 2010, 2016 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -19,12 +19,14 @@ import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.URL;
 import java.text.ParseException;
+import java.util.AbstractMap.SimpleEntry;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Scanner;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -82,6 +84,7 @@ import org.eclipse.swt.widgets.Text;
 import org.eclipse.tracecompass.internal.tmf.ui.Activator;
 import org.eclipse.tracecompass.internal.tmf.ui.Messages;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.Cardinality;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputData;
@@ -394,7 +397,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
         if (definition == null) {
             definition = new CustomTxtTraceDefinition();
             definition.inputs.add(new InputLine(Cardinality.ZERO_OR_MORE, DEFAULT_REGEX,
-                    Arrays.asList(new InputData(CustomTraceDefinition.TAG_MESSAGE, CustomTraceDefinition.ACTION_SET))));
+                    Arrays.asList(new InputData(Tag.MESSAGE, CustomTraceDefinition.ACTION_SET))));
         }
         loadDefinition(definition);
         treeViewer.expandAll();
@@ -564,16 +567,16 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
     }
 
     /**
-     * Get the global list of input names.
+     * Get the global list of inputs.
      *
-     * @return The list of input names
+     * @return The list of inputs
      */
-    public List<String> getInputNames() {
-        List<String> inputs = new ArrayList<>();
+    public List<Entry<Tag, String>> getInputs() {
+        List<Entry<Tag, String>> inputs = new ArrayList<>();
         for (InputLine inputLine : definition.inputs) {
-            for (String inputName : getInputNames(inputLine)) {
-                if (!inputs.contains(inputName)) {
-                    inputs.add(inputName);
+            for (Entry<Tag, String> input : getInputs(inputLine)) {
+                if (!inputs.contains(input)) {
+                    inputs.add(input);
                 }
             }
         }
@@ -581,27 +584,27 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
     }
 
     /**
-     * Get the list of input names for the given input line.
+     * Get the list of inputs for the given input line, recursively.
      *
      * @param inputLine
      *            The input line
-     * @return The list of input names
+     * @return The list of inputs
      */
-    public List<String> getInputNames(InputLine inputLine) {
-        List<String> inputs = new ArrayList<>();
+    private List<Entry<Tag, String>> getInputs(InputLine inputLine) {
+        List<Entry<Tag, String>> inputs = new ArrayList<>();
         if (inputLine.columns != null) {
             for (InputData inputData : inputLine.columns) {
-                String inputName = inputData.name;
-                if (!inputs.contains(inputName)) {
-                    inputs.add(inputName);
+                Entry<Tag, String> input = new SimpleEntry<>(inputData.tag, inputData.name);
+                if (!inputs.contains(input)) {
+                    inputs.add(input);
                 }
             }
         }
         if (inputLine.childrenInputs != null) {
             for (InputLine childInputLine : inputLine.childrenInputs) {
-                for (String inputName : getInputNames(childInputLine)) {
-                    if (!inputs.contains(inputName)) {
-                        inputs.add(inputName);
+                for (Entry<Tag, String> input : getInputs(childInputLine)) {
+                    if (!inputs.contains(input)) {
+                        inputs.add(input);
                     }
                 }
             }
@@ -677,7 +680,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
                 }
             }
 
-            Map<String, String> data = new HashMap<>();
+            Map<Object, String> data = new HashMap<>();
             int rootLineMatches = 0;
             String firstEntryTimeStamp = null;
             String firstEntryTimeStampInputFormat = null;
@@ -709,7 +712,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
                         timeStampFormat = null;
                         updatePreviewLine(rootInputLine, matcher, data, rawPos, rootLineMatches);
                         if (rootLineMatches == 1) {
-                            firstEntryTimeStamp = data.get(CustomTraceDefinition.TAG_TIMESTAMP);
+                            firstEntryTimeStamp = data.get(Tag.TIMESTAMP);
                             firstEntryTimeStampInputFormat = timeStampFormat;
                         }
                         HashMap<InputLine, Integer> countMap = new HashMap<>();
@@ -848,14 +851,14 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
             }
 
             if (rootLineMatches == 1) {
-                firstEntryTimeStamp = data.get(CustomTraceDefinition.TAG_TIMESTAMP);
+                firstEntryTimeStamp = data.get(Tag.TIMESTAMP);
                 firstEntryTimeStampInputFormat = timeStampFormat;
             }
             if (firstEntryTimeStamp == null) {
                 timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noTimestampGroup);
                 if (selectedLine != null) {
                     for (InputGroup group : selectedLine.inputs) {
-                        if (group.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+                        if (group.tagCombo.getText().equals(Tag.TIMESTAMP.toString())) {
                             timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noMatchingTimestamp);
                             break;
                         }
@@ -877,7 +880,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
         }
     }
 
-    private void updatePreviewLine(InputLine line, Matcher matcher, Map<String, String> data, int rawPos, int rootLineMatches) {
+    private void updatePreviewLine(InputLine line, Matcher matcher, Map<Object, String> data, int rawPos, int rootLineMatches) {
         for (int i = 0; i < line.columns.size(); i++) {
             InputData input = line.columns.get(i);
             if (i < matcher.groupCount() && matcher.group(i + 1) != null) {
@@ -896,19 +899,20 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
                 if (value.length() == 0) {
                     continue;
                 }
+                Object key = (input.tag.equals(Tag.OTHER) ? input.name : input.tag);
                 if (input.action == CustomTraceDefinition.ACTION_SET) {
-                    data.put(input.name, value);
-                    if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+                    data.put(key, value);
+                    if (input.tag.equals(Tag.TIMESTAMP)) {
                         timeStampFormat = input.format;
                     }
                 } else if (input.action == CustomTraceDefinition.ACTION_APPEND) {
-                    String s = data.get(input.name);
+                    String s = data.get(key);
                     if (s != null) {
-                        data.put(input.name, s + value);
+                        data.put(key, s + value);
                     } else {
-                        data.put(input.name, value);
+                        data.put(key, value);
                     }
-                    if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+                    if (input.tag.equals(Tag.TIMESTAMP)) {
                         if (timeStampFormat != null) {
                             timeStampFormat += input.format;
                         } else {
@@ -916,13 +920,13 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
                         }
                     }
                 } else if (input.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
-                    String s = data.get(input.name);
+                    String s = data.get(key);
                     if (s != null) {
-                        data.put(input.name, s + " | " + value); //$NON-NLS-1$
+                        data.put(key, s + " | " + value); //$NON-NLS-1$
                     } else {
-                        data.put(input.name, value);
+                        data.put(key, value);
                     }
-                    if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+                    if (input.tag.equals(Tag.TIMESTAMP)) {
                         if (timeStampFormat != null) {
                             timeStampFormat += " | " + input.format; //$NON-NLS-1$
                         } else {
@@ -1258,16 +1262,16 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
             if (inputLine.columns != null) {
                 for (InputData inputData : inputLine.columns) {
                     InputGroup inputGroup = new InputGroup(group, this, inputs.size() + 1);
-                    if (inputData.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+                    if (inputData.tag.equals(Tag.TIMESTAMP)) {
                         inputGroup.tagCombo.select(0);
                         inputGroup.tagText.setText(inputData.format);
                         inputGroup.tagLabel.setText(Messages.CustomTxtParserInputWizardPage_format);
                         inputGroup.tagLabel.setVisible(true);
                         inputGroup.tagText.setVisible(true);
                         inputGroup.tagText.addModifyListener(updateListener);
-                    } else if (inputData.name.equals(CustomTraceDefinition.TAG_EVENT_TYPE)) {
+                    } else if (inputData.tag.equals(Tag.EVENT_TYPE)) {
                         inputGroup.tagCombo.select(1);
-                    } else if (inputData.name.equals(CustomTraceDefinition.TAG_MESSAGE)) {
+                    } else if (inputData.tag.equals(Tag.MESSAGE)) {
                         inputGroup.tagCombo.select(2);
                     } else {
                         inputGroup.tagCombo.select(3);
@@ -1373,11 +1377,12 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
             for (int i = 0; i < inputs.size(); i++) {
                 InputGroup grp = inputs.get(i);
                 InputData inputData = new InputData();
-                if (grp.tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) {
+                inputData.tag = Tag.fromLabel(grp.tagCombo.getText());
+                if (inputData.tag.equals(Tag.OTHER)) {
                     inputData.name = grp.tagText.getText().trim();
                 } else {
-                    inputData.name = grp.tagCombo.getText();
-                    if (grp.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+                    inputData.name = inputData.tag.toString();
+                    if (inputData.tag.equals(Tag.TIMESTAMP)) {
                         inputData.format = grp.tagText.getText().trim();
                     }
                 }
@@ -1442,10 +1447,11 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
             tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
 
             tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
-            tagCombo.setItems(new String[] { CustomTraceDefinition.TAG_TIMESTAMP,
-                    CustomTraceDefinition.TAG_EVENT_TYPE,
-                    CustomTraceDefinition.TAG_MESSAGE,
-                    CustomTraceDefinition.TAG_OTHER});
+            tagCombo.setItems(new String[] {
+                    Tag.TIMESTAMP.toString(),
+                    Tag.EVENT_TYPE.toString(),
+                    Tag.MESSAGE.toString(),
+                    Tag.OTHER.toString()});
             tagCombo.select(2);
             tagCombo.addSelectionListener(new SelectionListener() {
                 @Override
@@ -1672,7 +1678,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
             if (line != null) {
                 group = line.inputs.get(i);
             }
-            if (inputData.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+            if (inputData.tag.equals(Tag.TIMESTAMP)) {
                 timestampFound = true;
                 if (inputData.format.length() == 0) {
                     errors.append("Enter the input format for the Time Stamp (Line " + name + " Group " + (i + 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@@ -1692,10 +1698,21 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
                         }
                     }
                 }
-            } else if (inputData.name.length() == 0) {
-                errors.append("Enter a name for the data group (Line " + name + " Group " + (i + 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-                if (group != null) {
-                    group.tagText.setBackground(COLOR_LIGHT_RED);
+            } else if (inputData.tag.equals(Tag.OTHER)) {
+                if (inputData.name.isEmpty()) {
+                    errors.append("Enter a name for the data group (Line " + name + " Group " + (i + 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                    if (group != null) {
+                        group.tagText.setBackground(COLOR_LIGHT_RED);
+                    }
+                } else if (Tag.fromLabel(inputData.name) != null) {
+                    errors.append("Cannot use reserved name for the data group (Line " + name + " Group " + (i + 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                    if (group != null) {
+                        group.tagText.setBackground(COLOR_LIGHT_RED);
+                    }
+                } else {
+                    if (group != null) {
+                        group.tagText.setBackground(COLOR_TEXT_BACKGROUND);
+                    }
                 }
             } else {
                 if (group != null) {
index 2a637b95615e1e96f9e0855b250987e9c3d3c9f9..abfb20f09e0c329b4f8a9af292655088836da5eb 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2015 Ericsson
+ * Copyright (c) 2010, 2016 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map.Entry;
 
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
@@ -38,6 +39,7 @@ import org.eclipse.tracecompass.internal.tmf.ui.Activator;
 import org.eclipse.tracecompass.internal.tmf.ui.Messages;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTrace;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
@@ -126,7 +128,7 @@ public class CustomTxtParserOutputWizardPage extends WizardPage {
 
     private void loadDefinition(final CustomTxtTraceDefinition def) {
         for (final OutputColumn outputColumn : def.outputs) {
-            final Output output = new Output(outputsContainer, outputColumn.name);
+            final Output output = new Output(outputsContainer, outputColumn.tag, outputColumn.name);
             outputs.add(output);
         }
     }
@@ -135,15 +137,16 @@ public class CustomTxtParserOutputWizardPage extends WizardPage {
     public void setVisible(final boolean visible) {
         if (visible) {
             this.definition = wizard.inputPage.getDefinition();
-            final List<String> outputNames = wizard.inputPage.getInputNames();
+            final List<Entry<Tag, String>> inputs = wizard.inputPage.getInputs();
 
             // dispose outputs that have been removed in the input page
             final Iterator<Output> iter = outputs.iterator();
             while (iter.hasNext()) {
                 final Output output = iter.next();
                 boolean found = false;
-                for (final String name : outputNames) {
-                    if (output.name.equals(name)) {
+                for (final Entry<Tag, String> input : inputs) {
+                    if (output.tag.equals(input.getKey()) &&
+                            output.name.equals(input.getValue())) {
                         found = true;
                         break;
                     }
@@ -155,16 +158,17 @@ public class CustomTxtParserOutputWizardPage extends WizardPage {
             }
 
             // create outputs that have been added in the input page
-            for (final String name : outputNames) {
+            for (final Entry<Tag, String> input : inputs) {
                 boolean found = false;
                 for (final Output output : outputs) {
-                    if (output.name.equals(name)) {
+                    if (output.tag.equals(input.getKey()) &&
+                            output.name.equals(input.getValue())) {
                         found = true;
                         break;
                     }
                 }
                 if (!found) {
-                    outputs.add(new Output(outputsContainer, name));
+                    outputs.add(new Output(outputsContainer, input.getKey(), input.getValue()));
                 }
             }
 
@@ -252,19 +256,10 @@ public class CustomTxtParserOutputWizardPage extends WizardPage {
      * @return The output columns
      */
     public List<OutputColumn> extractOutputs() {
-        int numColumns = 0;
-        for (int i = 0; i < outputs.size(); i++) {
-            if (outputs.get(i).enabledButton.getSelection()) {
-                numColumns++;
-            }
-        }
-        final List<OutputColumn> outputColumns = new ArrayList<>(numColumns);
-        numColumns = 0;
-        for (int i = 0; i < outputs.size(); i++) {
-            final Output output = outputs.get(i);
+        final List<OutputColumn> outputColumns = new ArrayList<>();
+        for (Output output : outputs) {
             if (output.enabledButton.getSelection()) {
-                final OutputColumn column = new OutputColumn();
-                column.name = checkNotNull(output.nameLabel.getText());
+                final OutputColumn column = new OutputColumn(checkNotNull(output.tag), checkNotNull(output.name));
                 outputColumns.add(column);
             }
         }
@@ -272,13 +267,15 @@ public class CustomTxtParserOutputWizardPage extends WizardPage {
     }
 
     private class Output {
+        Tag tag;
         String name;
         Button enabledButton;
         Text nameLabel;
         Button upButton;
         Button downButton;
 
-        public Output(final Composite parent, final String name) {
+        public Output(final Composite parent, final Tag tag, final String name) {
+            this.tag = tag;
             this.name = name;
 
             enabledButton = new Button(parent, SWT.CHECK);
index de8aac3c732a638512fde11934f7c1bdd4e49d83..4f9cc2f6237abf604ff116e9f97c3998ca5b7f84 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
+ * Copyright (c) 2010, 2016 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -19,8 +19,10 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.URL;
 import java.text.ParseException;
+import java.util.AbstractMap.SimpleEntry;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map.Entry;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -75,6 +77,7 @@ import org.eclipse.swt.widgets.Text;
 import org.eclipse.tracecompass.internal.tmf.ui.Activator;
 import org.eclipse.tracecompass.internal.tmf.ui.Messages;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlInputAttribute;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlInputElement;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace;
@@ -380,7 +383,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
         addChildButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                CustomXmlInputElement inputElement = new CustomXmlInputElement("", false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
+                CustomXmlInputElement inputElement = new CustomXmlInputElement("", false, Tag.IGNORE, Tag.IGNORE.toString(), 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
                 if (definition.rootInputElement == null) {
                     definition.rootInputElement = inputElement;
                     inputElement.setElementName(getChildNameSuggestion(null));
@@ -402,7 +405,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
         addNextButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                CustomXmlInputElement inputElement = new CustomXmlInputElement("", false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
+                CustomXmlInputElement inputElement = new CustomXmlInputElement("", false, Tag.IGNORE, Tag.IGNORE.toString(), 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
                 if (definition.rootInputElement == null) {
                     definition.rootInputElement = inputElement;
                     inputElement.setElementName(getChildNameSuggestion(null));
@@ -430,7 +433,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
                 CustomXmlInputElement inputElement = null;
                 if (definition.rootInputElement == null) {
                     if (getChildNameSuggestion(null).length() != 0) {
-                        inputElement = new CustomXmlInputElement(getChildNameSuggestion(null), false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$
+                        inputElement = new CustomXmlInputElement(getChildNameSuggestion(null), false, Tag.IGNORE, Tag.IGNORE.toString(), 0, "", null); //$NON-NLS-1$
                         definition.rootInputElement = inputElement;
                         feelingLucky(inputElement);
                     } else {
@@ -495,7 +498,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
             if (attributeName.length() == 0) {
                 break;
             }
-            CustomXmlInputAttribute attribute = new CustomXmlInputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$
+            CustomXmlInputAttribute attribute = new CustomXmlInputAttribute(attributeName, Tag.OTHER, attributeName, 0, ""); //$NON-NLS-1$
             inputElement.addAttribute(attribute);
         }
         while (true) {
@@ -503,7 +506,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
             if (childName.length() == 0) {
                 break;
             }
-            CustomXmlInputElement childElement = new CustomXmlInputElement(childName, false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$
+            CustomXmlInputElement childElement = new CustomXmlInputElement(childName, false, Tag.IGNORE, Tag.IGNORE.toString(), 0, "", null); //$NON-NLS-1$
             inputElement.addChild(childElement);
             feelingLucky(childElement);
         }
@@ -648,42 +651,42 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
     }
 
     /**
-     * Get the global list of input names.
+     * Get the global list of inputs.
      *
-     * @return The list of input names
+     * @return The list of inputs
      */
-    public List<String> getInputNames() {
-        return getInputNames(definition.rootInputElement);
+    public List<Entry<Tag, String>> getInputs() {
+        return getInputs(definition.rootInputElement);
     }
 
     /**
-     * Get the list of input names for a given element.
+     * Get the list of inputs for a given element, recursively.
      *
      * @param inputElement
      *            The element
-     * @return The input names for this element
+     * @return The list of inputs
      */
-    public List<String> getInputNames(CustomXmlInputElement inputElement) {
-        List<String> inputs = new ArrayList<>();
-        if (inputElement.getInputName() != null && !inputElement.getInputName().equals(CustomXmlTraceDefinition.TAG_IGNORE)) {
-            String inputName = inputElement.getInputName();
-            if (!inputs.contains(inputName)) {
-                inputs.add(inputName);
+    public List<Entry<Tag, String>> getInputs(CustomXmlInputElement inputElement) {
+        List<Entry<Tag, String>> inputs = new ArrayList<>();
+        if (inputElement.getInputTag() != null && !inputElement.getInputTag().equals(Tag.IGNORE)) {
+            Entry<Tag, String> input = new SimpleEntry<>(inputElement.getInputTag(), inputElement.getInputName());
+            if (!inputs.contains(input)) {
+                inputs.add(input);
             }
         }
         if (inputElement.getAttributes() != null) {
             for (CustomXmlInputAttribute attribute : inputElement.getAttributes()) {
-                String inputName = attribute.getInputName();
-                if (!inputs.contains(inputName)) {
-                    inputs.add(inputName);
+                Entry<Tag, String> input = new SimpleEntry<>(attribute.getInputTag(), attribute.getInputName());
+                if (!inputs.contains(input)) {
+                    inputs.add(input);
                 }
             }
         }
         if (inputElement.getChildElements() != null) {
             for (CustomXmlInputElement childInputElement : inputElement.getChildElements()) {
-                for (String inputName : getInputNames(childInputElement)) {
-                    if (!inputs.contains(inputName)) {
-                        inputs.add(inputName);
+                for (Entry<Tag, String> input : getInputs(childInputElement)) {
+                    if (!inputs.contains(input)) {
+                        inputs.add(input);
                     }
                 }
             }
@@ -943,8 +946,12 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
                 tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
 
                 tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
-                tagCombo.setItems(new String[] { CustomXmlTraceDefinition.TAG_IGNORE, CustomTraceDefinition.TAG_TIMESTAMP,
-                        CustomTraceDefinition.TAG_EVENT_TYPE, CustomTraceDefinition.TAG_MESSAGE, CustomTraceDefinition.TAG_OTHER });
+                tagCombo.setItems(new String[] {
+                        Tag.IGNORE.toString(),
+                        Tag.TIMESTAMP.toString(),
+                        Tag.EVENT_TYPE.toString(),
+                        Tag.MESSAGE.toString(),
+                        Tag.OTHER.toString() });
                 tagCombo.setVisibleItemCount(tagCombo.getItemCount());
                 tagCombo.addSelectionListener(new SelectionListener() {
                     @Override
@@ -1010,21 +1017,21 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
                 actionCombo.select(inputElement.getInputAction());
                 actionCombo.addSelectionListener(updateListener);
 
-                if (inputElement.getInputName().equals(CustomXmlTraceDefinition.TAG_IGNORE)) {
+                if (inputElement.getInputTag().equals(Tag.IGNORE)) {
                     tagCombo.select(0);
                     tagLabel.setVisible(false);
                     tagText.setVisible(false);
                     actionCombo.setVisible(false);
-                } else if (inputElement.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+                } else if (inputElement.getInputTag().equals(Tag.TIMESTAMP)) {
                     tagCombo.select(1);
                     tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);
                     tagText.setText(inputElement.getInputFormat());
                     tagText.addModifyListener(updateListener);
-                } else if (inputElement.getInputName().equals(CustomTraceDefinition.TAG_EVENT_TYPE)) {
+                } else if (inputElement.getInputTag().equals(Tag.EVENT_TYPE)) {
                     tagCombo.select(2);
                     tagLabel.setVisible(false);
                     tagText.setVisible(false);
-                } else if (inputElement.getInputName().equals(CustomTraceDefinition.TAG_MESSAGE)) {
+                } else if (inputElement.getInputTag().equals(Tag.MESSAGE)) {
                     tagCombo.select(3);
                     tagLabel.setVisible(false);
                     tagText.setVisible(false);
@@ -1090,7 +1097,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
                             logEntryButton.setSelection(false);
                         }
                     }
-                    if (tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP) && logEntriesCount <= 1) {
+                    if (tagCombo.getText().equals(Tag.TIMESTAMP.toString()) && logEntriesCount <= 1) {
                         String value = previewText.getText().trim();
                         if (value.length() != 0) {
                             if (actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_SET) {
@@ -1122,7 +1129,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
                     String value = element.getAttribute(attribute.attributeNameText.getText().trim());
                     if (value.length() != 0) {
                         attribute.previewText.setText(value);
-                        if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP) && logEntriesCount <= 1) {
+                        if (attribute.tagCombo.getText().equals(Tag.TIMESTAMP.toString()) && logEntriesCount <= 1) {
                             if (attribute.actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_SET) {
                                 timeStampValue = value;
                                 timeStampFormat = attribute.tagText.getText().trim();
@@ -1177,7 +1184,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
                 public void widgetSelected(SelectionEvent e) {
                     removeAddButton();
                     String attributeName = getAttributeNameSuggestion(inputElement);
-                    CustomXmlInputAttribute inputAttribute = new CustomXmlInputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$
+                    CustomXmlInputAttribute inputAttribute = new CustomXmlInputAttribute(attributeName, Tag.OTHER, attributeName, 0, ""); //$NON-NLS-1$
                     attributes.add(new Attribute(group, ElementNode.this, inputAttribute, attributes.size() + 1));
                     createAddButton();
                     elementContainer.layout();
@@ -1222,11 +1229,13 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
             if (inputElement.getParentElement() != null) {
                 inputElement.setLogEntry(logEntryButton.getSelection());
                 inputElement.setEventType(eventTypeButton.getSelection() ? eventTypeText.getText().trim() : null);
-                if (tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) {
+                Tag inputTag = Tag.fromLabel(tagCombo.getText());
+                inputElement.setInputTag(inputTag);
+                if (inputTag.equals(Tag.OTHER)) {
                     inputElement.setInputName(tagText.getText().trim());
                 } else {
-                    inputElement.setInputName(tagCombo.getText());
-                    if (tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+                    inputElement.setInputName(inputTag.toString());
+                    if (inputTag.equals(Tag.TIMESTAMP)) {
                         inputElement.setInputFormat(tagText.getText().trim());
                     }
                 }
@@ -1238,16 +1247,17 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
                 String inputFormat = null;
                 Attribute attribute = attributes.get(i);
                 String attributeName = attribute.attributeNameText.getText().trim();
-                if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) {
+                Tag inputTag = Tag.fromLabel(attribute.tagCombo.getText());
+                if (inputTag.equals(Tag.OTHER)) {
                     inputName = attribute.tagText.getText().trim();
                 } else {
-                    inputName = attribute.tagCombo.getText();
-                    if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+                    inputName = inputTag.toString();
+                    if (inputTag.equals(Tag.TIMESTAMP)) {
                         inputFormat = attribute.tagText.getText().trim();
                     }
                 }
                 int inputAction = attribute.actionCombo.getSelectionIndex();
-                inputElement.addAttribute(new CustomXmlInputAttribute(attributeName, inputName, inputAction, inputFormat));
+                inputElement.addAttribute(new CustomXmlInputAttribute(attributeName, inputTag, inputName, inputAction, inputFormat));
             }
         }
     }
@@ -1338,8 +1348,11 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
             tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
 
             tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
-            tagCombo.setItems(new String[] { CustomTraceDefinition.TAG_TIMESTAMP, CustomTraceDefinition.TAG_EVENT_TYPE,
-                    CustomTraceDefinition.TAG_MESSAGE, CustomTraceDefinition.TAG_OTHER });
+            tagCombo.setItems(new String[] {
+                    Tag.TIMESTAMP.toString(),
+                    Tag.EVENT_TYPE.toString(),
+                    Tag.MESSAGE.toString(),
+                    Tag.OTHER.toString() });
             tagCombo.select(3); // Other
             tagCombo.addSelectionListener(new SelectionListener() {
                 @Override
@@ -1397,16 +1410,16 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
             actionCombo.select(inputAttribute.getInputAction());
             actionCombo.addSelectionListener(updateListener);
 
-            if (inputAttribute.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+            if (inputAttribute.getInputTag().equals(Tag.TIMESTAMP)) {
                 tagCombo.select(0);
                 tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format);
                 tagText.setText(inputAttribute.getInputFormat());
                 tagText.addModifyListener(updateListener);
-            } else if (inputAttribute.getInputName().equals(CustomTraceDefinition.TAG_EVENT_TYPE)) {
+            } else if (inputAttribute.getInputTag().equals(Tag.EVENT_TYPE)) {
                 tagCombo.select(1);
                 tagLabel.setVisible(false);
                 tagText.setVisible(false);
-            } else if (inputAttribute.getInputName().equals(CustomTraceDefinition.TAG_MESSAGE)) {
+            } else if (inputAttribute.getInputTag().equals(Tag.MESSAGE)) {
                 tagCombo.select(2);
                 tagLabel.setVisible(false);
                 tagText.setVisible(false);
@@ -1635,7 +1648,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
             if (inputElement.isLogEntry()) {
                 logEntryFound = true;
             }
-            if (inputElement.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+            if (inputElement.getInputTag().equals(Tag.TIMESTAMP)) {
                 timeStampFound = true;
                 if (inputElement.getInputFormat().length() == 0) {
                     errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_elementMissingTimestampFmtError, getName(inputElement)));
@@ -1660,6 +1673,11 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
                 if (elementNode != null) {
                     elementNode.tagText.setBackground(COLOR_LIGHT_RED);
                 }
+            } else if (inputElement.getInputTag().equals(Tag.OTHER) && Tag.fromLabel(inputElement.getInputName()) != null) {
+                errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_elementReservedInputNameError, getName(inputElement)));
+                if (elementNode != null) {
+                    elementNode.tagText.setBackground(COLOR_LIGHT_RED);
+                }
             } else {
                 if (elementNode != null) {
                     elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND);
@@ -1705,7 +1723,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
                         elementNode.attributes.get(i).attributeNameText.setBackground(COLOR_LIGHT_RED);
                     }
                 }
-                if (attribute.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+                if (attribute.getInputTag().equals(Tag.TIMESTAMP)) {
                     timeStampFound = true;
                     if (attribute.getInputFormat().length() == 0) {
                         errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_attributeMissingTimestampFmtError, getName(attribute, inputElement)));
@@ -1730,6 +1748,11 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
                     if (elementNode != null) {
                         elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED);
                     }
+                } else if (attribute.getInputTag().equals(Tag.OTHER) && Tag.fromLabel(attribute.getInputName()) != null) {
+                    errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_attributeReservedInputNameError, getName(attribute, inputElement)));
+                    if (elementNode != null) {
+                        elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED);
+                    }
                 } else {
                     if (elementNode != null) {
                         elementNode.attributes.get(i).tagText.setBackground(COLOR_TEXT_BACKGROUND);
index bcf746899f28c168b6bcc5e3350901ba90faaffc..17766a7d683da4ec4288ed11934eed7bfa904bed 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2015 Ericsson
+ * Copyright (c) 2010, 2016 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map.Entry;
 
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
@@ -39,6 +40,7 @@ import org.eclipse.tracecompass.internal.tmf.ui.Messages;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
@@ -127,7 +129,7 @@ public class CustomXmlParserOutputWizardPage extends WizardPage {
 
     private void loadDefinition(final CustomTraceDefinition def) {
         for (final OutputColumn outputColumn : def.outputs) {
-            final Output output = new Output(outputsContainer, outputColumn.name);
+            final Output output = new Output(outputsContainer, outputColumn.tag, outputColumn.name);
             outputs.add(output);
         }
     }
@@ -136,15 +138,16 @@ public class CustomXmlParserOutputWizardPage extends WizardPage {
     public void setVisible(final boolean visible) {
         if (visible) {
             this.definition = wizard.inputPage.getDefinition();
-            final List<String> outputNames = wizard.inputPage.getInputNames();
+            final List<Entry<Tag, String>> inputs = wizard.inputPage.getInputs();
 
             // dispose outputs that have been removed in the input page
             final Iterator<Output> iter = outputs.iterator();
             while (iter.hasNext()) {
                 final Output output = iter.next();
                 boolean found = false;
-                for (final String name : outputNames) {
-                    if (output.name.equals(name)) {
+                for (final Entry<Tag, String> input : inputs) {
+                    if (output.tag.equals(input.getKey()) &&
+                            output.name.equals(input.getValue())) {
                         found = true;
                         break;
                     }
@@ -156,16 +159,17 @@ public class CustomXmlParserOutputWizardPage extends WizardPage {
             }
 
             // create outputs that have been added in the input page
-            for (final String name : outputNames) {
+            for (final Entry<Tag, String> input : inputs) {
                 boolean found = false;
                 for (final Output output : outputs) {
-                    if (output.name.equals(name)) {
+                    if (output.tag.equals(input.getKey()) &&
+                            output.name.equals(input.getValue())) {
                         found = true;
                         break;
                     }
                 }
                 if (!found) {
-                    outputs.add(new Output(outputsContainer, name));
+                    outputs.add(new Output(outputsContainer, input.getKey(), input.getValue()));
                 }
             }
 
@@ -253,19 +257,10 @@ public class CustomXmlParserOutputWizardPage extends WizardPage {
      * @return The list of output columns
      */
     public List<OutputColumn> extractOutputs() {
-        int numColumns = 0;
-        for (int i = 0; i < outputs.size(); i++) {
-            if (outputs.get(i).enabledButton.getSelection()) {
-                numColumns++;
-            }
-        }
-        final List<OutputColumn> outputColumns = new ArrayList<>(numColumns);
-        numColumns = 0;
-        for (int i = 0; i < outputs.size(); i++) {
-            final Output output = outputs.get(i);
+        final List<OutputColumn> outputColumns = new ArrayList<>();
+        for (Output output : outputs) {
             if (output.enabledButton.getSelection()) {
-                final OutputColumn column = new OutputColumn();
-                column.name = checkNotNull(output.nameLabel.getText());
+                final OutputColumn column = new OutputColumn(checkNotNull(output.tag), checkNotNull(output.name));
                 outputColumns.add(column);
             }
         }
@@ -273,13 +268,15 @@ public class CustomXmlParserOutputWizardPage extends WizardPage {
     }
 
     private class Output {
+        Tag tag;
         String name;
         Button enabledButton;
         Text nameLabel;
         Button upButton;
         Button downButton;
 
-        public Output(final Composite parent, final String name) {
+        public Output(final Composite parent, final Tag tag, final String name) {
+            this.tag = tag;
             this.name = name;
 
             enabledButton = new Button(parent, SWT.CHECK);
This page took 0.074669 seconds and 5 git commands to generate.