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
;
52 * Default (empty) constructor
54 public CustomXmlInputElement() {
63 * If this element is a log entry
65 * Name of the the input
71 * XML attributes of this element
73 public CustomXmlInputElement(String elementName
, boolean logEntry
,
74 String inputName
, int inputAction
, String inputFormat
,
75 List
<CustomXmlInputAttribute
> attributes
) {
76 fElementName
= elementName
;
78 fInputName
= inputName
;
79 fInputAction
= inputAction
;
80 fInputFormat
= inputFormat
;
81 fAttributes
= attributes
;
85 * Add a XML attribute to the element
88 * The attribute to add
90 public void addAttribute(CustomXmlInputAttribute attribute
) {
91 if (getAttributes() == null) {
92 fAttributes
= new ArrayList
<>(1);
94 getAttributes().add(attribute
);
98 * Add a child element to this one.
101 * The input element to add as child
103 public void addChild(CustomXmlInputElement input
) {
104 if (getChildElements() == null) {
105 fChildElements
= new ArrayList
<>(1);
106 } else if (getChildElements().size() > 0) {
107 CustomXmlInputElement last
= getChildElements().get(getChildElements().size() - 1);
108 last
.fNextElement
= input
;
110 getChildElements().add(input
);
111 input
.setParentElement(this);
115 * Set the following input element.
118 * The input element to add as next element
120 public void addNext(CustomXmlInputElement input
) {
121 if (getParentElement() != null) {
122 int index
= getParentElement().getChildElements().indexOf(this);
123 getParentElement().getChildElements().add(index
+ 1, input
);
124 CustomXmlInputElement next
= getNextElement();
125 fNextElement
= input
;
126 input
.fNextElement
= next
;
128 input
.setParentElement(getParentElement());
132 * Move this element up in its parent's list of children.
134 public void moveUp() {
135 if (getParentElement() != null) {
136 int index
= getParentElement().getChildElements().indexOf(this);
138 getParentElement().getChildElements().add(index
- 1, getParentElement().getChildElements().remove(index
));
139 getParentElement().getChildElements().get(index
).fNextElement
= fNextElement
;
140 fNextElement
= getParentElement().getChildElements().get(index
);
146 * Move this element down in its parent's list of children.
148 public void moveDown() {
149 if (getParentElement() != null) {
150 int index
= getParentElement().getChildElements().indexOf(this);
151 if (index
< getParentElement().getChildElements().size() - 1) {
152 getParentElement().getChildElements().add(index
+ 1, getParentElement().getChildElements().remove(index
));
153 fNextElement
= getParentElement().getChildElements().get(index
).getNextElement();
154 getParentElement().getChildElements().get(index
).fNextElement
= this;
160 * Get the element name
162 * @return the element name
164 public String
getElementName() {
169 * Set the element name
174 public void setElementName(String elementName
) {
175 fElementName
= elementName
;
179 * @return the logEntry
181 public boolean isLogEntry() {
187 * the logEntry to set
189 public void setLogEntry(boolean logEntry
) {
190 fLogEntry
= logEntry
;
194 * @return the inputName
196 public String
getInputName() {
202 * the inputName to set
204 public void setInputName(String inputName
) {
205 fInputName
= inputName
;
209 * @return the inputAction
211 public int getInputAction() {
217 * the inputAction to set
219 public void setInputAction(int inputAction
) {
220 fInputAction
= inputAction
;
224 * @return the inputFormat
226 public String
getInputFormat() {
232 * the inputFormat to set
234 public void setInputFormat(String inputFormat
) {
235 fInputFormat
= inputFormat
;
239 * @return the attributes
241 public List
<CustomXmlInputAttribute
> getAttributes() {
247 * the attributes to set
249 public void setAttributes(List
<CustomXmlInputAttribute
> attributes
) {
250 fAttributes
= attributes
;
254 * @return the parentElement
256 public CustomXmlInputElement
getParentElement() {
257 return fParentElement
;
261 * @param parentElement
262 * the parentElement to set
264 public void setParentElement(CustomXmlInputElement parentElement
) {
265 fParentElement
= parentElement
;
269 * @return the nextElement
271 public CustomXmlInputElement
getNextElement() {
277 * the nextElement to set
279 public void setNextElement(CustomXmlInputElement nextElement
) {
280 fNextElement
= nextElement
;
284 * @return the childElements
286 public List
<CustomXmlInputElement
> getChildElements() {
287 return fChildElements
;
291 * @param childElements
292 * the childElements to set
294 public void setChildElements(List
<CustomXmlInputElement
> childElements
) {
295 fChildElements
= childElements
;