Path: blob/trunk/third_party/closure/goog/net/bulkloaderhelper.js
2868 views
// Copyright 2008 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Helper class to load a list of URIs in bulk. All URIs16* must be a successfully loaded in order for the entire load to be considered17* a success.18*19*/2021goog.provide('goog.net.BulkLoaderHelper');2223goog.require('goog.Disposable');24252627/**28* Helper class used to load multiple URIs.29* @param {Array<string|goog.Uri>} uris The URIs to load.30* @constructor31* @extends {goog.Disposable}32* @final33*/34goog.net.BulkLoaderHelper = function(uris) {35goog.Disposable.call(this);3637/**38* The URIs to load.39* @type {Array<string|goog.Uri>}40* @private41*/42this.uris_ = uris;4344/**45* The response from the XHR's.46* @type {Array<string>}47* @private48*/49this.responseTexts_ = [];50};51goog.inherits(goog.net.BulkLoaderHelper, goog.Disposable);52535455/**56* Gets the URI by id.57* @param {number} id The id.58* @return {string|goog.Uri} The URI specified by the id.59*/60goog.net.BulkLoaderHelper.prototype.getUri = function(id) {61return this.uris_[id];62};636465/**66* Gets the URIs.67* @return {Array<string|goog.Uri>} The URIs.68*/69goog.net.BulkLoaderHelper.prototype.getUris = function() {70return this.uris_;71};727374/**75* Gets the response texts.76* @return {Array<string>} The response texts.77*/78goog.net.BulkLoaderHelper.prototype.getResponseTexts = function() {79return this.responseTexts_;80};818283/**84* Sets the response text by id.85* @param {number} id The id.86* @param {string} responseText The response texts.87*/88goog.net.BulkLoaderHelper.prototype.setResponseText = function(89id, responseText) {90this.responseTexts_[id] = responseText;91};929394/**95* Determines if the load of the URIs is complete.96* @return {boolean} TRUE iff the load is complete.97*/98goog.net.BulkLoaderHelper.prototype.isLoadComplete = function() {99var responseTexts = this.responseTexts_;100if (responseTexts.length == this.uris_.length) {101for (var i = 0; i < responseTexts.length; i++) {102if (!goog.isDefAndNotNull(responseTexts[i])) {103return false;104}105}106return true;107}108return false;109};110111112/** @override */113goog.net.BulkLoaderHelper.prototype.disposeInternal = function() {114goog.net.BulkLoaderHelper.superClass_.disposeInternal.call(this);115116this.uris_ = null;117this.responseTexts_ = null;118};119120121