75d4b82c7d0135e7c1498310a9dc8e080e2a66fa
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / parsers / custom / CustomXmlInputElement.java
1 /*******************************************************************************
2 * Copyright (c) 2014 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 /**
20 * Wrapper for input XML elements
21 */
22 public final class CustomXmlInputElement {
23
24 /** Name of the element */
25 private String fElementName;
26
27 /** Indicates if this is a log entry */
28 private boolean fLogEntry;
29
30 /** Name of the input element */
31 private String fInputName;
32
33 /** Input action */
34 private int fInputAction;
35
36 /** Input format */
37 private String fInputFormat;
38
39 /** XML attributes of this element */
40 private List<CustomXmlInputAttribute> fAttributes;
41
42 /** Parent element */
43 private CustomXmlInputElement fParentElement;
44
45 /** Following element in the file */
46 private CustomXmlInputElement fNextElement;
47
48 /** Child elements */
49 private List<CustomXmlInputElement> fChildElements;
50
51 /** Event type associated with this input element */
52 private String fEventType;
53
54 /**
55 * Default (empty) constructor
56 */
57 public CustomXmlInputElement() {
58 }
59
60 /**
61 * Constructor
62 *
63 * @param elementName
64 * Element name
65 * @param logEntry
66 * If this element is a log entry
67 * @param inputName
68 * Name of the the input
69 * @param inputAction
70 * Input action
71 * @param inputFormat
72 * Input format
73 * @param attributes
74 * XML attributes of this element
75 */
76 public CustomXmlInputElement(String elementName, boolean logEntry,
77 String inputName, int inputAction, String inputFormat,
78 List<CustomXmlInputAttribute> attributes) {
79 fElementName = elementName;
80 fLogEntry = logEntry;
81 fInputName = inputName;
82 fInputAction = inputAction;
83 fInputFormat = inputFormat;
84 fAttributes = attributes;
85 }
86
87 /**
88 * Add a XML attribute to the element
89 *
90 * @param attribute
91 * The attribute to add
92 */
93 public void addAttribute(CustomXmlInputAttribute attribute) {
94 if (getAttributes() == null) {
95 fAttributes = new ArrayList<>(1);
96 }
97 getAttributes().add(attribute);
98 }
99
100 /**
101 * Add a child element to this one.
102 *
103 * @param input
104 * The input element to add as child
105 */
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;
112 }
113 getChildElements().add(input);
114 input.setParentElement(this);
115 }
116
117 /**
118 * Set the following input element.
119 *
120 * @param input
121 * The input element to add as next element
122 */
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;
130 }
131 input.setParentElement(getParentElement());
132 }
133
134 /**
135 * Move this element up in its parent's list of children.
136 */
137 public void moveUp() {
138 if (getParentElement() != null) {
139 int index = getParentElement().getChildElements().indexOf(this);
140 if (index > 0) {
141 getParentElement().getChildElements().add(index - 1, getParentElement().getChildElements().remove(index));
142 getParentElement().getChildElements().get(index).fNextElement = fNextElement;
143 fNextElement = getParentElement().getChildElements().get(index);
144 }
145 }
146 }
147
148 /**
149 * Move this element down in its parent's list of children.
150 */
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;
158 }
159 }
160 }
161
162 /**
163 * Get the element name
164 *
165 * @return the element name
166 */
167 public String getElementName() {
168 return fElementName;
169 }
170
171 /**
172 * Set the element name
173 *
174 * @param elementName
175 * the element name
176 */
177 public void setElementName(String elementName) {
178 fElementName = elementName;
179 }
180
181 /**
182 * @return the logEntry
183 */
184 public boolean isLogEntry() {
185 return fLogEntry;
186 }
187
188 /**
189 * @param logEntry
190 * the logEntry to set
191 */
192 public void setLogEntry(boolean logEntry) {
193 fLogEntry = logEntry;
194 }
195
196 /**
197 * @return the inputName
198 */
199 public String getInputName() {
200 return fInputName;
201 }
202
203 /**
204 * @param inputName
205 * the inputName to set
206 */
207 public void setInputName(String inputName) {
208 fInputName = inputName;
209 }
210
211 /**
212 * @return the eventType, or null
213 * @since 2.1
214 */
215 public String getEventType() {
216 return fEventType;
217 }
218
219 /**
220 * @param eventType
221 * the eventType to set, or null
222 * @since 2.1
223 */
224 public void setEventType(String eventType) {
225 fEventType = eventType;
226 }
227
228 /**
229 * @return the inputAction
230 */
231 public int getInputAction() {
232 return fInputAction;
233 }
234
235 /**
236 * @param inputAction
237 * the inputAction to set
238 */
239 public void setInputAction(int inputAction) {
240 fInputAction = inputAction;
241 }
242
243 /**
244 * @return the inputFormat
245 */
246 public String getInputFormat() {
247 return fInputFormat;
248 }
249
250 /**
251 * @param inputFormat
252 * the inputFormat to set
253 */
254 public void setInputFormat(String inputFormat) {
255 fInputFormat = inputFormat;
256 }
257
258 /**
259 * @return the attributes
260 */
261 public List<CustomXmlInputAttribute> getAttributes() {
262 return fAttributes;
263 }
264
265 /**
266 * @param attributes
267 * the attributes to set
268 */
269 public void setAttributes(List<CustomXmlInputAttribute> attributes) {
270 fAttributes = attributes;
271 }
272
273 /**
274 * @return the parentElement
275 */
276 public CustomXmlInputElement getParentElement() {
277 return fParentElement;
278 }
279
280 /**
281 * @param parentElement
282 * the parentElement to set
283 */
284 public void setParentElement(CustomXmlInputElement parentElement) {
285 fParentElement = parentElement;
286 }
287
288 /**
289 * @return the nextElement
290 */
291 public CustomXmlInputElement getNextElement() {
292 return fNextElement;
293 }
294
295 /**
296 * @param nextElement
297 * the nextElement to set
298 */
299 public void setNextElement(CustomXmlInputElement nextElement) {
300 fNextElement = nextElement;
301 }
302
303 /**
304 * @return the childElements
305 */
306 public List<CustomXmlInputElement> getChildElements() {
307 return fChildElements;
308 }
309
310 /**
311 * @param childElements
312 * the childElements to set
313 */
314 public void setChildElements(List<CustomXmlInputElement> childElements) {
315 fChildElements = childElements;
316 }
317
318 }
This page took 0.062138 seconds and 5 git commands to generate.