001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.core.joran.event;
015
016import ch.qos.logback.core.joran.spi.ElementPath;
017import org.xml.sax.Attributes;
018import org.xml.sax.Locator;
019import org.xml.sax.helpers.AttributesImpl;
020
021public class StartEvent extends SaxEvent {
022
023    final public Attributes attributes;
024    final public ElementPath elementPath;
025
026    StartEvent(ElementPath elementPath, String namespaceURI, String localName, String qName, Attributes attributes,
027            Locator locator) {
028        super(namespaceURI, localName, qName, locator);
029        // locator impl is used to take a snapshot!
030        this.attributes = new AttributesImpl(attributes);
031        this.elementPath = elementPath;
032    }
033
034    public Attributes getAttributes() {
035        return attributes;
036    }
037
038    @Override
039    public String toString() {
040        StringBuilder b = new StringBuilder("StartEvent(");
041        b.append(getQName());
042        if (attributes != null) {
043            for (int i = 0; i < attributes.getLength(); i++) {
044                b.append(' ');
045                b.append(attributes.getLocalName(i)).append("=\"").append(attributes.getValue(i)).append("\"");
046            }
047        }
048        b.append(")  [");
049        b.append(locator.getLineNumber());
050        b.append(",");
051        b.append(locator.getColumnNumber());
052        b.append("]");
053        return b.toString();
054    }
055
056}