/*
 * 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
 *  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 org.dom4j.Element;
import org.dom4j.Namespace;
import org.dom4j.QName;
import org.dom4j.tree.AbstractAttribute;
import org.relaxng.datatype.DatatypeException;
import org.relaxng.datatype.ValidationContext;

public class DatatypeAttribute
extends AbstractAttribute
implements SerializationContext,
ValidationContext {
    private Object data;
    private XSDatatype datatype;
    private Element parent;
    private QName qname;
    private String text;

    public DatatypeAttribute(QName qName, XSDatatype xSDatatype) {
        this.qname = qName;
        this.datatype = xSDatatype;
    }

    public DatatypeAttribute(QName qName, XSDatatype xSDatatype, String string2) {
        this.qname = qName;
        this.datatype = xSDatatype;
        this.text = string2;
        this.data = this.convertToValue(string2);
    }

    protected Object convertToValue(String string2) {
        if (this.datatype instanceof DatabindableDatatype) {
            return this.datatype.createJavaObject(string2, (ValidationContext)this);
        }
        return this.datatype.createValue(string2, (ValidationContext)this);
    }

    public String getBaseUri() {
        return null;
    }

    @Override
    public Object getData() {
        return this.data;
    }

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

    @Override
    public Element getParent() {
        return this.parent;
    }

    @Override
    public QName getQName() {
        return this.qname;
    }

    @Override
    public String getValue() {
        return this.text;
    }

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

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

    @Override
    public boolean isReadOnly() {
        return false;
    }

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

    public String resolveNamespacePrefix(String string2) {
        Namespace namespace;
        if (string2.equals((Object)this.getNamespacePrefix())) {
            return this.getNamespaceURI();
        }
        Element element = this.getParent();
        if (element != null && (namespace = element.getNamespaceForPrefix(string2)) != null) {
            return namespace.getURI();
        }
        return null;
    }

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

    @Override
    public void setParent(Element element) {
        this.parent = element;
    }

    @Override
    public void setValue(String string2) {
        this.validate(string2);
        this.text = string2;
        this.data = this.convertToValue(string2);
    }

    @Override
    public boolean supportsParent() {
        return true;
    }

    @Override
    public String toString() {
        return new StringBuffer().append(this.getClass().getName()).append(this.hashCode()).append(" [Attribute: name ").append(this.getQualifiedName()).append(" value \"").append(this.getValue()).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());
        }
    }
}

