/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  java.io.File
 *  java.io.FileInputStream
 *  java.io.FileNotFoundException
 *  java.io.InputStream
 *  java.io.InputStreamReader
 *  java.io.Reader
 *  java.lang.ClassLoader
 *  java.lang.Exception
 *  java.lang.Object
 *  java.lang.String
 *  java.lang.Throwable
 *  java.net.URL
 *  java.nio.charset.Charset
 *  javax.xml.bind.Element
 *  org.xml.sax.InputSource
 */
package org.dom4j.jaxb;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.nio.charset.Charset;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.ElementHandler;
import org.dom4j.ElementPath;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.dom4j.jaxb.JAXBObjectHandler;
import org.dom4j.jaxb.JAXBRuntimeException;
import org.dom4j.jaxb.JAXBSupport;
import org.xml.sax.InputSource;

public class JAXBReader
extends JAXBSupport {
    private boolean pruneElements;
    private SAXReader reader;

    public JAXBReader(String string2) {
        super(string2);
    }

    public JAXBReader(String string2, ClassLoader classLoader) {
        super(string2, classLoader);
    }

    private SAXReader getReader() {
        if (this.reader == null) {
            this.reader = new SAXReader();
        }
        return this.reader;
    }

    public void addHandler(String string2, ElementHandler elementHandler) {
        super.getReader().addHandler(string2, elementHandler);
    }

    public void addObjectHandler(String string2, JAXBObjectHandler jAXBObjectHandler) {
        UnmarshalElementHandler unmarshalElementHandler = new UnmarshalElementHandler((JAXBReader)this, (JAXBReader)this, jAXBObjectHandler);
        super.getReader().addHandler(string2, unmarshalElementHandler);
    }

    public boolean isPruneElements() {
        return this.pruneElements;
    }

    public Document read(File file) throws DocumentException {
        return super.getReader().read(file);
    }

    public Document read(File file, Charset charset) throws DocumentException {
        try {
            InputStreamReader inputStreamReader = new InputStreamReader((InputStream)new FileInputStream(file), charset);
            Document document = super.getReader().read((Reader)inputStreamReader);
            return document;
        }
        catch (JAXBRuntimeException var5_5) {
            Throwable throwable = var5_5.getCause();
            throw new DocumentException(throwable.getMessage(), throwable);
        }
        catch (FileNotFoundException var4_7) {
            throw new DocumentException(var4_7.getMessage(), (Throwable)var4_7);
        }
    }

    public Document read(InputStream inputStream) throws DocumentException {
        try {
            Document document = super.getReader().read(inputStream);
            return document;
        }
        catch (JAXBRuntimeException var2_3) {
            Throwable throwable = var2_3.getCause();
            throw new DocumentException(throwable.getMessage(), throwable);
        }
    }

    public Document read(InputStream inputStream, String string2) throws DocumentException {
        try {
            Document document = super.getReader().read(inputStream);
            return document;
        }
        catch (JAXBRuntimeException var3_4) {
            Throwable throwable = var3_4.getCause();
            throw new DocumentException(throwable.getMessage(), throwable);
        }
    }

    public Document read(Reader reader) throws DocumentException {
        try {
            Document document = super.getReader().read(reader);
            return document;
        }
        catch (JAXBRuntimeException var2_3) {
            Throwable throwable = var2_3.getCause();
            throw new DocumentException(throwable.getMessage(), throwable);
        }
    }

    public Document read(Reader reader, String string2) throws DocumentException {
        try {
            Document document = super.getReader().read(reader);
            return document;
        }
        catch (JAXBRuntimeException var3_4) {
            Throwable throwable = var3_4.getCause();
            throw new DocumentException(throwable.getMessage(), throwable);
        }
    }

    public Document read(String string2) throws DocumentException {
        try {
            Document document = super.getReader().read(string2);
            return document;
        }
        catch (JAXBRuntimeException var2_3) {
            Throwable throwable = var2_3.getCause();
            throw new DocumentException(throwable.getMessage(), throwable);
        }
    }

    public Document read(URL uRL) throws DocumentException {
        try {
            Document document = super.getReader().read(uRL);
            return document;
        }
        catch (JAXBRuntimeException var2_3) {
            Throwable throwable = var2_3.getCause();
            throw new DocumentException(throwable.getMessage(), throwable);
        }
    }

    public Document read(InputSource inputSource) throws DocumentException {
        try {
            Document document = super.getReader().read(inputSource);
            return document;
        }
        catch (JAXBRuntimeException var2_3) {
            Throwable throwable = var2_3.getCause();
            throw new DocumentException(throwable.getMessage(), throwable);
        }
    }

    public void removeHandler(String string2) {
        super.getReader().removeHandler(string2);
    }

    public void removeObjectHandler(String string2) {
        super.getReader().removeHandler(string2);
    }

    public void resetHandlers() {
        this.getReader().resetHandlers();
    }

    public void setPruneElements(boolean bl) {
        this.pruneElements = bl;
        if (bl) {
            super.getReader().setDefaultHandler(new PruningElementHandler((JAXBReader)this));
        }
    }

    private class PruningElementHandler
    implements ElementHandler {
        private final JAXBReader this$0;

        public PruningElementHandler(JAXBReader jAXBReader) {
            this.this$0 = jAXBReader;
        }

        @Override
        public void onEnd(ElementPath elementPath) {
            elementPath.getCurrent().detach();
        }

        @Override
        public void onStart(ElementPath elementPath) {
        }
    }

    private class UnmarshalElementHandler
    implements ElementHandler {
        private JAXBObjectHandler handler;
        private JAXBReader jaxbReader;
        private final JAXBReader this$0;

        public UnmarshalElementHandler(JAXBReader jAXBReader, JAXBReader jAXBReader2, JAXBObjectHandler jAXBObjectHandler) {
            this.this$0 = jAXBReader;
            this.jaxbReader = jAXBReader2;
            this.handler = jAXBObjectHandler;
        }

        @Override
        public void onEnd(ElementPath elementPath) {
            try {
                Element element = elementPath.getCurrent();
                javax.xml.bind.Element element2 = this.jaxbReader.unmarshal(element);
                if (this.jaxbReader.isPruneElements()) {
                    element.detach();
                }
                this.handler.handleObject(element2);
                return;
            }
            catch (Exception var2_4) {
                throw new JAXBRuntimeException((Throwable)var2_4);
            }
        }

        @Override
        public void onStart(ElementPath elementPath) {
        }
    }

}

