20921013387937d3c94975715637713e9ff879af
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / parsers / custom / CustomXmlInputElement.java
1 /*******************************************************************************
2 * Copyright (c) 2014, 2016 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 * Matthew Khouzam - Pulled out class
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.tmf.core.parsers.custom;
15
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
20
21 /**
22 * Wrapper for input XML elements
23 */
24 public final class CustomXmlInputElement {
25
26 /** Name of the element */
27 private String fElementName;
28
29 /** Indicates if this is a log entry */
30 private boolean fLogEntry;
31
32 /** Tag of the input element */
33 private Tag fInputTag;
34
35 /** Name of the input element */
36 private String fInputName;
37
38 /** Input action */
39 private int fInputAction;
40
41 /** Input format */
42 private String fInputFormat;
43
44 /** XML attributes of this element */
45 private List<CustomXmlInputAttribute> fAttributes;
46
47 /** Parent element */
48 private CustomXmlInputElement fParentElement;
49
50 /** Following element in the file */
51 private CustomXmlInputElement fNextElement;
52
53 /** Child elements */
54 private List<CustomXmlInputElement> fChildElements;
55
56 /** Event type associated with this input element */
57 private String fEventType;
58
59 /**
60 * Default (empty) constructor
61 */
62 public CustomXmlInputElement() {
63 }
64
65 /**
66 * Constructor
67 *
68 * @param elementName
69 * Element name
70 * @param logEntry
71 * If this element is a log entry
72 * @param inputName
73 * Name of the input
74 * @param inputAction
75 * Input action
76 * @param inputFormat
77 * Input format
78 * @param attributes
79 * XML attributes of this element
80 * @deprecated Use
81 * {@link #CustomXmlInputElement(String, boolean, Tag, String, int, String, List)}
82 * instead.
83 */
84 @Deprecated
85 public CustomXmlInputElement(String elementName, boolean logEntry,
86 String inputName, int inputAction, String inputFormat,
87 List<CustomXmlInputAttribute> attributes) {
88 fElementName = elementName;
89 fLogEntry = logEntry;
90 fInputName = inputName;
91 fInputAction = inputAction;
92 fInputFormat = inputFormat;
93 fAttributes = attributes;
94 }
95
96 /**
97 * Constructor
98 *
99 * @param elementName
100 * Element name
101 * @param logEntry
102 * If this element is a log entry
103 * @param inputTag
104 * Tag of the input
105 * @param inputName
106 * Name of the input
107 * @param inputAction
108 * Input action
109 * @param inputFormat
110 * Input format
111 * @param attributes
112 * XML attributes of this element
113 * @since 2.1
114 */
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;
125 }
126
127 /**
128 * Add a XML attribute to the element
129 *
130 * @param attribute
131 * The attribute to add
132 */
133 public void addAttribute(CustomXmlInputAttribute attribute) {
134 if (getAttributes() == null) {
135 fAttributes = new ArrayList<>(1);
136 }
137 getAttributes().add(attribute);
138 }
139
140 /**
141 * Add a child element to this one.
142 *
143 * @param input
144 * The input element to add as child
145 */
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;
152 }
153 getChildElements().add(input);
154 input.setParentElement(this);
155 }
156
157 /**
158 * Set the following input element.
159 *
160 * @param input
161 * The input element to add as next element
162 */
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;
170 }
171 input.setParentElement(getParentElement());
172 }
173
174 /**
175 * Move this element up in its parent's list of children.
176 */
177 public void moveUp() {
178 if (getParentElement() != null) {
179 int index = getParentElement().getChildElements().indexOf(this);
180 if (index > 0) {
181 getParentElement().getChildElements().add(index - 1, getParentElement().getChildElements().remove(index));
182 getParentElement().getChildElements().get(index).fNextElement = fNextElement;
183 fNextElement = getParentElement().getChildElements().get(index);
184 }
185 }
186 }
187
188 /**
189 * Move this element down in its parent's list of children.
190 */
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;
198 }
199 }
200 }
201
202 /**
203 * Get the element name
204 *
205 * @return the element name
206 */
207 public String getElementName() {
208 return fElementName;
209 }
210
211 /**
212 * Set the element name
213 *
214 * @param elementName
215 * the element name
216 */
217 public void setElementName(String elementName) {
218 fElementName = elementName;
219 }
220
221 /**
222 * @return the logEntry
223 */
224 public boolean isLogEntry() {
225 return fLogEntry;
226 }
227
228 /**
229 * @param logEntry
230 * the logEntry to set
231 */
232 public void setLogEntry(boolean logEntry) {
233 fLogEntry = logEntry;
234 }
235
236 /**
237 * @return the inputTag
238 * @since 2.1
239 */
240 public Tag getInputTag() {
241 return fInputTag;
242 }
243
244 /**
245 * @param inputTag
246 * the inputTag to set
247 * @since 2.1
248 */
249 public void setInputTag(Tag inputTag) {
250 fInputTag = inputTag;
251 }
252
253 /**
254 * @return the inputName
255 */
256 public String getInputName() {
257 return fInputName;
258 }
259
260 /**
261 * @param inputName
262 * the inputName to set
263 */
264 public void setInputName(String inputName) {
265 fInputName = inputName;
266 }
267
268 /**
269 * @return the eventType, or null
270 * @since 2.1
271 */
272 public String getEventType() {
273 return fEventType;
274 }
275
276 /**
277 * @param eventType
278 * the eventType to set, or null
279 * @since 2.1
280 */
281 public void setEventType(String eventType) {
282 fEventType = eventType;
283 }
284
285 /**
286 * @return the inputAction
287 */
288 public int getInputAction() {
289 return fInputAction;
290 }
291
292 /**
293 * @param inputAction
294 * the inputAction to set
295 */
296 public void setInputAction(int inputAction) {
297 fInputAction = inputAction;
298 }
299
300 /**
301 * @return the inputFormat
302 */
303 public String getInputFormat() {
304 return fInputFormat;
305 }
306
307 /**
308 * @param inputFormat
309 * the inputFormat to set
310 */
311 public void setInputFormat(String inputFormat) {
312 fInputFormat = inputFormat;
313 }
314
315 /**
316 * @return the attributes
317 */
318 public List<CustomXmlInputAttribute> getAttributes() {
319 return fAttributes;
320 }
321
322 /**
323 * @param attributes
324 * the attributes to set
325 */
326 public void setAttributes(List<CustomXmlInputAttribute> attributes) {
327 fAttributes = attributes;
328 }
329
330 /**
331 * @return the parentElement
332 */
333 public CustomXmlInputElement getParentElement() {
334 return fParentElement;
335 }
336
337 /**
338 * @param parentElement
339 * the parentElement to set
340 */
341 public void setParentElement(CustomXmlInputElement parentElement) {
342 fParentElement = parentElement;
343 }
344
345 /**
346 * @return the nextElement
347 */
348 public CustomXmlInputElement getNextElement() {
349 return fNextElement;
350 }
351
352 /**
353 * @param nextElement
354 * the nextElement to set
355 */
356 public void setNextElement(CustomXmlInputElement nextElement) {
357 fNextElement = nextElement;
358 }
359
360 /**
361 * @return the childElements
362 */
363 public List<CustomXmlInputElement> getChildElements() {
364 return fChildElements;
365 }
366
367 /**
368 * @param childElements
369 * the childElements to set
370 */
371 public void setChildElements(List<CustomXmlInputElement> childElements) {
372 fChildElements = childElements;
373 }
374
375 }
This page took 0.038043 seconds and 4 git commands to generate.