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
79 * XML attributes of this element
81 * {@link #CustomXmlInputElement(String, boolean, Tag, String, int, String, List)}
85 public CustomXmlInputElement(String elementName
, boolean logEntry
,
86 String inputName
, int inputAction
, String inputFormat
,
87 List
<CustomXmlInputAttribute
> attributes
) {
88 fElementName
= elementName
;
90 fInputName
= inputName
;
91 fInputAction
= inputAction
;
92 fInputFormat
= inputFormat
;
93 fAttributes
= attributes
;
102 * If this element is a log entry
112 * XML attributes of this element
115 public CustomXmlInputElement(String elementName
, boolean logEntry
, Tag inputTag
,
116 String inputName
, int inputAction
, String inputFormat
,
117 List
<CustomXmlInputAttribute
> attributes
) {
118 fElementName
= elementName
;
119 fLogEntry
= logEntry
;
120 fInputTag
= inputTag
;
121 fInputName
= inputName
;
122 fInputAction
= inputAction
;
123 fInputFormat
= inputFormat
;
124 fAttributes
= attributes
;
128 * Add a XML attribute to the element
131 * The attribute to add
133 public void addAttribute(CustomXmlInputAttribute attribute
) {
134 if (getAttributes() == null) {
135 fAttributes
= new ArrayList
<>(1);
137 getAttributes().add(attribute
);
141 * Add a child element to this one.
144 * The input element to add as child
146 public void addChild(CustomXmlInputElement input
) {
147 if (getChildElements() == null) {
148 fChildElements
= new ArrayList
<>(1);
149 } else if (getChildElements().size() > 0) {
150 CustomXmlInputElement last
= getChildElements().get(getChildElements().size() - 1);
151 last
.fNextElement
= input
;
153 getChildElements().add(input
);
154 input
.setParentElement(this);
158 * Set the following input element.
161 * The input element to add as next element
163 public void addNext(CustomXmlInputElement input
) {
164 if (getParentElement() != null) {
165 int index
= getParentElement().getChildElements().indexOf(this);
166 getParentElement().getChildElements().add(index
+ 1, input
);
167 CustomXmlInputElement next
= getNextElement();
168 fNextElement
= input
;
169 input
.fNextElement
= next
;
171 input
.setParentElement(getParentElement());
175 * Move this element up in its parent's list of children.
177 public void moveUp() {
178 if (getParentElement() != null) {
179 int index
= getParentElement().getChildElements().indexOf(this);
181 getParentElement().getChildElements().add(index
- 1, getParentElement().getChildElements().remove(index
));
182 getParentElement().getChildElements().get(index
).fNextElement
= fNextElement
;
183 fNextElement
= getParentElement().getChildElements().get(index
);
189 * Move this element down in its parent's list of children.
191 public void moveDown() {
192 if (getParentElement() != null) {
193 int index
= getParentElement().getChildElements().indexOf(this);
194 if (index
< getParentElement().getChildElements().size() - 1) {
195 getParentElement().getChildElements().add(index
+ 1, getParentElement().getChildElements().remove(index
));
196 fNextElement
= getParentElement().getChildElements().get(index
).getNextElement();
197 getParentElement().getChildElements().get(index
).fNextElement
= this;
203 * Get the element name
205 * @return the element name
207 public String
getElementName() {
212 * Set the element name
217 public void setElementName(String elementName
) {
218 fElementName
= elementName
;
222 * @return the logEntry
224 public boolean isLogEntry() {
230 * the logEntry to set
232 public void setLogEntry(boolean logEntry
) {
233 fLogEntry
= logEntry
;
237 * @return the inputTag
240 public Tag
getInputTag() {
246 * the inputTag to set
249 public void setInputTag(Tag inputTag
) {
250 fInputTag
= inputTag
;
254 * @return the inputName
256 public String
getInputName() {
262 * the inputName to set
264 public void setInputName(String inputName
) {
265 fInputName
= inputName
;
269 * @return the eventType, or null
272 public String
getEventType() {
278 * the eventType to set, or null
281 public void setEventType(String eventType
) {
282 fEventType
= eventType
;
286 * @return the inputAction
288 public int getInputAction() {
294 * the inputAction to set
296 public void setInputAction(int inputAction
) {
297 fInputAction
= inputAction
;
301 * @return the inputFormat
303 public String
getInputFormat() {
309 * the inputFormat to set
311 public void setInputFormat(String inputFormat
) {
312 fInputFormat
= inputFormat
;
316 * @return the attributes
318 public List
<CustomXmlInputAttribute
> getAttributes() {
324 * the attributes to set
326 public void setAttributes(List
<CustomXmlInputAttribute
> attributes
) {
327 fAttributes
= attributes
;
331 * @return the parentElement
333 public CustomXmlInputElement
getParentElement() {
334 return fParentElement
;
338 * @param parentElement
339 * the parentElement to set
341 public void setParentElement(CustomXmlInputElement parentElement
) {
342 fParentElement
= parentElement
;
346 * @return the nextElement
348 public CustomXmlInputElement
getNextElement() {
354 * the nextElement to set
356 public void setNextElement(CustomXmlInputElement nextElement
) {
357 fNextElement
= nextElement
;
361 * @return the childElements
363 public List
<CustomXmlInputElement
> getChildElements() {
364 return fChildElements
;
368 * @param childElements
369 * the childElements to set
371 public void setChildElements(List
<CustomXmlInputElement
> childElements
) {
372 fChildElements
= childElements
;