/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  java.io.Reader
 *  java.io.StringReader
 *  java.lang.ClassLoader
 *  java.lang.Object
 *  java.lang.String
 *  javax.xml.bind.Element
 *  javax.xml.bind.JAXBContext
 *  javax.xml.bind.JAXBException
 *  javax.xml.bind.Marshaller
 *  javax.xml.bind.Unmarshaller
 *  javax.xml.transform.Source
 *  javax.xml.transform.stream.StreamSource
 *  org.w3c.dom.Node
 */
package org.dom4j.jaxb;

import java.io.Reader;
import java.io.StringReader;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import org.dom4j.Element;
import org.dom4j.dom.DOMDocument;
import org.w3c.dom.Node;

abstract class JAXBSupport {
    private ClassLoader classloader;
    private String contextPath;
    private JAXBContext jaxbContext;
    private Marshaller marshaller;
    private Unmarshaller unmarshaller;

    public JAXBSupport(String string2) {
        this.contextPath = string2;
    }

    public JAXBSupport(String string2, ClassLoader classLoader) {
        this.contextPath = string2;
        this.classloader = classLoader;
    }

    /*
     * Enabled aggressive block sorting
     */
    private JAXBContext getContext() throws JAXBException {
        if (this.jaxbContext != null) return this.jaxbContext;
        if (this.classloader == null) {
            this.jaxbContext = JAXBContext.newInstance((String)this.contextPath);
            return this.jaxbContext;
        }
        this.jaxbContext = JAXBContext.newInstance((String)this.contextPath, (ClassLoader)this.classloader);
        return this.jaxbContext;
    }

    private Marshaller getMarshaller() throws JAXBException {
        if (this.marshaller == null) {
            this.marshaller = this.getContext().createMarshaller();
        }
        return this.marshaller;
    }

    private Unmarshaller getUnmarshaller() throws JAXBException {
        if (this.unmarshaller == null) {
            this.unmarshaller = this.getContext().createUnmarshaller();
        }
        return this.unmarshaller;
    }

    protected Element marshal(javax.xml.bind.Element element) throws JAXBException {
        DOMDocument dOMDocument = new DOMDocument();
        super.getMarshaller().marshal((Object)element, (Node)dOMDocument);
        return dOMDocument.getRootElement();
    }

    protected javax.xml.bind.Element unmarshal(Element element) throws JAXBException {
        StreamSource streamSource = new StreamSource((Reader)new StringReader(element.asXML()));
        return (javax.xml.bind.Element)super.getUnmarshaller().unmarshal((Source)streamSource);
    }
}

