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;
15  
16  import ch.qos.logback.core.joran.spi.ElementPath;
17  import org.xml.sax.Attributes;
18  import org.xml.sax.Locator;
19  import org.xml.sax.helpers.AttributesImpl;
20  
21  public class StartEvent extends SaxEvent {
22  
23      final public Attributes attributes;
24      final public ElementPath elementPath;
25  
26      StartEvent(ElementPath elementPath, String namespaceURI, String localName, String qName, Attributes attributes,
27              Locator locator) {
28          super(namespaceURI, localName, qName, locator);
29          // locator impl is used to take a snapshot!
30          this.attributes = new AttributesImpl(attributes);
31          this.elementPath = elementPath;
32      }
33  
34      public Attributes getAttributes() {
35          return attributes;
36      }
37  
38      @Override
39      public String toString() {
40          StringBuilder b = new StringBuilder("StartEvent(");
41          b.append(getQName());
42          if (attributes != null) {
43              for (int i = 0; i < attributes.getLength(); i++) {
44                  b.append(' ');
45                  b.append(attributes.getLocalName(i)).append("=\"").append(attributes.getValue(i)).append("\"");
46              }
47          }
48          b.append(")  [");
49          b.append(locator.getLineNumber());
50          b.append(",");
51          b.append(locator.getColumnNumber());
52          b.append("]");
53          return b.toString();
54      }
55  
56  }