/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  java.io.File
 *  java.io.FileInputStream
 *  java.io.FileNotFoundException
 *  java.io.FileOutputStream
 *  java.io.IOException
 *  java.io.InputStream
 *  java.io.InputStreamReader
 *  java.io.OutputStream
 *  java.io.Reader
 *  java.io.Writer
 *  java.lang.ClassLoader
 *  java.lang.Exception
 *  java.lang.Object
 *  java.lang.String
 *  java.lang.Throwable
 *  java.net.URL
 *  java.nio.charset.Charset
 *  java.util.HashMap
 *  java.util.Map
 *  java.util.Map$Entry
 *  java.util.Set
 *  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.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.ElementModifier;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXModifier;
import org.dom4j.io.XMLWriter;
import org.dom4j.jaxb.JAXBObjectModifier;
import org.dom4j.jaxb.JAXBRuntimeException;
import org.dom4j.jaxb.JAXBSupport;
import org.xml.sax.InputSource;

public class JAXBModifier
extends JAXBSupport {
    private SAXModifier modifier;
    private HashMap modifiers = new HashMap();
    private OutputFormat outputFormat;
    private boolean pruneElements;
    private XMLWriter xmlWriter;

    public JAXBModifier(String string2) {
        super(string2);
        this.outputFormat = new OutputFormat();
    }

    public JAXBModifier(String string2, ClassLoader classLoader) {
        super(string2, classLoader);
        this.outputFormat = new OutputFormat();
    }

    public JAXBModifier(String string2, ClassLoader classLoader, OutputFormat outputFormat) {
        super(string2, classLoader);
        this.outputFormat = outputFormat;
    }

    public JAXBModifier(String string2, OutputFormat outputFormat) {
        super(string2);
        this.outputFormat = outputFormat;
    }

    private XMLWriter createXMLWriter() throws IOException {
        if (this.xmlWriter == null) {
            this.xmlWriter = new XMLWriter(this.outputFormat);
        }
        return this.xmlWriter;
    }

    private SAXModifier getModifier() {
        if (this.modifier == null) {
            this.modifier = new SAXModifier(this.isPruneElements());
        }
        return this.modifier;
    }

    private XMLWriter getXMLWriter() {
        return this.xmlWriter;
    }

    private SAXModifier installModifier() throws IOException {
        this.modifier = new SAXModifier(this.isPruneElements());
        this.modifier.resetModifiers();
        for (Map.Entry entry : this.modifiers.entrySet()) {
            JAXBElementModifier jAXBElementModifier = new JAXBElementModifier(this, this, (JAXBObjectModifier)entry.getValue());
            this.getModifier().addModifier((String)entry.getKey(), jAXBElementModifier);
        }
        this.modifier.setXMLWriter(this.getXMLWriter());
        return this.modifier;
    }

    public void addObjectModifier(String string2, JAXBObjectModifier jAXBObjectModifier) {
        this.modifiers.put((Object)string2, (Object)jAXBObjectModifier);
    }

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

    public Document modify(File file) throws DocumentException, IOException {
        return super.installModifier().modify(file);
    }

    public Document modify(File file, Charset charset) throws DocumentException, IOException {
        try {
            InputStreamReader inputStreamReader = new InputStreamReader((InputStream)new FileInputStream(file), charset);
            Document document = super.installModifier().modify((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 modify(InputStream inputStream) throws DocumentException, IOException {
        try {
            Document document = super.installModifier().modify(inputStream);
            return document;
        }
        catch (JAXBRuntimeException var2_3) {
            Throwable throwable = var2_3.getCause();
            throw new DocumentException(throwable.getMessage(), throwable);
        }
    }

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

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

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

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

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

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

    public void removeObjectModifier(String string2) {
        this.modifiers.remove((Object)string2);
        super.getModifier().removeModifier(string2);
    }

    public void resetObjectModifiers() {
        this.modifiers.clear();
        this.getModifier().resetModifiers();
    }

    public void setOutput(File file) throws IOException {
        super.createXMLWriter().setOutputStream((OutputStream)new FileOutputStream(file));
    }

    public void setOutput(OutputStream outputStream) throws IOException {
        super.createXMLWriter().setOutputStream(outputStream);
    }

    public void setOutput(Writer writer) throws IOException {
        super.createXMLWriter().setWriter(writer);
    }

    public void setPruneElements(boolean bl) {
        this.pruneElements = bl;
    }

    private class JAXBElementModifier
    implements ElementModifier {
        private JAXBModifier jaxbModifier;
        private JAXBObjectModifier objectModifier;
        private final JAXBModifier this$0;

        public JAXBElementModifier(JAXBModifier jAXBModifier, JAXBModifier jAXBModifier2, JAXBObjectModifier jAXBObjectModifier) {
            this.this$0 = jAXBModifier;
            this.jaxbModifier = jAXBModifier2;
            this.objectModifier = jAXBObjectModifier;
        }

        @Override
        public Element modifyElement(Element element) throws Exception {
            javax.xml.bind.Element element2 = this.jaxbModifier.unmarshal(element);
            javax.xml.bind.Element element3 = this.objectModifier.modifyObject(element2);
            return this.jaxbModifier.marshal(element3);
        }
    }

}

