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, Locator locator) {
27         super(namespaceURI, localName, qName, locator);
28         // locator impl is used to take a snapshot!
29         this.attributes = new AttributesImpl(attributes);
30         this.elementPath = elementPath;
31     }
32
33     public Attributes getAttributes() {
34         return attributes;
35     }
36
37     @Override
38     public String toString() {
39         StringBuilder b = new StringBuilder("StartEvent(");
40         b.append(getQName());
41         if(attributes != null) {
42             for(int i = 0; i < attributes.getLength(); i++) {
43                 if(i > 0) 
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 }
57