/**
 * @requires OpenLayers/Format/WFSDescribeFeatureType.js
 *
 * Class: OpenLayers.Format.WFSDescribeFeatureType_1_0
 * Read WFS DescribeFeatureType response for WFS 1.0
 * 
 * Inherits from:
 *  - <OpenLayers.Format.WFSDescribeFeatureType>
 */
OpenLayers.Format.WFSDescribeFeatureType.v1_0 = OpenLayers.Class(
    OpenLayers.Format.XML, {
    
    /**
     * Constant: VERSION
     * {String} 1.0
     */
    VERSION: "1.0",
    
    /**
     * Property: namespaces
     * {Object} Mapping of namespace aliases to namespace URIs.
     */
    namespaces: {
        xsd: "http://www.w3.org/2001/XMLSchema"
    },
    
    /**
     * Constructor: OpenLayers.Format.WFSDescribeFeatureType
     * Create a new parser for WFS DescribeFeatureType responses.
     *
     * Parameters:
     * options - {Object} An optional object whose properties will be set on
     *     this instance.
     */
    initialize: function(options) {
        OpenLayers.Format.WFSDescribeFeatureType.prototype.initialize.apply(this, 
            [options]);
    },

    /**
     * APIMethod: read
     * Read WFS DescribeFeatureType data from a string, return the response.
     * 
     * Parameters: 
     * data - {String} or {DOMElement} data to read/parse.
     * options - {Object} additional options that influence the result
     *     returned from the reader.
     *     
     * Currently supported reader options:
     * verbose - {Boolean} set to true to get more information than just the
     *     attributes. The reader will return a hash, containing the
     *     attributes in the attributes property, and the feature namespace
     *     in the featureNS property.
     *
     *
     * Returns:
     * {Array} Array of objects which have:
     * - {String} name: attribute names
     * - {String} type: attributes types, like xsd:string
     */
    read: function(data, options) {
        if(typeof data == "string") {
            data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
        }
        var describefeaturetype = [];
        var root = data.documentElement;
        var sequence = this.getElementsByTagNameNS(root, this.namespaces.xsd,
		    'sequence');
        if (sequence.length > 0) {
            var elements = this.getElementsByTagNameNS(sequence[0], this.namespaces.xsd,
			    'element');
            for(var i=0; i<elements.length; ++i) {
                var element = elements[i];
                var name = element.getAttribute('name');
                var type = element.getAttribute('type');
                describefeaturetype.push({name: name, type: type});
            }
        }
        if(options && options.verbose == true) {
            var featureNS = root.getAttribute("targetNamespace");
            return {
                featureNS: featureNS,
                attributes: describefeaturetype
            }
        } else {
            return describefeaturetype;
        }
    },
    
    CLASS_NAME: "OpenLayers.Format.WFSDescribeFeatureType_1_0" 

});

