2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
8 YUI.add('datasource-xmlschema', function(Y) {
11 * Extends DataSource with schema-parsing on XML data.
14 * @submodule datasource-xmlschema
18 * Adds schema-parsing to the DataSource Utility.
19 * @class DataSourceXMLSchema
20 * @extends Plugin.Base
22 var DataSourceXMLSchema = function() {
23 DataSourceXMLSchema.superclass.constructor.apply(this, arguments);
26 Y.mix(DataSourceXMLSchema, {
28 * The namespace for the plugin. This will be the property on the host which
29 * references the plugin instance.
46 * @value "dataSourceXMLSchema"
48 NAME: "dataSourceXMLSchema",
50 /////////////////////////////////////////////////////////////////////////////
52 // DataSourceXMLSchema Attributes
54 /////////////////////////////////////////////////////////////////////////////
63 Y.extend(DataSourceXMLSchema, Y.Plugin.Base, {
65 * Internal init() handler.
68 * @param config {Object} Config object.
71 initializer: function(config) {
72 this.doBefore("_defDataFn", this._beforeDefDataFn);
76 * Parses raw data into a normalized response.
78 * @method _beforeDefDataFn
80 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
81 * <dt>request (Object)</dt> <dd>The request.</dd>
82 * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
84 * <dt>success (Function)</dt> <dd>Success handler.</dd>
85 * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
88 * <dt>data (Object)</dt> <dd>Raw data.</dd>
92 _beforeDefDataFn: function(e) {
93 var data = (Y.DataSource.IO && (this.get("host") instanceof Y.DataSource.IO) && e.data.responseXML && (e.data.responseXML.nodeType === 9)) ? e.data.responseXML : e.data,
94 response = Y.DataSchema.XML.apply.call(this, this.get("schema"), data);
104 this.get("host").fire("response", Y.mix({response:response}, e));
105 return new Y.Do.Halt("DataSourceXMLSchema plugin halted _defDataFn");
109 Y.namespace('Plugin').DataSourceXMLSchema = DataSourceXMLSchema;
113 }, '3.3.0' ,{requires:['datasource-local', 'plugin', 'dataschema-xml']});