1 /*******************************************************************************
2 * Copyright (c) 2014, 2016 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Patrick Tasse - Initial API and implementation
11 * Matthew Khouzam - Pulled out class
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
;
16 import java
.util
.ArrayList
;
17 import java
.util
.List
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.parsers
.custom
.CustomTraceDefinition
.Tag
;
22 * Wrapper for input XML elements
24 public final class CustomXmlInputElement
{
26 /** Name of the element */
27 private String fElementName
;
29 /** Indicates if this is a log entry */
30 private boolean fLogEntry
;
32 /** Tag of the input element */
33 private Tag fInputTag
;
35 /** Name of the input element */
36 private String fInputName
;
39 private int fInputAction
;
42 private String fInputFormat
;
44 /** XML attributes of this element */
45 private List
<CustomXmlInputAttribute
> fAttributes
;
48 private CustomXmlInputElement fParentElement
;
50 /** Following element in the file */
51 private CustomXmlInputElement fNextElement
;
54 private List
<CustomXmlInputElement
> fChildElements
;
56 /** Event type associated with this input element */
57 private String fEventType
;
60 * Default (empty) constructor
62 public CustomXmlInputElement() {
71 * If this element is a log entry
81 * XML attributes of this element
84 public CustomXmlInputElement(String elementName
, boolean logEntry
, Tag inputTag
,
85 String inputName
, int inputAction
, String inputFormat
,
86 List
<CustomXmlInputAttribute
> attributes
) {
87 fElementName
= elementName
;
90 fInputName
= inputName
;
91 fInputAction
= inputAction
;
92 fInputFormat
= inputFormat
;
93 fAttributes
= attributes
;
97 * Add a XML attribute to the element
100 * The attribute to add
102 public void addAttribute(CustomXmlInputAttribute attribute
) {
103 if (getAttributes() == null) {
104 fAttributes
= new ArrayList
<>(1);
106 getAttributes().add(attribute
);
110 * Add a child element to this one.
113 * The input element to add as child
115 public void addChild(CustomXmlInputElement input
) {
116 if (getChildElements() == null) {
117 fChildElements
= new ArrayList
<>(1);
118 } else if (getChildElements().size() > 0) {
119 CustomXmlInputElement last
= getChildElements().get(getChildElements().size() - 1);
120 last
.fNextElement
= input
;
122 getChildElements().add(input
);
123 input
.setParentElement(this);
127 * Set the following input element.
130 * The input element to add as next element
132 public void addNext(CustomXmlInputElement input
) {
133 if (getParentElement() != null) {
134 int index
= getParentElement().getChildElements().indexOf(this);
135 getParentElement().getChildElements().add(index
+ 1, input
);
136 CustomXmlInputElement next
= getNextElement();
137 fNextElement
= input
;
138 input
.fNextElement
= next
;
140 input
.setParentElement(getParentElement());
144 * Move this element up in its parent's list of children.
146 public void moveUp() {
147 if (getParentElement() != null) {
148 int index
= getParentElement().getChildElements().indexOf(this);
150 getParentElement().getChildElements().add(index
- 1, getParentElement().getChildElements().remove(index
));
151 getParentElement().getChildElements().get(index
).fNextElement
= fNextElement
;
152 fNextElement
= getParentElement().getChildElements().get(index
);
158 * Move this element down in its parent's list of children.
160 public void moveDown() {
161 if (getParentElement() != null) {
162 int index
= getParentElement().getChildElements().indexOf(this);
163 if (index
< getParentElement().getChildElements().size() - 1) {
164 getParentElement().getChildElements().add(index
+ 1, getParentElement().getChildElements().remove(index
));
165 fNextElement
= getParentElement().getChildElements().get(index
).getNextElement();
166 getParentElement().getChildElements().get(index
).fNextElement
= this;
172 * Get the element name
174 * @return the element name
176 public String
getElementName() {
181 * Set the element name
186 public void setElementName(String elementName
) {
187 fElementName
= elementName
;
191 * @return the logEntry
193 public boolean isLogEntry() {
199 * the logEntry to set
201 public void setLogEntry(boolean logEntry
) {
202 fLogEntry
= logEntry
;
206 * @return the inputTag
209 public Tag
getInputTag() {
215 * the inputTag to set
218 public void setInputTag(Tag inputTag
) {
219 fInputTag
= inputTag
;
223 * @return the inputName
225 public String
getInputName() {
231 * the inputName to set
233 public void setInputName(String inputName
) {
234 fInputName
= inputName
;
238 * @return the eventType, or null
241 public String
getEventType() {
247 * the eventType to set, or null
250 public void setEventType(String eventType
) {
251 fEventType
= eventType
;
255 * @return the inputAction
257 public int getInputAction() {
263 * the inputAction to set
265 public void setInputAction(int inputAction
) {
266 fInputAction
= inputAction
;
270 * @return the inputFormat
272 public String
getInputFormat() {
278 * the inputFormat to set
280 public void setInputFormat(String inputFormat
) {
281 fInputFormat
= inputFormat
;
285 * @return the attributes
287 public List
<CustomXmlInputAttribute
> getAttributes() {
293 * the attributes to set
295 public void setAttributes(List
<CustomXmlInputAttribute
> attributes
) {
296 fAttributes
= attributes
;
300 * @return the parentElement
302 public CustomXmlInputElement
getParentElement() {
303 return fParentElement
;
307 * @param parentElement
308 * the parentElement to set
310 public void setParentElement(CustomXmlInputElement parentElement
) {
311 fParentElement
= parentElement
;
315 * @return the nextElement
317 public CustomXmlInputElement
getNextElement() {
323 * the nextElement to set
325 public void setNextElement(CustomXmlInputElement nextElement
) {
326 fNextElement
= nextElement
;
330 * @return the childElements
332 public List
<CustomXmlInputElement
> getChildElements() {
333 return fChildElements
;
337 * @param childElements
338 * the childElements to set
340 public void setChildElements(List
<CustomXmlInputElement
> childElements
) {
341 fChildElements
= childElements
;