Improve output: distinguish between failed assertions (failures) and unexpected exceptions (errors), and print a filtered stack trace for any exception.

This commit is contained in:
jeb228 2010-01-29 22:13:57 +00:00
commit 4f2e303079
1839 changed files with 235630 additions and 0 deletions

View file

@ -0,0 +1,183 @@
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
dojo.provide("dojo.data.provider.Base");
dojo.require("dojo.lang.assert");
// -------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------
dojo.data.provider.Base = function() {
/**
* summary:
* A Data Provider serves as a connection to some data source,
* like a relational database. This data provider Base class
* serves as an abstract superclass for other data provider
* classes.
*/
this._countOfNestedTransactions = 0;
this._changesInCurrentTransaction = null;
};
// -------------------------------------------------------------------
// Public instance methods
// -------------------------------------------------------------------
dojo.data.provider.Base.prototype.beginTransaction = function() {
/**
* Marks the beginning of a transaction.
*
* Each time you call beginTransaction() you open a new transaction,
* which you need to close later using endTransaction(). Transactions
* may be nested, but the beginTransaction and endTransaction calls
* always need to come in pairs.
*/
if (this._countOfNestedTransactions === 0) {
this._changesInCurrentTransaction = [];
}
this._countOfNestedTransactions += 1;
};
dojo.data.provider.Base.prototype.endTransaction = function() {
/**
* Marks the end of a transaction.
*/
this._countOfNestedTransactions -= 1;
dojo.lang.assert(this._countOfNestedTransactions >= 0);
if (this._countOfNestedTransactions === 0) {
var listOfChangesMade = this._saveChanges();
this._changesInCurrentTransaction = null;
if (listOfChangesMade.length > 0) {
// dojo.debug("endTransaction: " + listOfChangesMade.length + " changes made");
this._notifyObserversOfChanges(listOfChangesMade);
}
}
};
dojo.data.provider.Base.prototype.getNewItemToLoad = function() {
return this._newItem(); // dojo.data.Item
};
dojo.data.provider.Base.prototype.newItem = function(/* string */ itemName) {
/**
* Creates a new item.
*/
dojo.lang.assertType(itemName, [String, "optional"]);
var item = this._newItem();
if (itemName) {
item.set('name', itemName);
}
return item; // dojo.data.Item
};
dojo.data.provider.Base.prototype.newAttribute = function(/* string */ attributeId) {
/**
* Creates a new attribute.
*/
dojo.lang.assertType(attributeId, String); // FIXME: should be optional
var attribute = this._newAttribute(attributeId);
return attribute; // dojo.data.Attribute
};
dojo.data.provider.Base.prototype.getAttribute = function(/* string */ attributeId) {
dojo.unimplemented('dojo.data.provider.Base');
var attribute;
return attribute; // dojo.data.Attribute
};
dojo.data.provider.Base.prototype.getAttributes = function() {
dojo.unimplemented('dojo.data.provider.Base');
return this._arrayOfAttributes; // Array
};
dojo.data.provider.Base.prototype.fetchArray = function() {
dojo.unimplemented('dojo.data.provider.Base');
return []; // Array
};
dojo.data.provider.Base.prototype.fetchResultSet = function() {
dojo.unimplemented('dojo.data.provider.Base');
var resultSet;
return resultSet; // dojo.data.ResultSet
};
dojo.data.provider.Base.prototype.noteChange = function(/* dojo.data.Item */ item, /* string or dojo.data.Attribute */ attribute, /* anything */ value) {
var change = {item: item, attribute: attribute, value: value};
if (this._countOfNestedTransactions === 0) {
this.beginTransaction();
this._changesInCurrentTransaction.push(change);
this.endTransaction();
} else {
this._changesInCurrentTransaction.push(change);
}
};
dojo.data.provider.Base.prototype.addItemObserver = function(/* dojo.data.Item */ item, /* object */ observer) {
/**
* summary: Registers an object as an observer of an item,
* so that the object will be notified when the item changes.
*/
dojo.lang.assertType(item, dojo.data.Item);
item.addObserver(observer);
};
dojo.data.provider.Base.prototype.removeItemObserver = function(/* dojo.data.Item */ item, /* object */ observer) {
/**
* summary: Removes the observer registration for a previously
* registered object.
*/
dojo.lang.assertType(item, dojo.data.Item);
item.removeObserver(observer);
};
// -------------------------------------------------------------------
// Private instance methods
// -------------------------------------------------------------------
dojo.data.provider.Base.prototype._newItem = function() {
var item = new dojo.data.Item(this);
return item; // dojo.data.Item
};
dojo.data.provider.Base.prototype._newAttribute = function(/* String */ attributeId) {
var attribute = new dojo.data.Attribute(this);
return attribute; // dojo.data.Attribute
};
dojo.data.provider.Base.prototype._saveChanges = function() {
var arrayOfChangesMade = this._changesInCurrentTransaction;
return arrayOfChangesMade; // Array
};
dojo.data.provider.Base.prototype._notifyObserversOfChanges = function(/* Array */ arrayOfChanges) {
var arrayOfResultSets = this._getResultSets();
for (var i in arrayOfChanges) {
var change = arrayOfChanges[i];
var changedItem = change.item;
var arrayOfItemObservers = changedItem.getObservers();
for (var j in arrayOfItemObservers) {
var observer = arrayOfItemObservers[j];
observer.observedObjectHasChanged(changedItem, change);
}
for (var k in arrayOfResultSets) {
var resultSet = arrayOfResultSets[k];
var arrayOfResultSetObservers = resultSet.getObservers();
for (var m in arrayOfResultSetObservers) {
observer = arrayOfResultSetObservers[m];
observer.observedObjectHasChanged(resultSet, change);
}
}
}
};
dojo.data.provider.Base.prototype._getResultSets = function() {
dojo.unimplemented('dojo.data.provider.Base');
return []; // Array
};

View file

@ -0,0 +1,85 @@
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
dojo.provide("dojo.data.provider.Delicious");
dojo.require("dojo.data.provider.FlatFile");
dojo.require("dojo.data.format.Json");
// -------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------
dojo.data.provider.Delicious = function() {
/**
* summary:
* The Delicious Data Provider can be used to take data from
* del.icio.us and make it available as dojo.data.Items
* In order to use the Delicious Data Provider, you need
* to have loaded a script tag that looks like this:
* <script type="text/javascript" src="http://del.icio.us/feeds/json/gumption?count=8"></script>
*/
dojo.data.provider.FlatFile.call(this);
// Delicious = null;
if (Delicious && Delicious.posts) {
dojo.data.format.Json.loadDataProviderFromArrayOfJsonData(this, Delicious.posts);
} else {
// document.write("<script type='text/javascript'>dojo.data.provider.Delicious._fetchComplete()</script>");
/*
document.write("<script type='text/javascript'>alert('boo!');</script>");
document.write("<script type='text/javascript'>var foo = 'not dojo'; alert('dojo == ' + foo);</script>");
document.write("<script type='text/javascript'>var foo = fetchComplete; alert('dojo == ' + foo);</script>");
fetchComplete();
*/
// dojo.debug("Delicious line 29: constructor");
}
var u = this.registerAttribute('u');
var d = this.registerAttribute('d');
var t = this.registerAttribute('t');
u.load('name', 'Bookmark');
d.load('name', 'Description');
t.load('name', 'Tags');
u.load('type', 'String');
d.load('type', 'String');
t.load('type', 'String');
};
dojo.inherits(dojo.data.provider.Delicious, dojo.data.provider.FlatFile);
/********************************************************************
* FIXME: the rest of this is work in progress
*
dojo.data.provider.Delicious.prototype.getNewItemToLoad = function() {
var newItem = this._newItem();
this._currentArray.push(newItem);
return newItem; // dojo.data.Item
};
dojo.data.provider.Delicious.prototype.fetchArray = function(query) {
if (!query) {
query = "gumption";
}
this._currentArray = [];
alert("Delicious line 60: loadDataProviderFromArrayOfJsonData");
alert("Delicious line 61: " + dojo);
var sourceUrl = "http://del.icio.us/feeds/json/" + query + "?count=8";
document.write("<script type='text/javascript' src='" + sourceUrl + "'></script>");
document.write("<script type='text/javascript'>alert('line 63: ' + Delicious.posts[0].u);</script>");
document.write("<script type='text/javascript'>callMe();</script>");
alert("line 66");
dojo.data.format.Json.loadDataProviderFromArrayOfJsonData(this, Delicious.posts);
return this._currentArray; // Array
};
callMe = function() {
alert("callMe!");
};
*/

View file

@ -0,0 +1,153 @@
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
dojo.provide("dojo.data.provider.FlatFile");
dojo.require("dojo.data.provider.Base");
dojo.require("dojo.data.Item");
dojo.require("dojo.data.Attribute");
dojo.require("dojo.data.ResultSet");
dojo.require("dojo.data.format.Json");
dojo.require("dojo.data.format.Csv");
dojo.require("dojo.lang.assert");
// -------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------
dojo.data.provider.FlatFile = function(/* keywords */ keywordParameters) {
/**
* summary:
* A Json Data Provider knows how to read in simple JSON data
* tables and make their contents accessable as Items.
*/
dojo.lang.assertType(keywordParameters, ["pureobject", "optional"]);
dojo.data.provider.Base.call(this);
this._arrayOfItems = [];
this._resultSet = null;
this._dictionaryOfAttributes = {};
if (keywordParameters) {
var jsonObjects = keywordParameters["jsonObjects"];
var jsonString = keywordParameters["jsonString"];
var fileUrl = keywordParameters["url"];
if (jsonObjects) {
dojo.data.format.Json.loadDataProviderFromArrayOfJsonData(this, jsonObjects);
}
if (jsonString) {
dojo.data.format.Json.loadDataProviderFromFileContents(this, jsonString);
}
if (fileUrl) {
var arrayOfParts = fileUrl.split('.');
var lastPart = arrayOfParts[(arrayOfParts.length - 1)];
var formatParser = null;
if (lastPart == "json") {
formatParser = dojo.data.format.Json;
}
if (lastPart == "csv") {
formatParser = dojo.data.format.Csv;
}
if (formatParser) {
var fileContents = dojo.hostenv.getText(fileUrl);
formatParser.loadDataProviderFromFileContents(this, fileContents);
} else {
dojo.lang.assert(false, "new dojo.data.provider.FlatFile({url: }) was passed a file without a .csv or .json suffix");
}
}
}
};
dojo.inherits(dojo.data.provider.FlatFile, dojo.data.provider.Base);
// -------------------------------------------------------------------
// Public instance methods
// -------------------------------------------------------------------
dojo.data.provider.FlatFile.prototype.getProviderCapabilities = function(/* string */ keyword) {
dojo.lang.assertType(keyword, [String, "optional"]);
if (!this._ourCapabilities) {
this._ourCapabilities = {
transactions: false,
undo: false,
login: false,
versioning: false,
anonymousRead: true,
anonymousWrite: false,
permissions: false,
queries: false,
strongTyping: false,
datatypes: [String, Date, Number]
};
}
if (keyword) {
return this._ourCapabilities[keyword];
} else {
return this._ourCapabilities;
}
};
dojo.data.provider.FlatFile.prototype.registerAttribute = function(/* string or dojo.data.Attribute */ attributeId) {
var registeredAttribute = this.getAttribute(attributeId);
if (!registeredAttribute) {
var newAttribute = new dojo.data.Attribute(this, attributeId);
this._dictionaryOfAttributes[attributeId] = newAttribute;
registeredAttribute = newAttribute;
}
return registeredAttribute; // dojo.data.Attribute
};
dojo.data.provider.FlatFile.prototype.getAttribute = function(/* string or dojo.data.Attribute */ attributeId) {
var attribute = (this._dictionaryOfAttributes[attributeId] || null);
return attribute; // dojo.data.Attribute or null
};
dojo.data.provider.FlatFile.prototype.getAttributes = function() {
var arrayOfAttributes = [];
for (var key in this._dictionaryOfAttributes) {
var attribute = this._dictionaryOfAttributes[key];
arrayOfAttributes.push(attribute);
}
return arrayOfAttributes; // Array
};
dojo.data.provider.FlatFile.prototype.fetchArray = function(query) {
/**
* summary: Returns an Array containing all of the Items.
*/
return this._arrayOfItems; // Array
};
dojo.data.provider.FlatFile.prototype.fetchResultSet = function(query) {
/**
* summary: Returns a ResultSet containing all of the Items.
*/
if (!this._resultSet) {
this._resultSet = new dojo.data.ResultSet(this, this.fetchArray(query));
}
return this._resultSet; // dojo.data.ResultSet
};
// -------------------------------------------------------------------
// Private instance methods
// -------------------------------------------------------------------
dojo.data.provider.FlatFile.prototype._newItem = function() {
var item = new dojo.data.Item(this);
this._arrayOfItems.push(item);
return item; // dojo.data.Item
};
dojo.data.provider.FlatFile.prototype._newAttribute = function(/* String */ attributeId) {
dojo.lang.assertType(attributeId, String);
dojo.lang.assert(this.getAttribute(attributeId) === null);
var attribute = new dojo.data.Attribute(this, attributeId);
this._dictionaryOfAttributes[attributeId] = attribute;
return attribute; // dojo.data.Attribute
};
dojo.data.provider.Base.prototype._getResultSets = function() {
return [this._resultSet]; // Array
};

View file

@ -0,0 +1,27 @@
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
dojo.provide("dojo.data.provider.JotSpot");
dojo.require("dojo.data.provider.Base");
// -------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------
dojo.data.provider.JotSpot = function() {
/**
* summary:
* A JotSpot Data Provider knows how to read data from a JotSpot data
* store and make the contents accessable as dojo.data.Items.
*/
dojo.unimplemented('dojo.data.provider.JotSpot');
};
dojo.inherits(dojo.data.provider.JotSpot, dojo.data.provider.Base);

View file

@ -0,0 +1,27 @@
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
dojo.provide("dojo.data.provider.MySql");
dojo.require("dojo.data.provider.Base");
// -------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------
dojo.data.provider.MySql = function() {
/**
* summary:
* A MySql Data Provider knows how to connect to a MySQL database
* on a server and and make the content records available as
* dojo.data.Items.
*/
dojo.unimplemented('dojo.data.provider.MySql');
};
dojo.inherits(dojo.data.provider.MySql, dojo.data.provider.Base);