/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  java.io.Externalizable
 *  java.io.IOException
 *  java.io.ObjectInput
 *  java.io.ObjectOutput
 *  java.lang.ClassNotFoundException
 *  java.lang.Integer
 *  java.lang.Object
 *  java.lang.String
 *  java.lang.StringBuffer
 *  java.util.ArrayList
 *  java.util.HashMap
 *  java.util.Iterator
 *  java.util.List
 *  java.util.Map
 *  org.xml.sax.Attributes
 *  org.xml.sax.ContentHandler
 *  org.xml.sax.DTDHandler
 *  org.xml.sax.SAXException
 *  org.xml.sax.ext.DeclHandler
 *  org.xml.sax.ext.LexicalHandler
 *  org.xml.sax.helpers.AttributesImpl
 *  org.xml.sax.helpers.DefaultHandler
 */
package org.dom4j.io;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.dom4j.Namespace;
import org.dom4j.QName;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.DTDHandler;
import org.xml.sax.SAXException;
import org.xml.sax.ext.DeclHandler;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.DefaultHandler;

public class SAXEventRecorder
extends DefaultHandler
implements Externalizable,
DTDHandler,
DeclHandler,
LexicalHandler {
    private static final String EMPTY_STRING = "";
    private static final byte NULL = 2;
    private static final byte OBJECT = 1;
    private static final byte STRING = 0;
    private static final String XMLNS = "xmlns";
    public static final long serialVersionUID = 1;
    private List events = new ArrayList();
    private Map prefixMappings = new HashMap();

    public void attributeDecl(String string2, String string3, String string4, String string5, String string6) throws SAXException {
        SAXEvent sAXEvent = new SAXEvent(17);
        sAXEvent.addParm(string2);
        sAXEvent.addParm(string3);
        sAXEvent.addParm(string4);
        sAXEvent.addParm(string5);
        sAXEvent.addParm(string6);
        this.events.add((Object)sAXEvent);
    }

    public void characters(char[] arrc, int n, int n2) throws SAXException {
        SAXEvent sAXEvent = new SAXEvent(8);
        sAXEvent.addParm(arrc);
        sAXEvent.addParm((Object)new Integer(n));
        sAXEvent.addParm((Object)new Integer(n2));
        this.events.add((Object)sAXEvent);
    }

    public void comment(char[] arrc, int n, int n2) throws SAXException {
        SAXEvent sAXEvent = new SAXEvent(15);
        sAXEvent.addParm(arrc);
        sAXEvent.addParm((Object)new Integer(n));
        sAXEvent.addParm((Object)new Integer(n2));
        this.events.add((Object)sAXEvent);
    }

    public void elementDecl(String string2, String string3) throws SAXException {
        SAXEvent sAXEvent = new SAXEvent(16);
        sAXEvent.addParm(string2);
        sAXEvent.addParm(string3);
        this.events.add((Object)sAXEvent);
    }

    public void endCDATA() throws SAXException {
        SAXEvent sAXEvent = new SAXEvent(14);
        this.events.add((Object)sAXEvent);
    }

    public void endDTD() throws SAXException {
        SAXEvent sAXEvent = new SAXEvent(10);
        this.events.add((Object)sAXEvent);
    }

    public void endDocument() throws SAXException {
        SAXEvent sAXEvent = new SAXEvent(5);
        this.events.add((Object)sAXEvent);
    }

    /*
     * Enabled aggressive block sorting
     */
    public void endElement(String string2, String string3, String string4) throws SAXException {
        SAXEvent sAXEvent = new SAXEvent(7);
        sAXEvent.addParm(string2);
        sAXEvent.addParm(string3);
        sAXEvent.addParm(string4);
        this.events.add((Object)sAXEvent);
        QName qName = string2 != null ? new QName(string3, Namespace.get(string2)) : new QName(string3);
        List list = (List)this.prefixMappings.get((Object)qName);
        if (list != null) {
            Iterator iterator = list.iterator();
            while (iterator.hasNext()) {
                SAXEvent sAXEvent2 = new SAXEvent(3);
                sAXEvent2.addParm(iterator.next());
                this.events.add((Object)sAXEvent2);
            }
        }
    }

    public void endEntity(String string2) throws SAXException {
        SAXEvent sAXEvent = new SAXEvent(12);
        sAXEvent.addParm(string2);
        this.events.add((Object)sAXEvent);
    }

    public void endPrefixMapping(String string2) throws SAXException {
        SAXEvent sAXEvent = new SAXEvent(3);
        sAXEvent.addParm(string2);
        this.events.add((Object)sAXEvent);
    }

    public void externalEntityDecl(String string2, String string3, String string4) throws SAXException {
        SAXEvent sAXEvent = new SAXEvent(19);
        sAXEvent.addParm(string2);
        sAXEvent.addParm(string3);
        sAXEvent.addParm(string4);
        this.events.add((Object)sAXEvent);
    }

    public void internalEntityDecl(String string2, String string3) throws SAXException {
        SAXEvent sAXEvent = new SAXEvent(18);
        sAXEvent.addParm(string2);
        sAXEvent.addParm(string3);
        this.events.add((Object)sAXEvent);
    }

    public void processingInstruction(String string2, String string3) throws SAXException {
        SAXEvent sAXEvent = new SAXEvent(1);
        sAXEvent.addParm(string2);
        sAXEvent.addParm(string3);
        this.events.add((Object)sAXEvent);
    }

    public void readExternal(ObjectInput objectInput) throws ClassNotFoundException, IOException {
        if (objectInput.readByte() != 2) {
            this.events = (List)objectInput.readObject();
        }
    }

    public void replay(ContentHandler contentHandler) throws SAXException {
        block21 : for (SAXEvent sAXEvent : this.events) {
            switch (sAXEvent.event) {
                default: {
                    throw new SAXException(new StringBuffer().append("Unrecognized event: ").append((int)sAXEvent.event).toString());
                }
                case 1: {
                    contentHandler.processingInstruction((String)sAXEvent.getParm(0), (String)sAXEvent.getParm(1));
                    continue block21;
                }
                case 2: {
                    contentHandler.startPrefixMapping((String)sAXEvent.getParm(0), (String)sAXEvent.getParm(1));
                    continue block21;
                }
                case 3: {
                    contentHandler.endPrefixMapping((String)sAXEvent.getParm(0));
                    continue block21;
                }
                case 4: {
                    contentHandler.startDocument();
                    continue block21;
                }
                case 5: {
                    contentHandler.endDocument();
                    continue block21;
                }
                case 6: {
                    AttributesImpl attributesImpl = new AttributesImpl();
                    List list = (List)sAXEvent.getParm(3);
                    if (list != null) {
                        for (String[] arrstring : list) {
                            attributesImpl.addAttribute(arrstring[0], arrstring[1], arrstring[2], arrstring[3], arrstring[4]);
                        }
                    }
                    contentHandler.startElement((String)sAXEvent.getParm(0), (String)sAXEvent.getParm(1), (String)sAXEvent.getParm(2), (Attributes)attributesImpl);
                    continue block21;
                }
                case 7: {
                    contentHandler.endElement((String)sAXEvent.getParm(0), (String)sAXEvent.getParm(1), (String)sAXEvent.getParm(2));
                    continue block21;
                }
                case 8: {
                    contentHandler.characters((char[])sAXEvent.getParm(0), ((Integer)sAXEvent.getParm(1)).intValue(), ((Integer)sAXEvent.getParm(2)).intValue());
                    continue block21;
                }
                case 9: {
                    ((LexicalHandler)contentHandler).startDTD((String)sAXEvent.getParm(0), (String)sAXEvent.getParm(1), (String)sAXEvent.getParm(2));
                    continue block21;
                }
                case 10: {
                    ((LexicalHandler)contentHandler).endDTD();
                    continue block21;
                }
                case 11: {
                    ((LexicalHandler)contentHandler).startEntity((String)sAXEvent.getParm(0));
                    continue block21;
                }
                case 12: {
                    ((LexicalHandler)contentHandler).endEntity((String)sAXEvent.getParm(0));
                    continue block21;
                }
                case 13: {
                    ((LexicalHandler)contentHandler).startCDATA();
                    continue block21;
                }
                case 14: {
                    ((LexicalHandler)contentHandler).endCDATA();
                    continue block21;
                }
                case 15: {
                    char[] arrc = (char[])sAXEvent.getParm(0);
                    int n = (Integer)sAXEvent.getParm(1);
                    int n2 = (Integer)sAXEvent.getParm(2);
                    ((LexicalHandler)contentHandler).comment(arrc, n, n2);
                    continue block21;
                }
                case 16: {
                    ((DeclHandler)contentHandler).elementDecl((String)sAXEvent.getParm(0), (String)sAXEvent.getParm(1));
                    continue block21;
                }
                case 17: {
                    ((DeclHandler)contentHandler).attributeDecl((String)sAXEvent.getParm(0), (String)sAXEvent.getParm(1), (String)sAXEvent.getParm(2), (String)sAXEvent.getParm(3), (String)sAXEvent.getParm(4));
                    continue block21;
                }
                case 18: {
                    ((DeclHandler)contentHandler).internalEntityDecl((String)sAXEvent.getParm(0), (String)sAXEvent.getParm(1));
                    continue block21;
                }
                case 19: 
            }
            ((DeclHandler)contentHandler).externalEntityDecl((String)sAXEvent.getParm(0), (String)sAXEvent.getParm(1), (String)sAXEvent.getParm(2));
        }
    }

    public void startCDATA() throws SAXException {
        SAXEvent sAXEvent = new SAXEvent(13);
        this.events.add((Object)sAXEvent);
    }

    public void startDTD(String string2, String string3, String string4) throws SAXException {
        SAXEvent sAXEvent = new SAXEvent(9);
        sAXEvent.addParm(string2);
        sAXEvent.addParm(string3);
        sAXEvent.addParm(string4);
        this.events.add((Object)sAXEvent);
    }

    public void startDocument() throws SAXException {
        SAXEvent sAXEvent = new SAXEvent(4);
        this.events.add((Object)sAXEvent);
    }

    /*
     * Enabled aggressive block sorting
     */
    public void startElement(String string2, String string3, String string4, Attributes attributes) throws SAXException {
        SAXEvent sAXEvent = new SAXEvent(6);
        sAXEvent.addParm(string2);
        sAXEvent.addParm(string3);
        sAXEvent.addParm(string4);
        QName qName = string2 != null ? new QName(string3, Namespace.get(string2)) : new QName(string3);
        if (attributes != null && attributes.getLength() > 0) {
            ArrayList arrayList = new ArrayList(attributes.getLength());
            for (int i = 0; i < attributes.getLength(); ++i) {
                String string5 = attributes.getLocalName(i);
                if (string5.startsWith("xmlns")) {
                    String string6 = string5.length() > 5 ? string5.substring(6) : "";
                    SAXEvent sAXEvent2 = new SAXEvent(2);
                    sAXEvent2.addParm(string6);
                    sAXEvent2.addParm(attributes.getValue(i));
                    this.events.add((Object)sAXEvent2);
                    List list = (List)this.prefixMappings.get((Object)qName);
                    if (list == null) {
                        list = new ArrayList();
                        this.prefixMappings.put((Object)qName, (Object)list);
                    }
                    list.add((Object)string6);
                    continue;
                }
                String[] arrstring = new String[]{attributes.getURI(i), string5, attributes.getQName(i), attributes.getType(i), attributes.getValue(i)};
                arrayList.add((Object)arrstring);
            }
            sAXEvent.addParm((Object)arrayList);
        }
        this.events.add((Object)sAXEvent);
    }

    public void startEntity(String string2) throws SAXException {
        SAXEvent sAXEvent = new SAXEvent(11);
        sAXEvent.addParm(string2);
        this.events.add((Object)sAXEvent);
    }

    public void startPrefixMapping(String string2, String string3) throws SAXException {
        SAXEvent sAXEvent = new SAXEvent(2);
        sAXEvent.addParm(string2);
        sAXEvent.addParm(string3);
        this.events.add((Object)sAXEvent);
    }

    public void writeExternal(ObjectOutput objectOutput) throws IOException {
        if (this.events == null) {
            objectOutput.writeByte(2);
            return;
        }
        objectOutput.writeByte(1);
        objectOutput.writeObject((Object)this.events);
    }

    static class SAXEvent
    implements Externalizable {
        static final byte ATTRIBUTE_DECL = 17;
        static final byte CHARACTERS = 8;
        static final byte COMMENT = 15;
        static final byte ELEMENT_DECL = 16;
        static final byte END_CDATA = 14;
        static final byte END_DOCUMENT = 5;
        static final byte END_DTD = 10;
        static final byte END_ELEMENT = 7;
        static final byte END_ENTITY = 12;
        static final byte END_PREFIX_MAPPING = 3;
        static final byte EXTERNAL_ENTITY_DECL = 19;
        static final byte INTERNAL_ENTITY_DECL = 18;
        static final byte PROCESSING_INSTRUCTION = 1;
        static final byte START_CDATA = 13;
        static final byte START_DOCUMENT = 4;
        static final byte START_DTD = 9;
        static final byte START_ELEMENT = 6;
        static final byte START_ENTITY = 11;
        static final byte START_PREFIX_MAPPING = 2;
        public static final long serialVersionUID = 1;
        protected byte event;
        protected List parms;

        public SAXEvent() {
        }

        SAXEvent(byte by) {
            this.event = by;
        }

        void addParm(Object object) {
            if (this.parms == null) {
                this.parms = new ArrayList(3);
            }
            this.parms.add(object);
        }

        Object getParm(int n) {
            if (this.parms != null && n < this.parms.size()) {
                return this.parms.get(n);
            }
            return null;
        }

        public void readExternal(ObjectInput objectInput) throws ClassNotFoundException, IOException {
            this.event = objectInput.readByte();
            if (objectInput.readByte() != 2) {
                this.parms = (List)objectInput.readObject();
            }
        }

        public void writeExternal(ObjectOutput objectOutput) throws IOException {
            objectOutput.writeByte((int)this.event);
            if (this.parms == null) {
                objectOutput.writeByte(2);
                return;
            }
            objectOutput.writeByte(1);
            objectOutput.writeObject((Object)this.parms);
        }
    }

}

