1 | /* | |
2 | * Copyright 2006 - 2013 | |
3 | * Stefan Balev <stefan.balev@graphstream-project.org> | |
4 | * Julien Baudry <julien.baudry@graphstream-project.org> | |
5 | * Antoine Dutot <antoine.dutot@graphstream-project.org> | |
6 | * Yoann Pign�� <yoann.pigne@graphstream-project.org> | |
7 | * Guilhelm Savin <guilhelm.savin@graphstream-project.org> | |
8 | * | |
9 | * This file is part of GraphStream <http://graphstream-project.org>. | |
10 | * | |
11 | * GraphStream is a library whose purpose is to handle static or dynamic | |
12 | * graph, create them from scratch, file or any source and display them. | |
13 | * | |
14 | * This program is free software distributed under the terms of two licenses, the | |
15 | * CeCILL-C license that fits European law, and the GNU Lesser General Public | |
16 | * License. You can use, modify and/ or redistribute the software under the terms | |
17 | * of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following | |
18 | * URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by | |
19 | * the Free Software Foundation, either version 3 of the License, or (at your | |
20 | * option) any later version. | |
21 | * | |
22 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY | |
23 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | |
24 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | |
25 | * | |
26 | * You should have received a copy of the GNU Lesser General Public License | |
27 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
28 | * | |
29 | * The fact that you are presently reading this means that you have had | |
30 | * knowledge of the CeCILL-C and LGPL licenses and that you accept their terms. | |
31 | */ | |
32 | package org.graphstream.stream.file; | |
33 | ||
34 | import java.io.FileReader; | |
35 | import java.io.IOException; | |
36 | import java.io.InputStream; | |
37 | import java.io.InputStreamReader; | |
38 | import java.io.Reader; | |
39 | import java.net.URL; | |
40 | import java.util.EnumMap; | |
41 | import java.util.Iterator; | |
42 | import java.util.Stack; | |
43 | ||
44 | import javax.xml.stream.FactoryConfigurationError; | |
45 | import javax.xml.stream.XMLEventReader; | |
46 | import javax.xml.stream.XMLInputFactory; | |
47 | import javax.xml.stream.XMLStreamConstants; | |
48 | import javax.xml.stream.XMLStreamException; | |
49 | import javax.xml.stream.events.Attribute; | |
50 | import javax.xml.stream.events.StartElement; | |
51 | import javax.xml.stream.events.XMLEvent; | |
52 | ||
53 | import org.graphstream.stream.SourceBase; | |
54 | ||
55 | /** | |
56 | * Base for XML-based file format. It uses an xml events stream ( | |
57 | * {@link javax.xml.streams}). One who want to define a new xml-based fiel | |
58 | * source has to define actions after the document start and before the document | |
59 | * end. The {@link #nextEvents()}, called between start and end, has to be | |
60 | * defined too. | |
61 | * | |
62 | * @author Guilhelm Savin | |
63 | * | |
64 | */ | |
65 | public abstract class FileSourceXML extends SourceBase implements FileSource, | |
66 | XMLStreamConstants { | |
67 | ||
68 | /** | |
69 | * XML events stream. Should not be used directly but with | |
70 | * {@link #getNextEvent()}. | |
71 | */ | |
72 | protected XMLEventReader reader; | |
73 | /* | |
74 | * Used to allow 'pushback' of events. | |
75 | */ | |
76 | private Stack<XMLEvent> events; | |
77 | ||
78 | protected FileSourceXML() { | |
79 | events = new Stack<XMLEvent>(); | |
80 | } | |
81 | ||
82 | /* | |
83 | * (non-Javadoc) | |
84 | * | |
85 | * @see org.graphstream.stream.file.FileSource#readAll(java.lang.String) | |
86 | */ | |
87 | public void readAll(String fileName) throws IOException { | |
88 |
1
1. readAll : removed call to org/graphstream/stream/file/FileSourceXML::readAll → NO_COVERAGE |
readAll(new FileReader(fileName)); |
89 | } | |
90 | ||
91 | /* | |
92 | * (non-Javadoc) | |
93 | * | |
94 | * @see org.graphstream.stream.file.FileSource#readAll(java.net.URL) | |
95 | */ | |
96 | public void readAll(URL url) throws IOException { | |
97 |
1
1. readAll : removed call to org/graphstream/stream/file/FileSourceXML::readAll → NO_COVERAGE |
readAll(url.openStream()); |
98 | } | |
99 | ||
100 | /* | |
101 | * (non-Javadoc) | |
102 | * | |
103 | * @see org.graphstream.stream.file.FileSource#readAll(java.io.InputStream) | |
104 | */ | |
105 | public void readAll(InputStream stream) throws IOException { | |
106 |
1
1. readAll : removed call to org/graphstream/stream/file/FileSourceXML::readAll → NO_COVERAGE |
readAll(new InputStreamReader(stream)); |
107 | } | |
108 | ||
109 | /* | |
110 | * (non-Javadoc) | |
111 | * | |
112 | * @see org.graphstream.stream.file.FileSource#readAll(java.io.Reader) | |
113 | */ | |
114 | public void readAll(Reader reader) throws IOException { | |
115 |
1
1. readAll : removed call to org/graphstream/stream/file/FileSourceXML::begin → NO_COVERAGE |
begin(reader); |
116 |
1
1. readAll : negated conditional → NO_COVERAGE |
while (nextEvents()) |
117 | ; | |
118 |
1
1. readAll : removed call to org/graphstream/stream/file/FileSourceXML::end → NO_COVERAGE |
end(); |
119 | } | |
120 | ||
121 | /* | |
122 | * (non-Javadoc) | |
123 | * | |
124 | * @see org.graphstream.stream.file.FileSource#begin(java.lang.String) | |
125 | */ | |
126 | public void begin(String fileName) throws IOException { | |
127 |
1
1. begin : removed call to org/graphstream/stream/file/FileSourceXML::begin → NO_COVERAGE |
begin(new FileReader(fileName)); |
128 | } | |
129 | ||
130 | /* | |
131 | * (non-Javadoc) | |
132 | * | |
133 | * @see org.graphstream.stream.file.FileSource#begin(java.net.URL) | |
134 | */ | |
135 | public void begin(URL url) throws IOException { | |
136 |
1
1. begin : removed call to org/graphstream/stream/file/FileSourceXML::begin → NO_COVERAGE |
begin(url.openStream()); |
137 | } | |
138 | ||
139 | /* | |
140 | * (non-Javadoc) | |
141 | * | |
142 | * @see org.graphstream.stream.file.FileSource#begin(java.io.InputStream) | |
143 | */ | |
144 | public void begin(InputStream stream) throws IOException { | |
145 |
1
1. begin : removed call to org/graphstream/stream/file/FileSourceXML::begin → NO_COVERAGE |
begin(new InputStreamReader(stream)); |
146 | } | |
147 | ||
148 | /* | |
149 | * (non-Javadoc) | |
150 | * | |
151 | * @see org.graphstream.stream.file.FileSource#begin(java.io.Reader) | |
152 | */ | |
153 | public void begin(Reader reader) throws IOException { | |
154 |
1
1. begin : removed call to org/graphstream/stream/file/FileSourceXML::openStream → NO_COVERAGE |
openStream(reader); |
155 | } | |
156 | ||
157 | /** | |
158 | * Called after the event | |
159 | * {@link javax.xml.stream.events.XMLEvent.START_DOCUMENT} has been | |
160 | * received. | |
161 | * | |
162 | * @throws IOException | |
163 | * @throws XMLStreamException | |
164 | */ | |
165 | protected abstract void afterStartDocument() throws IOException, | |
166 | XMLStreamException; | |
167 | ||
168 | /** | |
169 | * Called before trying to receive the events | |
170 | * {@link javax.xml.stream.event.END_DOCUMENT}. | |
171 | * | |
172 | * @throws IOException | |
173 | * @throws XMLStreamException | |
174 | */ | |
175 | protected abstract void beforeEndDocument() throws IOException, | |
176 | XMLStreamException; | |
177 | ||
178 | /* | |
179 | * (non-Javadoc) | |
180 | * | |
181 | * @see org.graphstream.stream.file.FileSource#nextEvents() | |
182 | */ | |
183 | public abstract boolean nextEvents() throws IOException; | |
184 | ||
185 | /* | |
186 | * (non-Javadoc) | |
187 | * | |
188 | * @see org.graphstream.stream.file.FileSource#nextStep() | |
189 | */ | |
190 | public boolean nextStep() throws IOException { | |
191 |
1
1. nextStep : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return nextEvents(); |
192 | } | |
193 | ||
194 | /* | |
195 | * (non-Javadoc) | |
196 | * | |
197 | * @see org.graphstream.stream.file.FileSource#end() | |
198 | */ | |
199 | public void end() throws IOException { | |
200 |
1
1. end : removed call to org/graphstream/stream/file/FileSourceXML::closeStream → NO_COVERAGE |
closeStream(); |
201 | } | |
202 | ||
203 | /** | |
204 | * Get a new event from the stream. This method has to be used to allow the | |
205 | * {@link #pushback(XMLEvent)} method to work. | |
206 | * | |
207 | * @return the next event in the stream | |
208 | * @throws IOException | |
209 | * @throws XMLStreamException | |
210 | */ | |
211 | protected XMLEvent getNextEvent() throws IOException, XMLStreamException { | |
212 |
1
1. getNextEvent : removed call to org/graphstream/stream/file/FileSourceXML::skipWhiteSpaces → NO_COVERAGE |
skipWhiteSpaces(); |
213 | ||
214 |
2
1. getNextEvent : changed conditional boundary → NO_COVERAGE 2. getNextEvent : negated conditional → NO_COVERAGE |
if (events.size() > 0) |
215 |
1
1. getNextEvent : mutated return of Object value for org/graphstream/stream/file/FileSourceXML::getNextEvent to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return events.pop(); |
216 | ||
217 |
1
1. getNextEvent : mutated return of Object value for org/graphstream/stream/file/FileSourceXML::getNextEvent to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return reader.nextEvent(); |
218 | } | |
219 | ||
220 | /** | |
221 | * Pushback an event in the stream. | |
222 | * | |
223 | * @param e | |
224 | * the event | |
225 | */ | |
226 | protected void pushback(XMLEvent e) { | |
227 | events.push(e); | |
228 | } | |
229 | ||
230 | /** | |
231 | * Generate a new parse exception. | |
232 | * | |
233 | * @param e | |
234 | * event producing an error | |
235 | * @param msg | |
236 | * message to put in the exception | |
237 | * @param args | |
238 | * arguments of the message | |
239 | * @return a new parse exception | |
240 | */ | |
241 | protected XMLStreamException newParseError(XMLEvent e, String msg, | |
242 | Object... args) { | |
243 |
1
1. newParseError : mutated return of Object value for org/graphstream/stream/file/FileSourceXML::newParseError to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new XMLStreamException(String.format(msg, args), e.getLocation()); |
244 | } | |
245 | ||
246 | /** | |
247 | * Check is an event has an expected type and name. | |
248 | * | |
249 | * @param e | |
250 | * event to check | |
251 | * @param type | |
252 | * expected type | |
253 | * @param name | |
254 | * expected name | |
255 | * @return true is type and name are valid | |
256 | */ | |
257 | protected boolean isEvent(XMLEvent e, int type, String name) { | |
258 |
1
1. isEvent : negated conditional → NO_COVERAGE |
boolean valid = e.getEventType() == type; |
259 | ||
260 |
1
1. isEvent : negated conditional → NO_COVERAGE |
if (valid) { |
261 | switch (type) { | |
262 | case START_ELEMENT: | |
263 | valid = e.asStartElement().getName().getLocalPart() | |
264 | .equals(name); | |
265 | break; | |
266 | case END_ELEMENT: | |
267 | valid = e.asEndElement().getName().getLocalPart().equals(name); | |
268 | break; | |
269 | case ATTRIBUTE: | |
270 | valid = ((Attribute) e).getName().getLocalPart().equals(name); | |
271 | break; | |
272 | case CHARACTERS: | |
273 | case NAMESPACE: | |
274 | case PROCESSING_INSTRUCTION: | |
275 | case COMMENT: | |
276 | case START_DOCUMENT: | |
277 | case END_DOCUMENT: | |
278 | case DTD: | |
279 | } | |
280 | } | |
281 | ||
282 |
1
1. isEvent : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return valid; |
283 | } | |
284 | ||
285 | /** | |
286 | * Check is the event has valid type and name. If not, a new exception is | |
287 | * thrown. | |
288 | * | |
289 | * @param e | |
290 | * event to check | |
291 | * @param type | |
292 | * expected type | |
293 | * @param name | |
294 | * expected name | |
295 | * @throws XMLStreamException | |
296 | * if event has invalid type or name | |
297 | */ | |
298 | protected void checkValid(XMLEvent e, int type, String name) | |
299 | throws XMLStreamException { | |
300 | boolean valid = isEvent(e, type, name); | |
301 | ||
302 |
1
1. checkValid : negated conditional → NO_COVERAGE |
if (!valid) |
303 | throw newParseError(e, "expecting %s, got %s", gotWhat(type, name), | |
304 | gotWhat(e)); | |
305 | } | |
306 | ||
307 | private String gotWhat(XMLEvent e) { | |
308 | String v = null; | |
309 | ||
310 | switch (e.getEventType()) { | |
311 | case START_ELEMENT: | |
312 | v = e.asStartElement().getName().getLocalPart(); | |
313 | break; | |
314 | case END_ELEMENT: | |
315 | v = e.asEndElement().getName().getLocalPart(); | |
316 | break; | |
317 | case ATTRIBUTE: | |
318 | v = ((Attribute) e).getName().getLocalPart(); | |
319 | break; | |
320 | } | |
321 | ||
322 |
1
1. gotWhat : mutated return of Object value for org/graphstream/stream/file/FileSourceXML::gotWhat to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return gotWhat(e.getEventType(), v); |
323 | } | |
324 | ||
325 | private String gotWhat(int type, String v) { | |
326 | switch (type) { | |
327 | case START_ELEMENT: | |
328 |
1
1. gotWhat : mutated return of Object value for org/graphstream/stream/file/FileSourceXML::gotWhat to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return String.format("'<%s>'", v); |
329 | case END_ELEMENT: | |
330 |
1
1. gotWhat : mutated return of Object value for org/graphstream/stream/file/FileSourceXML::gotWhat to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return String.format("'</%s>'", v); |
331 | case ATTRIBUTE: | |
332 |
1
1. gotWhat : mutated return of Object value for org/graphstream/stream/file/FileSourceXML::gotWhat to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return String.format("attribute '%s'", v); |
333 | case NAMESPACE: | |
334 |
1
1. gotWhat : mutated return of Object value for org/graphstream/stream/file/FileSourceXML::gotWhat to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return "namespace"; |
335 | case PROCESSING_INSTRUCTION: | |
336 |
1
1. gotWhat : mutated return of Object value for org/graphstream/stream/file/FileSourceXML::gotWhat to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return "processing instruction"; |
337 | case COMMENT: | |
338 |
1
1. gotWhat : mutated return of Object value for org/graphstream/stream/file/FileSourceXML::gotWhat to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return "comment"; |
339 | case START_DOCUMENT: | |
340 |
1
1. gotWhat : mutated return of Object value for org/graphstream/stream/file/FileSourceXML::gotWhat to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return "document start"; |
341 | case END_DOCUMENT: | |
342 |
1
1. gotWhat : mutated return of Object value for org/graphstream/stream/file/FileSourceXML::gotWhat to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return "document end"; |
343 | case DTD: | |
344 |
1
1. gotWhat : mutated return of Object value for org/graphstream/stream/file/FileSourceXML::gotWhat to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return "dtd"; |
345 | case CHARACTERS: | |
346 |
1
1. gotWhat : mutated return of Object value for org/graphstream/stream/file/FileSourceXML::gotWhat to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return "characters"; |
347 | default: | |
348 |
1
1. gotWhat : mutated return of Object value for org/graphstream/stream/file/FileSourceXML::gotWhat to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return "UNKNOWN"; |
349 | } | |
350 | } | |
351 | ||
352 | private void skipWhiteSpaces() throws IOException, XMLStreamException { | |
353 | XMLEvent e; | |
354 | ||
355 | do { | |
356 |
2
1. skipWhiteSpaces : changed conditional boundary → NO_COVERAGE 2. skipWhiteSpaces : negated conditional → NO_COVERAGE |
if (events.size() > 0) |
357 | e = events.pop(); | |
358 | else | |
359 | e = reader.nextEvent(); | |
360 |
1
1. skipWhiteSpaces : negated conditional → NO_COVERAGE |
} while (isEvent(e, XMLEvent.CHARACTERS, null) |
361 |
1
1. skipWhiteSpaces : negated conditional → NO_COVERAGE |
&& e.asCharacters().getData().matches("^\\s*$")); |
362 | ||
363 |
1
1. skipWhiteSpaces : removed call to org/graphstream/stream/file/FileSourceXML::pushback → NO_COVERAGE |
pushback(e); |
364 | } | |
365 | ||
366 | /** | |
367 | * Open a new xml events stream. | |
368 | * | |
369 | * @param stream | |
370 | * @throws IOException | |
371 | */ | |
372 | protected void openStream(Reader stream) throws IOException { | |
373 |
1
1. openStream : negated conditional → NO_COVERAGE |
if (reader != null) |
374 |
1
1. openStream : removed call to org/graphstream/stream/file/FileSourceXML::closeStream → NO_COVERAGE |
closeStream(); |
375 | ||
376 | try { | |
377 | XMLEvent e; | |
378 | ||
379 | reader = XMLInputFactory.newInstance().createXMLEventReader(stream); | |
380 | ||
381 | e = getNextEvent(); | |
382 |
1
1. openStream : removed call to org/graphstream/stream/file/FileSourceXML::checkValid → NO_COVERAGE |
checkValid(e, XMLEvent.START_DOCUMENT, null); |
383 | ||
384 |
1
1. openStream : removed call to org/graphstream/stream/file/FileSourceXML::afterStartDocument → NO_COVERAGE |
afterStartDocument(); |
385 | } catch (XMLStreamException e) { | |
386 | throw new IOException(e); | |
387 | } catch (FactoryConfigurationError e) { | |
388 | throw new IOException(e); | |
389 | } | |
390 | } | |
391 | ||
392 | /** | |
393 | * Close the current opened stream. | |
394 | * | |
395 | * @throws IOException | |
396 | */ | |
397 | protected void closeStream() throws IOException { | |
398 | try { | |
399 |
1
1. closeStream : removed call to org/graphstream/stream/file/FileSourceXML::beforeEndDocument → NO_COVERAGE |
beforeEndDocument(); |
400 |
1
1. closeStream : removed call to javax/xml/stream/XMLEventReader::close → NO_COVERAGE |
reader.close(); |
401 | } catch (XMLStreamException e) { | |
402 | throw new IOException(e); | |
403 | } finally { | |
404 | reader = null; | |
405 | } | |
406 | } | |
407 | ||
408 | /** | |
409 | * Convert an attribute to a valid constant name. | |
410 | * | |
411 | * @see #toConstantName(String) | |
412 | * @param a | |
413 | * @return | |
414 | */ | |
415 | protected String toConstantName(Attribute a) { | |
416 |
1
1. toConstantName : mutated return of Object value for org/graphstream/stream/file/FileSourceXML::toConstantName to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return toConstantName(a.getName().getLocalPart()); |
417 | } | |
418 | ||
419 | /** | |
420 | * Convert a string to a valid constant name. String is put to upper case | |
421 | * and all non-word characters are replaced by '_'. | |
422 | * | |
423 | * @param value | |
424 | * @return | |
425 | */ | |
426 | protected String toConstantName(String value) { | |
427 |
1
1. toConstantName : mutated return of Object value for org/graphstream/stream/file/FileSourceXML::toConstantName to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return value.toUpperCase().replaceAll("\\W", "_"); |
428 | } | |
429 | ||
430 | /** | |
431 | * Base for parsers, providing some usefull features. | |
432 | * | |
433 | */ | |
434 | protected class Parser { | |
435 | /** | |
436 | * Read a sequence of characters and return these characters as a | |
437 | * string. Characters are read until a non-character event is reached. | |
438 | * | |
439 | * @return a sequence of characters | |
440 | * @throws IOException | |
441 | * @throws XMLStreamException | |
442 | */ | |
443 | protected String __characters() throws IOException, XMLStreamException { | |
444 | XMLEvent e; | |
445 | StringBuilder buffer = new StringBuilder(); | |
446 | ||
447 | e = getNextEvent(); | |
448 | ||
449 |
1
1. __characters : negated conditional → NO_COVERAGE |
while (e.getEventType() == XMLEvent.CHARACTERS) { |
450 | buffer.append(e.asCharacters()); | |
451 | e = getNextEvent(); | |
452 | } | |
453 | ||
454 |
1
1. __characters : removed call to org/graphstream/stream/file/FileSourceXML::pushback → NO_COVERAGE |
pushback(e); |
455 | ||
456 |
1
1. __characters : mutated return of Object value for org/graphstream/stream/file/FileSourceXML$Parser::__characters to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return buffer.toString(); |
457 | } | |
458 | ||
459 | /** | |
460 | * Get attributes of a start element in a map. Attributes should be | |
461 | * described in an enumeration such that | |
462 | * {@link FileSourceXML#toConstantName(Attribute)} correspond to names | |
463 | * of enumeration constants. | |
464 | * | |
465 | * @param <T> | |
466 | * type of the enumeration describing attributes | |
467 | * @param cls | |
468 | * class of the enumeration T | |
469 | * @param e | |
470 | * start event from which attributes have to be extracted | |
471 | * @return a mapping between enum constants and attribute values. | |
472 | */ | |
473 | protected <T extends Enum<T>> EnumMap<T, String> getAttributes( | |
474 | Class<T> cls, StartElement e) { | |
475 | EnumMap<T, String> values = new EnumMap<T, String>(cls); | |
476 | ||
477 | @SuppressWarnings("unchecked") | |
478 | Iterator<? extends Attribute> attributes = e.asStartElement() | |
479 | .getAttributes(); | |
480 | ||
481 |
1
1. getAttributes : negated conditional → NO_COVERAGE |
while (attributes.hasNext()) { |
482 | Attribute a = attributes.next(); | |
483 | ||
484 |
3
1. getAttributes : changed conditional boundary → NO_COVERAGE 2. getAttributes : Changed increment from 1 to -1 → NO_COVERAGE 3. getAttributes : negated conditional → NO_COVERAGE |
for (int i = 0; i < cls.getEnumConstants().length; i++) { |
485 | if (cls.getEnumConstants()[i].name().equals( | |
486 |
1
1. getAttributes : negated conditional → NO_COVERAGE |
toConstantName(a))) { |
487 | values.put(cls.getEnumConstants()[i], a.getValue()); | |
488 | break; | |
489 | } | |
490 | } | |
491 | } | |
492 | ||
493 |
1
1. getAttributes : mutated return of Object value for org/graphstream/stream/file/FileSourceXML$Parser::getAttributes to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return values; |
494 | } | |
495 | ||
496 | /** | |
497 | * Check if all required attributes are present. | |
498 | * | |
499 | * @param <T> | |
500 | * type of the enumeration describing attributes | |
501 | * @param e | |
502 | * the event | |
503 | * @param attributes | |
504 | * extracted attributes | |
505 | * @param required | |
506 | * array of required attributes | |
507 | * @throws XMLStreamException | |
508 | * if at least one required attribute is not found | |
509 | */ | |
510 | protected <T extends Enum<T>> void checkRequiredAttributes(XMLEvent e, | |
511 | EnumMap<T, String> attributes, T... required) | |
512 | throws XMLStreamException { | |
513 |
1
1. checkRequiredAttributes : negated conditional → NO_COVERAGE |
if (required != null) { |
514 |
3
1. checkRequiredAttributes : changed conditional boundary → NO_COVERAGE 2. checkRequiredAttributes : Changed increment from 1 to -1 → NO_COVERAGE 3. checkRequiredAttributes : negated conditional → NO_COVERAGE |
for (int i = 0; i < required.length; i++) { |
515 |
1
1. checkRequiredAttributes : negated conditional → NO_COVERAGE |
if (!attributes.containsKey(required[i])) |
516 | throw newParseError(e, | |
517 | "'%s' attribute is required for <%s> element", | |
518 | required[i].name().toLowerCase(), e | |
519 | .asStartElement().getName() | |
520 | .getLocalPart()); | |
521 | } | |
522 | } | |
523 | } | |
524 | } | |
525 | } | |
Mutations | ||
88 |
1.1 |
|
97 |
1.1 |
|
106 |
1.1 |
|
115 |
1.1 |
|
116 |
1.1 |
|
118 |
1.1 |
|
127 |
1.1 |
|
136 |
1.1 |
|
145 |
1.1 |
|
154 |
1.1 |
|
191 |
1.1 |
|
200 |
1.1 |
|
212 |
1.1 |
|
214 |
1.1 2.2 |
|
215 |
1.1 |
|
217 |
1.1 |
|
243 |
1.1 |
|
258 |
1.1 |
|
260 |
1.1 |
|
282 |
1.1 |
|
302 |
1.1 |
|
322 |
1.1 |
|
328 |
1.1 |
|
330 |
1.1 |
|
332 |
1.1 |
|
334 |
1.1 |
|
336 |
1.1 |
|
338 |
1.1 |
|
340 |
1.1 |
|
342 |
1.1 |
|
344 |
1.1 |
|
346 |
1.1 |
|
348 |
1.1 |
|
356 |
1.1 2.2 |
|
360 |
1.1 |
|
361 |
1.1 |
|
363 |
1.1 |
|
373 |
1.1 |
|
374 |
1.1 |
|
382 |
1.1 |
|
384 |
1.1 |
|
399 |
1.1 |
|
400 |
1.1 |
|
416 |
1.1 |
|
427 |
1.1 |
|
449 |
1.1 |
|
454 |
1.1 |
|
456 |
1.1 |
|
481 |
1.1 |
|
484 |
1.1 2.2 3.3 |
|
486 |
1.1 |
|
493 |
1.1 |
|
513 |
1.1 |
|
514 |
1.1 2.2 3.3 |
|
515 |
1.1 |