From a7418109d95ba4c544004862c3dbb6d2d2889a40 Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Fri, 21 Nov 2014 17:12:45 -0500 Subject: [PATCH] tmf.ui clean up CustomXmlTraceDefinition a bit Change-Id: Ia8c96e588307b892d08f8a5cc8e723f7a723cf53 Signed-off-by: Matthew Khouzam Reviewed-on: https://git.eclipse.org/r/36871 Tested-by: Hudson CI Reviewed-by: Marc-Andre Laperle Tested-by: Marc-Andre Laperle --- .../custom/CustomXmlInputAttribute.java | 80 +++++ .../parsers/custom/CustomXmlInputElement.java | 298 ++++++++++++++++++ .../core/parsers/custom/CustomXmlTrace.java | 52 +-- .../custom/CustomXmlTraceDefinition.java | 264 +++------------- .../ui/tests/trace/CustomXmlTraceTest.java | 4 +- .../CustomXmlParserInputWizardPage.java | 255 +++++++-------- 6 files changed, 575 insertions(+), 378 deletions(-) create mode 100644 org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlInputAttribute.java create mode 100644 org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlInputElement.java diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlInputAttribute.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlInputAttribute.java new file mode 100644 index 0000000000..5040c3df3b --- /dev/null +++ b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlInputAttribute.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2014 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Patrick Tasse - Initial API and implementation + * Matthew Khouzam - Pulled out class + *******************************************************************************/ +package org.eclipse.tracecompass.tmf.core.parsers.custom; + +/** + * Wrapper for XML element attributes + */ +public final class CustomXmlInputAttribute { + + /** Name of the XML attribute */ + private final String fAttributeName; + + /** Input name */ + private final String fInputName; + + /** Input action */ + private final int fInputAction; + + /** Input format */ + private final String fInputFormat; + + /** + * Constructor + * + * @param attributeName + * Name of the XML attribute + * @param inputName + * Input name + * @param inputAction + * Input action + * @param inputFormat + * Input format + */ + public CustomXmlInputAttribute(String attributeName, String inputName, + int inputAction, String inputFormat) { + fAttributeName = attributeName; + fInputName = inputName; + fInputAction = inputAction; + fInputFormat = inputFormat; + } + + /** + * @return the attributeName + */ + public String getAttributeName() { + return fAttributeName; + } + + /** + * @return the inputName + */ + public String getInputName() { + return fInputName; + } + + /** + * @return the inputAction + */ + public int getInputAction() { + return fInputAction; + } + + /** + * @return the inputFormat + */ + public String getInputFormat() { + return fInputFormat; + } + +} \ No newline at end of file diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlInputElement.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlInputElement.java new file mode 100644 index 0000000000..79fbf333ea --- /dev/null +++ b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlInputElement.java @@ -0,0 +1,298 @@ +/******************************************************************************* + * Copyright (c) 2014 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Patrick Tasse - Initial API and implementation + * Matthew Khouzam - Pulled out class + *******************************************************************************/ + +package org.eclipse.tracecompass.tmf.core.parsers.custom; + +import java.util.ArrayList; +import java.util.List; + +/** + * Wrapper for input XML elements + */ +public final class CustomXmlInputElement { + + /** Name of the element */ + private String fElementName; + + /** Indicates if this is a log entry */ + private boolean fLogEntry; + + /** Name of the input element */ + private String fInputName; + + /** Input action */ + private int fInputAction; + + /** Input format */ + private String fInputFormat; + + /** XML attributes of this element */ + private List fAttributes; + + /** Parent element */ + private CustomXmlInputElement fParentElement; + + /** Following element in the file */ + private CustomXmlInputElement fNextElement; + + /** Child elements */ + private List fChildElements; + + /** + * Default (empty) constructor + */ + public CustomXmlInputElement() { + } + + /** + * Constructor + * + * @param elementName + * Element name + * @param logEntry + * If this element is a log entry + * @param inputName + * Name of the the input + * @param inputAction + * Input action + * @param inputFormat + * Input format + * @param attributes + * XML attributes of this element + */ + public CustomXmlInputElement(String elementName, boolean logEntry, + String inputName, int inputAction, String inputFormat, + List attributes) { + fElementName = elementName; + fLogEntry = logEntry; + fInputName = inputName; + fInputAction = inputAction; + fInputFormat = inputFormat; + fAttributes = attributes; + } + + /** + * Add a XML attribute to the element + * + * @param attribute + * The attribute to add + */ + public void addAttribute(CustomXmlInputAttribute attribute) { + if (getAttributes() == null) { + fAttributes = new ArrayList<>(1); + } + getAttributes().add(attribute); + } + + /** + * Add a child element to this one. + * + * @param input + * The input element to add as child + */ + public void addChild(CustomXmlInputElement input) { + if (getChildElements() == null) { + fChildElements = new ArrayList<>(1); + } else if (getChildElements().size() > 0) { + CustomXmlInputElement last = getChildElements().get(getChildElements().size() - 1); + last.fNextElement = input; + } + getChildElements().add(input); + input.setParentElement(this); + } + + /** + * Set the following input element. + * + * @param input + * The input element to add as next element + */ + public void addNext(CustomXmlInputElement input) { + if (getParentElement() != null) { + int index = getParentElement().getChildElements().indexOf(this); + getParentElement().getChildElements().add(index + 1, input); + CustomXmlInputElement next = getNextElement(); + fNextElement = input; + input.fNextElement = next; + } + input.setParentElement(getParentElement()); + } + + /** + * Move this element up in its parent's list of children. + */ + public void moveUp() { + if (getParentElement() != null) { + int index = getParentElement().getChildElements().indexOf(this); + if (index > 0) { + getParentElement().getChildElements().add(index - 1, getParentElement().getChildElements().remove(index)); + getParentElement().getChildElements().get(index).fNextElement = fNextElement; + fNextElement = getParentElement().getChildElements().get(index); + } + } + } + + /** + * Move this element down in its parent's list of children. + */ + public void moveDown() { + if (getParentElement() != null) { + int index = getParentElement().getChildElements().indexOf(this); + if (index < getParentElement().getChildElements().size() - 1) { + getParentElement().getChildElements().add(index + 1, getParentElement().getChildElements().remove(index)); + fNextElement = getParentElement().getChildElements().get(index).getNextElement(); + getParentElement().getChildElements().get(index).fNextElement = this; + } + } + } + + /** + * Get the element name + * + * @return the element name + */ + public String getElementName() { + return fElementName; + } + + /** + * Set the element name + * + * @param elementName + * the element name + */ + public void setElementName(String elementName) { + fElementName = elementName; + } + + /** + * @return the logEntry + */ + public boolean isLogEntry() { + return fLogEntry; + } + + /** + * @param logEntry + * the logEntry to set + */ + public void setLogEntry(boolean logEntry) { + fLogEntry = logEntry; + } + + /** + * @return the inputName + */ + public String getInputName() { + return fInputName; + } + + /** + * @param inputName + * the inputName to set + */ + public void setInputName(String inputName) { + fInputName = inputName; + } + + /** + * @return the inputAction + */ + public int getInputAction() { + return fInputAction; + } + + /** + * @param inputAction + * the inputAction to set + */ + public void setInputAction(int inputAction) { + fInputAction = inputAction; + } + + /** + * @return the inputFormat + */ + public String getInputFormat() { + return fInputFormat; + } + + /** + * @param inputFormat + * the inputFormat to set + */ + public void setInputFormat(String inputFormat) { + fInputFormat = inputFormat; + } + + /** + * @return the attributes + */ + public List getAttributes() { + return fAttributes; + } + + /** + * @param attributes + * the attributes to set + */ + public void setAttributes(List attributes) { + fAttributes = attributes; + } + + /** + * @return the parentElement + */ + public CustomXmlInputElement getParentElement() { + return fParentElement; + } + + /** + * @param parentElement + * the parentElement to set + */ + public void setParentElement(CustomXmlInputElement parentElement) { + fParentElement = parentElement; + } + + /** + * @return the nextElement + */ + public CustomXmlInputElement getNextElement() { + return fNextElement; + } + + /** + * @param nextElement + * the nextElement to set + */ + public void setNextElement(CustomXmlInputElement nextElement) { + fNextElement = nextElement; + } + + /** + * @return the childElements + */ + public List getChildElements() { + return fChildElements; + } + + /** + * @param childElements + * the childElements to set + */ + public void setChildElements(List childElements) { + fChildElements = childElements; + } + +} \ No newline at end of file diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTrace.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTrace.java index f4b7ba5e3f..117b86c76f 100644 --- a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTrace.java +++ b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTrace.java @@ -30,8 +30,6 @@ import org.eclipse.tracecompass.internal.tmf.core.Activator; import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; import org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile; -import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition.InputAttribute; -import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition.InputElement; import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; import org.eclipse.tracecompass.tmf.core.trace.ITmfEventParser; @@ -70,7 +68,7 @@ public class CustomXmlTrace extends TmfTrace implements ITmfEventParser, ITmfPer private final CustomXmlTraceDefinition fDefinition; private final CustomXmlEventType fEventType; - private final InputElement fRecordInputElement; + private final CustomXmlInputElement fRecordInputElement; private BufferedRandomAccessFile fFile; /** @@ -151,7 +149,7 @@ public class CustomXmlTrace extends TmfTrace implements ITmfEventParser, ITmfPer long rawPos = fFile.getFilePointer(); String line = fFile.getNextLine(); while (line != null) { - final int idx = indexOfElement(fRecordInputElement.elementName, line, 0); + final int idx = indexOfElement(fRecordInputElement.getElementName(), line, 0); if (idx != -1) { context.setLocation(new TmfLongLocation(rawPos + idx)); return context; @@ -244,9 +242,9 @@ public class CustomXmlTrace extends TmfTrace implements ITmfEventParser, ITmfPer CustomXmlEvent event = null; try { - if (fFile.getFilePointer() != (Long) context.getLocation().getLocationInfo() + 1) - { - fFile.seek((Long) context.getLocation().getLocationInfo() + 1); // +1 is for the < + // Below +1 for the < + if (fFile.getFilePointer() != (Long) context.getLocation().getLocationInfo() + 1) { + fFile.seek((Long) context.getLocation().getLocationInfo() + 1); } final StringBuffer elementBuffer = new StringBuffer("<"); //$NON-NLS-1$ readElement(elementBuffer, fFile); @@ -258,7 +256,7 @@ public class CustomXmlTrace extends TmfTrace implements ITmfEventParser, ITmfPer long rawPos = fFile.getFilePointer(); String line = fFile.getNextLine(); while (line != null) { - final int idx = indexOfElement(fRecordInputElement.elementName, line, 0); + final int idx = indexOfElement(fRecordInputElement.getElementName(), line, 0); if (idx != -1) { context.setLocation(new TmfLongLocation(rawPos + idx)); return event; @@ -293,10 +291,12 @@ public class CustomXmlTrace extends TmfTrace implements ITmfEventParser, ITmfPer // The following catches xml parsing exceptions db.setErrorHandler(new ErrorHandler() { @Override - public void error(final SAXParseException saxparseexception) throws SAXException {} + public void error(final SAXParseException saxparseexception) throws SAXException { + } @Override - public void warning(final SAXParseException saxparseexception) throws SAXException {} + public void warning(final SAXParseException saxparseexception) throws SAXException { + } @Override public void fatalError(final SAXParseException saxparseexception) throws SAXException { @@ -455,12 +455,12 @@ public class CustomXmlTrace extends TmfTrace implements ITmfEventParser, ITmfPer * The main element to check for. * @return The record element */ - public InputElement getRecordInputElement(final InputElement inputElement) { - if (inputElement.logEntry) { + public CustomXmlInputElement getRecordInputElement(final CustomXmlInputElement inputElement) { + if (inputElement.isLogEntry()) { return inputElement; - } else if (inputElement.childElements != null) { - for (final InputElement childInputElement : inputElement.childElements) { - final InputElement recordInputElement = getRecordInputElement(childInputElement); + } else if (inputElement.getChildElements() != null) { + for (final CustomXmlInputElement childInputElement : inputElement.getChildElements()) { + final CustomXmlInputElement recordInputElement = getRecordInputElement(childInputElement); if (recordInputElement != null) { return recordInputElement; } @@ -478,29 +478,29 @@ public class CustomXmlTrace extends TmfTrace implements ITmfEventParser, ITmfPer * The input element * @return The extracted event */ - public CustomXmlEvent extractEvent(final Element element, final InputElement inputElement) { + public CustomXmlEvent extractEvent(final Element element, final CustomXmlInputElement inputElement) { final CustomXmlEvent event = new CustomXmlEvent(fDefinition, this, TmfTimestamp.ZERO, fEventType); event.setContent(new CustomEventContent(event, new StringBuffer())); parseElement(element, event, inputElement); return event; } - private void parseElement(final Element element, final CustomXmlEvent event, final InputElement inputElement) { - if (inputElement.inputName != null && !inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_IGNORE)) { - event.parseInput(parseElement(element, new StringBuffer()).toString(), inputElement.inputName, inputElement.inputAction, inputElement.inputFormat); + private void parseElement(final Element element, final CustomXmlEvent event, final CustomXmlInputElement inputElement) { + 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.attributes != null) { - for (final InputAttribute attribute : inputElement.attributes) { - event.parseInput(element.getAttribute(attribute.attributeName), attribute.inputName, attribute.inputAction, attribute.inputFormat); + if (inputElement.getAttributes() != null) { + for (final CustomXmlInputAttribute attribute : inputElement.getAttributes()) { + event.parseInput(element.getAttribute(attribute.getAttributeName()), attribute.getInputName(), attribute.getInputAction(), attribute.getInputFormat()); } } final NodeList childNodes = element.getChildNodes(); - if (inputElement.childElements != null) { + if (inputElement.getChildElements() != null) { for (int i = 0; i < childNodes.getLength(); i++) { final Node node = childNodes.item(i); if (node instanceof Element) { - for (final InputElement child : inputElement.childElements) { - if (node.getNodeName().equals(child.elementName)) { + for (final CustomXmlInputElement child : inputElement.getChildElements()) { + if (node.getNodeName().equals(child.getElementName())) { parseElement((Element) node, event, child); break; } @@ -538,7 +538,7 @@ public class CustomXmlTrace extends TmfTrace implements ITmfEventParser, ITmfPer long rawPos = 0; String line = rafile.getNextLine(); while ((line != null) && (lineCount++ < MAX_LINES)) { - final int idx = indexOfElement(fRecordInputElement.elementName, line, 0); + final int idx = indexOfElement(fRecordInputElement.getElementName(), line, 0); if (idx != -1) { rafile.seek(rawPos + idx + 1); // +1 is for the < final StringBuffer elementBuffer = new StringBuffer("<"); //$NON-NLS-1$ diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTraceDefinition.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTraceDefinition.java index 2efd8e491f..556458bdea 100644 --- a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTraceDefinition.java +++ b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTraceDefinition.java @@ -101,7 +101,7 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { private static final String OUTPUT_COLUMN_ELEMENT = Messages.CustomXmlTraceDefinition_outputColumn; /** Top-level input element */ - public InputElement rootInputElement; + public CustomXmlInputElement rootInputElement; /** * Default constructor @@ -121,10 +121,11 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { * The list of output columns * @param timeStampOutputFormat * The timestamp format to use - * @deprecated Use {@link #CustomXmlTraceDefinition(String, String, InputElement, List, String)} + * @deprecated Use + * {@link #CustomXmlTraceDefinition(String, String, CustomXmlInputElement, List, String)} */ @Deprecated - public CustomXmlTraceDefinition(String traceType, InputElement rootElement, + public CustomXmlTraceDefinition(String traceType, CustomXmlInputElement rootElement, List outputs, String timeStampOutputFormat) { this.definitionName = traceType; this.rootInputElement = rootElement; @@ -147,7 +148,7 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { * The timestamp format to use * @since 3.2 */ - public CustomXmlTraceDefinition(String category, String traceType, InputElement rootElement, + public CustomXmlTraceDefinition(String category, String traceType, CustomXmlInputElement rootElement, List outputs, String timeStampOutputFormat) { this.categoryName = category; this.definitionName = traceType; @@ -156,192 +157,6 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { this.timeStampOutputFormat = timeStampOutputFormat; } - /** - * Wrapper for input XML elements - */ - public static class InputElement { - - /** Name of the element */ - public String elementName; - - /** Indicates if this is a log entry */ - public boolean logEntry; - - /** Name of the input element */ - public String inputName; - - /** Input action */ - public int inputAction; - - /** Input format */ - public String inputFormat; - - /** XML attributes of this element */ - public List attributes; - - /** Parent element */ - public InputElement parentElement; - - /** Following element in the file */ - public InputElement nextElement; - - /** Child elements */ - public List childElements; - - /** - * Default (empty) constructor - */ - public InputElement() { - } - - /** - * Constructor - * - * @param elementName - * Element name - * @param logEntry - * If this element is a log entry - * @param inputName - * Name of the the input - * @param inputAction - * Input action - * @param inputFormat - * Input format - * @param attributes - * XML attributes of this element - */ - public InputElement(String elementName, boolean logEntry, - String inputName, int inputAction, String inputFormat, - List attributes) { - this.elementName = elementName; - this.logEntry = logEntry; - this.inputName = inputName; - this.inputAction = inputAction; - this.inputFormat = inputFormat; - this.attributes = attributes; - } - - /** - * Add a XML attribute to the element - * - * @param attribute - * The attribute to add - */ - public void addAttribute(InputAttribute attribute) { - if (attributes == null) { - attributes = new ArrayList<>(1); - } - attributes.add(attribute); - } - - /** - * Add a child element to this one. - * - * @param input - * The input element to add as child - */ - public void addChild(InputElement input) { - if (childElements == null) { - childElements = new ArrayList<>(1); - } else if (childElements.size() > 0) { - InputElement last = childElements.get(childElements.size() - 1); - last.nextElement = input; - } - childElements.add(input); - input.parentElement = this; - } - - /** - * Set the following input element. - * - * @param input - * The input element to add as next element - */ - public void addNext(InputElement input) { - if (parentElement != null) { - int index = parentElement.childElements.indexOf(this); - parentElement.childElements.add(index + 1, input); - InputElement next = nextElement; - nextElement = input; - input.nextElement = next; - } - input.parentElement = this.parentElement; - } - - /** - * Move this element up in its parent's list of children. - */ - public void moveUp() { - if (parentElement != null) { - int index = parentElement.childElements.indexOf(this); - if (index > 0) { - parentElement.childElements.add(index - 1, parentElement.childElements.remove(index)); - parentElement.childElements.get(index).nextElement = nextElement; - nextElement = parentElement.childElements.get(index); - } - } - } - - /** - * Move this element down in its parent's list of children. - */ - public void moveDown() { - if (parentElement != null) { - int index = parentElement.childElements.indexOf(this); - if (index < parentElement.childElements.size() - 1) { - parentElement.childElements.add(index + 1, parentElement.childElements.remove(index)); - nextElement = parentElement.childElements.get(index).nextElement; - parentElement.childElements.get(index).nextElement = this; - } - } - } - - } - - /** - * Wrapper for XML element attributes - */ - public static class InputAttribute { - - /** Name of the XML attribute */ - public String attributeName; - - /** Input name */ - public String inputName; - - /** Input action */ - public int inputAction; - - /** Input format */ - public String inputFormat; - - /** - * Default (empty) constructor - */ - public InputAttribute() { - } - - /** - * Constructor - * - * @param attributeName - * Name of the XML attribute - * @param inputName - * Input name - * @param inputAction - * Input action - * @param inputFormat - * Input format - */ - public InputAttribute(String attributeName, String inputName, - int inputAction, String inputFormat) { - this.attributeName = attributeName; - this.inputName = inputName; - this.inputAction = inputAction; - this.inputFormat = inputFormat; - } - } - @Override public void save() { save(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME); @@ -419,41 +234,41 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { } } - private Element createInputElementElement(InputElement inputElement, Document doc) { + private Element createInputElementElement(CustomXmlInputElement inputElement, Document doc) { Element inputElementElement = doc.createElement(INPUT_ELEMENT_ELEMENT); - inputElementElement.setAttribute(NAME_ATTRIBUTE, inputElement.elementName); + inputElementElement.setAttribute(NAME_ATTRIBUTE, inputElement.getElementName()); - if (inputElement.logEntry) { - inputElementElement.setAttribute(LOG_ENTRY_ATTRIBUTE, Boolean.toString(inputElement.logEntry)); + if (inputElement.isLogEntry()) { + inputElementElement.setAttribute(LOG_ENTRY_ATTRIBUTE, Boolean.toString(inputElement.isLogEntry())); } - if (inputElement.parentElement != null) { + if (inputElement.getParentElement() != null) { Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT); inputElementElement.appendChild(inputDataElement); - inputDataElement.setAttribute(NAME_ATTRIBUTE, inputElement.inputName); - inputDataElement.setAttribute(ACTION_ATTRIBUTE, Integer.toString(inputElement.inputAction)); - if (inputElement.inputFormat != null) { - inputDataElement.setAttribute(FORMAT_ATTRIBUTE, inputElement.inputFormat); + inputDataElement.setAttribute(NAME_ATTRIBUTE, inputElement.getInputName()); + inputDataElement.setAttribute(ACTION_ATTRIBUTE, Integer.toString(inputElement.getInputAction())); + if (inputElement.getInputFormat() != null) { + inputDataElement.setAttribute(FORMAT_ATTRIBUTE, inputElement.getInputFormat()); } } - if (inputElement.attributes != null) { - for (InputAttribute attribute : inputElement.attributes) { + if (inputElement.getAttributes() != null) { + for (CustomXmlInputAttribute attribute : inputElement.getAttributes()) { Element inputAttributeElement = doc.createElement(ATTRIBUTE_ELEMENT); inputElementElement.appendChild(inputAttributeElement); - inputAttributeElement.setAttribute(NAME_ATTRIBUTE, attribute.attributeName); + inputAttributeElement.setAttribute(NAME_ATTRIBUTE, attribute.getAttributeName()); Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT); inputAttributeElement.appendChild(inputDataElement); - inputDataElement.setAttribute(NAME_ATTRIBUTE, attribute.inputName); - inputDataElement.setAttribute(ACTION_ATTRIBUTE, Integer.toString(attribute.inputAction)); - if (attribute.inputFormat != null) { - inputDataElement.setAttribute(FORMAT_ATTRIBUTE, attribute.inputFormat); + inputDataElement.setAttribute(NAME_ATTRIBUTE, attribute.getInputName()); + inputDataElement.setAttribute(ACTION_ATTRIBUTE, Integer.toString(attribute.getInputAction())); + if (attribute.getInputFormat() != null) { + inputDataElement.setAttribute(FORMAT_ATTRIBUTE, attribute.getInputFormat()); } } } - if (inputElement.childElements != null) { - for (InputElement childInputElement : inputElement.childElements) { + if (inputElement.getChildElements() != null) { + for (CustomXmlInputElement childInputElement : inputElement.getChildElements()) { inputElementElement.appendChild(createInputElementElement(childInputElement, doc)); } } @@ -710,7 +525,7 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { Element formatElement = (Element) node; def.timeStampOutputFormat = formatElement.getTextContent(); } else if (nodeName.equals(INPUT_ELEMENT_ELEMENT)) { - InputElement inputElement = extractInputElement((Element) node); + CustomXmlInputElement inputElement = extractInputElement((Element) node); if (inputElement != null) { if (def.rootInputElement == null) { def.rootInputElement = inputElement; @@ -728,38 +543,41 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { return def; } - private static InputElement extractInputElement(Element inputElementElement) { - InputElement inputElement = new InputElement(); - inputElement.elementName = inputElementElement.getAttribute(NAME_ATTRIBUTE); - inputElement.logEntry = (Boolean.toString(true).equals(inputElementElement.getAttribute(LOG_ENTRY_ATTRIBUTE))) ? true : false; + private static CustomXmlInputElement extractInputElement(Element inputElementElement) { + CustomXmlInputElement inputElement = new CustomXmlInputElement(); + inputElement.setElementName(inputElementElement.getAttribute(NAME_ATTRIBUTE)); + inputElement.setLogEntry((Boolean.toString(true).equals(inputElementElement.getAttribute(LOG_ENTRY_ATTRIBUTE))) ? true : false); NodeList nodeList = inputElementElement.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); String nodeName = node.getNodeName(); if (nodeName.equals(INPUT_DATA_ELEMENT)) { Element inputDataElement = (Element) node; - inputElement.inputName = inputDataElement.getAttribute(NAME_ATTRIBUTE); - inputElement.inputAction = Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE)); - inputElement.inputFormat = inputDataElement.getAttribute(FORMAT_ATTRIBUTE); + inputElement.setInputName(inputDataElement.getAttribute(NAME_ATTRIBUTE)); + inputElement.setInputAction(Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE))); + inputElement.setInputFormat(inputDataElement.getAttribute(FORMAT_ATTRIBUTE)); } else if (nodeName.equals(ATTRIBUTE_ELEMENT)) { Element attributeElement = (Element) node; - InputAttribute attribute = new InputAttribute(); - attribute.attributeName = attributeElement.getAttribute(NAME_ATTRIBUTE); + + 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; - attribute.inputName = inputDataElement.getAttribute(NAME_ATTRIBUTE); - attribute.inputAction = Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE)); - attribute.inputFormat = inputDataElement.getAttribute(FORMAT_ATTRIBUTE); + inputName = inputDataElement.getAttribute(NAME_ATTRIBUTE); + inputAction = Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE)); + inputFormat = inputDataElement.getAttribute(FORMAT_ATTRIBUTE); } } - inputElement.addAttribute(attribute); + inputElement.addAttribute(new CustomXmlInputAttribute(attributeName, inputName, inputAction, inputFormat)); } else if (nodeName.equals(INPUT_ELEMENT_ELEMENT)) { Element childInputElementElement = (Element) node; - InputElement childInputElement = extractInputElement(childInputElementElement); + CustomXmlInputElement childInputElement = extractInputElement(childInputElementElement); if (childInputElement != null) { inputElement.addChild(childInputElement); } diff --git a/org.eclipse.tracecompass.tmf.ui.tests/src/org/eclipse/tracecompass/tmf/ui/tests/trace/CustomXmlTraceTest.java b/org.eclipse.tracecompass.tmf.ui.tests/src/org/eclipse/tracecompass/tmf/ui/tests/trace/CustomXmlTraceTest.java index e80e192605..826b989a02 100644 --- a/org.eclipse.tracecompass.tmf.ui.tests/src/org/eclipse/tracecompass/tmf/ui/tests/trace/CustomXmlTraceTest.java +++ b/org.eclipse.tracecompass.tmf.ui.tests/src/org/eclipse/tracecompass/tmf/ui/tests/trace/CustomXmlTraceTest.java @@ -17,7 +17,7 @@ import java.util.ArrayList; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn; -import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition.InputElement; +import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlInputElement; import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType; import org.junit.Before; @@ -44,7 +44,7 @@ public abstract class CustomXmlTraceTest { */ @Before public void init() { - cxtd = new CustomXmlTraceDefinition(TmfTraceType.CUSTOM_XML_CATEGORY, "test", new InputElement(), new ArrayList(), "s"); + cxtd = new CustomXmlTraceDefinition(TmfTraceType.CUSTOM_XML_CATEGORY, "test", new CustomXmlInputElement(), new ArrayList(), "s"); t = new CustomXmlTrace(cxtd); } diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomXmlParserInputWizardPage.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomXmlParserInputWizardPage.java index d959a7e665..9e106b5e67 100644 --- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomXmlParserInputWizardPage.java +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomXmlParserInputWizardPage.java @@ -77,10 +77,10 @@ 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.CustomXmlInputElement; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition; -import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition.InputAttribute; -import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition.InputElement; +import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlInputAttribute; import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType; import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper; import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat; @@ -359,11 +359,11 @@ public class CustomXmlParserInputWizardPage extends WizardPage { return; } removeElement(); - InputElement inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); + CustomXmlInputElement inputElement = (CustomXmlInputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); if (inputElement == definition.rootInputElement) { definition.rootInputElement = null; } else { - inputElement.parentElement.childElements.remove(inputElement); + inputElement.getParentElement().getChildElements().remove(inputElement); } treeViewer.refresh(); validate(); @@ -387,16 +387,16 @@ public class CustomXmlParserInputWizardPage extends WizardPage { addChildButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - InputElement inputElement = new InputElement("", false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$ + CustomXmlInputElement inputElement = new CustomXmlInputElement("", false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$ if (definition.rootInputElement == null) { definition.rootInputElement = inputElement; - inputElement.elementName = getChildNameSuggestion(null); + inputElement.setElementName(getChildNameSuggestion(null)); } else if (treeViewer.getSelection().isEmpty()) { return; } else { - InputElement parentInputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); + CustomXmlInputElement parentInputElement = (CustomXmlInputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); parentInputElement.addChild(inputElement); - inputElement.elementName = getChildNameSuggestion(parentInputElement); + inputElement.setElementName(getChildNameSuggestion(parentInputElement)); } treeViewer.refresh(); treeViewer.setSelection(new StructuredSelection(inputElement), true); @@ -409,19 +409,19 @@ public class CustomXmlParserInputWizardPage extends WizardPage { addNextButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - InputElement inputElement = new InputElement("", false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$ + CustomXmlInputElement inputElement = new CustomXmlInputElement("", false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$ if (definition.rootInputElement == null) { definition.rootInputElement = inputElement; - inputElement.elementName = getChildNameSuggestion(null); + inputElement.setElementName(getChildNameSuggestion(null)); } else if (treeViewer.getSelection().isEmpty()) { return; } else { - InputElement previousInputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); + CustomXmlInputElement previousInputElement = (CustomXmlInputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); if (previousInputElement == definition.rootInputElement) { return; } previousInputElement.addNext(inputElement); - inputElement.elementName = getChildNameSuggestion(inputElement.parentElement); + inputElement.setElementName(getChildNameSuggestion(inputElement.getParentElement())); } treeViewer.refresh(); treeViewer.setSelection(new StructuredSelection(inputElement), true); @@ -434,10 +434,10 @@ public class CustomXmlParserInputWizardPage extends WizardPage { feelingLuckyButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - InputElement inputElement = null; + CustomXmlInputElement inputElement = null; if (definition.rootInputElement == null) { if (getChildNameSuggestion(null).length() != 0) { - inputElement = new InputElement(getChildNameSuggestion(null), false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ + inputElement = new CustomXmlInputElement(getChildNameSuggestion(null), false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ definition.rootInputElement = inputElement; feelingLucky(inputElement); } else { @@ -446,7 +446,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { } else if (treeViewer.getSelection().isEmpty()) { return; } else { - inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); + inputElement = (CustomXmlInputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); feelingLucky(inputElement); } treeViewer.refresh(); @@ -464,7 +464,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { if (treeViewer.getSelection().isEmpty()) { return; } - InputElement inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); + CustomXmlInputElement inputElement = (CustomXmlInputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); if (inputElement == definition.rootInputElement) { return; } @@ -484,7 +484,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { if (treeViewer.getSelection().isEmpty()) { return; } - InputElement inputElement = (InputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); + CustomXmlInputElement inputElement = (CustomXmlInputElement) ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); if (inputElement == definition.rootInputElement) { return; } @@ -496,13 +496,13 @@ public class CustomXmlParserInputWizardPage extends WizardPage { }); } - private void feelingLucky(InputElement inputElement) { + private void feelingLucky(CustomXmlInputElement inputElement) { while (true) { String attributeName = getAttributeNameSuggestion(inputElement); if (attributeName.length() == 0) { break; } - InputAttribute attribute = new InputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$ + CustomXmlInputAttribute attribute = new CustomXmlInputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$ inputElement.addAttribute(attribute); } while (true) { @@ -510,7 +510,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { if (childName.length() == 0) { break; } - InputElement childElement = new InputElement(childName, false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ + CustomXmlInputElement childElement = new CustomXmlInputElement(childName, false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ inputElement.addChild(childElement); feelingLucky(childElement); } @@ -529,17 +529,17 @@ public class CustomXmlParserInputWizardPage extends WizardPage { @Override public Object[] getChildren(Object parentElement) { - InputElement inputElement = (InputElement) parentElement; - if (inputElement.childElements == null) { - return new InputElement[0]; + CustomXmlInputElement inputElement = (CustomXmlInputElement) parentElement; + if (inputElement.getChildElements() == null) { + return new CustomXmlInputElement[0]; } - return inputElement.childElements.toArray(); + return inputElement.getChildElements().toArray(); } @Override public boolean hasChildren(Object element) { - InputElement inputElement = (InputElement) element; - return (inputElement.childElements != null && inputElement.childElements.size() > 0); + CustomXmlInputElement inputElement = (CustomXmlInputElement) element; + return (inputElement.getChildElements() != null && inputElement.getChildElements().size() > 0); } @Override @@ -552,8 +552,8 @@ public class CustomXmlParserInputWizardPage extends WizardPage { @Override public Object getParent(Object element) { - InputElement inputElement = (InputElement) element; - return inputElement.parentElement; + CustomXmlInputElement inputElement = (CustomXmlInputElement) element; + return inputElement.getParentElement(); } } @@ -566,8 +566,8 @@ public class CustomXmlParserInputWizardPage extends WizardPage { @Override public String getText(Object element) { - InputElement inputElement = (InputElement) element; - return (inputElement.elementName.trim().length() == 0) ? "?" : inputElement.elementName; //$NON-NLS-1$ + CustomXmlInputElement inputElement = (CustomXmlInputElement) element; + return (inputElement.getElementName().trim().length() == 0) ? "?" : inputElement.getElementName(); //$NON-NLS-1$ } } @@ -579,7 +579,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { } if (!(event.getSelection().isEmpty()) && event.getSelection() instanceof IStructuredSelection) { IStructuredSelection sel = (IStructuredSelection) event.getSelection(); - InputElement inputElement = (InputElement) sel.getFirstElement(); + CustomXmlInputElement inputElement = (CustomXmlInputElement) sel.getFirstElement(); selectedElement = new ElementNode(elementContainer, inputElement); elementContainer.layout(); elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, @@ -632,16 +632,16 @@ public class CustomXmlParserInputWizardPage extends WizardPage { } } - private String getName(InputElement inputElement) { - String name = (inputElement.elementName.trim().length() == 0) ? "?" : inputElement.elementName.trim(); //$NON-NLS-1$ - if (inputElement.parentElement == null) { + private String getName(CustomXmlInputElement inputElement) { + String name = (inputElement.getElementName().trim().length() == 0) ? "?" : inputElement.getElementName().trim(); //$NON-NLS-1$ + if (inputElement.getParentElement() == null) { return name; } - return getName(inputElement.parentElement) + " : " + name; //$NON-NLS-1$ + return getName(inputElement.getParentElement()) + " : " + name; //$NON-NLS-1$ } - private String getName(InputAttribute inputAttribute, InputElement inputElement) { - String name = (inputAttribute.attributeName.trim().length() == 0) ? "?" : inputAttribute.attributeName.trim(); //$NON-NLS-1$ + private String getName(CustomXmlInputAttribute inputAttribute, CustomXmlInputElement inputElement) { + String name = (inputAttribute.getAttributeName().trim().length() == 0) ? "?" : inputAttribute.getAttributeName().trim(); //$NON-NLS-1$ return getName(inputElement) + " : " + name; //$NON-NLS-1$ } @@ -670,24 +670,24 @@ public class CustomXmlParserInputWizardPage extends WizardPage { * The element * @return The input names for this element */ - public List getInputNames(InputElement inputElement) { + public List getInputNames(CustomXmlInputElement inputElement) { List inputs = new ArrayList<>(); - if (inputElement.inputName != null && !inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_IGNORE)) { - String inputName = inputElement.inputName; + if (inputElement.getInputName() != null && !inputElement.getInputName().equals(CustomXmlTraceDefinition.TAG_IGNORE)) { + String inputName = inputElement.getInputName(); if (!inputs.contains(inputName)) { inputs.add(inputName); } } - if (inputElement.attributes != null) { - for (InputAttribute attribute : inputElement.attributes) { - String inputName = attribute.inputName; + if (inputElement.getAttributes() != null) { + for (CustomXmlInputAttribute attribute : inputElement.getAttributes()) { + String inputName = attribute.getInputName(); if (!inputs.contains(inputName)) { inputs.add(inputName); } } } - if (inputElement.childElements != null) { - for (InputElement childInputElement : inputElement.childElements) { + if (inputElement.getChildElements() != null) { + for (CustomXmlInputElement childInputElement : inputElement.getChildElements()) { for (String inputName : getInputNames(childInputElement)) { if (!inputs.contains(inputName)) { inputs.add(inputName); @@ -873,7 +873,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { } private class ElementNode { - private final InputElement inputElement; + private final CustomXmlInputElement inputElement; private final Group group; private List attributes = new ArrayList<>(); private List childElements = new ArrayList<>(); @@ -891,7 +891,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { private Button addAttributeButton; private Label addAttributeLabel; - public ElementNode(Composite parent, InputElement inputElement) { + public ElementNode(Composite parent, CustomXmlInputElement inputElement) { this.inputElement = inputElement; group = new Group(parent, SWT.NONE); @@ -912,14 +912,14 @@ public class CustomXmlParserInputWizardPage extends WizardPage { elementNameText.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { - ElementNode.this.inputElement.elementName = elementNameText.getText().trim(); + ElementNode.this.inputElement.setElementName(elementNameText.getText().trim()); group.setText(getName(ElementNode.this.inputElement)); } }); - elementNameText.setText(inputElement.elementName); + elementNameText.setText(inputElement.getElementName()); elementNameText.addModifyListener(updateListener); - if (inputElement.parentElement != null) { + if (inputElement.getParentElement() != null) { previewLabel = new Label(group, SWT.NULL); previewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); previewLabel.setText(Messages.CustomXmlParserInputWizardPage_preview); @@ -933,7 +933,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { logEntryButton = new Button(group, SWT.CHECK); logEntryButton.setText(Messages.CustomXmlParserInputWizardPage_logEntry); - logEntryButton.setSelection(inputElement.logEntry); + logEntryButton.setSelection(inputElement.isLogEntry()); logEntryButton.addSelectionListener(new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent e) { @@ -941,10 +941,10 @@ public class CustomXmlParserInputWizardPage extends WizardPage { @Override public void widgetSelected(SelectionEvent e) { - InputElement parentElem = ElementNode.this.inputElement.parentElement; + CustomXmlInputElement parentElem = ElementNode.this.inputElement.getParentElement(); while (parentElem != null) { - parentElem.logEntry = false; - parentElem = parentElem.parentElement; + parentElem.setLogEntry(false); + parentElem = parentElem.getParentElement(); } } }); @@ -1017,33 +1017,33 @@ public class CustomXmlParserInputWizardPage extends WizardPage { actionCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY); actionCombo.setItems(new String[] { Messages.CustomXmlParserInputWizardPage_set, Messages.CustomXmlParserInputWizardPage_append, Messages.CustomXmlParserInputWizardPage_appendWith }); - actionCombo.select(inputElement.inputAction); + actionCombo.select(inputElement.getInputAction()); actionCombo.addSelectionListener(updateListener); - if (inputElement.inputName.equals(CustomXmlTraceDefinition.TAG_IGNORE)) { + if (inputElement.getInputName().equals(CustomXmlTraceDefinition.TAG_IGNORE)) { tagCombo.select(0); tagLabel.setVisible(false); tagText.setVisible(false); actionCombo.setVisible(false); - } else if (inputElement.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { + } else if (inputElement.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { tagCombo.select(1); tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format); - tagText.setText(inputElement.inputFormat); + tagText.setText(inputElement.getInputFormat()); tagText.addModifyListener(updateListener); - } else if (inputElement.inputName.equals(CustomTraceDefinition.TAG_MESSAGE)) { + } else if (inputElement.getInputName().equals(CustomTraceDefinition.TAG_MESSAGE)) { tagCombo.select(2); tagLabel.setVisible(false); tagText.setVisible(false); } else { tagCombo.select(3); tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName); - tagText.setText(inputElement.inputName); + tagText.setText(inputElement.getInputName()); tagText.addModifyListener(updateListener); } } - if (inputElement.attributes != null) { - for (InputAttribute inputAttribute : inputElement.attributes) { + if (inputElement.getAttributes() != null) { + for (CustomXmlInputAttribute inputAttribute : inputElement.getAttributes()) { Attribute attribute = new Attribute(group, this, inputAttribute, attributes.size() + 1); attributes.add(attribute); } @@ -1054,7 +1054,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { private void updatePreview() { Element element = getPreviewElement(inputElement); - if (inputElement.parentElement != null) { // no preview text for + if (inputElement.getParentElement() != null) { // no preview text for // document element previewText.setText(Messages.CustomXmlParserInputWizardPage_noMatchingElement); if (element != null) { @@ -1155,7 +1155,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { public void widgetSelected(SelectionEvent e) { removeAddButton(); String attributeName = getAttributeNameSuggestion(inputElement); - InputAttribute inputAttribute = new InputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$ + CustomXmlInputAttribute inputAttribute = new CustomXmlInputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$ attributes.add(new Attribute(group, ElementNode.this, inputAttribute, attributes.size() + 1)); createAddButton(); elementContainer.layout(); @@ -1196,34 +1196,35 @@ public class CustomXmlParserInputWizardPage extends WizardPage { } private void extractInputs() { - inputElement.elementName = elementNameText.getText().trim(); - if (inputElement.parentElement != null) { - inputElement.logEntry = logEntryButton.getSelection(); + inputElement.setElementName(elementNameText.getText().trim()); + if (inputElement.getParentElement() != null) { + inputElement.setLogEntry(logEntryButton.getSelection()); if (tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) { - inputElement.inputName = tagText.getText().trim(); + inputElement.setInputName(tagText.getText().trim()); } else { - inputElement.inputName = tagCombo.getText(); + inputElement.setInputName(tagCombo.getText()); if (tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { - inputElement.inputFormat = tagText.getText().trim(); + inputElement.setInputFormat(tagText.getText().trim()); } } - inputElement.inputAction = actionCombo.getSelectionIndex(); + inputElement.setInputAction(actionCombo.getSelectionIndex()); } - inputElement.attributes = new ArrayList<>(attributes.size()); + inputElement.setAttributes(new ArrayList(attributes.size())); for (int i = 0; i < attributes.size(); i++) { + String inputName = null; + String inputFormat = null; Attribute attribute = attributes.get(i); - InputAttribute inputAttribute = new InputAttribute(); - inputAttribute.attributeName = attribute.attributeNameText.getText().trim(); + String attributeName = attribute.attributeNameText.getText().trim(); if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) { - inputAttribute.inputName = attribute.tagText.getText().trim(); + inputName = attribute.tagText.getText().trim(); } else { - inputAttribute.inputName = attribute.tagCombo.getText(); + inputName = attribute.tagCombo.getText(); if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { - inputAttribute.inputFormat = attribute.tagText.getText().trim(); + inputFormat = attribute.tagText.getText().trim(); } } - inputAttribute.inputAction = attribute.actionCombo.getSelectionIndex(); - inputElement.addAttribute(inputAttribute); + int inputAction = attribute.actionCombo.getSelectionIndex(); + inputElement.addAttribute(new CustomXmlInputAttribute(attributeName, inputName, inputAction, inputFormat)); } } } @@ -1251,7 +1252,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { private Text tagText; private Combo actionCombo; - public Attribute(Composite parent, ElementNode element, InputAttribute inputAttribute, int attributeNumber) { + public Attribute(Composite parent, ElementNode element, CustomXmlInputAttribute inputAttribute, int attributeNumber) { this.element = element; this.attributeNumber = attributeNumber; @@ -1291,7 +1292,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { attributeNameText = new Text(attributeComposite, SWT.BORDER | SWT.SINGLE); attributeNameText.setLayoutData(new GridData(120, SWT.DEFAULT)); - attributeNameText.setText(inputAttribute.attributeName); + attributeNameText.setText(inputAttribute.getAttributeName()); attributeNameText.addModifyListener(updateListener); Label previewLabel = new Label(attributeComposite, SWT.NONE); @@ -1366,22 +1367,22 @@ public class CustomXmlParserInputWizardPage extends WizardPage { actionCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY); actionCombo.setItems(new String[] { Messages.CustomXmlParserInputWizardPage_set, Messages.CustomXmlParserInputWizardPage_append, Messages.CustomXmlParserInputWizardPage_appendWith }); - actionCombo.select(inputAttribute.inputAction); + actionCombo.select(inputAttribute.getInputAction()); actionCombo.addSelectionListener(updateListener); - if (inputAttribute.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { + if (inputAttribute.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { tagCombo.select(0); tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format); - tagText.setText(inputAttribute.inputFormat); + tagText.setText(inputAttribute.getInputFormat()); tagText.addModifyListener(updateListener); - } else if (inputAttribute.inputName.equals(CustomTraceDefinition.TAG_MESSAGE)) { + } else if (inputAttribute.getInputName().equals(CustomTraceDefinition.TAG_MESSAGE)) { tagCombo.select(1); tagLabel.setVisible(false); tagText.setVisible(false); } else { tagCombo.select(2); tagLabel.setText(Messages.CustomXmlParserInputWizardPage_tagName); - tagText.setText(inputAttribute.inputName); + tagText.setText(inputAttribute.getInputName()); tagText.addModifyListener(updateListener); } } @@ -1399,17 +1400,17 @@ public class CustomXmlParserInputWizardPage extends WizardPage { } } - private Element getPreviewElement(InputElement inputElement) { - InputElement currentElement = inputElement; + private Element getPreviewElement(CustomXmlInputElement inputElement) { + CustomXmlInputElement currentElement = inputElement; Element element = documentElement; if (element != null) { - if (!documentElement.getNodeName().equals(definition.rootInputElement.elementName)) { + if (!documentElement.getNodeName().equals(definition.rootInputElement.getElementName())) { return null; } ArrayList elementNames = new ArrayList<>(); while (currentElement != null) { - elementNames.add(currentElement.elementName); - currentElement = currentElement.parentElement; + elementNames.add(currentElement.getElementName()); + currentElement = currentElement.getParentElement(); } for (int i = elementNames.size() - 1; --i >= 0;) { NodeList childList = element.getChildNodes(); @@ -1432,7 +1433,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { return null; } - private String getChildNameSuggestion(InputElement inputElement) { + private String getChildNameSuggestion(CustomXmlInputElement inputElement) { if (inputElement == null) { if (documentElement != null) { return documentElement.getNodeName(); @@ -1445,9 +1446,9 @@ public class CustomXmlParserInputWizardPage extends WizardPage { Node node = childNodes.item(i); if (node instanceof Element) { boolean unused = true; - if (inputElement.childElements != null) { - for (InputElement child : inputElement.childElements) { - if (child.elementName.equals(node.getNodeName())) { + if (inputElement.getChildElements() != null) { + for (CustomXmlInputElement child : inputElement.getChildElements()) { + if (child.getElementName().equals(node.getNodeName())) { unused = false; break; } @@ -1463,16 +1464,16 @@ public class CustomXmlParserInputWizardPage extends WizardPage { return ""; //$NON-NLS-1$ } - private String getAttributeNameSuggestion(InputElement inputElement) { + private String getAttributeNameSuggestion(CustomXmlInputElement inputElement) { Element element = getPreviewElement(inputElement); if (element != null) { NamedNodeMap attributeMap = element.getAttributes(); for (int i = 0; i < attributeMap.getLength(); i++) { Node node = attributeMap.item(i); boolean unused = true; - if (inputElement.attributes != null) { - for (InputAttribute attribute : inputElement.attributes) { - if (attribute.attributeName.equals(node.getNodeName())) { + if (inputElement.getAttributes() != null) { + for (CustomXmlInputAttribute attribute : inputElement.getAttributes()) { + if (attribute.getAttributeName().equals(node.getNodeName())) { unused = false; break; } @@ -1537,8 +1538,8 @@ public class CustomXmlParserInputWizardPage extends WizardPage { errors.addAll(validateElement(definition.rootInputElement)); - if ((definition.rootInputElement.attributes != null && definition.rootInputElement.attributes.size() != 0) - || (definition.rootInputElement.childElements != null && definition.rootInputElement.childElements.size() != 0) + if ((definition.rootInputElement.getAttributes() != null && definition.rootInputElement.getAttributes().size() != 0) + || (definition.rootInputElement.getChildElements() != null && definition.rootInputElement.getChildElements().size() != 0) || errors.size() == 0) { if (!logEntryFound) { errors.add(Messages.CustomXmlParserInputWizardPage_missingLogEntryError); @@ -1581,14 +1582,14 @@ public class CustomXmlParserInputWizardPage extends WizardPage { * The element to clean up * @return The validated element */ - public List validateElement(InputElement inputElement) { + public List validateElement(CustomXmlInputElement inputElement) { List errors = new ArrayList<>(); ElementNode elementNode = null; if (selectedElement != null && selectedElement.inputElement.equals(inputElement)) { elementNode = selectedElement; } if (inputElement == definition.rootInputElement) { - if (inputElement.elementName.length() == 0) { + if (inputElement.getElementName().length() == 0) { errors.add(Messages.CustomXmlParserInputWizardPage_missingDocumentElementError); if (elementNode != null) { elementNode.elementNameText.setBackground(COLOR_LIGHT_RED); @@ -1600,19 +1601,19 @@ public class CustomXmlParserInputWizardPage extends WizardPage { } } if (inputElement != definition.rootInputElement) { - if (inputElement.logEntry) { + if (inputElement.isLogEntry()) { logEntryFound = true; } - if (inputElement.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { + if (inputElement.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { timeStampFound = true; - if (inputElement.inputFormat.length() == 0) { + if (inputElement.getInputFormat().length() == 0) { errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_elementMissingTimestampFmtError, getName(inputElement))); if (elementNode != null) { elementNode.tagText.setBackground(COLOR_LIGHT_RED); } } else { try { - new TmfTimestampFormat(inputElement.inputFormat); + new TmfTimestampFormat(inputElement.getInputFormat()); if (elementNode != null) { elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND); } @@ -1623,7 +1624,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { } } } - } else if (inputElement.inputName.length() == 0) { + } else if (inputElement.getInputName().length() == 0) { errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_elementMissingInputNameError, getName(inputElement))); if (elementNode != null) { elementNode.tagText.setBackground(COLOR_LIGHT_RED); @@ -1634,25 +1635,25 @@ public class CustomXmlParserInputWizardPage extends WizardPage { } } } - if (inputElement.attributes != null) { + if (inputElement.getAttributes() != null) { if (elementNode != null) { for (Attribute attribute : elementNode.attributes) { attribute.attributeNameText.setBackground(COLOR_TEXT_BACKGROUND); } } - for (int i = 0; i < inputElement.attributes.size(); i++) { - InputAttribute attribute = inputElement.attributes.get(i); + for (int i = 0; i < inputElement.getAttributes().size(); i++) { + CustomXmlInputAttribute attribute = inputElement.getAttributes().get(i); boolean duplicate = false; - for (int j = i + 1; j < inputElement.attributes.size(); j++) { - InputAttribute otherAttribute = inputElement.attributes.get(j); - if (otherAttribute.attributeName.equals(attribute.attributeName)) { + for (int j = i + 1; j < inputElement.getAttributes().size(); j++) { + CustomXmlInputAttribute otherAttribute = inputElement.getAttributes().get(j); + if (otherAttribute.getAttributeName().equals(attribute.getAttributeName())) { duplicate = true; if (elementNode != null) { elementNode.attributes.get(j).attributeNameText.setBackground(COLOR_LIGHT_RED); } } } - if (attribute.attributeName.length() == 0) { + if (attribute.getAttributeName().length() == 0) { errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_attributeMissingNameError, getName(inputElement))); if (elementNode != null) { elementNode.attributes.get(i).attributeNameText.setBackground(COLOR_LIGHT_RED); @@ -1663,16 +1664,16 @@ public class CustomXmlParserInputWizardPage extends WizardPage { elementNode.attributes.get(i).attributeNameText.setBackground(COLOR_LIGHT_RED); } } - if (attribute.inputName.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { + if (attribute.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { timeStampFound = true; - if (attribute.inputFormat.length() == 0) { + if (attribute.getInputFormat().length() == 0) { errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_attributeMissingTimestampFmtError, getName(attribute, inputElement))); if (elementNode != null) { elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED); } } else { try { - new TmfTimestampFormat(attribute.inputFormat); + new TmfTimestampFormat(attribute.getInputFormat()); if (elementNode != null) { elementNode.attributes.get(i).tagText.setBackground(COLOR_TEXT_BACKGROUND); } @@ -1683,7 +1684,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { } } } - } else if (attribute.inputName.length() == 0) { + } else if (attribute.getInputName().length() == 0) { errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_attributeMissingInputNameError, getName(attribute, inputElement))); if (elementNode != null) { elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED); @@ -1695,8 +1696,8 @@ public class CustomXmlParserInputWizardPage extends WizardPage { } } } - if (inputElement.childElements != null) { - for (InputElement child : inputElement.childElements) { + if (inputElement.getChildElements() != null) { + for (CustomXmlInputElement child : inputElement.getChildElements()) { ElementNode childElementNode = null; if (selectedElement != null && selectedElement.inputElement.equals(child)) { childElementNode = selectedElement; @@ -1705,22 +1706,22 @@ public class CustomXmlParserInputWizardPage extends WizardPage { childElementNode.elementNameText.setBackground(COLOR_TEXT_BACKGROUND); } } - for (int i = 0; i < inputElement.childElements.size(); i++) { - InputElement child = inputElement.childElements.get(i); + for (int i = 0; i < inputElement.getChildElements().size(); i++) { + CustomXmlInputElement child = inputElement.getChildElements().get(i); ElementNode childElementNode = null; if (selectedElement != null && selectedElement.inputElement.equals(child)) { childElementNode = selectedElement; } - if (child.elementName.length() == 0) { + if (child.getElementName().length() == 0) { errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_elementMissingNameError, getName(child))); if (childElementNode != null) { childElementNode.elementNameText.setBackground(COLOR_LIGHT_RED); } } else { boolean duplicate = false; - for (int j = i + 1; j < inputElement.childElements.size(); j++) { - InputElement otherChild = inputElement.childElements.get(j); - if (otherChild.elementName.equals(child.elementName)) { + for (int j = i + 1; j < inputElement.getChildElements().size(); j++) { + CustomXmlInputElement otherChild = inputElement.getChildElements().get(j); + if (otherChild.getElementName().equals(child.getElementName())) { duplicate = true; ElementNode otherChildElementNode = null; if (selectedElement != null && selectedElement.inputElement.equals(otherChild)) { -- 2.34.1