/*
 * Decompiled with CFR 0_110.
 * 
 * Could not load the following classes:
 *  com.sun.msv.datatype.DatabindableDatatype
 *  com.sun.msv.datatype.SerializationContext
 *  com.sun.msv.datatype.xsd.XSDatatype
 *  java.lang.Class
 *  java.lang.IllegalArgumentException
 *  java.lang.Object
 *  java.lang.String
 *  java.lang.StringBuffer
 *  java.util.List
 *  org.relaxng.datatype.DatatypeException
 *  org.relaxng.datatype.ValidationContext
 */
package org.dom4j.datatype;

import com.sun.msv.datatype.DatabindableDatatype;
import com.sun.msv.datatype.SerializationContext;
import com.sun.msv.datatype.xsd.XSDatatype;
import java.util.List;
import org.dom4j.Element;
import org.dom4j.Namespace;
import org.dom4j.Node;
import org.dom4j.QName;
import org.dom4j.tree.DefaultElement;
import org.relaxng.datatype.DatatypeException;
import org.relaxng.datatype.ValidationContext;

public class DatatypeElement
extends DefaultElement
implements SerializationContext,
ValidationContext {
    private Object data;
    private XSDatatype datatype;

    public DatatypeElement(QName qName, int n, XSDatatype xSDatatype) {
        super(qName, n);
        this.datatype = xSDatatype;
    }

    public DatatypeElement(QName qName, XSDatatype xSDatatype) {
        super(qName);
        this.datatype = xSDatatype;
    }

    @Override
    public Element addText(String string2) {
        this.validate(string2);
        return super.addText(string2);
    }

    @Override
    protected void childAdded(Node node) {
        this.data = null;
        super.childAdded(node);
    }

    @Override
    protected void childRemoved(Node node) {
        this.data = null;
        super.childRemoved(node);
    }

    public String getBaseUri() {
        return null;
    }

    /*
     * Enabled aggressive block sorting
     */
    @Override
    public Object getData() {
        if (this.data != null) return this.data;
        String string2 = this.getTextTrim();
        if (string2 == null) return this.data;
        if (string2.length() <= 0) return this.data;
        if (this.datatype instanceof DatabindableDatatype) {
            this.data = this.datatype.createJavaObject(string2, (ValidationContext)this);
            return this.data;
        }
        this.data = this.datatype.createValue(string2, (ValidationContext)this);
        return this.data;
    }

    public String getNamespacePrefix(String string2) {
        Namespace namespace = this.getNamespaceForURI(string2);
        if (namespace != null) {
            return namespace.getPrefix();
        }
        return null;
    }

    public XSDatatype getXSDatatype() {
        return this.datatype;
    }

    public boolean isNotation(String string2) {
        return false;
    }

    public boolean isUnparsedEntity(String string2) {
        return true;
    }

    public String resolveNamespacePrefix(String string2) {
        Namespace namespace = this.getNamespaceForPrefix(string2);
        if (namespace != null) {
            return namespace.getURI();
        }
        return null;
    }

    @Override
    public void setData(Object object) {
        String string2 = this.datatype.convertToLexicalValue(object, (SerializationContext)this);
        this.validate(string2);
        this.data = object;
        this.setText(string2);
    }

    @Override
    public void setText(String string2) {
        this.validate(string2);
        super.setText(string2);
    }

    @Override
    public String toString() {
        return new StringBuffer().append(this.getClass().getName()).append(this.hashCode()).append(" [Element: <").append(this.getQualifiedName()).append(" attributes: ").append((Object)this.attributeList()).append(" data: ").append(this.getData()).append(" />]").toString();
    }

    protected void validate(String string2) throws IllegalArgumentException {
        try {
            this.datatype.checkValid(string2, (ValidationContext)this);
            return;
        }
        catch (DatatypeException var2_2) {
            throw new IllegalArgumentException(var2_2.getMessage());
        }
    }
}

