View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
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  }