1 /*******************************************************************************
2 * Copyright (c) 2014 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
;
20 * Wrapper for input XML elements
22 public final class CustomXmlInputElement
{
24 /** Name of the element */
25 private String fElementName
;
27 /** Indicates if this is a log entry */
28 private boolean fLogEntry
;
30 /** Name of the input element */
31 private String fInputName
;
34 private int fInputAction
;
37 private String fInputFormat
;
39 /** XML attributes of this element */
40 private List
<CustomXmlInputAttribute
> fAttributes
;
43 private CustomXmlInputElement fParentElement
;
45 /** Following element in the file */
46 private CustomXmlInputElement fNextElement
;
49 private List
<CustomXmlInputElement
> fChildElements
;
51 /** Event type associated with this input element */
52 private String fEventType
;
55 * Default (empty) constructor
57 public CustomXmlInputElement() {
66 * If this element is a log entry
68 * Name of the the input
74 * XML attributes of this element
76 public CustomXmlInputElement(String elementName
, boolean logEntry
,
77 String inputName
, int inputAction
, String inputFormat
,
78 List
<CustomXmlInputAttribute
> attributes
) {
79 fElementName
= elementName
;
81 fInputName
= inputName
;
82 fInputAction
= inputAction
;
83 fInputFormat
= inputFormat
;
84 fAttributes
= attributes
;
88 * Add a XML attribute to the element
91 * The attribute to add
93 public void addAttribute(CustomXmlInputAttribute attribute
) {
94 if (getAttributes() == null) {
95 fAttributes
= new ArrayList
<>(1);
97 getAttributes().add(attribute
);
101 * Add a child element to this one.
104 * The input element to add as child
106 public void addChild(CustomXmlInputElement input
) {
107 if (getChildElements() == null) {
108 fChildElements
= new ArrayList
<>(1);
109 } else if (getChildElements().size() > 0) {
110 CustomXmlInputElement last
= getChildElements().get(getChildElements().size() - 1);
111 last
.fNextElement
= input
;
113 getChildElements().add(input
);
114 input
.setParentElement(this);
118 * Set the following input element.
121 * The input element to add as next element
123 public void addNext(CustomXmlInputElement input
) {
124 if (getParentElement() != null) {
125 int index
= getParentElement().getChildElements().indexOf(this);
126 getParentElement().getChildElements().add(index
+ 1, input
);
127 CustomXmlInputElement next
= getNextElement();
128 fNextElement
= input
;
129 input
.fNextElement
= next
;
131 input
.setParentElement(getParentElement());
135 * Move this element up in its parent's list of children.
137 public void moveUp() {
138 if (getParentElement() != null) {
139 int index
= getParentElement().getChildElements().indexOf(this);
141 getParentElement().getChildElements().add(index
- 1, getParentElement().getChildElements().remove(index
));
142 getParentElement().getChildElements().get(index
).fNextElement
= fNextElement
;
143 fNextElement
= getParentElement().getChildElements().get(index
);
149 * Move this element down in its parent's list of children.
151 public void moveDown() {
152 if (getParentElement() != null) {
153 int index
= getParentElement().getChildElements().indexOf(this);
154 if (index
< getParentElement().getChildElements().size() - 1) {
155 getParentElement().getChildElements().add(index
+ 1, getParentElement().getChildElements().remove(index
));
156 fNextElement
= getParentElement().getChildElements().get(index
).getNextElement();
157 getParentElement().getChildElements().get(index
).fNextElement
= this;
163 * Get the element name
165 * @return the element name
167 public String
getElementName() {
172 * Set the element name
177 public void setElementName(String elementName
) {
178 fElementName
= elementName
;
182 * @return the logEntry
184 public boolean isLogEntry() {
190 * the logEntry to set
192 public void setLogEntry(boolean logEntry
) {
193 fLogEntry
= logEntry
;
197 * @return the inputName
199 public String
getInputName() {
205 * the inputName to set
207 public void setInputName(String inputName
) {
208 fInputName
= inputName
;
212 * @return the eventType, or null
215 public String
getEventType() {
221 * the eventType to set, or null
224 public void setEventType(String eventType
) {
225 fEventType
= eventType
;
229 * @return the inputAction
231 public int getInputAction() {
237 * the inputAction to set
239 public void setInputAction(int inputAction
) {
240 fInputAction
= inputAction
;
244 * @return the inputFormat
246 public String
getInputFormat() {
252 * the inputFormat to set
254 public void setInputFormat(String inputFormat
) {
255 fInputFormat
= inputFormat
;
259 * @return the attributes
261 public List
<CustomXmlInputAttribute
> getAttributes() {
267 * the attributes to set
269 public void setAttributes(List
<CustomXmlInputAttribute
> attributes
) {
270 fAttributes
= attributes
;
274 * @return the parentElement
276 public CustomXmlInputElement
getParentElement() {
277 return fParentElement
;
281 * @param parentElement
282 * the parentElement to set
284 public void setParentElement(CustomXmlInputElement parentElement
) {
285 fParentElement
= parentElement
;
289 * @return the nextElement
291 public CustomXmlInputElement
getNextElement() {
297 * the nextElement to set
299 public void setNextElement(CustomXmlInputElement nextElement
) {
300 fNextElement
= nextElement
;
304 * @return the childElements
306 public List
<CustomXmlInputElement
> getChildElements() {
307 return fChildElements
;
311 * @param childElements
312 * the childElements to set
314 public void setChildElements(List
<CustomXmlInputElement
> childElements
) {
315 fChildElements
= childElements
;