Commit | Line | Data |
---|---|---|
a7418109 MK |
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 | /** | |
52 | * Default (empty) constructor | |
53 | */ | |
54 | public CustomXmlInputElement() { | |
55 | } | |
56 | ||
57 | /** | |
58 | * Constructor | |
59 | * | |
60 | * @param elementName | |
61 | * Element name | |
62 | * @param logEntry | |
63 | * If this element is a log entry | |
64 | * @param inputName | |
65 | * Name of the the input | |
66 | * @param inputAction | |
67 | * Input action | |
68 | * @param inputFormat | |
69 | * Input format | |
70 | * @param attributes | |
71 | * XML attributes of this element | |
72 | */ | |
73 | public CustomXmlInputElement(String elementName, boolean logEntry, | |
74 | String inputName, int inputAction, String inputFormat, | |
75 | List<CustomXmlInputAttribute> attributes) { | |
76 | fElementName = elementName; | |
77 | fLogEntry = logEntry; | |
78 | fInputName = inputName; | |
79 | fInputAction = inputAction; | |
80 | fInputFormat = inputFormat; | |
81 | fAttributes = attributes; | |
82 | } | |
83 | ||
84 | /** | |
85 | * Add a XML attribute to the element | |
86 | * | |
87 | * @param attribute | |
88 | * The attribute to add | |
89 | */ | |
90 | public void addAttribute(CustomXmlInputAttribute attribute) { | |
91 | if (getAttributes() == null) { | |
92 | fAttributes = new ArrayList<>(1); | |
93 | } | |
94 | getAttributes().add(attribute); | |
95 | } | |
96 | ||
97 | /** | |
98 | * Add a child element to this one. | |
99 | * | |
100 | * @param input | |
101 | * The input element to add as child | |
102 | */ | |
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; | |
109 | } | |
110 | getChildElements().add(input); | |
111 | input.setParentElement(this); | |
112 | } | |
113 | ||
114 | /** | |
115 | * Set the following input element. | |
116 | * | |
117 | * @param input | |
118 | * The input element to add as next element | |
119 | */ | |
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; | |
127 | } | |
128 | input.setParentElement(getParentElement()); | |
129 | } | |
130 | ||
131 | /** | |
132 | * Move this element up in its parent's list of children. | |
133 | */ | |
134 | public void moveUp() { | |
135 | if (getParentElement() != null) { | |
136 | int index = getParentElement().getChildElements().indexOf(this); | |
137 | if (index > 0) { | |
138 | getParentElement().getChildElements().add(index - 1, getParentElement().getChildElements().remove(index)); | |
139 | getParentElement().getChildElements().get(index).fNextElement = fNextElement; | |
140 | fNextElement = getParentElement().getChildElements().get(index); | |
141 | } | |
142 | } | |
143 | } | |
144 | ||
145 | /** | |
146 | * Move this element down in its parent's list of children. | |
147 | */ | |
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; | |
155 | } | |
156 | } | |
157 | } | |
158 | ||
159 | /** | |
160 | * Get the element name | |
161 | * | |
162 | * @return the element name | |
163 | */ | |
164 | public String getElementName() { | |
165 | return fElementName; | |
166 | } | |
167 | ||
168 | /** | |
169 | * Set the element name | |
170 | * | |
171 | * @param elementName | |
172 | * the element name | |
173 | */ | |
174 | public void setElementName(String elementName) { | |
175 | fElementName = elementName; | |
176 | } | |
177 | ||
178 | /** | |
179 | * @return the logEntry | |
180 | */ | |
181 | public boolean isLogEntry() { | |
182 | return fLogEntry; | |
183 | } | |
184 | ||
185 | /** | |
186 | * @param logEntry | |
187 | * the logEntry to set | |
188 | */ | |
189 | public void setLogEntry(boolean logEntry) { | |
190 | fLogEntry = logEntry; | |
191 | } | |
192 | ||
193 | /** | |
194 | * @return the inputName | |
195 | */ | |
196 | public String getInputName() { | |
197 | return fInputName; | |
198 | } | |
199 | ||
200 | /** | |
201 | * @param inputName | |
202 | * the inputName to set | |
203 | */ | |
204 | public void setInputName(String inputName) { | |
205 | fInputName = inputName; | |
206 | } | |
207 | ||
208 | /** | |
209 | * @return the inputAction | |
210 | */ | |
211 | public int getInputAction() { | |
212 | return fInputAction; | |
213 | } | |
214 | ||
215 | /** | |
216 | * @param inputAction | |
217 | * the inputAction to set | |
218 | */ | |
219 | public void setInputAction(int inputAction) { | |
220 | fInputAction = inputAction; | |
221 | } | |
222 | ||
223 | /** | |
224 | * @return the inputFormat | |
225 | */ | |
226 | public String getInputFormat() { | |
227 | return fInputFormat; | |
228 | } | |
229 | ||
230 | /** | |
231 | * @param inputFormat | |
232 | * the inputFormat to set | |
233 | */ | |
234 | public void setInputFormat(String inputFormat) { | |
235 | fInputFormat = inputFormat; | |
236 | } | |
237 | ||
238 | /** | |
239 | * @return the attributes | |
240 | */ | |
241 | public List<CustomXmlInputAttribute> getAttributes() { | |
242 | return fAttributes; | |
243 | } | |
244 | ||
245 | /** | |
246 | * @param attributes | |
247 | * the attributes to set | |
248 | */ | |
249 | public void setAttributes(List<CustomXmlInputAttribute> attributes) { | |
250 | fAttributes = attributes; | |
251 | } | |
252 | ||
253 | /** | |
254 | * @return the parentElement | |
255 | */ | |
256 | public CustomXmlInputElement getParentElement() { | |
257 | return fParentElement; | |
258 | } | |
259 | ||
260 | /** | |
261 | * @param parentElement | |
262 | * the parentElement to set | |
263 | */ | |
264 | public void setParentElement(CustomXmlInputElement parentElement) { | |
265 | fParentElement = parentElement; | |
266 | } | |
267 | ||
268 | /** | |
269 | * @return the nextElement | |
270 | */ | |
271 | public CustomXmlInputElement getNextElement() { | |
272 | return fNextElement; | |
273 | } | |
274 | ||
275 | /** | |
276 | * @param nextElement | |
277 | * the nextElement to set | |
278 | */ | |
279 | public void setNextElement(CustomXmlInputElement nextElement) { | |
280 | fNextElement = nextElement; | |
281 | } | |
282 | ||
283 | /** | |
284 | * @return the childElements | |
285 | */ | |
286 | public List<CustomXmlInputElement> getChildElements() { | |
287 | return fChildElements; | |
288 | } | |
289 | ||
290 | /** | |
291 | * @param childElements | |
292 | * the childElements to set | |
293 | */ | |
294 | public void setChildElements(List<CustomXmlInputElement> childElements) { | |
295 | fChildElements = childElements; | |
296 | } | |
297 | ||
298 | } |