1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.joran.event.stax;
15
16 import ch.qos.logback.core.joran.spi.ElementPath;
17
18 import javax.xml.stream.Location;
19 import javax.xml.stream.events.Attribute;
20 import java.util.ArrayList;
21 import java.util.Iterator;
22 import java.util.List;
23
24 public class StartEvent extends StaxEvent {
25
26 List<Attribute> attributes;
27 public ElementPath elementPath;
28
29 StartEvent(ElementPath elementPath, String name, Iterator<Attribute> attributeIterator, Location location) {
30 super(name, location);
31 populateAttributes(attributeIterator);
32 this.elementPath = elementPath;
33 }
34
35 private void populateAttributes(Iterator<Attribute> attributeIterator) {
36 while (attributeIterator.hasNext()) {
37 if (attributes == null) {
38 attributes = new ArrayList<Attribute>(2);
39 }
40 attributes.add(attributeIterator.next());
41 }
42 }
43
44 public ElementPath getElementPath() {
45 return elementPath;
46 }
47
48 public List<Attribute> getAttributeList() {
49 return attributes;
50 }
51
52 Attribute getAttributeByName(String name) {
53 if (attributes == null)
54 return null;
55
56 for (Attribute attr : attributes) {
57 if (name.equals(attr.getName().getLocalPart()))
58 return attr;
59 }
60 return null;
61 }
62
63 @Override
64 public String toString() {
65 return "StartEvent(" + getName() + ") [" + location.getLineNumber() + "," + location.getColumnNumber() + "]";
66 }
67 }