package org.dom4j.schema.basic;

import org.apache.xerces.xs.AttributePSVI;
import org.apache.xerces.xs.ItemPSVI;
import org.dom4j.Element;
import org.dom4j.Namespace;
import org.dom4j.QName;
import org.dom4j.schema.SchemaAwareAttribute;
import org.dom4j.tree.DefaultAttribute;



/**
 * <p>
 * <code>SchemaAttribute</code> represents an Attribute which supports the
 * <a href="http://www.w3.org/TR/xmlschema-2/">XML Schema Data Types </a>
 * specification.
 * </p>
 *
 * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
 * @version $Revision: 1.9 $
 */
public class DefaultSchemaAttribute extends DefaultAttribute implements SchemaAwareAttribute{
    
    /** The <code>XSSchema</code> of the <code>Attribute</code> */
    private AttributePSVI psvi;
    
    public DefaultSchemaAttribute(QName qname) {
        super(qname);
    }
    
    public DefaultSchemaAttribute(QName qname, String value) {
        super(qname, value);
    }
    
    public DefaultSchemaAttribute(Element parent, QName qname, String value) {
        super(parent, qname, value);
    }
    
    /**
     * Creates the <code>Attribute</code> with the specified local name and
     * value.
     *
     * @param name
     *            is the name of the attribute
     * @param value
     *            is the value of the attribute
     */
    public DefaultSchemaAttribute(String name, String value) {
        super(name, value);
    }
    
    /**
     * Creates the <code>Attribute</code> with the specified local name, value
     * and <code>Namespace</code>.
     *
     * @param name
     *            is the name of the attribute
     * @param value
     *            is the value of the attribute
     * @param namespace
     *            is the namespace of the attribute
     */
    public DefaultSchemaAttribute(String name, String value, Namespace namespace) {
        super(name, value, namespace);
    }
    
    /**
     * Creates the <code>Attribute</code> with the specified local name, value
     * and <code>Namespace</code>.
     *
     * @param parent
     *            is the parent element
     * @param name
     *            is the name of the attribute
     * @param value
     *            is the value of the attribute
     * @param namespace
     *            is the namespace of the attribute
     */
    public DefaultSchemaAttribute(Element parent, String name, String value,  Namespace namespace) {
        super(parent,name,value,namespace);
    }
    
    
    
    // SchemaAwareAttribute interface
    // -------------------------------------------------------------------------
    public AttributePSVI getAttributePsvi() {
        return psvi;
    }
    public ItemPSVI getItemPsvi() {
        return getAttributePsvi();
    }
    
    public void initAttributePsvi(AttributePSVI psvi) {
        if (this.psvi != null) {
            throw new IllegalStateException("Already Initialised");
        }
        if (psvi == null) {
            throw new IllegalStateException("cannot be initialised to null");
        }
        this.psvi = psvi;
    }
    
    
}
