You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2014/08/20 09:53:24 UTC

[1/5] [OLINGO-407] JS- V4's window.OData is not defined yet: part 1 - change window.datajs.V4 into window.odatajs (while V3: window.datajs).

Repository: olingo-odata4-js
Updated Branches:
  refs/heads/master dd24c1f09 -> 5c98f9f3e


http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/datajs/tests/odata-cache-filter-functional-tests.js
----------------------------------------------------------------------
diff --git a/datajs/tests/odata-cache-filter-functional-tests.js b/datajs/tests/odata-cache-filter-functional-tests.js
index c1775cf..1d19771 100644
--- a/datajs/tests/odata-cache-filter-functional-tests.js
+++ b/datajs/tests/odata-cache-filter-functional-tests.js
@@ -222,7 +222,7 @@
         djstest.assertsExpected(2);
         var options = { name: "cache" + new Date().valueOf(), source: params.feed, pageSize: params.pageSize, prefetchSize: params.prefetchSize };
 
-        var cache = datajs.cache.createDataCache(options);
+        var cache = odatajs.cache.createDataCache(options);
         var cacheOracle = new CacheOracle(params.feed, params.pageSize, itemsInCollection);
         var session = this.observableHttpClient.newSession();
         validateFilterResultsAndRequests(params.feed, cache, params.index, params.count, params.predicate, function () { djstest.destroyCacheAndDone(cache) }, params.backwards, session, cacheOracle);
@@ -232,7 +232,7 @@
         djstest.assertsExpected(3);
         var options = { name: "cache" + new Date().valueOf(), source: params.feed, pageSize: params.pageSize, prefetchSize: params.prefetchSize };
 
-        var cache = datajs.cache.createDataCache(options);
+        var cache = odatajs.cache.createDataCache(options);
         var cacheOracle = new CacheOracle(params.feed, params.pageSize, itemsInCollection);
         var session = this.observableHttpClient.newSession();
 
@@ -247,7 +247,7 @@
         djstest.assertsExpected(2);
         var options = { name: "cache" + new Date().valueOf(), source: params.feed, pageSize: params.pageSize, prefetchSize: params.prefetchSize };
 
-        var cache = datajs.cache.createDataCache(options);
+        var cache = odatajs.cache.createDataCache(options);
 
         var firstfilter = function (finished) {
             validateFilterResultsAndRequests(params.feed, cache, params.firstIndex, params.firstCount, params.predicate, finished, params.backwards);
@@ -266,7 +266,7 @@
         djstest.assertsExpected(4);
         var options = { name: "cache" + new Date().valueOf(), source: params.feed, pageSize: params.pageSize, prefetchSize: params.prefetchSize };
 
-        var cache = datajs.cache.createDataCache(options);
+        var cache = odatajs.cache.createDataCache(options);
         var cacheOracle = new CacheOracle(params.feed, params.pageSize, itemsInCollection);
         var session = this.observableHttpClient.newSession();
 
@@ -387,7 +387,7 @@
                 function (params) {
                     djstest.assertsExpected(1);
                     var options = { name: "cache" + new Date().valueOf(), source: params.feed };
-                    var cache = datajs.cache.createDataCache(options);
+                    var cache = odatajs.cache.createDataCache(options);
                     try {
                         params.backwards ?
                             cache.filterForward(params.index, params.count, params.predicate).then(function (results) {
@@ -411,7 +411,7 @@
                 function (params) {
                     djstest.assertsExpected(1);
                     var options = { name: "cache" + new Date().valueOf(), source: params.feed };
-                    var cache = datajs.cache.createDataCache(options);
+                    var cache = odatajs.cache.createDataCache(options);
                     try {
                         params.backwards ?
                             cache.filterBack(params.index, params.count, params.predicate).then(function (results) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/datajs/tests/odata-cache-fperf-tests.js
----------------------------------------------------------------------
diff --git a/datajs/tests/odata-cache-fperf-tests.js b/datajs/tests/odata-cache-fperf-tests.js
index 47abbca..caf75ad 100644
--- a/datajs/tests/odata-cache-fperf-tests.js
+++ b/datajs/tests/odata-cache-fperf-tests.js
@@ -56,7 +56,7 @@
          * @returns The test function
          */
         return function () {
-            var cache = datajs.cache.createDataCache({ name: "cache" + new Date().valueOf(), source: source, pageSize: pageSize, prefetchSize: prefetchSize });
+            var cache = odatajs.cache.createDataCache({ name: "cache" + new Date().valueOf(), source: source, pageSize: pageSize, prefetchSize: prefetchSize });
             var totalTime = 0;
             var readCount = 0;
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/datajs/tests/odata-cache-functional-tests.js
----------------------------------------------------------------------
diff --git a/datajs/tests/odata-cache-functional-tests.js b/datajs/tests/odata-cache-functional-tests.js
index 331da08..fc8d230 100644
--- a/datajs/tests/odata-cache-functional-tests.js
+++ b/datajs/tests/odata-cache-functional-tests.js
@@ -335,7 +335,7 @@
                 /** Returns a cache created from the options object and 
                  * @param {Object} options - Object to create a cache from. 
                  */
-                var cache = datajs.cache.createDataCache(options);
+                var cache = odatajs.cache.createDataCache(options);
                 this.caches.push({ name: options.name, cache: cache });
                 return cache;
             };

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/datajs/tests/odata-cache-rx-functional-tests.js
----------------------------------------------------------------------
diff --git a/datajs/tests/odata-cache-rx-functional-tests.js b/datajs/tests/odata-cache-rx-functional-tests.js
index 9261dfe..453e586 100644
--- a/datajs/tests/odata-cache-rx-functional-tests.js
+++ b/datajs/tests/odata-cache-rx-functional-tests.js
@@ -73,7 +73,7 @@
                 djstest.addTest(function (params) {
                     djstest.assertsExpected(1);
                     var options = { name: "cache" + new Date().valueOf(), source: params.feedUri, pageSize: params.pageSize, prefetchSize: 0 };
-                    var cache = datajs.cache.createDataCache(options);
+                    var cache = odatajs.cache.createDataCache(options);
 
                     ODataReadOracle.readJsonAcrossServerPages(params.feedUri, function (collection) {
                         assertObservables(params.operator(cache.toObservable()), params.operator(window.Rx.Observable.FromArray(collection.value)), function () {

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/datajs/tests/odata-json-tests.js
----------------------------------------------------------------------
diff --git a/datajs/tests/odata-json-tests.js b/datajs/tests/odata-json-tests.js
index 630ff55..72a8a07 100644
--- a/datajs/tests/odata-json-tests.js
+++ b/datajs/tests/odata-json-tests.js
@@ -23,12 +23,12 @@
    
     
     djstest.addTest(function isArrayTest() {
-        djstest.assert(datajs.utils.isArray([]));
-        djstest.assert(datajs.utils.isArray([1, 2]));
-        djstest.assert(!datajs.utils.isArray({}));
-        djstest.assert(!datajs.utils.isArray("1,2,3,4"));
-        djstest.assert(!datajs.utils.isArray());
-        djstest.assert(!datajs.utils.isArray(null));
+        djstest.assert(odatajs.utils.isArray([]));
+        djstest.assert(odatajs.utils.isArray([1, 2]));
+        djstest.assert(!odatajs.utils.isArray({}));
+        djstest.assert(!odatajs.utils.isArray("1,2,3,4"));
+        djstest.assert(!odatajs.utils.isArray());
+        djstest.assert(!odatajs.utils.isArray(null));
         djstest.done();
     });
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/datajs/tests/odata-metadata-tests.js
----------------------------------------------------------------------
diff --git a/datajs/tests/odata-metadata-tests.js b/datajs/tests/odata-metadata-tests.js
index 2918c8b..6f18e4f 100644
--- a/datajs/tests/odata-metadata-tests.js
+++ b/datajs/tests/odata-metadata-tests.js
@@ -424,7 +424,7 @@
 
         var i, len;
         for (i = 0, len = cases.length; i < len; i++) {
-            var doc = window.datajs.xml.xmlParse(cases[i].i);
+            var doc = window.odatajs.xml.xmlParse(cases[i].i);
             var schema = window.OData.metadata.parseConceptualModelElement(doc.documentElement);
             djstest.assertAreEqualDeep(schema, cases[i].e, "parseConceptualModelElement result matches target");
         }
@@ -446,7 +446,7 @@
         '      </EntityType></Schema></edmx:DataServices></edmx:Edmx>';
 
 
-        var doc = window.datajs.xml.xmlParse(testCsdl);
+        var doc = window.odatajs.xml.xmlParse(testCsdl);
         var schema = window.OData.metadata.parseConceptualModelElement(doc.documentElement);
 
         djstest.assertAreEqual(schema.dataServices.schema[0].term.length, 2, "schema.DataServices.Schema.Term.length === 2");
@@ -480,7 +480,7 @@
         '    </Schema></edmx:DataServices></edmx:Edmx>';
 
 
-        var doc = window.datajs.xml.xmlParse(testCsdl);
+        var doc = window.odatajs.xml.xmlParse(testCsdl);
         var schema = window.OData.metadata.parseConceptualModelElement(doc.documentElement);
 
         djstest.assertAreEqual(schema.dataServices.schema[0].annotations.length, 2, "Annotations number");

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/datajs/tests/odata-read-crossdomain-functional-tests.js
----------------------------------------------------------------------
diff --git a/datajs/tests/odata-read-crossdomain-functional-tests.js b/datajs/tests/odata-read-crossdomain-functional-tests.js
index fb90658..167db54 100644
--- a/datajs/tests/odata-read-crossdomain-functional-tests.js
+++ b/datajs/tests/odata-read-crossdomain-functional-tests.js
@@ -119,7 +119,7 @@
     var dataCacheReadRangeSingleTest = function (params) {
         var options = { name: "cache", source: params.feed, pageSize: params.pageSize, prefetchSize: params.prefetchSize, cacheSize: params.cacheSize };
         OData.net.defaultHttpClient.enableJsonpCallback = true;
-        var cache = datajs.cache.createDataCache(options);
+        var cache = odatajs.cache.createDataCache(options);
         cache.readRange(params.skip, params.take).then(function (data) {
             validateExpectedRange(cache, data, params.feed, params.skip, params.take);
         }, unexpectedErrorHandler);

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/datajs/tests/odata-xml-tests.js
----------------------------------------------------------------------
diff --git a/datajs/tests/odata-xml-tests.js b/datajs/tests/odata-xml-tests.js
index 897a9fd..465b42b 100644
--- a/datajs/tests/odata-xml-tests.js
+++ b/datajs/tests/odata-xml-tests.js
@@ -40,7 +40,7 @@
 
         var i, len;
         for (i = 0, len = tests.length; i < len; i++) {
-            var actual = datajs.utils.getURIInfo(tests[i].input);
+            var actual = odatajs.utils.getURIInfo(tests[i].input);
             djstest.assertAreEqualDeep(actual, tests[i].expected, "test " + i + "didn't return the expected URI parts");
         }
         djstest.done();
@@ -56,7 +56,7 @@
 
         var i, len;
         for (i = 0, len = tests.length; i < len; i++) {
-            var actual = datajs.utils.normalizeURICase(tests[i].uri, tests[i].base);
+            var actual = odatajs.utils.normalizeURICase(tests[i].uri, tests[i].base);
             djstest.assertAreEqual(actual, tests[i].expected, "test " + i + "didn't return the expected URI");
         }
         djstest.done();
@@ -84,7 +84,7 @@
 
         var i, len;
         for (i = 0, len = tests.length; i < len; i++) {
-            var actual = datajs.utils.normalizeURI(tests[i].uri, tests[i].base);
+            var actual = odatajs.utils.normalizeURI(tests[i].uri, tests[i].base);
             djstest.assertAreEqual(actual, tests[i].expected, "test " + i + "didn't return the expected normalized URI");
         }
         djstest.done();
@@ -92,7 +92,7 @@
 
     djstest.addTest(function xmlParseTest() {
         var xml = '<root xmlns:n1="http://namespace1" xml:base="http://base.org" />';
-        var root = datajs.xml.xmlParse(xml);
+        var root = odatajs.xml.xmlParse(xml);
         djstest.assert(root, "xml._parse didn't return a xml dom object");
         djstest.done();
     });
@@ -104,12 +104,12 @@
            <element base=\"this is not a xml base attribute\" /> \r\n\
          </root>\r\n";
 
-        var doc = datajs.xml.xmlParse(xml);
-        var root = datajs.xml.xmlFirstChildElement(doc);
-        var child = datajs.xml.xmlFirstChildElement(root);
+        var doc = odatajs.xml.xmlParse(xml);
+        var root = odatajs.xml.xmlFirstChildElement(doc);
+        var child = odatajs.xml.xmlFirstChildElement(root);
 
-        djstest.assertAreEqual(datajs.xml.xmlBaseURI(root), "http://base.org", "xml._baseURI didn't return the expected value");
-        djstest.assert(!datajs.xml.xmlBaseURI(child), "xml._baseURI returned a value when it wasn't expected");
+        djstest.assertAreEqual(odatajs.xml.xmlBaseURI(root), "http://base.org", "xml._baseURI didn't return the expected value");
+        djstest.assert(!odatajs.xml.xmlBaseURI(child), "xml._baseURI returned a value when it wasn't expected");
         djstest.done();
     });
 
@@ -120,13 +120,13 @@
         <element attribute=\"value\" n1:nsAttribute=\"nsValue\" /> \r\n\
      </root> \r\n";
 
-        var doc = datajs.xml.xmlParse(xml);
-        var root = datajs.xml.xmlFirstChildElement(doc);
-        var child = datajs.xml.xmlFirstChildElement(root);
+        var doc = odatajs.xml.xmlParse(xml);
+        var root = odatajs.xml.xmlFirstChildElement(doc);
+        var child = odatajs.xml.xmlFirstChildElement(root);
 
-        djstest.assertAreEqual(datajs.xml.xmlAttributeValue(child, "attribute"), "value", "xml._attribute didn't return the expected value for attribute");
-        djstest.assertAreEqual(datajs.xml.xmlAttributeValue(child, "nsAttribute", "http://namespace1"), "nsValue", "xml._attribute didn't return the expected value for nsAttribute");
-        djstest.assert(!datajs.xml.xmlAttributeValue(child, "nsAttribute"), "xml._attribute returned a value for nsAttribute without specifying a namespace");
+        djstest.assertAreEqual(odatajs.xml.xmlAttributeValue(child, "attribute"), "value", "xml._attribute didn't return the expected value for attribute");
+        djstest.assertAreEqual(odatajs.xml.xmlAttributeValue(child, "nsAttribute", "http://namespace1"), "nsValue", "xml._attribute didn't return the expected value for nsAttribute");
+        djstest.assert(!odatajs.xml.xmlAttributeValue(child, "nsAttribute"), "xml._attribute returned a value for nsAttribute without specifying a namespace");
 
         djstest.done();
     });
@@ -134,10 +134,10 @@
     djstest.addTest(function xmlLocalNameTest() {
         var xml = "<root xmlns:n1=\"http://namespace1\" /> \r\n";
 
-        var doc = datajs.xml.xmlParse(xml);
-        var root = datajs.xml.xmlFirstChildElement(doc);
+        var doc = odatajs.xml.xmlParse(xml);
+        var root = odatajs.xml.xmlFirstChildElement(doc);
 
-        djstest.assertAreEqual(datajs.xml.xmlLocalName(root), "root", "xml._localName didn't return the expected localName of the root element");
+        djstest.assertAreEqual(odatajs.xml.xmlLocalName(root), "root", "xml._localName didn't return the expected localName of the root element");
         djstest.done();
     });
 
@@ -150,11 +150,11 @@
          </root>\r\n";
 
 
-        var doc = datajs.xml.xmlParse(xml);
-        var root = datajs.xml.xmlFirstChildElement(doc);
-        var child = datajs.xml.xmlFirstChildElement(root);
+        var doc = odatajs.xml.xmlParse(xml);
+        var root = odatajs.xml.xmlFirstChildElement(doc);
+        var child = odatajs.xml.xmlFirstChildElement(root);
 
-        djstest.assertAreEqual(datajs.xml.xmlLocalName(child), "element1", "xml.firstElement returned didn't return the expected element");
+        djstest.assertAreEqual(odatajs.xml.xmlLocalName(child), "element1", "xml.firstElement returned didn't return the expected element");
         djstest.done();
     });
 
@@ -175,14 +175,14 @@
 
         var actual = [];
 
-        var doc = datajs.xml.xmlParse(xml);
-        var root = datajs.xml.xmlFirstChildElement(doc);
+        var doc = odatajs.xml.xmlParse(xml);
+        var root = odatajs.xml.xmlFirstChildElement(doc);
     
-        datajs.xml.xmlChildElements(root, function (child) {
+        odatajs.xml.xmlChildElements(root, function (child) {
             djstest.log("in child elements callback");
             actual.push({
-                localName: datajs.xml.xmlLocalName(child),
-                nsURI: datajs.xml.xmlNamespaceURI(child)
+                localName: odatajs.xml.xmlLocalName(child),
+                nsURI: odatajs.xml.xmlNamespaceURI(child)
             });
         });
 
@@ -206,15 +206,15 @@
 
         var actual = {};
 
-        var doc = datajs.xml.xmlParse(xml);
-        var root = datajs.xml.xmlFirstChildElement(doc);
+        var doc = odatajs.xml.xmlParse(xml);
+        var root = odatajs.xml.xmlFirstChildElement(doc);
 
-        datajs.xml.xmlAttributes(root, function (attribute) {
+        odatajs.xml.xmlAttributes(root, function (attribute) {
             djstest.log("in child elements callback");
-            var localName = datajs.xml.xmlLocalName(attribute);
+            var localName = odatajs.xml.xmlLocalName(attribute);
             actual[localName] = {
                 localName: localName, 
-                nsURI: datajs.xml.xmlNamespaceURI(attribute),
+                nsURI: odatajs.xml.xmlNamespaceURI(attribute),
                 value: attribute.value
             };
         });
@@ -240,7 +240,7 @@
 
         var i, len;
         for (i = 0, len = tests.length; i < len; i++) {
-            var result = datajs.xml.hasLeadingOrTrailingWhitespace(tests[i].t);
+            var result = odatajs.xml.hasLeadingOrTrailingWhitespace(tests[i].t);
             djstest.assertAreEqual(result, tests[i].r, "match for " + tests[i].t);
         }
 
@@ -263,8 +263,8 @@
         var i, len;
         for (i = 0, len = tests.length; i < len; i++) {
             var test = tests[i];
-            var doc = datajs.xml.xmlParse(test.t);
-            var actual = datajs.xml.xmlInnerText(doc);
+            var doc = odatajs.xml.xmlParse(test.t);
+            var actual = odatajs.xml.xmlInnerText(doc);
             djstest.assertAreEqual(actual, test.r, "test for [" + test.t + "]");
         }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/datajs/tests/store-indexeddb-tests.js
----------------------------------------------------------------------
diff --git a/datajs/tests/store-indexeddb-tests.js b/datajs/tests/store-indexeddb-tests.js
index 4a04378..47690a4 100644
--- a/datajs/tests/store-indexeddb-tests.js
+++ b/datajs/tests/store-indexeddb-tests.js
@@ -74,14 +74,14 @@
         });
 
         djstest.addTest(function testIndexedDBStoreConstructor() {
-            var store = this.store = window.datajs.store.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
             djstest.assertAreEqual(store.name, getCurrentStoreName());
             djstest.assertAreEqual(store.mechanism, "indexeddb");
             djstest.done();
         });
 
         djstest.addTest(function testIndexedDBStoreAddGet() {
-            var store = this.store = window.datajs.store.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
             store.add("key", "value", function (key, value) {
                 djstest.assertAreEqual(key, "key");
                 djstest.assertAreEqual(value, "value");
@@ -94,7 +94,7 @@
         });
 
         djstest.addTest(function testIndexedDBStoreAddUpdateGet() {
-            var store = this.store = window.datajs.store.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
             store.add("key", "value", function (key, value) {
                 store.update("key", "value2", function (key, value) {
                     djstest.assertAreEqual(key, "key");
@@ -109,7 +109,7 @@
         });
 
         djstest.addTest(function testIndexedDBStoreAddOrUpdateGet() {
-            var store = this.store = window.datajs.store.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
             store.addOrUpdate("key", "value", function (key, value) {
                 djstest.assertAreEqual(key, "key");
                 djstest.assertAreEqual(value, "value");
@@ -126,7 +126,7 @@
         });
 
         djstest.addTest(function testIndexedDBStoreAddRemoveContains() {
-            var store = this.store = window.datajs.store.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
             store.add("key", "value", function (key, value) {
                 store.contains("key", function (result) {
                     djstest.assert(result);
@@ -142,7 +142,7 @@
         });
 
         djstest.addTest(function testIndexedDBStoreAddConsecutiveGetAllKeys() {
-            var store = this.store = window.datajs.store.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
             store.add("key", "value", function (key, value) {
                 store.add("key2", "value2", function (key, value) {
                     store.add("key3", "value3", function (key, value) {
@@ -158,7 +158,7 @@
         djstest.addTest(function testIndexedDBStoreAddArrayClear() {
             var addedKeys = ["key", "key2", "key3"];
             var addedValues = ["value", "value2", "value3"];
-            var store = this.store = window.datajs.store.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
             store.add(addedKeys, addedValues, function (keys, values) {
                 djstest.assertAreEqualDeep(keys, addedKeys);
                 djstest.assertAreEqualDeep(values, addedValues);
@@ -174,7 +174,7 @@
         djstest.addTest(function testIndexedDBStoreAddArrayUpdateArrayGetArray() {
             var addedKeys = ["key", "key2", "key3"];
             var addedValues = ["value", "value2", "value3"];
-            var store = this.store = window.datajs.store.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
             store.add(addedKeys, addedValues, function (keys, values) {
                 djstest.assertAreEqualDeep(keys, addedKeys);
                 djstest.assertAreEqualDeep(values, addedValues);
@@ -195,7 +195,7 @@
         djstest.addTest(function testIndexedDBStoreAddOrUpdateArrayGetArray() {
             var expectedKeys = ["key", "key2", "key3"];
             var expectedValues = ["value", "value2", "value3"];
-            var store = this.store = window.datajs.store.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
             store.add("key2", "value", function (key, value) {
                 store.addOrUpdate(expectedKeys, expectedValues, function (keys, values) {
                     djstest.assertAreEqualDeep(keys, expectedKeys);
@@ -209,7 +209,7 @@
         });
 
         djstest.addTest(function testIndexedDBStoreAddDuplicate() {
-            var store = this.store = window.datajs.store.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
             store.add("key", "value", function (key, value) {
                 store.add("key", "value2", unexpectedSuccess, function (err) {
                     djstest.pass("Error callback called as expected");
@@ -219,7 +219,7 @@
         });
 
         djstest.addTest(function testIndexedDBStoreAddArrayDuplicate() {
-            var store = this.store = window.datajs.store.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
             store.add(["key", "key2", "key"], ["value", "value2", "value3"], unexpectedSuccess, function (err) {
                 djstest.pass("Error callback called as expected");
                 djstest.done();
@@ -227,7 +227,7 @@
         });
 
         djstest.addTest(function testIndexedDBStoreGetArrayNonExistent() {
-            var store = this.store = window.datajs.store.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
             store.add("key", "value", function (key, value) {
                 store.read(["key", "badkey"], function (keys, values) {
                     djstest.assertAreEqualDeep(keys, ["key", "badkey"]);
@@ -238,7 +238,7 @@
         });
 
         djstest.addTest(function testIndexedDBStoreUpdateNonExistent() {
-            var store = this.store = window.datajs.store.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
             store.update("badkey", "badvalue", unexpectedSuccess, function (err) {
                 djstest.pass("Error callback called as expected");
                 djstest.done();
@@ -246,7 +246,7 @@
         });
 
         djstest.addTest(function testIndexedDBStoreUpdateArrayNonExistent() {
-            var store = this.store = window.datajs.store.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.store.IndexedDBStore.create(getCurrentStoreName());
             store.add("key", "value", function (key, value) {
                 store.update(["key", "badkey"], ["value", "badvalue"], unexpectedSuccess, function (err) {
                     djstest.pass("Error callback called as expected");

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/datajs/tests/store-tests.js
----------------------------------------------------------------------
diff --git a/datajs/tests/store-tests.js b/datajs/tests/store-tests.js
index 8148ead..48169c3 100644
--- a/datajs/tests/store-tests.js
+++ b/datajs/tests/store-tests.js
@@ -88,9 +88,9 @@
     };
 
     var mechanismImplementations = {
-        indexeddb: { factory: datajs.IndexedDBStore, canCreate: canCreateIndexedDb, cleanup: cleanIndexedDbStorage },
-        dom: { factory: datajs.DomStore, canCreate: canCreateDomStore, cleanup: cleanDomStorage },
-        memory: { factory: datajs.MemoryStore, canCreate: canCreateMemoryStore, cleanup: cleanMemoryStorage }
+        indexeddb: { factory: odatajs.IndexedDBStore, canCreate: canCreateIndexedDb, cleanup: cleanIndexedDbStorage },
+        dom: { factory: odatajs.DomStore, canCreate: canCreateDomStore, cleanup: cleanDomStorage },
+        memory: { factory: odatajs.MemoryStore, canCreate: canCreateMemoryStore, cleanup: cleanMemoryStorage }
     };
 
     var oldWindowOnError;
@@ -99,7 +99,7 @@
         module("Unit", {
             mechanism: mechanism,
             createStore: function (name) {
-                var store = datajs.store.createStore(name + "_" + this.mechanism, this.mechanism);
+                var store = odatajs.store.createStore(name + "_" + this.mechanism, this.mechanism);
                 this.stores.push(store);
                 return store;
             },
@@ -662,7 +662,7 @@
         for (i = 0, len = tests.length; i < len; i++) {
             try {
                 var test = tests[i];
-                var store = datajs.store.createStore("testStore" + i, tests[i].mechanism);
+                var store = odatajs.store.createStore("testStore" + i, tests[i].mechanism);
 
                 if (!test.exception) {
                     djstest.assertAreEqual(store.mechanism, test.expected, "Created store of the expected mechanism");
@@ -693,7 +693,7 @@
             ];
 
             for (var i in tests) {
-                var store = datajs.store.createStore("best store ever " + i, tests[i]);
+                var store = odatajs.store.createStore("best store ever " + i, tests[i]);
                 djstest.assertAreEqual(store.mechanism, bestMechanism, "Mechanisms match");
             }
         } else {


[3/5] [OLINGO-407] JS- V4's window.OData is not defined yet: part 1 - change window.datajs.V4 into window.odatajs (while V3: window.datajs).

Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/datajs/tests/e2etest/chh.js
----------------------------------------------------------------------
diff --git a/datajs/tests/e2etest/chh.js b/datajs/tests/e2etest/chh.js
new file mode 100644
index 0000000..1ad5912
--- /dev/null
+++ b/datajs/tests/e2etest/chh.js
@@ -0,0 +1,8373 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+(function e(t, n, r) {
+    function s(o, u) {
+        if (!n[o]) {
+            if (!t[o]) {
+                var a = typeof require == "function" && require;
+                if (!u && a) return a(o, !0);
+                if (i) return i(o, !0);
+                throw new Error("Cannot find module '" + o + "'")
+            }
+            var f = n[o] = {
+                exports: {}
+            };
+            t[o][0].call(f.exports, function(e) {
+                var n = t[o][1][e];
+                return s(n ? n : e)
+            }, f, f.exports, e, t, n, r)
+        }
+        return n[o].exports
+    }
+    var i = typeof require == "function" && require;
+    for (var o = 0; o < r.length; o++) s(r[o]);
+    return s
+})({
+    1: [
+        function(require, module, exports) {
+
+
+            if (window.odatajs === undefined) {
+                window.odatajs = {};
+            }
+
+            window.odatajs = require('./lib/datajs.js');
+            window.odatajs.oData = require('./lib/odata.js');
+
+            window.odatajs.store = require('./lib/store.js');
+            window.odatajs.cache = require('./lib/cache.js');
+
+            /*
+            function extend(target) {
+                var sources = [].slice.call(arguments, 1);
+                sources.forEach(function (source) {
+                    for (var prop in source) {
+                        target[prop] = source[prop];
+                    }
+                });
+                return target;
+            }*/
+
+
+
+        }, {
+            "./lib/cache.js": 2,
+            "./lib/datajs.js": 4,
+            "./lib/odata.js": 8,
+            "./lib/store.js": 15
+        }
+    ],
+    2: [
+        function(require, module, exports) {
+
+
+            /** @module cache */
+
+            var utils = require('./datajs.js').utils;
+
+
+            var assigned = utils.assigned;
+            var delay = utils.delay;
+            var extend = utils.extend;
+            var djsassert = utils.djsassert;
+            var isArray = utils.isArray;
+            var normalizeURI = utils.normalizeURI;
+            var parseInt10 = utils.parseInt10;
+            var undefinedDefault = utils.undefinedDefault;
+
+            var deferred = require('./datajs/deferred.js');
+
+            var createDeferred = deferred.createDeferred;
+            var DjsDeferred = deferred.DjsDeferred;
+            var ODataCacheSource = require('./cache/source').ODataCacheSource;
+
+            var getJsonValueArraryLength = utils.getJsonValueArraryLength;
+            var sliceJsonValueArray = utils.sliceJsonValueArray;
+            var concatJsonValueArray = utils.concatJsonValueArray;
+            var storeReq = require('./datajs.js').store;
+
+
+            /** Appending a page appendPage */
+            var appendPage = function(operation, page) {
+                /// <summary>Appends a page's data to the operation data.</summary>
+                /// <param name="operation" type="Object">Operation with (i)ndex, (c)ount and (d)ata.</param>
+                /// <param name="page" type="Object">Page with (i)ndex, (c)ount and (d)ata.</param>
+
+                var intersection = intersectRanges(operation, page);
+                var start = 0;
+                var end = 0;
+                if (intersection) {
+                    start = intersection.i - page.i;
+                    end = start + (operation.c - getJsonValueArraryLength(operation.d));
+                }
+
+                operation.d = concatJsonValueArray(operation.d, sliceJsonValueArray(page.d, start, end));
+            };
+
+            var intersectRanges = function(x, y) {
+                /// <summary>Returns the {(i)ndex, (c)ount} range for the intersection of x and y.</summary>
+                /// <param name="x" type="Object">Range with (i)ndex and (c)ount members.</param>
+                /// <param name="y" type="Object">Range with (i)ndex and (c)ount members.</param>
+                /// <returns type="Object">The intersection (i)ndex and (c)ount; undefined if there is no intersection.</returns>
+
+                var xLast = x.i + x.c;
+                var yLast = y.i + y.c;
+                var resultIndex = (x.i > y.i) ? x.i : y.i;
+                var resultLast = (xLast < yLast) ? xLast : yLast;
+                var result;
+                if (resultLast >= resultIndex) {
+                    result = {
+                        i: resultIndex,
+                        c: resultLast - resultIndex
+                    };
+                }
+
+                return result;
+            };
+
+            var checkZeroGreater = function(val, name) {
+                /// <summary>Checks whether val is a defined number with value zero or greater.</summary>
+                /// <param name="val" type="Number">Value to check.</param>
+                /// <param name="name" type="String">Parameter name to use in exception.</param>
+
+                if (val === undefined || typeof val !== "number") {
+                    throw {
+                        message: "'" + name + "' must be a number."
+                    };
+                }
+
+                if (isNaN(val) || val < 0 || !isFinite(val)) {
+                    throw {
+                        message: "'" + name + "' must be greater than or equal to zero."
+                    };
+                }
+            };
+
+            var checkUndefinedGreaterThanZero = function(val, name) {
+                /// <summary>Checks whether val is undefined or a number with value greater than zero.</summary>
+                /// <param name="val" type="Number">Value to check.</param>
+                /// <param name="name" type="String">Parameter name to use in exception.</param>
+
+                if (val !== undefined) {
+                    if (typeof val !== "number") {
+                        throw {
+                            message: "'" + name + "' must be a number."
+                        };
+                    }
+
+                    if (isNaN(val) || val <= 0 || !isFinite(val)) {
+                        throw {
+                            message: "'" + name + "' must be greater than zero."
+                        };
+                    }
+                }
+            };
+
+            var checkUndefinedOrNumber = function(val, name) {
+                /// <summary>Checks whether val is undefined or a number</summary>
+                /// <param name="val" type="Number">Value to check.</param>
+                /// <param name="name" type="String">Parameter name to use in exception.</param>
+                if (val !== undefined && (typeof val !== "number" || isNaN(val) || !isFinite(val))) {
+                    throw {
+                        message: "'" + name + "' must be a number."
+                    };
+                }
+            };
+
+            var removeFromArray = function(arr, item) {
+                /// <summary>Performs a linear search on the specified array and removes the first instance of 'item'.</summary>
+                /// <param name="arr" type="Array">Array to search.</param>
+                /// <param name="item">Item being sought.</param>
+                /// <returns type="Boolean">Whether the item was removed.</returns>
+
+                var i, len;
+                for (i = 0, len = arr.length; i < len; i++) {
+                    if (arr[i] === item) {
+                        arr.splice(i, 1);
+                        return true;
+                    }
+                }
+
+                return false;
+            };
+
+            var estimateSize = function(obj) {
+                /// <summary>Estimates the size of an object in bytes.</summary>
+                /// <param name="obj" type="Object">Object to determine the size of.</param>
+                /// <returns type="Integer">Estimated size of the object in bytes.</returns>
+                var size = 0;
+                var type = typeof obj;
+
+                if (type === "object" && obj) {
+                    for (var name in obj) {
+                        size += name.length * 2 + estimateSize(obj[name]);
+                    }
+                } else if (type === "string") {
+                    size = obj.length * 2;
+                } else {
+                    size = 8;
+                }
+                return size;
+            };
+
+            var snapToPageBoundaries = function(lowIndex, highIndex, pageSize) {
+                /// <summary>Snaps low and high indices into page sizes and returns a range.</summary>
+                /// <param name="lowIndex" type="Number">Low index to snap to a lower value.</param>
+                /// <param name="highIndex" type="Number">High index to snap to a higher value.</param>
+                /// <param name="pageSize" type="Number">Page size to snap to.</param>
+                /// <returns type="Object">A range with (i)ndex and (c)ount of elements.</returns>
+
+                lowIndex = Math.floor(lowIndex / pageSize) * pageSize;
+                highIndex = Math.ceil((highIndex + 1) / pageSize) * pageSize;
+                return {
+                    i: lowIndex,
+                    c: highIndex - lowIndex
+                };
+            };
+
+            // The DataCache is implemented using state machines.  The following constants are used to properly
+            // identify and label the states that these machines transition to.
+
+            // DataCache state constants
+
+            var CACHE_STATE_DESTROY = "destroy";
+            var CACHE_STATE_IDLE = "idle";
+            var CACHE_STATE_INIT = "init";
+            var CACHE_STATE_READ = "read";
+            var CACHE_STATE_PREFETCH = "prefetch";
+            var CACHE_STATE_WRITE = "write";
+
+            // DataCacheOperation state machine states.
+            // Transitions on operations also depend on the cache current of the cache.
+
+            var OPERATION_STATE_CANCEL = "cancel";
+            var OPERATION_STATE_END = "end";
+            var OPERATION_STATE_ERROR = "error";
+            var OPERATION_STATE_START = "start";
+            var OPERATION_STATE_WAIT = "wait";
+
+            // Destroy state machine states
+
+            var DESTROY_STATE_CLEAR = "clear";
+
+            // Read / Prefetch state machine states
+
+            var READ_STATE_DONE = "done";
+            var READ_STATE_LOCAL = "local";
+            var READ_STATE_SAVE = "save";
+            var READ_STATE_SOURCE = "source";
+
+            var DataCacheOperation = function(stateMachine, promise, isCancelable, index, count, data, pending) {
+                /// <summary>Creates a new operation object.</summary>
+                /// <param name="stateMachine" type="Function">State machine that describes the specific behavior of the operation.</param>
+                /// <param name="promise" type ="DjsDeferred">Promise for requested values.</param>
+                /// <param name="isCancelable" type ="Boolean">Whether this operation can be canceled or not.</param>
+                /// <param name="index" type="Number">Index of first item requested.</param>
+                /// <param name="count" type="Number">Count of items requested.</param>
+                /// <param name="data" type="Array">Array with the items requested by the operation.</param>
+                /// <param name="pending" type="Number">Total number of pending prefetch records.</param>
+                /// <returns type="DataCacheOperation">A new data cache operation instance.</returns>
+
+                /// <field name="p" type="DjsDeferred">Promise for requested values.</field>
+                /// <field name="i" type="Number">Index of first item requested.</field>
+                /// <field name="c" type="Number">Count of items requested.</field>
+                /// <field name="d" type="Array">Array with the items requested by the operation.</field>
+                /// <field name="s" type="Array">Current state of the operation.</field>
+                /// <field name="canceled" type="Boolean">Whether the operation has been canceled.</field>
+                /// <field name="pending" type="Number">Total number of pending prefetch records.</field>
+                /// <field name="oncomplete" type="Function">Callback executed when the operation reaches the end state.</field>
+
+                var stateData;
+                var cacheState;
+                var that = this;
+
+                that.p = promise;
+                that.i = index;
+                that.c = count;
+                that.d = data;
+                that.s = OPERATION_STATE_START;
+
+                that.canceled = false;
+                that.pending = pending;
+                that.oncomplete = null;
+
+                that.cancel = function() {
+                    /// <summary>Transitions this operation to the cancel state and sets the canceled flag to true.</summary>
+                    /// <remarks>The function is a no-op if the operation is non-cancelable.</summary>
+
+                    if (!isCancelable) {
+                        return;
+                    }
+
+                    var state = that.s;
+                    if (state !== OPERATION_STATE_ERROR && state !== OPERATION_STATE_END && state !== OPERATION_STATE_CANCEL) {
+                        that.canceled = true;
+                        transition(OPERATION_STATE_CANCEL, stateData);
+                    }
+                };
+
+                that.complete = function() {
+                    /// <summary>Transitions this operation to the end state.</summary>
+
+                    djsassert(that.s !== OPERATION_STATE_END, "DataCacheOperation.complete() - operation is in the end state", that);
+                    transition(OPERATION_STATE_END, stateData);
+                };
+
+                that.error = function(err) {
+                    /// <summary>Transitions this operation to the error state.</summary>
+                    if (!that.canceled) {
+                        djsassert(that.s !== OPERATION_STATE_END, "DataCacheOperation.error() - operation is in the end state", that);
+                        djsassert(that.s !== OPERATION_STATE_ERROR, "DataCacheOperation.error() - operation is in the error state", that);
+                        transition(OPERATION_STATE_ERROR, err);
+                    }
+                };
+
+                that.run = function(state) {
+                    /// <summary>Executes the operation's current state in the context of a new cache state.</summary>
+                    /// <param name="state" type="Object">New cache state.</param>
+
+                    cacheState = state;
+                    that.transition(that.s, stateData);
+                };
+
+                that.wait = function(data) {
+                    /// <summary>Transitions this operation to the wait state.</summary>
+
+                    djsassert(that.s !== OPERATION_STATE_END, "DataCacheOperation.wait() - operation is in the end state", that);
+                    transition(OPERATION_STATE_WAIT, data);
+                };
+
+                var operationStateMachine = function(opTargetState, cacheState, data) {
+                    /// <summary>State machine that describes all operations common behavior.</summary>
+                    /// <param name="opTargetState" type="Object">Operation state to transition to.</param>
+                    /// <param name="cacheState" type="Object">Current cache state.</param>
+                    /// <param name="data" type="Object" optional="true">Additional data passed to the state.</param>
+
+                    switch (opTargetState) {
+                        case OPERATION_STATE_START:
+                            // Initial state of the operation. The operation will remain in this state until the cache has been fully initialized.
+                            if (cacheState !== CACHE_STATE_INIT) {
+                                stateMachine(that, opTargetState, cacheState, data);
+                            }
+                            break;
+
+                        case OPERATION_STATE_WAIT:
+                            // Wait state indicating that the operation is active but waiting for an asynchronous operation to complete.
+                            stateMachine(that, opTargetState, cacheState, data);
+                            break;
+
+                        case OPERATION_STATE_CANCEL:
+                            // Cancel state.
+                            stateMachine(that, opTargetState, cacheState, data);
+                            that.fireCanceled();
+                            transition(OPERATION_STATE_END);
+                            break;
+
+                        case OPERATION_STATE_ERROR:
+                            // Error state. Data is expected to be an object detailing the error condition.
+                            stateMachine(that, opTargetState, cacheState, data);
+                            that.canceled = true;
+                            that.fireRejected(data);
+                            transition(OPERATION_STATE_END);
+                            break;
+
+                        case OPERATION_STATE_END:
+                            // Final state of the operation.
+                            if (that.oncomplete) {
+                                that.oncomplete(that);
+                            }
+                            if (!that.canceled) {
+                                that.fireResolved();
+                            }
+                            stateMachine(that, opTargetState, cacheState, data);
+                            break;
+
+                        default:
+                            // Any other state is passed down to the state machine describing the operation's specific behavior.
+                            // DATAJS INTERNAL START 
+                            if (true) {
+                                // Check that the state machine actually handled the sate.
+                                var handled = stateMachine(that, opTargetState, cacheState, data);
+                                djsassert(handled, "Bad operation state: " + opTargetState + " cacheState: " + cacheState, this);
+                            } else {
+                                // DATAJS INTERNAL END 
+                                stateMachine(that, opTargetState, cacheState, data);
+                                // DATAJS INTERNAL START
+                            }
+                            // DATAJS INTERNAL END
+                            break;
+                    }
+                };
+
+                var transition = function(state, data) {
+                    /// <summary>Transitions this operation to a new state.</summary>
+                    /// <param name="state" type="Object">State to transition the operation to.</param>
+                    /// <param name="data" type="Object" optional="true">Additional data passed to the state.</param>
+
+                    that.s = state;
+                    stateData = data;
+                    operationStateMachine(state, cacheState, data);
+                };
+
+                that.transition = transition;
+
+                return that;
+            };
+
+            DataCacheOperation.prototype.fireResolved = function() {
+                /// <summary>Fires a resolved notification as necessary.</summary>
+
+                // Fire the resolve just once.
+                var p = this.p;
+                if (p) {
+                    this.p = null;
+                    p.resolve(this.d);
+                }
+            };
+
+            DataCacheOperation.prototype.fireRejected = function(reason) {
+                /// <summary>Fires a rejected notification as necessary.</summary>
+
+                // Fire the rejection just once.
+                var p = this.p;
+                if (p) {
+                    this.p = null;
+                    p.reject(reason);
+                }
+            };
+
+            DataCacheOperation.prototype.fireCanceled = function() {
+                /// <summary>Fires a canceled notification as necessary.</summary>
+
+                this.fireRejected({
+                    canceled: true,
+                    message: "Operation canceled"
+                });
+            };
+
+
+            var DataCache = function(options) {
+                /// <summary>Creates a data cache for a collection that is efficiently loaded on-demand.</summary>
+                /// <param name="options">
+                /// Options for the data cache, including name, source, pageSize,
+                /// prefetchSize, cacheSize, storage mechanism, and initial prefetch and local-data handler.
+                /// </param>
+                /// <returns type="DataCache">A new data cache instance.</returns>
+
+                var state = CACHE_STATE_INIT;
+                var stats = {
+                    counts: 0,
+                    netReads: 0,
+                    prefetches: 0,
+                    cacheReads: 0
+                };
+
+                var clearOperations = [];
+                var readOperations = [];
+                var prefetchOperations = [];
+
+                var actualCacheSize = 0; // Actual cache size in bytes.
+                var allDataLocal = false; // Whether all data is local.
+                var cacheSize = undefinedDefault(options.cacheSize, 1048576); // Requested cache size in bytes, default 1 MB.
+                var collectionCount = 0; // Number of elements in the server collection.
+                var highestSavedPage = 0; // Highest index of all the saved pages.
+                var highestSavedPageSize = 0; // Item count of the saved page with the highest index.
+                var overflowed = cacheSize === 0; // If the cache has overflowed (actualCacheSize > cacheSize or cacheSize == 0);
+                var pageSize = undefinedDefault(options.pageSize, 50); // Number of elements to store per page.
+                var prefetchSize = undefinedDefault(options.prefetchSize, pageSize); // Number of elements to prefetch from the source when the cache is idling.
+                var version = "1.0";
+                var cacheFailure;
+
+                var pendingOperations = 0;
+
+                var source = options.source;
+                if (typeof source === "string") {
+                    // Create a new cache source.
+                    source = new ODataCacheSource(options);
+                }
+                source.options = options;
+
+                // Create a cache local store.
+                var store = storeReq.createStore(options.name, options.mechanism);
+
+                var that = this;
+
+                that.onidle = options.idle;
+                that.stats = stats;
+
+                that.count = function() {
+                    /// <summary>Counts the number of items in the collection.</summary>
+                    /// <returns type="Object">A promise with the number of items.</returns>
+
+                    if (cacheFailure) {
+                        throw cacheFailure;
+                    }
+
+                    var deferred = createDeferred();
+                    var canceled = false;
+
+                    if (allDataLocal) {
+                        delay(function() {
+                            deferred.resolve(collectionCount);
+                        });
+
+                        return deferred.promise();
+                    }
+
+                    // TODO: Consider returning the local data count instead once allDataLocal flag is set to true.
+                    var request = source.count(function(count) {
+                        request = null;
+                        stats.counts++;
+                        deferred.resolve(count);
+                    }, function(err) {
+                        request = null;
+                        deferred.reject(extend(err, {
+                            canceled: canceled
+                        }));
+                    });
+
+                    return extend(deferred.promise(), {
+                        cancel: function() {
+                            /// <summary>Aborts the count operation.</summary>
+                            if (request) {
+                                canceled = true;
+                                request.abort();
+                                request = null;
+                            }
+                        }
+                    });
+                };
+
+                that.clear = function() {
+                    /// <summary>Cancels all running operations and clears all local data associated with this cache.</summary>
+                    /// <remarks>
+                    /// New read requests made while a clear operation is in progress will not be canceled.
+                    /// Instead they will be queued for execution once the operation is completed.
+                    /// </remarks>
+                    /// <returns type="Object">A promise that has no value and can't be canceled.</returns>
+
+                    if (cacheFailure) {
+                        throw cacheFailure;
+                    }
+
+                    if (clearOperations.length === 0) {
+                        var deferred = createDeferred();
+                        var op = new DataCacheOperation(destroyStateMachine, deferred, false);
+                        queueAndStart(op, clearOperations);
+                        return deferred.promise();
+                    }
+                    return clearOperations[0].p;
+                };
+
+                that.filterForward = function(index, count, predicate) {
+                    /// <summary>Filters the cache data based a predicate.</summary>
+                    /// <param name="index" type="Number">The index of the item to start filtering forward from.</param>
+                    /// <param name="count" type="Number">Maximum number of items to include in the result.</param>
+                    /// <param name="predicate" type="Function">Callback function returning a boolean that determines whether an item should be included in the result or not.</param>
+                    /// <remarks>
+                    /// Specifying a negative count value will yield all the items in the cache that satisfy the predicate.
+                    /// </remarks>
+                    /// <returns type="DjsDeferred">A promise for an array of results.</returns>
+                    return filter(index, count, predicate, false);
+                };
+
+                that.filterBack = function(index, count, predicate) {
+                    /// <summary>Filters the cache data based a predicate.</summary>
+                    /// <param name="index" type="Number">The index of the item to start filtering backward from.</param>
+                    /// <param name="count" type="Number">Maximum number of items to include in the result.</param>
+                    /// <param name="predicate" type="Function">Callback function returning a boolean that determines whether an item should be included in the result or not.</param>
+                    /// <remarks>
+                    /// Specifying a negative count value will yield all the items in the cache that satisfy the predicate.
+                    /// </remarks>
+                    /// <returns type="DjsDeferred">A promise for an array of results.</returns>
+                    return filter(index, count, predicate, true);
+                };
+
+                that.readRange = function(index, count) {
+                    /// <summary>Reads a range of adjacent records.</summary>
+                    /// <param name="index" type="Number">Zero-based index of record range to read.</param>
+                    /// <param name="count" type="Number">Number of records in the range.</param>
+                    /// <remarks>
+                    /// New read requests made while a clear operation is in progress will not be canceled.
+                    /// Instead they will be queued for execution once the operation is completed.
+                    /// </remarks>
+                    /// <returns type="DjsDeferred">
+                    /// A promise for an array of records; less records may be returned if the
+                    /// end of the collection is found.
+                    /// </returns>
+
+                    checkZeroGreater(index, "index");
+                    checkZeroGreater(count, "count");
+
+                    if (cacheFailure) {
+                        throw cacheFailure;
+                    }
+
+                    var deferred = createDeferred();
+
+                    // Merging read operations would be a nice optimization here.
+                    var op = new DataCacheOperation(readStateMachine, deferred, true, index, count, {}, 0);
+                    queueAndStart(op, readOperations);
+
+                    return extend(deferred.promise(), {
+                        cancel: function() {
+                            /// <summary>Aborts the readRange operation.</summary>
+                            op.cancel();
+                        }
+                    });
+                };
+
+                that.ToObservable = that.toObservable = function() {
+                    /// <summary>Creates an Observable object that enumerates all the cache contents.</summary>
+                    /// <returns>A new Observable object that enumerates all the cache contents.</returns>
+                    if (!window.Rx || !window.Rx.Observable) {
+                        throw {
+                            message: "Rx library not available - include rx.js"
+                        };
+                    }
+
+                    if (cacheFailure) {
+                        throw cacheFailure;
+                    }
+
+                    return window.Rx.Observable.CreateWithDisposable(function(obs) {
+                        var disposed = false;
+                        var index = 0;
+
+                        var errorCallback = function(error) {
+                            if (!disposed) {
+                                obs.OnError(error);
+                            }
+                        };
+
+                        var successCallback = function(data) {
+                            if (!disposed) {
+                                var i, len;
+                                for (i = 0, len = data.value.length; i < len; i++) {
+                                    // The wrapper automatically checks for Dispose
+                                    // on the observer, so we don't need to check it here.
+                                    obs.OnNext(data.value[i]);
+                                }
+
+                                if (data.value.length < pageSize) {
+                                    obs.OnCompleted();
+                                } else {
+                                    index += pageSize;
+                                    that.readRange(index, pageSize).then(successCallback, errorCallback);
+                                }
+                            }
+                        };
+
+                        that.readRange(index, pageSize).then(successCallback, errorCallback);
+
+                        return {
+                            Dispose: function() {
+                                disposed = true;
+                            }
+                        };
+                    });
+                };
+
+                var cacheFailureCallback = function(message) {
+                    /// <summary>Creates a function that handles a callback by setting the cache into failure mode.</summary>
+                    /// <param name="message" type="String">Message text.</param>
+                    /// <returns type="Function">Function to use as error callback.</returns>
+                    /// <remarks>
+                    /// This function will specifically handle problems with critical store resources
+                    /// during cache initialization.
+                    /// </remarks>
+
+                    return function(error) {
+                        cacheFailure = {
+                            message: message,
+                            error: error
+                        };
+
+                        // Destroy any pending clear or read operations.
+                        // At this point there should be no prefetch operations.
+                        // Count operations will go through but are benign because they
+                        // won't interact with the store.
+                        djsassert(prefetchOperations.length === 0, "prefetchOperations.length === 0");
+                        var i, len;
+                        for (i = 0, len = readOperations.length; i < len; i++) {
+                            readOperations[i].fireRejected(cacheFailure);
+                        }
+                        for (i = 0, len = clearOperations.length; i < len; i++) {
+                            clearOperations[i].fireRejected(cacheFailure);
+                        }
+
+                        // Null out the operation arrays.
+                        readOperations = clearOperations = null;
+                    };
+                };
+
+                var changeState = function(newState) {
+                    /// <summary>Updates the cache's state and signals all pending operations of the change.</summary>
+                    /// <param name="newState" type="Object">New cache state.</param>
+                    /// <remarks>This method is a no-op if the cache's current state and the new state are the same.</remarks>
+
+                    if (newState !== state) {
+                        state = newState;
+                        var operations = clearOperations.concat(readOperations, prefetchOperations);
+                        var i, len;
+                        for (i = 0, len = operations.length; i < len; i++) {
+                            operations[i].run(state);
+                        }
+                    }
+                };
+
+                var clearStore = function() {
+                    /// <summary>Removes all the data stored in the cache.</summary>
+                    /// <returns type="DjsDeferred">A promise with no value.</returns>
+                    djsassert(state === CACHE_STATE_DESTROY || state === CACHE_STATE_INIT, "DataCache.clearStore() - cache is not on the destroy or initialize state, current sate = " + state);
+
+                    var deferred = new DjsDeferred();
+                    store.clear(function() {
+
+                        // Reset the cache settings.
+                        actualCacheSize = 0;
+                        allDataLocal = false;
+                        collectionCount = 0;
+                        highestSavedPage = 0;
+                        highestSavedPageSize = 0;
+                        overflowed = cacheSize === 0;
+
+                        // version is not reset, in case there is other state in eg V1.1 that is still around.
+
+                        // Reset the cache stats.
+                        stats = {
+                            counts: 0,
+                            netReads: 0,
+                            prefetches: 0,
+                            cacheReads: 0
+                        };
+                        that.stats = stats;
+
+                        store.close();
+                        deferred.resolve();
+                    }, function(err) {
+                        deferred.reject(err);
+                    });
+                    return deferred;
+                };
+
+                var dequeueOperation = function(operation) {
+                    /// <summary>Removes an operation from the caches queues and changes the cache state to idle.</summary>
+                    /// <param name="operation" type="DataCacheOperation">Operation to dequeue.</param>
+                    /// <remarks>This method is used as a handler for the operation's oncomplete event.</remarks>
+
+                    var removed = removeFromArray(clearOperations, operation);
+                    if (!removed) {
+                        removed = removeFromArray(readOperations, operation);
+                        if (!removed) {
+                            removeFromArray(prefetchOperations, operation);
+                        }
+                    }
+
+                    pendingOperations--;
+                    changeState(CACHE_STATE_IDLE);
+                };
+
+                var fetchPage = function(start) {
+                    /// <summary>Requests data from the cache source.</summary>
+                    /// <param name="start" type="Number">Zero-based index of items to request.</param>
+                    /// <returns type="DjsDeferred">A promise for a page object with (i)ndex, (c)ount, (d)ata.</returns>
+
+                    djsassert(state !== CACHE_STATE_DESTROY, "DataCache.fetchPage() - cache is on the destroy state");
+                    djsassert(state !== CACHE_STATE_IDLE, "DataCache.fetchPage() - cache is on the idle state");
+
+                    var deferred = new DjsDeferred();
+                    var canceled = false;
+
+                    var request = source.read(start, pageSize, function(data) {
+                        var length = getJsonValueArraryLength(data);
+                        var page = {
+                            i: start,
+                            c: length,
+                            d: data
+                        };
+                        deferred.resolve(page);
+                    }, function(err) {
+                        deferred.reject(err);
+                    });
+
+                    return extend(deferred, {
+                        cancel: function() {
+                            if (request) {
+                                request.abort();
+                                canceled = true;
+                                request = null;
+                            }
+                        }
+                    });
+                };
+
+                var filter = function(index, count, predicate, backwards) {
+                    /// <summary>Filters the cache data based a predicate.</summary>
+                    /// <param name="index" type="Number">The index of the item to start filtering from.</param>
+                    /// <param name="count" type="Number">Maximum number of items to include in the result.</param>
+                    /// <param name="predicate" type="Function">Callback function returning a boolean that determines whether an item should be included in the result or not.</param>
+                    /// <param name="backwards" type="Boolean">True if the filtering should move backward from the specified index, falsey otherwise.</param>
+                    /// <remarks>
+                    /// Specifying a negative count value will yield all the items in the cache that satisfy the predicate.
+                    /// </remarks>
+                    /// <returns type="DjsDeferred">A promise for an array of results.</returns>
+                    index = parseInt10(index);
+                    count = parseInt10(count);
+
+                    if (isNaN(index)) {
+                        throw {
+                            message: "'index' must be a valid number.",
+                            index: index
+                        };
+                    }
+                    if (isNaN(count)) {
+                        throw {
+                            message: "'count' must be a valid number.",
+                            count: count
+                        };
+                    }
+
+                    if (cacheFailure) {
+                        throw cacheFailure;
+                    }
+
+                    index = Math.max(index, 0);
+
+                    var deferred = createDeferred();
+                    var returnData = {};
+                    returnData.value = [];
+                    var canceled = false;
+                    var pendingReadRange = null;
+
+                    var readMore = function(readIndex, readCount) {
+                        if (!canceled) {
+                            if (count > 0 && returnData.value.length >= count) {
+                                deferred.resolve(returnData);
+                            } else {
+                                pendingReadRange = that.readRange(readIndex, readCount).then(function(data) {
+                                    if (data["@odata.context"] && !returnData["@odata.context"]) {
+                                        returnData["@odata.context"] = data["@odata.context"];
+                                    }
+
+                                    for (var i = 0, length = data.value.length; i < length && (count < 0 || returnData.value.length < count); i++) {
+                                        var dataIndex = backwards ? length - i - 1 : i;
+                                        var item = data.value[dataIndex];
+                                        if (predicate(item)) {
+                                            var element = {
+                                                index: readIndex + dataIndex,
+                                                item: item
+                                            };
+
+                                            backwards ? returnData.value.unshift(element) : returnData.value.push(element);
+                                        }
+                                    }
+
+                                    // Have we reached the end of the collection?
+                                    if ((!backwards && data.value.length < readCount) || (backwards && readIndex <= 0)) {
+                                        deferred.resolve(returnData);
+                                    } else {
+                                        var nextIndex = backwards ? Math.max(readIndex - pageSize, 0) : readIndex + readCount;
+                                        readMore(nextIndex, pageSize);
+                                    }
+                                }, function(err) {
+                                    deferred.reject(err);
+                                });
+                            }
+                        }
+                    };
+
+                    // Initially, we read from the given starting index to the next/previous page boundary
+                    var initialPage = snapToPageBoundaries(index, index, pageSize);
+                    var initialIndex = backwards ? initialPage.i : index;
+                    var initialCount = backwards ? index - initialPage.i + 1 : initialPage.i + initialPage.c - index;
+                    readMore(initialIndex, initialCount);
+
+                    return extend(deferred.promise(), {
+                        cancel: function() {
+                            /// <summary>Aborts the filter operation</summary>
+                            if (pendingReadRange) {
+                                pendingReadRange.cancel();
+                            }
+                            canceled = true;
+                        }
+                    });
+                };
+
+                var fireOnIdle = function() {
+                    /// <summary>Fires an onidle event if any functions are assigned.</summary>
+
+                    if (that.onidle && pendingOperations === 0) {
+                        that.onidle();
+                    }
+                };
+
+                var prefetch = function(start) {
+                    /// <summary>Creates and starts a new prefetch operation.</summary>
+                    /// <param name="start" type="Number">Zero-based index of the items to prefetch.</param>
+                    /// <remarks>
+                    /// This method is a no-op if any of the following conditions is true:
+                    ///     1.- prefetchSize is 0
+                    ///     2.- All data has been read and stored locally in the cache.
+                    ///     3.- There is already an all data prefetch operation queued.
+                    ///     4.- The cache has run out of available space (overflowed).
+                    /// <remarks>
+
+                    if (allDataLocal || prefetchSize === 0 || overflowed) {
+                        return;
+                    }
+
+                    djsassert(state === CACHE_STATE_READ, "DataCache.prefetch() - cache is not on the read state, current state: " + state);
+
+                    if (prefetchOperations.length === 0 || (prefetchOperations[0] && prefetchOperations[0].c !== -1)) {
+                        // Merging prefetch operations would be a nice optimization here.
+                        var op = new DataCacheOperation(prefetchStateMachine, null, true, start, prefetchSize, null, prefetchSize);
+                        queueAndStart(op, prefetchOperations);
+                    }
+                };
+
+                var queueAndStart = function(op, queue) {
+                    /// <summary>Queues an operation and runs it.</summary>
+                    /// <param name="op" type="DataCacheOperation">Operation to queue.</param>
+                    /// <param name="queue" type="Array">Array that will store the operation.</param>
+
+                    op.oncomplete = dequeueOperation;
+                    queue.push(op);
+                    pendingOperations++;
+                    op.run(state);
+                };
+
+                var readPage = function(key) {
+                    /// <summary>Requests a page from the cache local store.</summary>
+                    /// <param name="key" type="Number">Zero-based index of the reuqested page.</param>
+                    /// <returns type="DjsDeferred">A promise for a found flag and page object with (i)ndex, (c)ount, (d)ata, and (t)icks.</returns>
+
+                    djsassert(state !== CACHE_STATE_DESTROY, "DataCache.readPage() - cache is on the destroy state");
+
+                    var canceled = false;
+                    var deferred = extend(new DjsDeferred(), {
+                        cancel: function() {
+                            /// <summary>Aborts the readPage operation.</summary>
+                            canceled = true;
+                        }
+                    });
+
+                    var error = storeFailureCallback(deferred, "Read page from store failure");
+
+                    store.contains(key, function(contained) {
+                        if (canceled) {
+                            return;
+                        }
+                        if (contained) {
+                            store.read(key, function(_, data) {
+                                if (!canceled) {
+                                    deferred.resolve(data !== undefined, data);
+                                }
+                            }, error);
+                            return;
+                        }
+                        deferred.resolve(false);
+                    }, error);
+                    return deferred;
+                };
+
+                var savePage = function(key, page) {
+                    /// <summary>Saves a page to the cache local store.</summary>
+                    /// <param name="key" type="Number">Zero-based index of the requested page.</param>
+                    /// <param name="page" type="Object">Object with (i)ndex, (c)ount, (d)ata, and (t)icks.</param>
+                    /// <returns type="DjsDeferred">A promise with no value.</returns>
+
+                    djsassert(state !== CACHE_STATE_DESTROY, "DataCache.savePage() - cache is on the destroy state");
+                    djsassert(state !== CACHE_STATE_IDLE, "DataCache.savePage() - cache is on the idle state");
+
+                    var canceled = false;
+
+                    var deferred = extend(new DjsDeferred(), {
+                        cancel: function() {
+                            /// <summary>Aborts the readPage operation.</summary>
+                            canceled = true;
+                        }
+                    });
+
+                    var error = storeFailureCallback(deferred, "Save page to store failure");
+
+                    var resolve = function() {
+                        deferred.resolve(true);
+                    };
+
+                    if (page.c > 0) {
+                        var pageBytes = estimateSize(page);
+                        overflowed = cacheSize >= 0 && cacheSize < actualCacheSize + pageBytes;
+
+                        if (!overflowed) {
+                            store.addOrUpdate(key, page, function() {
+                                updateSettings(page, pageBytes);
+                                saveSettings(resolve, error);
+                            }, error);
+                        } else {
+                            resolve();
+                        }
+                    } else {
+                        updateSettings(page, 0);
+                        saveSettings(resolve, error);
+                    }
+                    return deferred;
+                };
+
+                var saveSettings = function(success, error) {
+                    /// <summary>Saves the cache's current settings to the local store.</summary>
+                    /// <param name="success" type="Function">Success callback.</param>
+                    /// <param name="error" type="Function">Errror callback.</param>
+
+                    var settings = {
+                        actualCacheSize: actualCacheSize,
+                        allDataLocal: allDataLocal,
+                        cacheSize: cacheSize,
+                        collectionCount: collectionCount,
+                        highestSavedPage: highestSavedPage,
+                        highestSavedPageSize: highestSavedPageSize,
+                        pageSize: pageSize,
+                        sourceId: source.identifier,
+                        version: version
+                    };
+
+                    store.addOrUpdate("__settings", settings, success, error);
+                };
+
+                var storeFailureCallback = function(deferred /*, message*/ ) {
+                    /// <summary>Creates a function that handles a store error.</summary>
+                    /// <param name="deferred" type="DjsDeferred">Deferred object to resolve.</param>
+                    /// <param name="message" type="String">Message text.</param>
+                    /// <returns type="Function">Function to use as error callback.</returns>
+                    /// <remarks>
+                    /// This function will specifically handle problems when interacting with the store.
+                    /// </remarks>
+
+                    return function( /*error*/ ) {
+                        // var console = window.console;
+                        // if (console && console.log) {
+                        //    console.log(message);
+                        //    console.dir(error);
+                        // }
+                        deferred.resolve(false);
+                    };
+                };
+
+                var updateSettings = function(page, pageBytes) {
+                    /// <summary>Updates the cache's settings based on a page object.</summary>
+                    /// <param name="page" type="Object">Object with (i)ndex, (c)ount, (d)ata.</param>
+                    /// <param name="pageBytes" type="Number">Size of the page in bytes.</param>
+
+                    var pageCount = page.c;
+                    var pageIndex = page.i;
+
+                    // Detect the collection size.
+                    if (pageCount === 0) {
+                        if (highestSavedPage === pageIndex - pageSize) {
+                            collectionCount = highestSavedPage + highestSavedPageSize;
+                        }
+                    } else {
+                        highestSavedPage = Math.max(highestSavedPage, pageIndex);
+                        if (highestSavedPage === pageIndex) {
+                            highestSavedPageSize = pageCount;
+                        }
+                        actualCacheSize += pageBytes;
+                        if (pageCount < pageSize && !collectionCount) {
+                            collectionCount = pageIndex + pageCount;
+                        }
+                    }
+
+                    // Detect the end of the collection.
+                    if (!allDataLocal && collectionCount === highestSavedPage + highestSavedPageSize) {
+                        allDataLocal = true;
+                    }
+                };
+
+                var cancelStateMachine = function(operation, opTargetState, cacheState, data) {
+                    /// <summary>State machine describing the behavior for cancelling a read or prefetch operation.</summary>
+                    /// <param name="operation" type="DataCacheOperation">Operation being run.</param>
+                    /// <param name="opTargetState" type="Object">Operation state to transition to.</param>
+                    /// <param name="cacheState" type="Object">Current cache state.</param>
+                    /// <param name="data" type="Object" optional="true">Additional data passed to the state.</param>
+                    /// <remarks>
+                    /// This state machine contains behavior common to read and prefetch operations.
+                    /// </remarks>
+
+                    var canceled = operation.canceled && opTargetState !== OPERATION_STATE_END;
+                    if (canceled) {
+                        if (opTargetState === OPERATION_STATE_CANCEL) {
+                            // Cancel state.
+                            // Data is expected to be any pending request made to the cache.
+                            if (data && data.cancel) {
+                                data.cancel();
+                            }
+                        }
+                    }
+                    return canceled;
+                };
+
+                var destroyStateMachine = function(operation, opTargetState, cacheState) {
+                    /// <summary>State machine describing the behavior of a clear operation.</summary>
+                    /// <param name="operation" type="DataCacheOperation">Operation being run.</param>
+                    /// <param name="opTargetState" type="Object">Operation state to transition to.</param>
+                    /// <param name="cacheState" type="Object">Current cache state.</param>
+                    /// <remarks>
+                    /// Clear operations have the highest priority and can't be interrupted by other operations; however,
+                    /// they will preempt any other operation currently executing.
+                    /// </remarks>
+
+                    var transition = operation.transition;
+
+                    // Signal the cache that a clear operation is running.
+                    if (cacheState !== CACHE_STATE_DESTROY) {
+                        changeState(CACHE_STATE_DESTROY);
+                        return true;
+                    }
+
+                    switch (opTargetState) {
+                        case OPERATION_STATE_START:
+                            // Initial state of the operation.
+                            transition(DESTROY_STATE_CLEAR);
+                            break;
+
+                        case OPERATION_STATE_END:
+                            // State that signals the operation is done.
+                            fireOnIdle();
+                            break;
+
+                        case DESTROY_STATE_CLEAR:
+                            // State that clears all the local data of the cache.
+                            clearStore().then(function() {
+                                // Terminate the operation once the local store has been cleared.
+                                operation.complete();
+                            });
+                            // Wait until the clear request completes.
+                            operation.wait();
+                            break;
+
+                        default:
+                            return false;
+                    }
+                    return true;
+                };
+
+                var prefetchStateMachine = function(operation, opTargetState, cacheState, data) {
+                    /// <summary>State machine describing the behavior of a prefetch operation.</summary>
+                    /// <param name="operation" type="DataCacheOperation">Operation being run.</param>
+                    /// <param name="opTargetState" type="Object">Operation state to transition to.</param>
+                    /// <param name="cacheState" type="Object">Current cache state.</param>
+                    /// <param name="data" type="Object" optional="true">Additional data passed to the state.</param>
+                    /// <remarks>
+                    /// Prefetch operations have the lowest priority and will be interrupted by operations of
+                    /// other kinds. A preempted prefetch operation will resume its execution only when the state
+                    /// of the cache returns to idle.
+                    ///
+                    /// If a clear operation starts executing then all the prefetch operations are canceled,
+                    /// even if they haven't started executing yet.
+                    /// </remarks>
+
+                    // Handle cancelation
+                    if (!cancelStateMachine(operation, opTargetState, cacheState, data)) {
+
+                        var transition = operation.transition;
+
+                        // Handle preemption
+                        if (cacheState !== CACHE_STATE_PREFETCH) {
+                            if (cacheState === CACHE_STATE_DESTROY) {
+                                if (opTargetState !== OPERATION_STATE_CANCEL) {
+                                    operation.cancel();
+                                }
+                            } else if (cacheState === CACHE_STATE_IDLE) {
+                                // Signal the cache that a prefetch operation is running.
+                                changeState(CACHE_STATE_PREFETCH);
+                            }
+                            return true;
+                        }
+
+                        switch (opTargetState) {
+                            case OPERATION_STATE_START:
+                                // Initial state of the operation.
+                                if (prefetchOperations[0] === operation) {
+                                    transition(READ_STATE_LOCAL, operation.i);
+                                }
+                                break;
+
+                            case READ_STATE_DONE:
+                                // State that determines if the operation can be resolved or has to
+                                // continue processing.
+                                // Data is expected to be the read page.
+                                var pending = operation.pending;
+
+                                if (pending > 0) {
+                                    pending -= Math.min(pending, data.c);
+                                }
+
+                                // Are we done, or has all the data been stored?
+                                if (allDataLocal || pending === 0 || data.c < pageSize || overflowed) {
+                                    operation.complete();
+                                } else {
+                                    // Continue processing the operation.
+                                    operation.pending = pending;
+                                    transition(READ_STATE_LOCAL, data.i + pageSize);
+                                }
+                                break;
+
+                            default:
+                                return readSaveStateMachine(operation, opTargetState, cacheState, data, true);
+                        }
+                    }
+                    return true;
+                };
+
+                var readStateMachine = function(operation, opTargetState, cacheState, data) {
+                    /// <summary>State machine describing the behavior of a read operation.</summary>
+                    /// <param name="operation" type="DataCacheOperation">Operation being run.</param>
+                    /// <param name="opTargetState" type="Object">Operation state to transition to.</param>
+                    /// <param name="cacheState" type="Object">Current cache state.</param>
+                    /// <param name="data" type="Object" optional="true">Additional data passed to the state.</param>
+                    /// <remarks>
+                    /// Read operations have a higher priority than prefetch operations, but lower than
+                    /// clear operations. They will preempt any prefetch operation currently running
+                    /// but will be interrupted by a clear operation.
+                    ///
+                    /// If a clear operation starts executing then all the currently running
+                    /// read operations are canceled. Read operations that haven't started yet will
+                    /// wait in the start state until the destory operation finishes.
+                    /// </remarks>
+
+                    // Handle cancelation
+                    if (!cancelStateMachine(operation, opTargetState, cacheState, data)) {
+
+                        var transition = operation.transition;
+
+                        // Handle preemption
+                        if (cacheState !== CACHE_STATE_READ && opTargetState !== OPERATION_STATE_START) {
+                            if (cacheState === CACHE_STATE_DESTROY) {
+                                if (opTargetState !== OPERATION_STATE_START) {
+                                    operation.cancel();
+                                }
+                            } else if (cacheState !== CACHE_STATE_WRITE) {
+                                // Signal the cache that a read operation is running.
+                                djsassert(state == CACHE_STATE_IDLE || state === CACHE_STATE_PREFETCH, "DataCache.readStateMachine() - cache is not on the read or idle state.");
+                                changeState(CACHE_STATE_READ);
+                            }
+
+                            return true;
+                        }
+
+                        switch (opTargetState) {
+                            case OPERATION_STATE_START:
+                                // Initial state of the operation.
+                                // Wait until the cache is idle or prefetching.
+                                if (cacheState === CACHE_STATE_IDLE || cacheState === CACHE_STATE_PREFETCH) {
+                                    // Signal the cache that a read operation is running.
+                                    changeState(CACHE_STATE_READ);
+                                    if (operation.c >= 0) {
+                                        // Snap the requested range to a page boundary.
+                                        var range = snapToPageBoundaries(operation.i, operation.c, pageSize);
+                                        transition(READ_STATE_LOCAL, range.i);
+                                    } else {
+                                        transition(READ_STATE_DONE, operation);
+                                    }
+                                }
+                                break;
+
+                            case READ_STATE_DONE:
+                                // State that determines if the operation can be resolved or has to
+                                // continue processing.
+                                // Data is expected to be the read page.
+                                appendPage(operation, data);
+                                var len = getJsonValueArraryLength(operation.d);
+                                // Are we done?
+                                if (operation.c === len || data.c < pageSize) {
+                                    // Update the stats, request for a prefetch operation.
+                                    stats.cacheReads++;
+                                    prefetch(data.i + data.c);
+                                    // Terminate the operation.
+                                    operation.complete();
+                                } else {
+                                    // Continue processing the operation.
+                                    transition(READ_STATE_LOCAL, data.i + pageSize);
+                                }
+                                break;
+
+                            default:
+                                return readSaveStateMachine(operation, opTargetState, cacheState, data, false);
+                        }
+                    }
+
+                    return true;
+                };
+
+                var readSaveStateMachine = function(operation, opTargetState, cacheState, data, isPrefetch) {
+                    /// <summary>State machine describing the behavior for reading and saving data into the cache.</summary>
+                    /// <param name="operation" type="DataCacheOperation">Operation being run.</param>
+                    /// <param name="opTargetState" type="Object">Operation state to transition to.</param>
+                    /// <param name="cacheState" type="Object">Current cache state.</param>
+                    /// <param name="data" type="Object" optional="true">Additional data passed to the state.</param>
+                    /// <param name="isPrefetch" type="Boolean">Flag indicating whether a read (false) or prefetch (true) operation is running.
+                    /// <remarks>
+                    /// This state machine contains behavior common to read and prefetch operations.
+                    /// </remarks>
+
+                    var error = operation.error;
+                    var transition = operation.transition;
+                    var wait = operation.wait;
+                    var request;
+
+                    switch (opTargetState) {
+                        case OPERATION_STATE_END:
+                            // State that signals the operation is done.
+                            fireOnIdle();
+                            break;
+
+                        case READ_STATE_LOCAL:
+                            // State that requests for a page from the local store.
+                            // Data is expected to be the index of the page to request.
+                            request = readPage(data).then(function(found, page) {
+                                // Signal the cache that a read operation is running.
+                                if (!operation.canceled) {
+                                    if (found) {
+                                        // The page is in the local store, check if the operation can be resolved.
+                                        transition(READ_STATE_DONE, page);
+                                    } else {
+                                        // The page is not in the local store, request it from the source.
+                                        transition(READ_STATE_SOURCE, data);
+                                    }
+                                }
+                            });
+                            break;
+
+                        case READ_STATE_SOURCE:
+                            // State that requests for a page from the cache source.
+                            // Data is expected to be the index of the page to request.
+                            request = fetchPage(data).then(function(page) {
+                                // Signal the cache that a read operation is running.
+                                if (!operation.canceled) {
+                                    // Update the stats and save the page to the local store.
+                                    if (isPrefetch) {
+                                        stats.prefetches++;
+                                    } else {
+                                        stats.netReads++;
+                                    }
+                                    transition(READ_STATE_SAVE, page);
+                                }
+                            }, error);
+                            break;
+
+                        case READ_STATE_SAVE:
+                            // State that saves a  page to the local store.
+                            // Data is expected to be the page to save.
+                            // Write access to the store is exclusive.
+                            if (cacheState !== CACHE_STATE_WRITE) {
+                                changeState(CACHE_STATE_WRITE);
+                                request = savePage(data.i, data).then(function(saved) {
+                                    if (!operation.canceled) {
+                                        if (!saved && isPrefetch) {
+                                            operation.pending = 0;
+                                        }
+                                        // Check if the operation can be resolved.
+                                        transition(READ_STATE_DONE, data);
+                                    }
+                                    changeState(CACHE_STATE_IDLE);
+                                });
+                            }
+                            break;
+
+                        default:
+                            // Unknown state that can't be handled by this state machine.
+                            return false;
+                    }
+
+                    if (request) {
+                        // The operation might have been canceled between stack frames do to the async calls.
+                        if (operation.canceled) {
+                            request.cancel();
+                        } else if (operation.s === opTargetState) {
+                            // Wait for the request to complete.
+                            wait(request);
+                        }
+                    }
+
+                    return true;
+                };
+
+                // Initialize the cache.
+                store.read("__settings", function(_, settings) {
+                    if (assigned(settings)) {
+                        var settingsVersion = settings.version;
+                        if (!settingsVersion || settingsVersion.indexOf("1.") !== 0) {
+                            cacheFailureCallback("Unsupported cache store version " + settingsVersion)();
+                            return;
+                        }
+
+                        if (pageSize !== settings.pageSize || source.identifier !== settings.sourceId) {
+                            // The shape or the source of the data was changed so invalidate the store.
+                            clearStore().then(function() {
+                                // Signal the cache is fully initialized.
+                                changeState(CACHE_STATE_IDLE);
+                            }, cacheFailureCallback("Unable to clear store during initialization"));
+                        } else {
+                            // Restore the saved settings.
+                            actualCacheSize = settings.actualCacheSize;
+                            allDataLocal = settings.allDataLocal;
+                            cacheSize = settings.cacheSize;
+                            collectionCount = settings.collectionCount;
+                            highestSavedPage = settings.highestSavedPage;
+                            highestSavedPageSize = settings.highestSavedPageSize;
+                            version = settingsVersion;
+
+                            // Signal the cache is fully initialized.
+                            changeState(CACHE_STATE_IDLE);
+                        }
+                    } else {
+                        // This is a brand new cache.
+                        saveSettings(function() {
+                            // Signal the cache is fully initialized.
+                            changeState(CACHE_STATE_IDLE);
+                        }, cacheFailureCallback("Unable to write settings during initialization."));
+                    }
+                }, cacheFailureCallback("Unable to read settings from store."));
+
+                return that;
+            };
+
+            exports.createDataCache = function(options) {
+                /// <summary>Creates a data cache for a collection that is efficiently loaded on-demand.</summary>
+                /// <param name="options">
+                /// Options for the data cache, including name, source, pageSize,
+                /// prefetchSize, cacheSize, storage mechanism, and initial prefetch and local-data handler.
+                /// </param>
+                /// <returns type="DataCache">A new data cache instance.</returns>
+                checkUndefinedGreaterThanZero(options.pageSize, "pageSize");
+                checkUndefinedOrNumber(options.cacheSize, "cacheSize");
+                checkUndefinedOrNumber(options.prefetchSize, "prefetchSize");
+
+                if (!assigned(options.name)) {
+                    throw {
+                        message: "Undefined or null name",
+                        options: options
+                    };
+                }
+
+                if (!assigned(options.source)) {
+                    throw {
+                        message: "Undefined source",
+                        options: options
+                    };
+                }
+
+                return new DataCache(options);
+            };
+
+            exports.estimateSize = estimateSize;
+
+
+        }, {
+            "./cache/source": 3,
+            "./datajs.js": 4,
+            "./datajs/deferred.js": 5
+        }
+    ],
+    3: [
+        function(require, module, exports) {
+            /*
+             * Licensed to the Apache Software Foundation (ASF) under one
+             * or more contributor license agreements.  See the NOTICE file
+             * distributed with this work for additional information
+             * regarding copyright ownership.  The ASF licenses this file
+             * to you under the Apache License, Version 2.0 (the
+             * "License"); you may not use this file except in compliance
+             * with the License.  You may obtain a copy of the License at
+             *
+             *   http://www.apache.org/licenses/LICENSE-2.0
+             *
+             * Unless required by applicable law or agreed to in writing,
+             * software distributed under the License is distributed on an
+             * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+             * KIND, either express or implied.  See the License for the
+             * specific language governing permissions and limitations
+             * under the License.
+             */
+
+            var utils = require("./../datajs.js").utils;
+            var odataRequest = require("./../odata.js");
+
+            var parseInt10 = utils.parseInt10;
+            var normalizeURICase = utils.normalizeURICase;
+
+            var appendQueryOption = function(uri, queryOption) {
+                /// <summary>Appends the specified escaped query option to the specified URI.</summary>
+                /// <param name="uri" type="String">URI to append option to.</param>
+                /// <param name="queryOption" type="String">Escaped query option to append.</param>
+                var separator = (uri.indexOf("?") >= 0) ? "&" : "?";
+                return uri + separator + queryOption;
+            };
+
+            var appendSegment = function(uri, segment) {
+                /// <summary>Appends the specified segment to the given URI.</summary>
+                /// <param name="uri" type="String">URI to append a segment to.</param>
+                /// <param name="segment" type="String">Segment to append.</param>
+                /// <returns type="String">The original URI with a new segment appended.</returns>
+
+                var index = uri.indexOf("?");
+                var queryPortion = "";
+                if (index >= 0) {
+                    queryPortion = uri.substr(index);
+                    uri = uri.substr(0, index);
+                }
+
+                if (uri[uri.length - 1] !== "/") {
+                    uri += "/";
+                }
+                return uri + segment + queryPortion;
+            };
+
+            var buildODataRequest = function(uri, options) {
+                /// <summary>Builds a request object to GET the specified URI.</summary>
+                /// <param name="uri" type="String">URI for request.</param>
+                /// <param name="options" type="Object">Additional options.</param>
+
+                return {
+                    method: "GET",
+                    requestUri: uri,
+                    user: options.user,
+                    password: options.password,
+                    enableJsonpCallback: options.enableJsonpCallback,
+                    callbackParameterName: options.callbackParameterName,
+                    formatQueryString: options.formatQueryString
+                };
+            };
+
+            var findQueryOptionStart = function(uri, name) {
+                /// <summary>Finds the index where the value of a query option starts.</summary>
+                /// <param name="uri" type="String">URI to search in.</param>
+                /// <param name="name" type="String">Name to look for.</param>
+                /// <returns type="Number">The index where the query option starts.</returns>
+
+                var result = -1;
+                var queryIndex = uri.indexOf("?");
+                if (queryIndex !== -1) {
+                    var start = uri.indexOf("?" + name + "=", queryIndex);
+                    if (start === -1) {
+                        start = uri.indexOf("&" + name + "=", queryIndex);
+                    }
+                    if (start !== -1) {
+                        result = start + name.length + 2;
+                    }
+                }
+                return result;
+            };
+
+            var queryForData = function(uri, options, success, error) {
+                /// <summary>Gets data from an OData service.</summary>
+                /// <param name="uri" type="String">URI to the OData service.</param>
+                /// <param name="options" type="Object">Object with additional well-known request options.</param>
+                /// <param name="success" type="Function">Success callback.</param>
+                /// <param name="error" type="Function">Error callback.</param>
+                /// <returns type="Object">Object with an abort method.</returns>
+
+                var request = queryForDataInternal(uri, options, {}, success, error);
+                return request;
+            };
+
+            var queryForDataInternal = function(uri, options, data, success, error) {
+                /// <summary>Gets data from an OData service taking into consideration server side paging.</summary>
+                /// <param name="uri" type="String">URI to the OData service.</param>
+                /// <param name="options" type="Object">Object with additional well-known request options.</param>
+                /// <param name="data" type="Array">Array that stores the data provided by the OData service.</param>
+                /// <param name="success" type="Function">Success callback.</param>
+                /// <param name="error" type="Function">Error callback.</param>
+                /// <returns type="Object">Object with an abort method.</returns>
+
+                var request = buildODataRequest(uri, options);
+                var currentRequest = odataRequest.request(request, function(newData) {
+                    var nextLink = newData["@odata.nextLink"];
+                    if (nextLink) {
+                        var index = uri.indexOf(".svc/", 0);
+                        if (index != -1) {
+                            nextLink = uri.substring(0, index + 5) + nextLink;
+                        }
+                    }
+
+                    if (data.value && newData.value) {
+                        data.value = data.value.concat(newData.value);
+                    } else {
+                        for (var property in newData) {
+                            if (property != "@odata.nextLink") {
+                                data[property] = newData[property];
+                            }
+                        }
+                    }
+
+                    if (nextLink) {
+                        currentRequest = queryForDataInternal(nextLink, options, data, success, error);
+                    } else {
+                        success(data);
+                    }
+                }, error, undefined, options.httpClient, options.metadata);
+
+                return {
+                    abort: function() {
+                        currentRequest.abort();
+                    }
+                };
+            };
+
+            var ODataCacheSource = function(options) {
+                /// <summary>Creates a data cache source object for requesting data from an OData service.</summary>
+                /// <param name="options">Options for the cache data source.</param>
+                /// <returns type="ODataCacheSource">A new data cache source instance.</returns>
+
+                var that = this;
+                var uri = options.source;
+
+                that.identifier = normalizeURICase(encodeURI(decodeURI(uri)));
+                that.options = options;
+
+                that.count = function(success, error) {
+                    /// <summary>Gets the number of items in the collection.</summary>
+                    /// <param name="success" type="Function">Success callback with the item count.</param>
+                    /// <param name="error" type="Function">Error callback.</param>
+                    /// <returns type="Object">Request object with an abort method./<param>
+
+                    var options = that.options;
+                    return odataRequest.request(
+                        buildODataRequest(appendSegment(uri, "$count"), options),
+                        function(data) {
+                            var count = parseInt10(data.toString());
+                            if (isNaN(count)) {
+                                error({
+                                    message: "Count is NaN",
+                                    count: count
+                                });
+                            } else {
+                                success(count);
+                            }
+                        }, error, undefined, options.httpClient, options.metadata);
+                };
+
+                that.read = function(index, count, success, error) {
+                    /// <summary>Gets a number of consecutive items from the collection.</summary>
+                    /// <param name="index" type="Number">Zero-based index of the items to retrieve.</param>
+                    /// <param name="count" type="Number">Number of items to retrieve.</param>
+                    /// <param name="success" type="Function">Success callback with the requested items.</param>
+                    /// <param name="error" type="Function">Error callback.</param>
+                    /// <returns type="Object">Request object with an abort method./<param>
+
+                    var queryOptions = "$skip=" + index + "&$top=" + count;
+                    return queryForData(appendQueryOption(uri, queryOptions), that.options, success, error);
+                };
+
+                return that;
+            };
+
+            exports.ODataCacheSource = ODataCacheSource;
+
+        }, {
+            "./../datajs.js": 4,
+            "./../odata.js": 8
+        }
+    ],
+    4: [
+        function(require, module, exports) {
+
+
+
+            //expose all external usable functions via self.apiFunc = function
+            exports.version = {
+                major: 1,
+                minor: 1,
+                build: 1
+            };
+
+
+            exports.deferred = require('./datajs/deferred.js');
+            exports.utils = require('./datajs/utils.js');
+            exports.xml = require('./datajs/xml.js');
+
+
+        }, {
+            "./datajs/deferred.js": 5,
+            "./datajs/utils.js": 6,
+            "./datajs/xml.js": 7
+        }
+    ],
+    5: [
+        function(require, module, exports) {
+            /*
+             * Licensed to the Apache Software Foundation (ASF) under one
+             * or more contributor license agreements.  See the NOTICE file
+             * distributed with this work for additional information
+             * regarding copyright ownership.  The ASF licenses this file
+             * to you under the Apache License, Version 2.0 (the
+             * "License"); you may not use this file except in compliance
+             * with the License.  You may obtain a copy of the License at
+             *
+             *   http://www.apache.org/licenses/LICENSE-2.0
+             *
+             * Unless required by applicable law or agreed to in writing,
+             * software distributed under the License is distributed on an
+             * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+             * KIND, either express or implied.  See the License for the
+             * specific language governing permissions and limitations
+             * under the License.
+             */
+
+            var forwardCall = function(thisValue, name, returnValue) {
+                /// <summary>Creates a new function to forward a call.</summary>
+                /// <param name="thisValue" type="Object">Value to use as the 'this' object.</param>
+                /// <param name="name" type="String">Name of function to forward to.</param>
+                /// <param name="returnValue" type="Object">Return value for the forward call (helps keep identity when chaining calls).</param>
+                /// <returns type="Function">A new function that will forward a call.</returns>
+
+                return function() {
+                    thisValue[name].apply(thisValue, arguments);
+                    return returnValue;
+                };
+            };
+
+            var DjsDeferred = function() {
+                /// <summary>Initializes a new DjsDeferred object.</summary>
+                /// <remarks>
+                /// Compability Note A - Ordering of callbacks through chained 'then' invocations
+                ///
+                /// The Wiki entry at http://wiki.commonjs.org/wiki/Promises/A
+                /// implies that .then() returns a distinct object.
+                ////
+                /// For compatibility with http://api.jquery.com/category/deferred-object/
+                /// we return this same object. This affects ordering, as
+                /// the jQuery version will fire callbacks in registration
+                /// order regardless of whether they occur on the result
+                /// or the original object.
+                ///
+                /// Compability Note B - Fulfillment value
+                ///
+                /// The Wiki entry at http://wiki.commonjs.org/wiki/Promises/A
+                /// implies that the result of a success callback is the
+                /// fu

<TRUNCATED>

[5/5] git commit: [OLINGO-407] JS- V4's window.OData is not defined yet: part 1 - change window.datajs.V4 into window.odatajs (while V3: window.datajs).

Posted by ch...@apache.org.
[OLINGO-407] JS- V4's window.OData is not defined yet: part 1 - change window.datajs.V4 into window.odatajs  (while V3: window.datajs).


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/commit/5c98f9f3
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/tree/5c98f9f3
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/diff/5c98f9f3

Branch: refs/heads/master
Commit: 5c98f9f3ec260eac81f5beb05f34c5c2eca3d988
Parents: dd24c1f
Author: challenh <ch...@microsoft.com>
Authored: Wed Aug 20 15:51:43 2014 +0800
Committer: challenh <ch...@microsoft.com>
Committed: Wed Aug 20 15:51:43 2014 +0800

----------------------------------------------------------------------
 JSLib/src/cache-source.js                       |     8 +-
 JSLib/src/cache.js                              |    40 +-
 JSLib/src/datajs.js                             |     8 +-
 JSLib/src/deferred.js                           |     4 +-
 JSLib/src/odata-atom.js                         |    74 +-
 JSLib/src/odata-batch.js                        |     8 +-
 JSLib/src/odata-gml.js                          |    28 +-
 JSLib/src/odata-handler.js                      |     8 +-
 JSLib/src/odata-json-light.js                   |    22 +-
 JSLib/src/odata-json.js                         |    14 +-
 JSLib/src/odata-metadata.js                     |    24 +-
 JSLib/src/odata-net.js                          |     6 +-
 JSLib/src/odata-utils.js                        |    16 +-
 JSLib/src/odata-xml.js                          |    56 +-
 JSLib/src/odata.js                              |     8 +-
 JSLib/src/store-dom.js                          |     8 +-
 JSLib/src/store-indexeddb.js                    |     8 +-
 JSLib/src/store-memory.js                       |     8 +-
 JSLib/src/store.js                              |    16 +-
 JSLib/src/utils.js                              |    50 +-
 JSLib/src/xml.js                                |    82 +-
 JSLib/tests/cache-tests.js                      |    76 +-
 ...s-cache-large-collection-functional-tests.js |     4 +-
 JSLib/tests/odata-atom-tests.js                 |    62 +-
 .../odata-cache-filter-functional-tests.js      |    12 +-
 JSLib/tests/odata-cache-fperf-tests.js          |     2 +-
 JSLib/tests/odata-cache-functional-tests.js     |     2 +-
 JSLib/tests/odata-cache-rx-functional-tests.js  |     2 +-
 JSLib/tests/odata-json-tests.js                 |    12 +-
 JSLib/tests/odata-metadata-tests.js             |     6 +-
 .../odata-read-crossdomain-functional-tests.js  |     2 +-
 JSLib/tests/odata-xml-tests.js                  |    70 +-
 JSLib/tests/store-indexeddb-tests.js            |    28 +-
 JSLib/tests/store-tests.js                      |    12 +-
 datajs/demo/scripts/datajs_demo.js              |     6 +-
 datajs/src/index.js                             |    12 +-
 datajs/src/lib/cache.js                         |     6 +-
 datajs/tests/cache-tests.js                     |    76 +-
 datajs/tests/common/common.js                   |    10 +-
 ...s-cache-large-collection-functional-tests.js |     4 +-
 datajs/tests/e2etest/chh.js                     |  8373 +++++++++++++
 datajs/tests/e2etest/datajs-1.1.2.js            | 10577 +++++++++++++++++
 .../odata-cache-filter-functional-tests.js      |    12 +-
 datajs/tests/odata-cache-fperf-tests.js         |     2 +-
 datajs/tests/odata-cache-functional-tests.js    |     2 +-
 datajs/tests/odata-cache-rx-functional-tests.js |     2 +-
 datajs/tests/odata-json-tests.js                |    12 +-
 datajs/tests/odata-metadata-tests.js            |     6 +-
 .../odata-read-crossdomain-functional-tests.js  |     2 +-
 datajs/tests/odata-xml-tests.js                 |    70 +-
 datajs/tests/store-indexeddb-tests.js           |    28 +-
 datajs/tests/store-tests.js                     |    12 +-
 52 files changed, 19474 insertions(+), 524 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/cache-source.js
----------------------------------------------------------------------
diff --git a/JSLib/src/cache-source.js b/JSLib/src/cache-source.js
index 6348a92..da55d1f 100644
--- a/JSLib/src/cache-source.js
+++ b/JSLib/src/cache-source.js
@@ -17,10 +17,10 @@
 
 (function (window, undefined) {
 
-    var datajs = window.datajs || {};
+    var datajs = window.odatajs || {};
     var odata = window.OData || {};
-    var parseInt10 = datajs.parseInt10;
-    var normalizeURICase = datajs.normalizeURICase;
+    var parseInt10 = odatajs.parseInt10;
+    var normalizeURICase = odatajs.normalizeURICase;
 
     // CONTENT START
 
@@ -190,7 +190,7 @@
     };
 
     // DATAJS INTERNAL START
-    window.datajs.ODataCacheSource = ODataCacheSource;
+    window.odatajs.ODataCacheSource = ODataCacheSource;
     // DATAJS INTERNAL END
 
     // CONTENT END

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/cache.js
----------------------------------------------------------------------
diff --git a/JSLib/src/cache.js b/JSLib/src/cache.js
index 2092af4..b3669a9 100644
--- a/JSLib/src/cache.js
+++ b/JSLib/src/cache.js
@@ -17,23 +17,23 @@
 
 (function (window, undefined) {
 
-    var datajs = window.datajs || {};
-
-    var assigned = datajs.assigned;
-    var delay = datajs.delay;
-    var extend = datajs.extend;
-    var djsassert = datajs.djsassert;
-    var isArray = datajs.isArray;
-    var normalizeURI = datajs.normalizeURI;
-    var parseInt10 = datajs.parseInt10;
-    var undefinedDefault = datajs.undefinedDefault;
-
-    var createDeferred = datajs.createDeferred;
-    var DjsDeferred = datajs.DjsDeferred;
-    var ODataCacheSource = datajs.ODataCacheSource;
-    var getJsonValueArraryLength = datajs.getJsonValueArraryLength;
-    var sliceJsonValueArray = datajs.sliceJsonValueArray;
-    var concatJsonValueArray = datajs.concatJsonValueArray;
+    var datajs = window.odatajs || {};
+
+    var assigned = odatajs.assigned;
+    var delay = odatajs.delay;
+    var extend = odatajs.extend;
+    var djsassert = odatajs.djsassert;
+    var isArray = odatajs.isArray;
+    var normalizeURI = odatajs.normalizeURI;
+    var parseInt10 = odatajs.parseInt10;
+    var undefinedDefault = odatajs.undefinedDefault;
+
+    var createDeferred = odatajs.createDeferred;
+    var DjsDeferred = odatajs.DjsDeferred;
+    var ODataCacheSource = odatajs.ODataCacheSource;
+    var getJsonValueArraryLength = odatajs.getJsonValueArraryLength;
+    var sliceJsonValueArray = odatajs.sliceJsonValueArray;
+    var concatJsonValueArray = odatajs.concatJsonValueArray;
 
     // CONTENT START
 
@@ -413,7 +413,7 @@
         source.options = options;
 
         // Create a cache local store.
-        var store = datajs.createStore(options.name, options.mechanism);
+        var store = odatajs.createStore(options.name, options.mechanism);
 
         var that = this;
 
@@ -1331,7 +1331,7 @@
         return that;
     };
 
-    datajs.createDataCache = function (options) {
+    odatajs.createDataCache = function (options) {
         /// <summary>Creates a data cache for a collection that is efficiently loaded on-demand.</summary>
         /// <param name="options">
         /// Options for the data cache, including name, source, pageSize,
@@ -1354,7 +1354,7 @@
     };
 
     // DATAJS INTERNAL START
-    window.datajs.estimateSize = estimateSize;
+    window.odatajs.estimateSize = estimateSize;
     // DATAJS INTERNAL END
 
     // CONTENT END

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/datajs.js
----------------------------------------------------------------------
diff --git a/JSLib/src/datajs.js b/JSLib/src/datajs.js
index fc5bb62..f5251be 100644
--- a/JSLib/src/datajs.js
+++ b/JSLib/src/datajs.js
@@ -11,11 +11,11 @@
 // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-// datajs.js
+// odatajs.js
 
 (function (window, undefined) {
 
-    var datajs = window.datajs || {};
+    var datajs = window.odatajs || {};
     var odata = window.OData || {};
 
     // AMD support
@@ -23,11 +23,11 @@
         define('datajs', datajs);
         define('OData', odata);
     } else {
-        window.datajs = datajs;
+        window.odatajs = datajs;
         window.OData = odata;
     }
 
-    datajs.version = {
+    odatajs.version = {
         major: 1,
         minor: 1,
         build: 1

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/deferred.js
----------------------------------------------------------------------
diff --git a/JSLib/src/deferred.js b/JSLib/src/deferred.js
index 7f6f6a8..1fe1657 100644
--- a/JSLib/src/deferred.js
+++ b/JSLib/src/deferred.js
@@ -171,8 +171,8 @@
     };
 
     // DATAJS INTERNAL START
-    window.datajs.createDeferred = createDeferred;
-    window.datajs.DjsDeferred = DjsDeferred;
+    window.odatajs.createDeferred = createDeferred;
+    window.odatajs.DjsDeferred = DjsDeferred;
     // DATAJS INTERNAL END
 
     // CONTENT END

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/odata-atom.js
----------------------------------------------------------------------
diff --git a/JSLib/src/odata-atom.js b/JSLib/src/odata-atom.js
index e360e3c..09e994f 100644
--- a/JSLib/src/odata-atom.js
+++ b/JSLib/src/odata-atom.js
@@ -19,46 +19,46 @@
 
 (function (window, undefined) {
 
-    var datajs = window.datajs || {};
+    var datajs = window.odatajs || {};
     var odata = window.OData || {};
 
     // imports
-    var contains = datajs.contains;
-    var djsassert = datajs.djsassert;
-    var isArray = datajs.isArray;
-    var isObject = datajs.isObject;
-    var isXmlNSDeclaration = datajs.isXmlNSDeclaration;
-    var normalizeURI = datajs.normalizeURI;
-    var parseInt10 = datajs.parseInt10;
-    var xmlAppendChild = datajs.xmlAppendChild;
-    var xmlAppendChildren = datajs.xmlAppendChildren
-    var xmlAttributes = datajs.xmlAttributes;
-    var xmlAttributeNode = datajs.xmlAttributeNode;
-    var xmlAttributeValue = datajs.xmlAttributeValue;
-    var xmlBaseURI = datajs.xmlBaseURI;
-    var xmlChildElements = datajs.xmlChildElements;
-    var xmlDom = datajs.xmlDom;
-    var xmlFirstChildElement = datajs.xmlFirstChildElement;
-    var xmlFindElementByPath = datajs.xmlFindElementByPath;
-    var xmlFindNodeByPath = datajs.xmlFindNodeByPath;
-    var xmlInnerText = datajs.xmlInnerText;
-    var xmlLocalName = datajs.xmlLocalName;
-    var xmlNamespaceURI = datajs.xmlNamespaceURI;
-    var xmlNewAttribute = datajs.xmlNewAttribute;
-    var xmlNewElement = datajs.xmlNewElement;
-    var xmlNewFragment = datajs.xmlNewFragment;
-    var xmlNewNodeByPath = datajs.xmlNewNodeByPath;
-    var xmlNewNSDeclaration = datajs.xmlNewNSDeclaration;
-    var xmlNewText = datajs.xmlNewText;
-    var xmlNodeValue = datajs.xmlNodeValue;
-    var xmlNS = datajs.xmlNS;
-    var xmlnsNS = datajs.xmlnsNS;
-    var xmlQualifiedName = datajs.xmlQualifiedName;
-    var xmlParse = datajs.xmlParse;
-    var xmlSerialize = datajs.xmlSerialize;
-    var xmlSerializeDescendants = datajs.xmlSerializeDescendants;
-    var xmlSibling = datajs.xmlSibling;
-    var w3org = datajs.w3org;
+    var contains = odatajs.contains;
+    var djsassert = odatajs.djsassert;
+    var isArray = odatajs.isArray;
+    var isObject = odatajs.isObject;
+    var isXmlNSDeclaration = odatajs.isXmlNSDeclaration;
+    var normalizeURI = odatajs.normalizeURI;
+    var parseInt10 = odatajs.parseInt10;
+    var xmlAppendChild = odatajs.xmlAppendChild;
+    var xmlAppendChildren = odatajs.xmlAppendChildren
+    var xmlAttributes = odatajs.xmlAttributes;
+    var xmlAttributeNode = odatajs.xmlAttributeNode;
+    var xmlAttributeValue = odatajs.xmlAttributeValue;
+    var xmlBaseURI = odatajs.xmlBaseURI;
+    var xmlChildElements = odatajs.xmlChildElements;
+    var xmlDom = odatajs.xmlDom;
+    var xmlFirstChildElement = odatajs.xmlFirstChildElement;
+    var xmlFindElementByPath = odatajs.xmlFindElementByPath;
+    var xmlFindNodeByPath = odatajs.xmlFindNodeByPath;
+    var xmlInnerText = odatajs.xmlInnerText;
+    var xmlLocalName = odatajs.xmlLocalName;
+    var xmlNamespaceURI = odatajs.xmlNamespaceURI;
+    var xmlNewAttribute = odatajs.xmlNewAttribute;
+    var xmlNewElement = odatajs.xmlNewElement;
+    var xmlNewFragment = odatajs.xmlNewFragment;
+    var xmlNewNodeByPath = odatajs.xmlNewNodeByPath;
+    var xmlNewNSDeclaration = odatajs.xmlNewNSDeclaration;
+    var xmlNewText = odatajs.xmlNewText;
+    var xmlNodeValue = odatajs.xmlNodeValue;
+    var xmlNS = odatajs.xmlNS;
+    var xmlnsNS = odatajs.xmlnsNS;
+    var xmlQualifiedName = odatajs.xmlQualifiedName;
+    var xmlParse = odatajs.xmlParse;
+    var xmlSerialize = odatajs.xmlSerialize;
+    var xmlSerializeDescendants = odatajs.xmlSerializeDescendants;
+    var xmlSibling = odatajs.xmlSibling;
+    var w3org = odatajs.w3org;
 
     var adoDs = odata.adoDs;
     var contentType = odata.contentType;

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/odata-batch.js
----------------------------------------------------------------------
diff --git a/JSLib/src/odata-batch.js b/JSLib/src/odata-batch.js
index 770d875..dccac1b 100644
--- a/JSLib/src/odata-batch.js
+++ b/JSLib/src/odata-batch.js
@@ -17,14 +17,14 @@
 
 (function (window, undefined) {
 
-    var datajs = window.datajs || {};
+    var datajs = window.odatajs || {};
     var odata = window.OData || {};
 
     // Imports
 
-    var extend = datajs.extend;
-    var isArray = datajs.isArray;
-    var trimString = datajs.trimString;
+    var extend = odatajs.extend;
+    var isArray = odatajs.isArray;
+    var trimString = odatajs.trimString;
 
     var contentType = odata.contentType;
     var handler = odata.handler;

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/odata-gml.js
----------------------------------------------------------------------
diff --git a/JSLib/src/odata-gml.js b/JSLib/src/odata-gml.js
index 2bcf5f5..3ddf432 100644
--- a/JSLib/src/odata-gml.js
+++ b/JSLib/src/odata-gml.js
@@ -15,24 +15,24 @@
 
 (function (window, undefined) {
 
-    var datajs = window.datajs || {};
+    var datajs = window.odatajs || {};
     var odata = window.OData || {};
 
     // Imports.
 
-    var contains = datajs.contains;
-    var djsassert = datajs.djsassert;
-    var http = datajs.http;
-    var isArray = datajs.isArray;
-    var xmlAppendChild = datajs.xmlAppendChild;
-    var xmlAttributeValue = datajs.xmlAttributeValue;
-    var xmlChildElements = datajs.xmlChildElements;
-    var xmlFirstChildElement = datajs.xmlFirstChildElement;
-    var xmlInnerText = datajs.xmlInnerText;
-    var xmlLocalName = datajs.xmlLocalName;
-    var xmlNamespaceURI = datajs.xmlNamespaceURI;
-    var xmlNewElement = datajs.xmlNewElement;
-    var xmlQualifiedName = datajs.xmlQualifiedName;
+    var contains = odatajs.contains;
+    var djsassert = odatajs.djsassert;
+    var http = odatajs.http;
+    var isArray = odatajs.isArray;
+    var xmlAppendChild = odatajs.xmlAppendChild;
+    var xmlAttributeValue = odatajs.xmlAttributeValue;
+    var xmlChildElements = odatajs.xmlChildElements;
+    var xmlFirstChildElement = odatajs.xmlFirstChildElement;
+    var xmlInnerText = odatajs.xmlInnerText;
+    var xmlLocalName = odatajs.xmlLocalName;
+    var xmlNamespaceURI = odatajs.xmlNamespaceURI;
+    var xmlNewElement = odatajs.xmlNewElement;
+    var xmlQualifiedName = odatajs.xmlQualifiedName;
     var GEOJSON_POINT = odata.GEOJSON_POINT;
     var GEOJSON_LINESTRING = odata.GEOJSON_LINESTRING;
     var GEOJSON_POLYGON = odata.GEOJSON_POLYGON;

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/odata-handler.js
----------------------------------------------------------------------
diff --git a/JSLib/src/odata-handler.js b/JSLib/src/odata-handler.js
index bb83836..fa79197 100644
--- a/JSLib/src/odata-handler.js
+++ b/JSLib/src/odata-handler.js
@@ -15,13 +15,13 @@
 
 (function (window, undefined) {
 
-    var datajs = window.datajs || {};
+    var datajs = window.odatajs || {};
     var odata = window.OData || {};
 
     // Imports.
-    var assigned = datajs.assigned;
-    var extend = datajs.extend;
-    var trimString = datajs.trimString;
+    var assigned = odatajs.assigned;
+    var extend = odatajs.extend;
+    var trimString = odatajs.trimString;
 
     var maxVersion = odata.maxVersion;
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/odata-json-light.js
----------------------------------------------------------------------
diff --git a/JSLib/src/odata-json-light.js b/JSLib/src/odata-json-light.js
index bf654ce..d963852 100644
--- a/JSLib/src/odata-json-light.js
+++ b/JSLib/src/odata-json-light.js
@@ -15,21 +15,21 @@
 
 (function (window, undefined) {
 
-    var datajs = window.datajs || {};
+    var datajs = window.odatajs || {};
     var odata = window.OData || {};
 
     // Imports
 
-    var assigned = datajs.assigned;
-    var djsassert = datajs.djsassert;
-    var extend = datajs.extend;
-    var getURIInfo = datajs.getURIInfo;
-    var isArray = datajs.isArray;
-    var isDate = datajs.isDate;
-    var normalizeURI = datajs.normalizeURI;
-    var renameProperty = datajs.renameProperty;
-    var undefinedDefault = datajs.undefinedDefault;
-    var convertByteArrayToHexString = datajs.convertByteArrayToHexString;
+    var assigned = odatajs.assigned;
+    var djsassert = odatajs.djsassert;
+    var extend = odatajs.extend;
+    var getURIInfo = odatajs.getURIInfo;
+    var isArray = odatajs.isArray;
+    var isDate = odatajs.isDate;
+    var normalizeURI = odatajs.normalizeURI;
+    var renameProperty = odatajs.renameProperty;
+    var undefinedDefault = odatajs.undefinedDefault;
+    var convertByteArrayToHexString = odatajs.convertByteArrayToHexString;
 
     var dataItemTypeName = odata.dataItemTypeName;
     var EDM_DATETIME = odata.EDM_DATETIME;

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/odata-json.js
----------------------------------------------------------------------
diff --git a/JSLib/src/odata-json.js b/JSLib/src/odata-json.js
index 933f980..1434fa3 100644
--- a/JSLib/src/odata-json.js
+++ b/JSLib/src/odata-json.js
@@ -15,17 +15,17 @@
 
 (function (window, undefined) {
 
-    var datajs = window.datajs || {};
+    var datajs = window.odatajs || {};
     var odata = window.OData || {};
 
     // Imports 
 
-    var defined = datajs.defined;
-    var extend = datajs.extend;
-    var isArray = datajs.isArray;
-    var isDate = datajs.isDate;
-    var normalizeURI = datajs.normalizeURI;
-    var parseInt10 = datajs.parseInt10;
+    var defined = odatajs.defined;
+    var extend = odatajs.extend;
+    var isArray = odatajs.isArray;
+    var isDate = odatajs.isDate;
+    var normalizeURI = odatajs.normalizeURI;
+    var parseInt10 = odatajs.parseInt10;
 
     var contentType = odata.contentType;
     var jsonLightReadPayload = odata.jsonLightReadPayload;

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/odata-metadata.js
----------------------------------------------------------------------
diff --git a/JSLib/src/odata-metadata.js b/JSLib/src/odata-metadata.js
index 4978c32..4908fc0 100644
--- a/JSLib/src/odata-metadata.js
+++ b/JSLib/src/odata-metadata.js
@@ -15,22 +15,22 @@
 
 (function (window, undefined) {
 
-    var datajs = window.datajs || {};
+    var datajs = window.odatajs || {};
     var odata = window.OData || {};
 
     // imports 
 
-    var contains = datajs.contains;
-    var normalizeURI = datajs.normalizeURI;
-    var xmlAttributes = datajs.xmlAttributes;
-    var xmlChildElements = datajs.xmlChildElements;
-    var xmlFirstChildElement = datajs.xmlFirstChildElement;
-    var xmlInnerText = datajs.xmlInnerText;
-    var xmlLocalName = datajs.xmlLocalName;
-    var xmlNamespaceURI = datajs.xmlNamespaceURI;
-    var xmlNS = datajs.xmlNS;
-    var xmlnsNS = datajs.xmlnsNS;
-    var xmlParse = datajs.xmlParse;
+    var contains = odatajs.contains;
+    var normalizeURI = odatajs.normalizeURI;
+    var xmlAttributes = odatajs.xmlAttributes;
+    var xmlChildElements = odatajs.xmlChildElements;
+    var xmlFirstChildElement = odatajs.xmlFirstChildElement;
+    var xmlInnerText = odatajs.xmlInnerText;
+    var xmlLocalName = odatajs.xmlLocalName;
+    var xmlNamespaceURI = odatajs.xmlNamespaceURI;
+    var xmlNS = odatajs.xmlNS;
+    var xmlnsNS = odatajs.xmlnsNS;
+    var xmlParse = odatajs.xmlParse;
 
     var edmxNs = odata.edmxNs;
     var edmNs1 = odata.edmNs1;

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/odata-net.js
----------------------------------------------------------------------
diff --git a/JSLib/src/odata-net.js b/JSLib/src/odata-net.js
index 35e3d33..a87417b 100644
--- a/JSLib/src/odata-net.js
+++ b/JSLib/src/odata-net.js
@@ -15,13 +15,13 @@
 
 (function (window, undefined) {
 
-    var datajs = window.datajs || {};
+    var datajs = window.odatajs || {};
     var odata = window.OData || {};
 
     // Imports.
 
-    var defined = datajs.defined;
-    var delay = datajs.delay;
+    var defined = odatajs.defined;
+    var delay = odatajs.delay;
 
     // CONTENT START
     var ticks = 0;

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/odata-utils.js
----------------------------------------------------------------------
diff --git a/JSLib/src/odata-utils.js b/JSLib/src/odata-utils.js
index 066bc50..2f9c4a2 100644
--- a/JSLib/src/odata-utils.js
+++ b/JSLib/src/odata-utils.js
@@ -15,17 +15,17 @@
 
 (function (window, undefined) {
 
-    var datajs = window.datajs || {};
+    var datajs = window.odatajs || {};
     var odata = window.OData || {};
 
     // Imports
-    var assigned = datajs.assigned;
-    var contains = datajs.contains;
-    var find = datajs.find;
-    var isArray = datajs.isArray;
-    var isDate = datajs.isDate;
-    var isObject = datajs.isObject;
-    var parseInt10 = datajs.parseInt10;
+    var assigned = odatajs.assigned;
+    var contains = odatajs.contains;
+    var find = odatajs.find;
+    var isArray = odatajs.isArray;
+    var isDate = odatajs.isDate;
+    var isObject = odatajs.isObject;
+    var parseInt10 = odatajs.parseInt10;
 
     // CONTENT START
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/odata-xml.js
----------------------------------------------------------------------
diff --git a/JSLib/src/odata-xml.js b/JSLib/src/odata-xml.js
index ef974af..da050bd 100644
--- a/JSLib/src/odata-xml.js
+++ b/JSLib/src/odata-xml.js
@@ -15,38 +15,38 @@
 
 (function (window, undefined) {
 
-    var datajs = window.datajs || {};
+    var datajs = window.odatajs || {};
     var odata = window.OData || {};
 
     // Imports.
 
-    var djsassert = datajs.djsassert;
-    var http = datajs.http;
-    var isArray = datajs.isArray;
-    var isDate = datajs.isDate;
-    var isObject = datajs.isObject;
-    var normalizeURI = datajs.normalizeURI;
-    var parseInt10 = datajs.parseInt10;
-    var xmlAppendChild = datajs.xmlAppendChild;
-    var xmlAppendChildren = datajs.xmlAppendChildren;
-    var xmlAttributes = datajs.xmlAttributes;
-    var xmlBaseURI = datajs.xmlBaseURI;
-    var xmlChildElements = datajs.xmlChildElements;
-    var xmlDom = datajs.xmlDom;
-    var xmlFirstChildElement = datajs.xmlFirstChildElement;
-    var xmlInnerText = datajs.xmlInnerText;
-    var xmlLocalName = datajs.xmlLocalName;
-    var xmlNamespaceURI = datajs.xmlNamespaceURI;
-    var xmlNewAttribute = datajs.xmlNewAttribute;
-    var xmlNewElement = datajs.xmlNewElement;
-    var xmlNodeValue = datajs.xmlNodeValue;
-    var xmlNS = datajs.xmlNS;
-    var xmlnsNS = datajs.xmlnsNS;
-    var xmlParse = datajs.xmlParse;
-    var xmlQualifiedName = datajs.xmlQualifiedName;
-    var xmlSerialize = datajs.xmlSerialize;
-    var xmlSiblingElement = datajs.xmlSiblingElement;
-    var w3org = datajs.w3org;
+    var djsassert = odatajs.djsassert;
+    var http = odatajs.http;
+    var isArray = odatajs.isArray;
+    var isDate = odatajs.isDate;
+    var isObject = odatajs.isObject;
+    var normalizeURI = odatajs.normalizeURI;
+    var parseInt10 = odatajs.parseInt10;
+    var xmlAppendChild = odatajs.xmlAppendChild;
+    var xmlAppendChildren = odatajs.xmlAppendChildren;
+    var xmlAttributes = odatajs.xmlAttributes;
+    var xmlBaseURI = odatajs.xmlBaseURI;
+    var xmlChildElements = odatajs.xmlChildElements;
+    var xmlDom = odatajs.xmlDom;
+    var xmlFirstChildElement = odatajs.xmlFirstChildElement;
+    var xmlInnerText = odatajs.xmlInnerText;
+    var xmlLocalName = odatajs.xmlLocalName;
+    var xmlNamespaceURI = odatajs.xmlNamespaceURI;
+    var xmlNewAttribute = odatajs.xmlNewAttribute;
+    var xmlNewElement = odatajs.xmlNewElement;
+    var xmlNodeValue = odatajs.xmlNodeValue;
+    var xmlNS = odatajs.xmlNS;
+    var xmlnsNS = odatajs.xmlnsNS;
+    var xmlParse = odatajs.xmlParse;
+    var xmlQualifiedName = odatajs.xmlQualifiedName;
+    var xmlSerialize = odatajs.xmlSerialize;
+    var xmlSiblingElement = odatajs.xmlSiblingElement;
+    var w3org = odatajs.w3org;
 
     var dataItemTypeName = odata.dataItemTypeName;
     var EDM_BINARY = odata.EDM_BINARY;

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/odata.js
----------------------------------------------------------------------
diff --git a/JSLib/src/odata.js b/JSLib/src/odata.js
index 29f3955..10a6d2b 100644
--- a/JSLib/src/odata.js
+++ b/JSLib/src/odata.js
@@ -15,14 +15,14 @@
 
 (function (window, undefined) {
 
-    var datajs = window.datajs || {};
+    var datajs = window.odatajs || {};
     var odata = window.OData || {};
 
     // Imports
 
-    var assigned = datajs.assigned;
-    var defined = datajs.defined;
-    var throwErrorCallback = datajs.throwErrorCallback;
+    var assigned = odatajs.assigned;
+    var defined = odatajs.defined;
+    var throwErrorCallback = odatajs.throwErrorCallback;
 
     var invokeRequest = odata.invokeRequest;
     var MAX_DATA_SERVICE_VERSION = odata.MAX_DATA_SERVICE_VERSION;

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/store-dom.js
----------------------------------------------------------------------
diff --git a/JSLib/src/store-dom.js b/JSLib/src/store-dom.js
index bf8a887..d3aafa0 100644
--- a/JSLib/src/store-dom.js
+++ b/JSLib/src/store-dom.js
@@ -15,11 +15,11 @@
 
 (function (window, undefined) {
 
-    var datajs = window.datajs || {};
+    var datajs = window.odatajs || {};
 
     // Imports.
-    var throwErrorCallback = datajs.throwErrorCallback;
-    var delay = datajs.delay;
+    var throwErrorCallback = odatajs.throwErrorCallback;
+    var delay = odatajs.delay;
 
     // CONTENT START
 
@@ -313,7 +313,7 @@
     };
 
     // DATAJS INTERNAL START
-    datajs.DomStore = DomStore;
+    odatajs.DomStore = DomStore;
     // DATAJS INTERNAL END
 
     // CONTENT END

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/store-indexeddb.js
----------------------------------------------------------------------
diff --git a/JSLib/src/store-indexeddb.js b/JSLib/src/store-indexeddb.js
index b56828f..1a0483c 100644
--- a/JSLib/src/store-indexeddb.js
+++ b/JSLib/src/store-indexeddb.js
@@ -15,11 +15,11 @@
 
 (function (window, undefined) {
 
-    var datajs = window.datajs || {};
+    var datajs = window.odatajs || {};
 
     // Imports.
-    var throwErrorCallback = datajs.throwErrorCallback;
-    var delay = datajs.delay;
+    var throwErrorCallback = odatajs.throwErrorCallback;
+    var delay = odatajs.delay;
 
     // CONTENT START
 
@@ -410,7 +410,7 @@
     };
 
     // DATAJS INTERNAL START
-    datajs.IndexedDBStore = IndexedDBStore;
+    odatajs.IndexedDBStore = IndexedDBStore;
     // DATAJS INTERNAL END
 
     // CONTENT END

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/store-memory.js
----------------------------------------------------------------------
diff --git a/JSLib/src/store-memory.js b/JSLib/src/store-memory.js
index 4f35090..467ebc7 100644
--- a/JSLib/src/store-memory.js
+++ b/JSLib/src/store-memory.js
@@ -15,11 +15,11 @@
 
 (function (window, undefined) {
 
-    var datajs = window.datajs || {};
+    var datajs = window.odatajs || {};
 
     // Imports.
-    var throwErrorCallback = datajs.throwErrorCallback;
-    var delay = datajs.delay;
+    var throwErrorCallback = odatajs.throwErrorCallback;
+    var delay = odatajs.delay;
 
     // CONTENT START
 
@@ -224,7 +224,7 @@
     MemoryStore.prototype.mechanism = "memory";
 
     // DATAJS INTERNAL START
-    datajs.MemoryStore = MemoryStore;
+    odatajs.MemoryStore = MemoryStore;
     // DATAJS INTERNAL END
 
     // CONTENT END

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/store.js
----------------------------------------------------------------------
diff --git a/JSLib/src/store.js b/JSLib/src/store.js
index 688e88e..4db01aa 100644
--- a/JSLib/src/store.js
+++ b/JSLib/src/store.js
@@ -15,11 +15,11 @@
 
 (function (window, undefined) {
    
-    var datajs = window.datajs || {};
+    var datajs = window.odatajs || {};
 
-    var DomStore = datajs.DomStore;
-    var IndexedDBStore = datajs.IndexedDBStore;
-    var MemoryStore = datajs.MemoryStore;
+    var DomStore = odatajs.DomStore;
+    var IndexedDBStore = odatajs.IndexedDBStore;
+    var MemoryStore = odatajs.MemoryStore;
 
     // CONTENT START
 
@@ -29,16 +29,16 @@
         memory: MemoryStore
     };
 
-    datajs.defaultStoreMechanism = "best";
+    odatajs.defaultStoreMechanism = "best";
 
-    datajs.createStore = function (name, mechanism) {
+    odatajs.createStore = function (name, mechanism) {
         /// <summary>Creates a new store object.</summary>
         /// <param name="name" type="String">Store name.</param>
         /// <param name="mechanism" type="String" optional="true">A specific mechanism to use (defaults to best, can be "best", "dom", "indexeddb", "webdb").</param>
         /// <returns type="Object">Store object.</returns>
 
         if (!mechanism) {
-            mechanism = datajs.defaultStoreMechanism;
+            mechanism = odatajs.defaultStoreMechanism;
         }
 
         if (mechanism === "best") {
@@ -54,7 +54,7 @@
     };
 
     // DATAJS INTERNAL START
-    datajs.mechanisms = mechanisms;
+    odatajs.mechanisms = mechanisms;
     // DATAJS INTERNAL END
 
     // CONTENT END

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/utils.js
----------------------------------------------------------------------
diff --git a/JSLib/src/utils.js b/JSLib/src/utils.js
index 3a6da46..dab73d3 100644
--- a/JSLib/src/utils.js
+++ b/JSLib/src/utils.js
@@ -15,7 +15,7 @@
 
 (function (window, undefined) {
 
-    var datajs = window.datajs || {};
+    var datajs = window.odatajs || {};
 
     // CONTENT START
 
@@ -517,30 +517,30 @@
 
     // DATAJS INTERNAL START
 
-    datajs.activeXObject = activeXObject;
-    datajs.assigned = assigned;
-    datajs.contains = contains;
-    datajs.defined = defined;
-    datajs.delay = delay;
-    datajs.djsassert = djsassert;
-    datajs.extend = extend;
-    datajs.find = find;
-    datajs.getURIInfo = getURIInfo;
-    datajs.isArray = isArray;
-    datajs.isDate = isDate;
-    datajs.isObject = isObject;
-    datajs.normalizeURI = normalizeURI;
-    datajs.normalizeURICase = normalizeURICase;
-    datajs.parseInt10 = parseInt10;
-    datajs.renameProperty = renameProperty;
-    datajs.throwErrorCallback = throwErrorCallback;
-    datajs.trimString = trimString;
-    datajs.undefinedDefault = undefinedDefault;
-    datajs.decodeBase64 = decodeBase64;
-    datajs.convertByteArrayToHexString = convertByteArrayToHexString;
-    datajs.getJsonValueArraryLength = getJsonValueArraryLength;
-    datajs.sliceJsonValueArray = sliceJsonValueArray;
-    datajs.concatJsonValueArray = concatJsonValueArray;
+    odatajs.activeXObject = activeXObject;
+    odatajs.assigned = assigned;
+    odatajs.contains = contains;
+    odatajs.defined = defined;
+    odatajs.delay = delay;
+    odatajs.djsassert = djsassert;
+    odatajs.extend = extend;
+    odatajs.find = find;
+    odatajs.getURIInfo = getURIInfo;
+    odatajs.isArray = isArray;
+    odatajs.isDate = isDate;
+    odatajs.isObject = isObject;
+    odatajs.normalizeURI = normalizeURI;
+    odatajs.normalizeURICase = normalizeURICase;
+    odatajs.parseInt10 = parseInt10;
+    odatajs.renameProperty = renameProperty;
+    odatajs.throwErrorCallback = throwErrorCallback;
+    odatajs.trimString = trimString;
+    odatajs.undefinedDefault = undefinedDefault;
+    odatajs.decodeBase64 = decodeBase64;
+    odatajs.convertByteArrayToHexString = convertByteArrayToHexString;
+    odatajs.getJsonValueArraryLength = getJsonValueArraryLength;
+    odatajs.sliceJsonValueArray = sliceJsonValueArray;
+    odatajs.concatJsonValueArray = concatJsonValueArray;
     // DATAJS INTERNAL END
 
     // CONTENT END

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/src/xml.js
----------------------------------------------------------------------
diff --git a/JSLib/src/xml.js b/JSLib/src/xml.js
index 895a4c7..d0b315d 100644
--- a/JSLib/src/xml.js
+++ b/JSLib/src/xml.js
@@ -15,14 +15,14 @@
 
 (function (window, undefined) {
 
-    var datajs = window.datajs;
+    var datajs = window.odatajs;
 
-    var activeXObject = datajs.activeXObject;
-    var djsassert = datajs.djsassert;
-    var extend = datajs.extend;
-    var isArray = datajs.isArray;
-    var isObject = datajs.isObject;
-    var normalizeURI = datajs.normalizeURI;
+    var activeXObject = odatajs.activeXObject;
+    var djsassert = odatajs.djsassert;
+    var extend = odatajs.extend;
+    var isArray = odatajs.isArray;
+    var isObject = odatajs.isObject;
+    var normalizeURI = odatajs.normalizeURI;
 
     // CONTENT START
 
@@ -783,40 +783,40 @@
 
     // DATAJS INTERNAL START
 
-    datajs.http = http;
-    datajs.w3org = w3org;
-    datajs.xmlNS = xmlNS;
-    datajs.xmlnsNS = xmlnsNS;
-
-    datajs.hasLeadingOrTrailingWhitespace = hasLeadingOrTrailingWhitespace;
-    datajs.isXmlNSDeclaration = isXmlNSDeclaration;
-    datajs.xmlAppendChild = xmlAppendChild;
-    datajs.xmlAppendChildren = xmlAppendChildren;
-    datajs.xmlAttributeNode = xmlAttributeNode;
-    datajs.xmlAttributes = xmlAttributes;
-    datajs.xmlAttributeValue = xmlAttributeValue;
-    datajs.xmlBaseURI = xmlBaseURI;
-    datajs.xmlChildElements = xmlChildElements;
-    datajs.xmlFindElementByPath = xmlFindElementByPath;
-    datajs.xmlFindNodeByPath = xmlFindNodeByPath;
-    datajs.xmlFirstChildElement = xmlFirstChildElement;
-    datajs.xmlFirstDescendantElement = xmlFirstDescendantElement;
-    datajs.xmlInnerText = xmlInnerText;
-    datajs.xmlLocalName = xmlLocalName;
-    datajs.xmlNamespaceURI = xmlNamespaceURI;
-    datajs.xmlNodeValue = xmlNodeValue;
-    datajs.xmlDom = xmlDom;
-    datajs.xmlNewAttribute = xmlNewAttribute;
-    datajs.xmlNewElement = xmlNewElement;
-    datajs.xmlNewFragment = xmlNewFragment;
-    datajs.xmlNewNodeByPath = xmlNewNodeByPath;
-    datajs.xmlNewNSDeclaration = xmlNewNSDeclaration;
-    datajs.xmlNewText = xmlNewText;
-    datajs.xmlParse = xmlParse;
-    datajs.xmlQualifiedName = xmlQualifiedName;
-    datajs.xmlSerialize = xmlSerialize;
-    datajs.xmlSerializeDescendants = xmlSerializeDescendants;
-    datajs.xmlSiblingElement = xmlSiblingElement;
+    odatajs.http = http;
+    odatajs.w3org = w3org;
+    odatajs.xmlNS = xmlNS;
+    odatajs.xmlnsNS = xmlnsNS;
+
+    odatajs.hasLeadingOrTrailingWhitespace = hasLeadingOrTrailingWhitespace;
+    odatajs.isXmlNSDeclaration = isXmlNSDeclaration;
+    odatajs.xmlAppendChild = xmlAppendChild;
+    odatajs.xmlAppendChildren = xmlAppendChildren;
+    odatajs.xmlAttributeNode = xmlAttributeNode;
+    odatajs.xmlAttributes = xmlAttributes;
+    odatajs.xmlAttributeValue = xmlAttributeValue;
+    odatajs.xmlBaseURI = xmlBaseURI;
+    odatajs.xmlChildElements = xmlChildElements;
+    odatajs.xmlFindElementByPath = xmlFindElementByPath;
+    odatajs.xmlFindNodeByPath = xmlFindNodeByPath;
+    odatajs.xmlFirstChildElement = xmlFirstChildElement;
+    odatajs.xmlFirstDescendantElement = xmlFirstDescendantElement;
+    odatajs.xmlInnerText = xmlInnerText;
+    odatajs.xmlLocalName = xmlLocalName;
+    odatajs.xmlNamespaceURI = xmlNamespaceURI;
+    odatajs.xmlNodeValue = xmlNodeValue;
+    odatajs.xmlDom = xmlDom;
+    odatajs.xmlNewAttribute = xmlNewAttribute;
+    odatajs.xmlNewElement = xmlNewElement;
+    odatajs.xmlNewFragment = xmlNewFragment;
+    odatajs.xmlNewNodeByPath = xmlNewNodeByPath;
+    odatajs.xmlNewNSDeclaration = xmlNewNSDeclaration;
+    odatajs.xmlNewText = xmlNewText;
+    odatajs.xmlParse = xmlParse;
+    odatajs.xmlQualifiedName = xmlQualifiedName;
+    odatajs.xmlSerialize = xmlSerialize;
+    odatajs.xmlSerializeDescendants = xmlSerializeDescendants;
+    odatajs.xmlSiblingElement = xmlSiblingElement;
 
     // DATAJS INTERNAL END
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/tests/cache-tests.js
----------------------------------------------------------------------
diff --git a/JSLib/tests/cache-tests.js b/JSLib/tests/cache-tests.js
index 13fd4b9..e25d2f8 100644
--- a/JSLib/tests/cache-tests.js
+++ b/JSLib/tests/cache-tests.js
@@ -35,7 +35,7 @@
     };
 
     djstest.addTest(function dataCacheCountTest() {
-        var cache = datajs.createDataCache({ name: "cache", source: foodsFeed });
+        var cache = odatajs.createDataCache({ name: "cache", source: foodsFeed });
         cache.count().then(function (count) {
             djstest.assertAreEqual(count, collectionSize, "expected count for Foods");
             djstest.destroyCacheAndDone(cache);
@@ -43,7 +43,7 @@
     });
 
     djstest.addTest(function dataCacheCountOnLocalTest() {
-        var cache = datajs.createDataCache({ name: "cache", source: foodsFeed, pageSize: collectionSize + 10, mechanism: "memory" });
+        var cache = odatajs.createDataCache({ name: "cache", source: foodsFeed, pageSize: collectionSize + 10, mechanism: "memory" });
         cache.readRange(0, collectionSize + 10).then(function (data) {
             var expectedCount = data.value ? data.value.length : 0;
             cache.count().then(function (count) {
@@ -55,7 +55,7 @@
 
     djstest.addTest(function dataCacheCountAbortTest() {
         // Abort before completion.
-        var cache = datajs.createDataCache({ name: "cache", source: foodsFeed });
+        var cache = odatajs.createDataCache({ name: "cache", source: foodsFeed });
         var item = cache.count().then(thenFailTest, function (err) {
             djstest.assertAreEqual(true, err.canceled, "err.aborted is true");
             djstest.destroyCacheAndDone(cache);
@@ -87,9 +87,9 @@
             }
         };
 
-        var cache = datajs.createDataCache(options);
+        var cache = odatajs.createDataCache(options);
         cache.clear().then(function () {
-            var newCache = datajs.createDataCache(options);
+            var newCache = odatajs.createDataCache(options);
             resolve(newCache);
         }, function (err) {
             rejected = true;
@@ -350,7 +350,7 @@
             then(function (cache) {
                 cache.readRange(0, 2).then(function () {
                     options.source = "HtTp://ExampleURI.cOm/my%20service.svc";
-                    var newCache = datajs.createDataCache(options);
+                    var newCache = odatajs.createDataCache(options);
                     newCache.readRange(0, 2).then(function (data) {
                         djstest.assertAreEqualDeep(data.value, [1, 2], "Got the expected data from the new cache instance");
                         newCache.clear().then(function () {
@@ -503,7 +503,7 @@
                 return null;
             }
         };
-        var cache = datajs.createDataCache({
+        var cache = odatajs.createDataCache({
             name: "mem", mechanism: "memory", source: "http://www.example.org/service/",
             httpClient: httpClient
         });
@@ -675,53 +675,53 @@
         var cache;
 
         // Verify the defaults.
-        cache = datajs.createDataCache({ name: "name", source: "src" });
+        cache = odatajs.createDataCache({ name: "name", source: "src" });
 
         djstest.assertAreEqual(cache.onidle, undefined, "onidle is undefined");
 
         // Verify specific values.
-        cache = datajs.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: 2, prefetchSize: 3, idle: 123 });
+        cache = odatajs.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: 2, prefetchSize: 3, idle: 123 });
 
         djstest.assertAreEqual(cache.onidle, 123, "onidle is as specified");
 
         // Verify 0 pageSize 
         djstest.expectException(function () {
-            datajs.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: 0, prefetchSize: 3, idle: 123 });
+            odatajs.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: 0, prefetchSize: 3, idle: 123 });
         }, "zero pageSize");
 
         // Verify negative pageSize
         djstest.expectException(function () {
-            datajs.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: -2, prefetchSize: 3, idle: 123 });
+            odatajs.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: -2, prefetchSize: 3, idle: 123 });
         }, "negative pageSize");
 
         // Verify NaN pageSize
         djstest.expectException(function () {
-            cache = datajs.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: "2", prefetchSize: 3, idle: 123 });
+            cache = odatajs.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: "2", prefetchSize: 3, idle: 123 });
         }, "NaN pageSize");
 
         // Verify NaN cacheSize
         djstest.expectException(function () {
-            cache = datajs.createDataCache({ name: "name", source: "src", cacheSize: "1", pageSize: 2, prefetchSize: 3, idle: 123 });
+            cache = odatajs.createDataCache({ name: "name", source: "src", cacheSize: "1", pageSize: 2, prefetchSize: 3, idle: 123 });
         }, "NaN cacheSize");
 
         // Verify NaN prefetchSize
         djstest.expectException(function () {
-            cache = datajs.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: 2, prefetchSize: "3", idle: 123 });
+            cache = odatajs.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: 2, prefetchSize: "3", idle: 123 });
         }, "NaN prefetchSize");
 
         // Verify undefined name 
         djstest.expectException(function () {
-            datajs.createDataCache({ source: "src", cacheSize: 1, pageSize: 1, prefetchSize: 3, idle: 123 });
+            odatajs.createDataCache({ source: "src", cacheSize: 1, pageSize: 1, prefetchSize: 3, idle: 123 });
         }, "undefined name");
 
         // Verify null name 
         djstest.expectException(function () {
-            datajs.createDataCache({ name: null, source: "src", cacheSize: 1, pageSize: 1, prefetchSize: 3, idle: 123 });
+            odatajs.createDataCache({ name: null, source: "src", cacheSize: 1, pageSize: 1, prefetchSize: 3, idle: 123 });
         }, "null name");
 
         // Verify undefined source 
         djstest.expectException(function () {
-            datajs.createDataCache({ name: "name", cacheSize: 1, pageSize: 1, prefetchSize: 3, idle: 123 });
+            odatajs.createDataCache({ name: "name", cacheSize: 1, pageSize: 1, prefetchSize: 3, idle: 123 });
         }, "undefined source");
 
         djstest.done();
@@ -747,7 +747,7 @@
             }
         };
 
-        var cache = datajs.createDataCache({ name: "name", source: cacheSource, mechanism: "memory", pageSize: 10 });
+        var cache = odatajs.createDataCache({ name: "name", source: cacheSource, mechanism: "memory", pageSize: 10 });
         cache.count().then(function () {
             cache.readRange(0, 5).then(function () {
                 djstest.done();
@@ -760,13 +760,13 @@
         var failures = ["read-settings", "write-settings", "v2"];
         var failureIndex = 0;
 
-        var originalStore = datajs.createStore;
+        var originalStore = odatajs.createStore;
         var restoreStore = function () {
-            datajs.createStore = originalStore;
+            odatajs.createStore = originalStore;
         };
 
         var storeError = { message: "cacheInitializationFailTest error" };
-        datajs.createStore = function (name, mechanism) {
+        odatajs.createStore = function (name, mechanism) {
             return {
                 addOrUpdate: function (key, value, successCallback, errorCallback) {
                     if (failures[failureIndex] === "write-settings") {
@@ -795,7 +795,7 @@
 
         var nextFailure = function () {
             djstest.log("Failure mode: " + failures[failureIndex]);
-            var cache = datajs.createDataCache({ name: "name", source: "foo", mechanism: "memory", pageSize: 10 });
+            var cache = odatajs.createDataCache({ name: "name", source: "foo", mechanism: "memory", pageSize: 10 });
             try {
                 // The first readRange should succeed, because the data cache isn't really initialized at this time.
                 cache.readRange(1, 2).then(djstest.failAndDoneCallback("No function should succeed"), function (err) {
@@ -854,7 +854,7 @@
             }
         };
 
-        var cache = datajs.createDataCache({ name: "name", source: cacheSource, mechanism: "memory", pageSize: 10 });
+        var cache = odatajs.createDataCache({ name: "name", source: cacheSource, mechanism: "memory", pageSize: 10 });
         cache.readRange(0, 5).then(function () {
             djstest.fail("unexpected call to then success");
             djstest.done();
@@ -975,7 +975,7 @@
 
     djstest.addTest(function createDeferredTest() {
         // Verify basic use of deferred object.
-        var deferred = datajs.createDeferred();
+        var deferred = odatajs.createDeferred();
         deferred.then(function (val1, val2) {
             djstest.assertAreEqual(val1, 1, "val1 is as specified");
             djstest.assertAreEqual(val2, 2, "val2 is as specified");
@@ -986,7 +986,7 @@
 
     djstest.addTest(function deferredThenTest() {
         // Verify then registration and chaining.
-        var deferred = datajs.createDeferred();
+        var deferred = odatajs.createDeferred();
         deferred.then(function (val1, val2) {
             djstest.assertAreEqual(val1, 1, "val1 is as specified");
             djstest.assertAreEqual(val2, 2, "val2 is as specified");
@@ -996,7 +996,7 @@
             djstest.assert(foo !== "foo", "argument for chained 'then' is *not* result of previous call");
             djstest.assert(foo === 1, "argument for chained 'then' is same as for previous call");
 
-            var other = datajs.createDeferred();
+            var other = odatajs.createDeferred();
             other.then(null, function (err, msg) {
                 djstest.assertAreEqual("error", err, "err is as specified");
                 djstest.assertAreEqual("message", msg, "msg is as specified");
@@ -1007,7 +1007,7 @@
                 djstest.assertAreEqual("error", err, "err is as specified");
                 djstest.assertAreEqual("message", msg, "msg is as specified");
 
-                var multiple = datajs.createDeferred();
+                var multiple = odatajs.createDeferred();
                 var count = 0;
 
                 // See Compatibility Note A in DjsDeferred remarks.
@@ -1037,12 +1037,12 @@
 
     djstest.addTest(function deferredResolveTest() {
         // Resolve with no arguments.
-        var deferred = datajs.createDeferred();
+        var deferred = odatajs.createDeferred();
         deferred.then(function (arg) {
             djstest.assertAreEqual(arg, undefined, "resolve with no args shows up as undefined");
 
             // Resolve with no callbacks.
-            var other = datajs.createDeferred();
+            var other = odatajs.createDeferred();
             other.resolve();
             djstest.done();
         });
@@ -1052,12 +1052,12 @@
 
     djstest.addTest(function deferredRejectTest() {
         // Resolve with no arguments.   
-        var deferred = datajs.createDeferred();
+        var deferred = odatajs.createDeferred();
         deferred.then(null, function (arg) {
             djstest.assertAreEqual(arg, undefined, "reject with no args shows up as undefined");
 
             // Resolve with no callbacks.
-            var other = datajs.createDeferred();
+            var other = odatajs.createDeferred();
             other.reject();
             djstest.done();
         });
@@ -1079,7 +1079,7 @@
         var i, len;
         for (i = 0, len = tests.length; i < len; i++) {
             var test = tests[i];
-            djstest.assertAreEqual(datajs.estimateSize(test.i), test.e);
+            djstest.assertAreEqual(odatajs.estimateSize(test.i), test.e);
         }
         djstest.done();
     });
@@ -1099,7 +1099,7 @@
             }
         });
 
-        var cache = datajs.createDataCache({
+        var cache = odatajs.createDataCache({
             name: "cacheOptionsTunnel",
             source: "http://foo-bar/",
             user: "the-user",
@@ -1121,7 +1121,7 @@
     djstest.addTest(function dataCacheHandlesFullStoreTest() {
 
         var TestStore = function (name) {
-            var that = new window.datajs.MemoryStore(name);
+            var that = new window.odatajs.MemoryStore(name);
             that.addOrUpdate = function (key, value, success, error) {
                 if (key === "__settings") {
                     window.setTimeout(function () {
@@ -1160,14 +1160,14 @@
             }
         };
 
-        var originalCreateStore = window.datajs.createStore;
+        var originalCreateStore = window.odatajs.createStore;
 
-        window.datajs.createStore = function (name, mechanism) {
+        window.odatajs.createStore = function (name, mechanism) {
             return TestStore(name);
         };
 
         try {
-            var cache = datajs.createDataCache({
+            var cache = odatajs.createDataCache({
                 name: "cache",
                 pageSize: 5,
                 prefetchSize: 0,
@@ -1175,7 +1175,7 @@
                 mechanism: "teststore"
             });
         } finally {
-            window.datajs.createStore = originalCreateStore;
+            window.odatajs.createStore = originalCreateStore;
         }
 
         cache.readRange(0, 5).then(function (data) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/tests/datajs-cache-large-collection-functional-tests.js
----------------------------------------------------------------------
diff --git a/JSLib/tests/datajs-cache-large-collection-functional-tests.js b/JSLib/tests/datajs-cache-large-collection-functional-tests.js
index fd4e826..1dd4c00 100644
--- a/JSLib/tests/datajs-cache-large-collection-functional-tests.js
+++ b/JSLib/tests/datajs-cache-large-collection-functional-tests.js
@@ -111,7 +111,7 @@
                         mechanism: params.mechanism, cacheSize: params.cacheSize
                     };
 
-                    var cache = datajs.createDataCache(options);
+                    var cache = odatajs.createDataCache(options);
                     this.caches.push({ name: options.name,
                         cache: cache
                     });
@@ -144,7 +144,7 @@
                             mechanism: params.mechanism, cacheSize: params.cacheSize
                         };
 
-                        var cache = datajs.createDataCache(options);
+                        var cache = odatajs.createDataCache(options);
                         this.caches.push({ name: options.name, cache: cache });
 
                         var cacheOracle = new CacheOracle(params.feed, params.pageSize, itemsInCollection);

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/tests/odata-atom-tests.js
----------------------------------------------------------------------
diff --git a/JSLib/tests/odata-atom-tests.js b/JSLib/tests/odata-atom-tests.js
index 7131e1e..49d9538 100644
--- a/JSLib/tests/odata-atom-tests.js
+++ b/JSLib/tests/odata-atom-tests.js
@@ -1070,10 +1070,10 @@
            <title>empty entry</title> \r\n\
         </notAtom> \r\n";
 
-        var service = OData.atomReadDocument(datajs.xmlParse(emptyServiceString).documentElement);
-        var feed = OData.atomReadDocument(datajs.xmlParse(emptyFeedString).documentElement);
-        var entry = OData.atomReadDocument(datajs.xmlParse(emptyEntryString).documentElement);
-        var nonAtom = OData.atomReadDocument(datajs.xmlParse(nonAtomString).documentElement);
+        var service = OData.atomReadDocument(odatajs.xmlParse(emptyServiceString).documentElement);
+        var feed = OData.atomReadDocument(odatajs.xmlParse(emptyFeedString).documentElement);
+        var entry = OData.atomReadDocument(odatajs.xmlParse(emptyEntryString).documentElement);
+        var nonAtom = OData.atomReadDocument(odatajs.xmlParse(nonAtomString).documentElement);
 
         djstest.assert(service && service.workspaces.length === 1, "atomReadDocument deserialized a service document");
         djstest.assert(feed && feed.results.length === 0, "atomReadDocument deserialized a feed document");
@@ -1172,7 +1172,7 @@
            <title>test feed</title> \r\n\
         </feed> \r\n"
 
-        var feed = OData.atomReadFeed(datajs.xmlParse(feedWithExtensionsString).documentElement);
+        var feed = OData.atomReadFeed(odatajs.xmlParse(feedWithExtensionsString).documentElement);
         djstest.assert(feed, "atomReadFeed didn't return a feed object for a payload with feed extensions");
         djstest.assertAreEqual(feed.__metadata.feed_extensions.length, 4, "atomReadFeed didn't return the expected number of extensions");
 
@@ -1190,9 +1190,9 @@
           <link rel=\'alternate\' href=\'http://otheruri\'/> \r\n\
         </feed> \r\n";
 
-        var root = datajs.xmlParse(feedLinksString).documentElement;
+        var root = odatajs.xmlParse(feedLinksString).documentElement;
         var feed = { __metadata: {} };
-        datajs.xmlChildElements(root, function (child) {
+        odatajs.xmlChildElements(root, function (child) {
             OData.atomReadFeedLink(child, feed);
         });
 
@@ -1214,7 +1214,7 @@
               me:attr1=\'a1\' \r\n\
               attr2=\'a2\'/> \r\n";
 
-        var link = OData.atomReadLink(datajs.xmlParse(linkString).documentElement);
+        var link = OData.atomReadLink(odatajs.xmlParse(linkString).documentElement);
 
         djstest.assert(link, "atomReadLink didn't return a link object");
         djstest.assertAreEqual(link.href, "http://nexturi", "atomReadLink, link object href field has an unexpected value");
@@ -1236,7 +1236,7 @@
               attr2=\'a2\'/> \r\n";
 
 
-        var linkRoot = datajs.xmlParse(linkString).documentElement;
+        var linkRoot = odatajs.xmlParse(linkString).documentElement;
         djstest.expectException(function () {
             OData.atomReadLink(linkRoot);
         }, "atomReadLink didn't throw an exception when the link doesn't have the href attribute");
@@ -1258,7 +1258,7 @@
             djstest.assertAreEqual(ext.value, value, "atomReadExtensionElement, extension object value field has an unexpected value");
         };
 
-        var extension = OData.atomReadExtensionElement(datajs.xmlParse(extensionString).documentElement);
+        var extension = OData.atomReadExtensionElement(odatajs.xmlParse(extensionString).documentElement);
         validateExtension(extension, "ext", "http://myExtensions", 2, 1);
 
         extension = extension.children[0];
@@ -1271,7 +1271,7 @@
         var extensionString = "\
         <me:ext xmlns:me=\'http://myExtensions\' me:attr1=\'a1\' attr2=\'a2\' /> \r\n";
 
-        var extensionAttributes = OData.atomReadExtensionAttributes(datajs.xmlParse(extensionString).documentElement);
+        var extensionAttributes = OData.atomReadExtensionAttributes(odatajs.xmlParse(extensionString).documentElement);
         djstest.assertAreEqual(extensionAttributes.length, 2, "atomReadExtensionAttribute, returned collection doesn't have the expected number of attributes");
         djstest.done();
     });
@@ -1291,7 +1291,7 @@
 
         for (var name in tests) {
             var test = tests[name];
-            var xmlElement = datajs.xmlParse(test.i).documentElement;
+            var xmlElement = odatajs.xmlParse(test.i).documentElement;
             var extensions = OData.atomReadExtensionAttributes(xmlElement);
 
             djstest.assertAreEqualDeep(extensions[0], test.e, name + " - extension object is the expected one");
@@ -1342,7 +1342,7 @@
             Typed: 100
         };
 
-        var entry = OData.atomReadEntry(datajs.xmlParse(entryString).documentElement);
+        var entry = OData.atomReadEntry(odatajs.xmlParse(entryString).documentElement);
 
         djstest.assert(entry, "atomReadEntry didn't return an entry object");
         djstest.assertAreEqualDeep(entry, expectedEntry);
@@ -2571,7 +2571,7 @@
             Typed: 100
         };
 
-        var entry = OData.atomReadEntry(datajs.xmlParse(entryString).documentElement);
+        var entry = OData.atomReadEntry(odatajs.xmlParse(entryString).documentElement);
 
         djstest.assert(entry, "atomReadFeed didn't return an entry object for the media link entry payload");
         djstest.assertAreEqualDeep(entry, expectedEntry);
@@ -2586,7 +2586,7 @@
                   xmlns:me=\'http//:myExtensions\' \r\n\
                   xmlns=\'http://www.w3.org/2005/Atom\'/> \r\n";
         var entryMetadata = {};
-        OData.atomReadEntryType(datajs.xmlParse(categoryString).documentElement, entryMetadata);
+        OData.atomReadEntryType(odatajs.xmlParse(categoryString).documentElement, entryMetadata);
 
         djstest.assertAreEqual(entryMetadata.type, "the type", "atomReadEntryType, entry type has an unexpected value");
         djstest.assertAreEqual(entryMetadata.type_extensions.length, 2, "readATomEntryType, entry type_extensions doens't have the expected number of extensions");
@@ -2602,7 +2602,7 @@
                   xmlns=\'http://www.w3.org/2005/Atom\'/> \r\n";
 
         var entry = { __metadata: {} };
-        OData.atomReadEntryType(datajs.xmlParse(categoryString).documentElement, entry, entry.__metadata);
+        OData.atomReadEntryType(odatajs.xmlParse(categoryString).documentElement, entry, entry.__metadata);
 
         djstest.assert(!entry.__metadata.type, "atomReadEntryType, processed a category of without a scheme attribute!!");
         djstest.done();
@@ -2622,8 +2622,8 @@
         var entry = { __metadata: {} };
 
         djstest.expectException(function () {
-            var categories = datajs.xmlParse(categoryString).documentElement;
-            datajs.xmlChildElements(categories, function (child) {
+            var categories = odatajs.xmlParse(categoryString).documentElement;
+            odatajs.xmlChildElements(categories, function (child) {
                 OData.atomReadEntryType(child, entry, entry.__metadata);
             });
         }, "atomReadEntryType didn't throw the expected exception");
@@ -2636,7 +2636,7 @@
             <content src=\'http://mediasource\' xmlns=\'http://www.w3.org/2005/Atom\'/> \r\n"
 
         var entry = { __metadata: {} };
-        var content = datajs.xmlParse(contentString).documentElement;
+        var content = odatajs.xmlParse(contentString).documentElement;
         djstest.expectException(function () {
             OData.atomReadEntryContent(content, entry);
         }, "atomReadEntryContent didn't throw the expected exception");
@@ -2656,7 +2656,7 @@
            </content> \r\n";
 
         var entry = { __metadata: {} };
-        var content = datajs.xmlParse(contentString).documentElement;
+        var content = odatajs.xmlParse(contentString).documentElement;
         djstest.expectException(function () {
             OData.atomReadEntryContent(content, entry);
         }, "atomReadEntryContent didn't throw the expected exception");
@@ -2674,7 +2674,7 @@
 
         var entry = { __metadata: {} };
 
-        OData.atomReadEntryLink(datajs.xmlParse(linkString).documentElement, entry, entry.__metadata);
+        OData.atomReadEntryLink(odatajs.xmlParse(linkString).documentElement, entry, entry.__metadata);
 
         djstest.assertAreEqual(entry.__metadata.edit_media, "http://editmediauri", "edit_media field has a un expected value");
         djstest.assertAreEqual(entry.__metadata.media_etag, "etag", "media_etag field has a un expected value");
@@ -2713,8 +2713,8 @@
         };
 
         var entry = { __metadata: {} };
-        var links = datajs.xmlParse(linksString).documentElement;
-        datajs.xmlChildElements(links, function (child) {
+        var links = odatajs.xmlParse(linksString).documentElement;
+        odatajs.xmlChildElements(links, function (child) {
             OData.atomReadEntryLink(child, entry, entry.__metadata);
         });
 
@@ -2788,7 +2788,7 @@
             Typed: 100
         };
 
-        var entry = OData.atomReadEntry(datajs.xmlParse(entryString).documentElement);
+        var entry = OData.atomReadEntry(odatajs.xmlParse(entryString).documentElement);
 
         djstest.assertAreEqualDeep(entry, expectedEntry);
         djstest.done();
@@ -2810,7 +2810,7 @@
                </d:Complex>\r\n \
            </d:Data>\r\n";
 
-        var dataElement = datajs.xmlParse(content).documentElement;
+        var dataElement = odatajs.xmlParse(content).documentElement;
         var data = {};
         var metadata = {};
 
@@ -2950,7 +2950,7 @@
             }
         };
 
-        var entry = OData.atomReadEntry(datajs.xmlParse(entryString).documentElement);
+        var entry = OData.atomReadEntry(odatajs.xmlParse(entryString).documentElement);
 
         djstest.assert(entry, "atomReadEntry didn't return an entry object");
         djstest.assertAreEqualDeep(entry, expectedEntry, "atomReadEntry didn't return the expected entry object");
@@ -3261,7 +3261,7 @@
         };
 
         // Todo refactor all this tests to use the mock http client instead. 
-        var entry = OData.atomReadEntry(datajs.xmlParse(entryString).documentElement);
+        var entry = OData.atomReadEntry(odatajs.xmlParse(entryString).documentElement);
 
         djstest.assert(entry, "atomReadEntry didn't return an entry object");
         djstest.assertAreEqualDeep(entry, expectedEntry, "atomReadEntry didn't return the expected entry object");
@@ -4292,7 +4292,7 @@
 
     djstest.addFullTest(true, function getXmlPathValueTest() {
         // Tests with expected value and result based on doc.
-        var doc = datajs.xmlParse(
+        var doc = odatajs.xmlParse(
         "<atom:entry xmlns:atom='http://www.w3.org/2005/Atom' xmlns:c='custom'>" +
         " <atom:title>title</atom:title>" +
         " <atom:summary>summary</atom:summary>" +
@@ -4303,7 +4303,7 @@
         " <c:third><c:item><c:a>a</c:a><c:b>b</c:b><c:empty /></c:item></c:third>" +
         "</atom:entry>");
 
-        var root = datajs.xmlFirstChildElement(doc);
+        var root = odatajs.xmlFirstChildElement(doc);
 
         var atomXmlNs = "http://www.w3.org/2005/Atom";
         var tests = [
@@ -4331,8 +4331,8 @@
         var i, len;
         for (i = 0, len = tests.length; i < len; i++) {
             var test = tests[i];
-            var node = datajs.xmlFindNodeByPath(root, test.ns, test.path);
-            var actual = node && datajs.xmlNodeValue(node);
+            var node = odatajs.xmlFindNodeByPath(root, test.ns, test.path);
+            var actual = node && odatajs.xmlNodeValue(node);
             djstest.assertAreEqual(actual, test.e, "match for test #" + i + "(" + test.path + ")");
         }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/tests/odata-cache-filter-functional-tests.js
----------------------------------------------------------------------
diff --git a/JSLib/tests/odata-cache-filter-functional-tests.js b/JSLib/tests/odata-cache-filter-functional-tests.js
index b11cad3..eaf9d48 100644
--- a/JSLib/tests/odata-cache-filter-functional-tests.js
+++ b/JSLib/tests/odata-cache-filter-functional-tests.js
@@ -207,7 +207,7 @@
         djstest.assertsExpected(2);
         var options = { name: "cache" + new Date().valueOf(), source: params.feed, pageSize: params.pageSize, prefetchSize: params.prefetchSize };
 
-        var cache = datajs.createDataCache(options);
+        var cache = odatajs.createDataCache(options);
         var cacheOracle = new CacheOracle(params.feed, params.pageSize, itemsInCollection);
         var session = this.observableHttpClient.newSession();
         validateFilterResultsAndRequests(params.feed, cache, params.index, params.count, params.predicate, function () { djstest.destroyCacheAndDone(cache) }, params.backwards, session, cacheOracle);
@@ -217,7 +217,7 @@
         djstest.assertsExpected(3);
         var options = { name: "cache" + new Date().valueOf(), source: params.feed, pageSize: params.pageSize, prefetchSize: params.prefetchSize };
 
-        var cache = datajs.createDataCache(options);
+        var cache = odatajs.createDataCache(options);
         var cacheOracle = new CacheOracle(params.feed, params.pageSize, itemsInCollection);
         var session = this.observableHttpClient.newSession();
 
@@ -232,7 +232,7 @@
         djstest.assertsExpected(2);
         var options = { name: "cache" + new Date().valueOf(), source: params.feed, pageSize: params.pageSize, prefetchSize: params.prefetchSize };
 
-        var cache = datajs.createDataCache(options);
+        var cache = odatajs.createDataCache(options);
 
         var firstfilter = function (finished) {
             validateFilterResultsAndRequests(params.feed, cache, params.firstIndex, params.firstCount, params.predicate, finished, params.backwards);
@@ -251,7 +251,7 @@
         djstest.assertsExpected(4);
         var options = { name: "cache" + new Date().valueOf(), source: params.feed, pageSize: params.pageSize, prefetchSize: params.prefetchSize };
 
-        var cache = datajs.createDataCache(options);
+        var cache = odatajs.createDataCache(options);
         var cacheOracle = new CacheOracle(params.feed, params.pageSize, itemsInCollection);
         var session = this.observableHttpClient.newSession();
 
@@ -372,7 +372,7 @@
                 function (params) {
                     djstest.assertsExpected(1);
                     var options = { name: "cache" + new Date().valueOf(), source: params.feed };
-                    var cache = datajs.createDataCache(options);
+                    var cache = odatajs.createDataCache(options);
                     try {
                         params.backwards ?
                             cache.filterForward(params.index, params.count, params.predicate).then(function (results) {
@@ -396,7 +396,7 @@
                 function (params) {
                     djstest.assertsExpected(1);
                     var options = { name: "cache" + new Date().valueOf(), source: params.feed };
-                    var cache = datajs.createDataCache(options);
+                    var cache = odatajs.createDataCache(options);
                     try {
                         params.backwards ?
                             cache.filterBack(params.index, params.count, params.predicate).then(function (results) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/tests/odata-cache-fperf-tests.js
----------------------------------------------------------------------
diff --git a/JSLib/tests/odata-cache-fperf-tests.js b/JSLib/tests/odata-cache-fperf-tests.js
index 441022c..68c415f 100644
--- a/JSLib/tests/odata-cache-fperf-tests.js
+++ b/JSLib/tests/odata-cache-fperf-tests.js
@@ -44,7 +44,7 @@
         /// <param name="threshold">The average read time threshold for test to pass; if not specified, defaults to the slowHttpClient latency</param>
         /// <returns>The test function</param>
         return function () {
-            var cache = datajs.createDataCache({ name: "cache" + new Date().valueOf(), source: source, pageSize: pageSize, prefetchSize: prefetchSize });
+            var cache = odatajs.createDataCache({ name: "cache" + new Date().valueOf(), source: source, pageSize: pageSize, prefetchSize: prefetchSize });
             var totalTime = 0;
             var readCount = 0;
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/tests/odata-cache-functional-tests.js
----------------------------------------------------------------------
diff --git a/JSLib/tests/odata-cache-functional-tests.js b/JSLib/tests/odata-cache-functional-tests.js
index 1a65c6f..e8c32ec 100644
--- a/JSLib/tests/odata-cache-functional-tests.js
+++ b/JSLib/tests/odata-cache-functional-tests.js
@@ -316,7 +316,7 @@
             this.createAndAddCache = function (options) {
                 /// <summary>Returns a cache created from the options object and </summary>
                 /// <param name="options" type="Object">Object to create a cache from.</param> 
-                var cache = datajs.createDataCache(options);
+                var cache = odatajs.createDataCache(options);
                 this.caches.push({ name: options.name, cache: cache });
                 return cache;
             };

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/tests/odata-cache-rx-functional-tests.js
----------------------------------------------------------------------
diff --git a/JSLib/tests/odata-cache-rx-functional-tests.js b/JSLib/tests/odata-cache-rx-functional-tests.js
index cb47982..f1d4f1f 100644
--- a/JSLib/tests/odata-cache-rx-functional-tests.js
+++ b/JSLib/tests/odata-cache-rx-functional-tests.js
@@ -60,7 +60,7 @@
                 djstest.addTest(function (params) {
                     djstest.assertsExpected(1);
                     var options = { name: "cache" + new Date().valueOf(), source: params.feedUri, pageSize: params.pageSize, prefetchSize: 0 };
-                    var cache = datajs.createDataCache(options);
+                    var cache = odatajs.createDataCache(options);
 
                     ODataReadOracle.readJsonAcrossServerPages(params.feedUri, function (collection) {
                         assertObservables(params.operator(cache.toObservable()), params.operator(window.Rx.Observable.FromArray(collection.value)), function () {

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/tests/odata-json-tests.js
----------------------------------------------------------------------
diff --git a/JSLib/tests/odata-json-tests.js b/JSLib/tests/odata-json-tests.js
index 775b0d0..70f98be 100644
--- a/JSLib/tests/odata-json-tests.js
+++ b/JSLib/tests/odata-json-tests.js
@@ -8,12 +8,12 @@
 
     // DATAJS INTERNAL START
     djstest.addTest(function isArrayTest() {
-        djstest.assert(datajs.isArray([]));
-        djstest.assert(datajs.isArray([1, 2]));
-        djstest.assert(!datajs.isArray({}));
-        djstest.assert(!datajs.isArray("1,2,3,4"));
-        djstest.assert(!datajs.isArray());
-        djstest.assert(!datajs.isArray(null));
+        djstest.assert(odatajs.isArray([]));
+        djstest.assert(odatajs.isArray([1, 2]));
+        djstest.assert(!odatajs.isArray({}));
+        djstest.assert(!odatajs.isArray("1,2,3,4"));
+        djstest.assert(!odatajs.isArray());
+        djstest.assert(!odatajs.isArray(null));
         djstest.done();
     });
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/tests/odata-metadata-tests.js
----------------------------------------------------------------------
diff --git a/JSLib/tests/odata-metadata-tests.js b/JSLib/tests/odata-metadata-tests.js
index 85e96ed..84c6e89 100644
--- a/JSLib/tests/odata-metadata-tests.js
+++ b/JSLib/tests/odata-metadata-tests.js
@@ -411,7 +411,7 @@
 
         var i, len;
         for (i = 0, len = cases.length; i < len; i++) {
-            var doc = window.datajs.xmlParse(cases[i].i);
+            var doc = window.odatajs.xmlParse(cases[i].i);
             var schema = window.OData.parseConceptualModelElement(doc.documentElement);
             djstest.assertAreEqualDeep(schema, cases[i].e, "parseConceptualModelElement result matches target");
         }
@@ -433,7 +433,7 @@
         '      </EntityType></Schema></edmx:DataServices></edmx:Edmx>';
 
 
-        var doc = window.datajs.xmlParse(testCsdl);
+        var doc = window.odatajs.xmlParse(testCsdl);
         var schema = window.OData.parseConceptualModelElement(doc.documentElement);
 
         djstest.assertAreEqual(schema.dataServices.schema[0].term.length, 2, "schema.DataServices.Schema.Term.length === 2");
@@ -467,7 +467,7 @@
         '    </Schema></edmx:DataServices></edmx:Edmx>';
 
 
-        var doc = window.datajs.xmlParse(testCsdl);
+        var doc = window.odatajs.xmlParse(testCsdl);
         var schema = window.OData.parseConceptualModelElement(doc.documentElement);
 
         djstest.assertAreEqual(schema.dataServices.schema[0].annotations.length, 2, "Annotations number");

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/tests/odata-read-crossdomain-functional-tests.js
----------------------------------------------------------------------
diff --git a/JSLib/tests/odata-read-crossdomain-functional-tests.js b/JSLib/tests/odata-read-crossdomain-functional-tests.js
index 7d1a013..2af4e97 100644
--- a/JSLib/tests/odata-read-crossdomain-functional-tests.js
+++ b/JSLib/tests/odata-read-crossdomain-functional-tests.js
@@ -105,7 +105,7 @@
     var dataCacheReadRangeSingleTest = function (params) {
         var options = { name: "cache", source: params.feed, pageSize: params.pageSize, prefetchSize: params.prefetchSize, cacheSize: params.cacheSize };
         OData.defaultHttpClient.enableJsonpCallback = true;
-        var cache = datajs.createDataCache(options);
+        var cache = odatajs.createDataCache(options);
         cache.readRange(params.skip, params.take).then(function (data) {
             validateExpectedRange(cache, data, params.feed, params.skip, params.take);
         }, unexpectedErrorHandler);

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/tests/odata-xml-tests.js
----------------------------------------------------------------------
diff --git a/JSLib/tests/odata-xml-tests.js b/JSLib/tests/odata-xml-tests.js
index 64605e8..9eb936e 100644
--- a/JSLib/tests/odata-xml-tests.js
+++ b/JSLib/tests/odata-xml-tests.js
@@ -24,7 +24,7 @@
 
         var i, len;
         for (i = 0, len = tests.length; i < len; i++) {
-            var actual = datajs.getURIInfo(tests[i].input);
+            var actual = odatajs.getURIInfo(tests[i].input);
             djstest.assertAreEqualDeep(actual, tests[i].expected, "test " + i + "didn't return the expected URI parts");
         }
         djstest.done();
@@ -40,7 +40,7 @@
 
         var i, len;
         for (i = 0, len = tests.length; i < len; i++) {
-            var actual = datajs.normalizeURICase(tests[i].uri, tests[i].base);
+            var actual = odatajs.normalizeURICase(tests[i].uri, tests[i].base);
             djstest.assertAreEqual(actual, tests[i].expected, "test " + i + "didn't return the expected URI");
         }
         djstest.done();
@@ -68,7 +68,7 @@
 
         var i, len;
         for (i = 0, len = tests.length; i < len; i++) {
-            var actual = datajs.normalizeURI(tests[i].uri, tests[i].base);
+            var actual = odatajs.normalizeURI(tests[i].uri, tests[i].base);
             djstest.assertAreEqual(actual, tests[i].expected, "test " + i + "didn't return the expected normalized URI");
         }
         djstest.done();
@@ -76,7 +76,7 @@
 
     djstest.addTest(function xmlParseTest() {
         var xml = '<root xmlns:n1="http://namespace1" xml:base="http://base.org" />';
-        var root = datajs.xmlParse(xml);
+        var root = odatajs.xmlParse(xml);
         djstest.assert(root, "xml._parse didn't return a xml dom object");
         djstest.done();
     });
@@ -88,12 +88,12 @@
            <element base=\"this is not a xml base attribute\" /> \r\n\
          </root>\r\n";
 
-        var doc = datajs.xmlParse(xml);
-        var root = datajs.xmlFirstChildElement(doc);
-        var child = datajs.xmlFirstChildElement(root);
+        var doc = odatajs.xmlParse(xml);
+        var root = odatajs.xmlFirstChildElement(doc);
+        var child = odatajs.xmlFirstChildElement(root);
 
-        djstest.assertAreEqual(datajs.xmlBaseURI(root), "http://base.org", "xml._baseURI didn't return the expected value");
-        djstest.assert(!datajs.xmlBaseURI(child), "xml._baseURI returned a value when it wasn't expected");
+        djstest.assertAreEqual(odatajs.xmlBaseURI(root), "http://base.org", "xml._baseURI didn't return the expected value");
+        djstest.assert(!odatajs.xmlBaseURI(child), "xml._baseURI returned a value when it wasn't expected");
         djstest.done();
     });
 
@@ -104,13 +104,13 @@
         <element attribute=\"value\" n1:nsAttribute=\"nsValue\" /> \r\n\
      </root> \r\n";
 
-        var doc = datajs.xmlParse(xml);
-        var root = datajs.xmlFirstChildElement(doc);
-        var child = datajs.xmlFirstChildElement(root);
+        var doc = odatajs.xmlParse(xml);
+        var root = odatajs.xmlFirstChildElement(doc);
+        var child = odatajs.xmlFirstChildElement(root);
 
-        djstest.assertAreEqual(datajs.xmlAttributeValue(child, "attribute"), "value", "xml._attribute didn't return the expected value for attribute");
-        djstest.assertAreEqual(datajs.xmlAttributeValue(child, "nsAttribute", "http://namespace1"), "nsValue", "xml._attribute didn't return the expected value for nsAttribute");
-        djstest.assert(!datajs.xmlAttributeValue(child, "nsAttribute"), "xml._attribute returned a value for nsAttribute without specifying a namespace");
+        djstest.assertAreEqual(odatajs.xmlAttributeValue(child, "attribute"), "value", "xml._attribute didn't return the expected value for attribute");
+        djstest.assertAreEqual(odatajs.xmlAttributeValue(child, "nsAttribute", "http://namespace1"), "nsValue", "xml._attribute didn't return the expected value for nsAttribute");
+        djstest.assert(!odatajs.xmlAttributeValue(child, "nsAttribute"), "xml._attribute returned a value for nsAttribute without specifying a namespace");
 
         djstest.done();
     });
@@ -118,10 +118,10 @@
     djstest.addTest(function xmlLocalNameTest() {
         var xml = "<root xmlns:n1=\"http://namespace1\" /> \r\n";
 
-        var doc = datajs.xmlParse(xml);
-        var root = datajs.xmlFirstChildElement(doc);
+        var doc = odatajs.xmlParse(xml);
+        var root = odatajs.xmlFirstChildElement(doc);
 
-        djstest.assertAreEqual(datajs.xmlLocalName(root), "root", "xml._localName didn't return the expected localName of the root element");
+        djstest.assertAreEqual(odatajs.xmlLocalName(root), "root", "xml._localName didn't return the expected localName of the root element");
         djstest.done();
     });
 
@@ -134,11 +134,11 @@
          </root>\r\n";
 
 
-        var doc = datajs.xmlParse(xml);
-        var root = datajs.xmlFirstChildElement(doc);
-        var child = datajs.xmlFirstChildElement(root);
+        var doc = odatajs.xmlParse(xml);
+        var root = odatajs.xmlFirstChildElement(doc);
+        var child = odatajs.xmlFirstChildElement(root);
 
-        djstest.assertAreEqual(datajs.xmlLocalName(child), "element1", "xml.firstElement returned didn't return the expected element");
+        djstest.assertAreEqual(odatajs.xmlLocalName(child), "element1", "xml.firstElement returned didn't return the expected element");
         djstest.done();
     });
 
@@ -159,14 +159,14 @@
 
         var actual = [];
 
-        var doc = datajs.xmlParse(xml);
-        var root = datajs.xmlFirstChildElement(doc);
+        var doc = odatajs.xmlParse(xml);
+        var root = odatajs.xmlFirstChildElement(doc);
     
-        datajs.xmlChildElements(root, function (child) {
+        odatajs.xmlChildElements(root, function (child) {
             djstest.log("in child elements callback");
             actual.push({
-                localName: datajs.xmlLocalName(child),
-                nsURI: datajs.xmlNamespaceURI(child)
+                localName: odatajs.xmlLocalName(child),
+                nsURI: odatajs.xmlNamespaceURI(child)
             });
         });
 
@@ -190,15 +190,15 @@
 
         var actual = {};
 
-        var doc = datajs.xmlParse(xml);
-        var root = datajs.xmlFirstChildElement(doc);
+        var doc = odatajs.xmlParse(xml);
+        var root = odatajs.xmlFirstChildElement(doc);
 
-        datajs.xmlAttributes(root, function (attribute) {
+        odatajs.xmlAttributes(root, function (attribute) {
             djstest.log("in child elements callback");
-            var localName = datajs.xmlLocalName(attribute);
+            var localName = odatajs.xmlLocalName(attribute);
             actual[localName] = {
                 localName: localName, 
-                nsURI: datajs.xmlNamespaceURI(attribute),
+                nsURI: odatajs.xmlNamespaceURI(attribute),
                 value: attribute.value
             };
         });
@@ -224,7 +224,7 @@
 
         var i, len;
         for (i = 0, len = tests.length; i < len; i++) {
-            var result = datajs.hasLeadingOrTrailingWhitespace(tests[i].t);
+            var result = odatajs.hasLeadingOrTrailingWhitespace(tests[i].t);
             djstest.assertAreEqual(result, tests[i].r, "match for " + tests[i].t);
         }
 
@@ -247,8 +247,8 @@
         var i, len;
         for (i = 0, len = tests.length; i < len; i++) {
             var test = tests[i];
-            var doc = datajs.xmlParse(test.t);
-            var actual = datajs.xmlInnerText(doc);
+            var doc = odatajs.xmlParse(test.t);
+            var actual = odatajs.xmlInnerText(doc);
             djstest.assertAreEqual(actual, test.r, "test for [" + test.t + "]");
         }
 


[2/5] [OLINGO-407] JS- V4's window.OData is not defined yet: part 1 - change window.datajs.V4 into window.odatajs (while V3: window.datajs).

Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/datajs/tests/e2etest/datajs-1.1.2.js
----------------------------------------------------------------------
diff --git a/datajs/tests/e2etest/datajs-1.1.2.js b/datajs/tests/e2etest/datajs-1.1.2.js
new file mode 100644
index 0000000..5040efc
--- /dev/null
+++ b/datajs/tests/e2etest/datajs-1.1.2.js
@@ -0,0 +1,10577 @@
+// Copyright (c) Microsoft Open Technologies, Inc.  All rights reserved.
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal  in the Software without restriction, including without limitation the rights  to use, copy,
+// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+// WARRANTIES OF MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+// odatajs.js
+
+(function (window, undefined) {
+
+    var datajs = window.odatajs || {};
+    var odata = window.OData || {};
+
+    // AMD support
+    if (typeof define === 'function' && define.amd) {
+        define('datajs', datajs);
+        define('OData', odata);
+    } else {
+        window.odatajs = datajs;
+        window.OData = odata;
+    }
+
+    odatajs.version = {
+        major: 1,
+        minor: 1,
+        build: 1
+    };
+
+
+    var activeXObject = function (progId) {
+        /// <summary>Creates a new ActiveXObject from the given progId.</summary>
+        /// <param name="progId" type="String" mayBeNull="false" optional="false">
+        ///    ProgId string of the desired ActiveXObject.
+        /// </param>
+        /// <remarks>
+        ///    This function throws whatever exception might occur during the creation
+        ///    of the ActiveXObject.
+        /// </remarks>
+        /// <returns type="Object">
+        ///     The ActiveXObject instance. Null if ActiveX is not supported by the
+        ///     browser.
+        /// </returns>
+        if (window.ActiveXObject) {
+            return new window.ActiveXObject(progId);
+        }
+        return null;
+    };
+
+    var assigned = function (value) {
+        /// <summary>Checks whether the specified value is different from null and undefined.</summary>
+        /// <param name="value" mayBeNull="true" optional="true">Value to check.</param>
+        /// <returns type="Boolean">true if the value is assigned; false otherwise.</returns>
+        return value !== null && value !== undefined;
+    };
+
+    var contains = function (arr, item) {
+        /// <summary>Checks whether the specified item is in the array.</summary>
+        /// <param name="arr" type="Array" optional="false" mayBeNull="false">Array to check in.</param>
+        /// <param name="item">Item to look for.</param>
+        /// <returns type="Boolean">true if the item is contained, false otherwise.</returns>
+
+        var i, len;
+        for (i = 0, len = arr.length; i < len; i++) {
+            if (arr[i] === item) {
+                return true;
+            }
+        }
+
+        return false;
+    };
+
+    var defined = function (a, b) {
+        /// <summary>Given two values, picks the first one that is not undefined.</summary>
+        /// <param name="a">First value.</param>
+        /// <param name="b">Second value.</param>
+        /// <returns>a if it's a defined value; else b.</returns>
+        return (a !== undefined) ? a : b;
+    };
+
+    var delay = function (callback) {
+        /// <summary>Delays the invocation of the specified function until execution unwinds.</summary>
+        /// <param name="callback" type="Function">Callback function.</param>
+        if (arguments.length === 1) {
+            window.setTimeout(callback, 0);
+            return;
+        }
+
+        var args = Array.prototype.slice.call(arguments, 1);
+        window.setTimeout(function () {
+            callback.apply(this, args);
+        }, 0);
+    };
+
+
+    var extend = function (target, values) {
+        /// <summary>Extends the target with the specified values.</summary>
+        /// <param name="target" type="Object">Object to add properties to.</param>
+        /// <param name="values" type="Object">Object with properties to add into target.</param>
+        /// <returns type="Object">The target object.</returns>
+
+        for (var name in values) {
+            target[name] = values[name];
+        }
+
+        return target;
+    };
+
+    var find = function (arr, callback) {
+        /// <summary>Returns the first item in the array that makes the callback function true.</summary>
+        /// <param name="arr" type="Array" optional="false" mayBeNull="true">Array to check in.</param>
+        /// <param name="callback" type="Function">Callback function to invoke once per item in the array.</param>
+        /// <returns>The first item that makes the callback return true; null otherwise or if the array is null.</returns>
+
+        if (arr) {
+            var i, len;
+            for (i = 0, len = arr.length; i < len; i++) {
+                if (callback(arr[i])) {
+                    return arr[i];
+                }
+            }
+        }
+        return null;
+    };
+
+    var isArray = function (value) {
+        /// <summary>Checks whether the specified value is an array object.</summary>
+        /// <param name="value">Value to check.</param>
+        /// <returns type="Boolean">true if the value is an array object; false otherwise.</returns>
+
+        return Object.prototype.toString.call(value) === "[object Array]";
+    };
+
+    var isDate = function (value) {
+        /// <summary>Checks whether the specified value is a Date object.</summary>
+        /// <param name="value">Value to check.</param>
+        /// <returns type="Boolean">true if the value is a Date object; false otherwise.</returns>
+
+        return Object.prototype.toString.call(value) === "[object Date]";
+    };
+
+    var isObject = function (value) {
+        /// <summary>Tests whether a value is an object.</summary>
+        /// <param name="value">Value to test.</param>
+        /// <remarks>
+        ///     Per javascript rules, null and array values are objects and will cause this function to return true.
+        /// </remarks>
+        /// <returns type="Boolean">True is the value is an object; false otherwise.</returns>
+
+        return typeof value === "object";
+    };
+
+    var parseInt10 = function (value) {
+        /// <summary>Parses a value in base 10.</summary>
+        /// <param name="value" type="String">String value to parse.</param>
+        /// <returns type="Number">The parsed value, NaN if not a valid value.</returns>
+
+        return parseInt(value, 10);
+    };
+
+    var renameProperty = function (obj, oldName, newName) {
+        /// <summary>Renames a property in an object.</summary>
+        /// <param name="obj" type="Object">Object in which the property will be renamed.</param>
+        /// <param name="oldName" type="String">Name of the property that will be renamed.</param>
+        /// <param name="newName" type="String">New name of the property.</param>
+        /// <remarks>
+        ///    This function will not do anything if the object doesn't own a property with the specified old name.
+        /// </remarks>
+
+        if (obj.hasOwnProperty(oldName)) {
+            obj[newName] = obj[oldName];
+            delete obj[oldName];
+        }
+    };
+
+    var throwErrorCallback = function (error) {
+        /// <summary>Default error handler.</summary>
+        /// <param name="error" type="Object">Error to handle.</param>
+        throw error;
+    };
+
+    var trimString = function (str) {
+        /// <summary>Removes leading and trailing whitespaces from a string.</summary>
+        /// <param name="str" type="String" optional="false" mayBeNull="false">String to trim</param>
+        /// <returns type="String">The string with no leading or trailing whitespace.</returns>
+
+        if (str.trim) {
+            return str.trim();
+        }
+
+        return str.replace(/^\s+|\s+$/g, '');
+    };
+
+    var undefinedDefault = function (value, defaultValue) {
+        /// <summary>Returns a default value in place of undefined.</summary>
+        /// <param name="value" mayBeNull="true" optional="true">Value to check.</param>
+        /// <param name="defaultValue">Value to return if value is undefined.</param>
+        /// <returns>value if it's defined; defaultValue otherwise.</returns>
+        /// <remarks>
+        /// This should only be used for cases where falsy values are valid;
+        /// otherwise the pattern should be 'x = (value) ? value : defaultValue;'.
+        /// </remarks>
+        return (value !== undefined) ? value : defaultValue;
+    };
+
+    // Regular expression that splits a uri into its components:
+    // 0 - is the matched string.
+    // 1 - is the scheme.
+    // 2 - is the authority.
+    // 3 - is the path.
+    // 4 - is the query.
+    // 5 - is the fragment.
+    var uriRegEx = /^([^:\/?#]+:)?(\/\/[^\/?#]*)?([^?#:]+)?(\?[^#]*)?(#.*)?/;
+    var uriPartNames = ["scheme", "authority", "path", "query", "fragment"];
+
+    var getURIInfo = function (uri) {
+        /// <summary>Gets information about the components of the specified URI.</summary>
+        /// <param name="uri" type="String">URI to get information from.</param>
+        /// <returns type="Object">
+        /// An object with an isAbsolute flag and part names (scheme, authority, etc.) if available.
+        /// </returns>
+
+        var result = { isAbsolute: false };
+
+        if (uri) {
+            var matches = uriRegEx.exec(uri);
+            if (matches) {
+                var i, len;
+                for (i = 0, len = uriPartNames.length; i < len; i++) {
+                    if (matches[i + 1]) {
+                        result[uriPartNames[i]] = matches[i + 1];
+                    }
+                }
+            }
+            if (result.scheme) {
+                result.isAbsolute = true;
+            }
+        }
+
+        return result;
+    };
+
+    var getURIFromInfo = function (uriInfo) {
+        /// <summary>Builds a URI string from its components.</summary>
+        /// <param name="uriInfo" type="Object"> An object with uri parts (scheme, authority, etc.).</param>
+        /// <returns type="String">URI string.</returns>
+
+        return "".concat(
+            uriInfo.scheme || "",
+            uriInfo.authority || "",
+            uriInfo.path || "",
+            uriInfo.query || "",
+            uriInfo.fragment || "");
+    };
+
+    // Regular expression that splits a uri authority into its subcomponents:
+    // 0 - is the matched string.
+    // 1 - is the userinfo subcomponent.
+    // 2 - is the host subcomponent.
+    // 3 - is the port component.
+    var uriAuthorityRegEx = /^\/{0,2}(?:([^@]*)@)?([^:]+)(?::{1}(\d+))?/;
+
+    // Regular expression that matches percentage enconded octects (i.e %20 or %3A);
+    var pctEncodingRegEx = /%[0-9A-F]{2}/ig;
+
+    var normalizeURICase = function (uri) {
+        /// <summary>Normalizes the casing of a URI.</summary>
+        /// <param name="uri" type="String">URI to normalize, absolute or relative.</param>
+        /// <returns type="String">The URI normalized to lower case.</returns>
+
+        var uriInfo = getURIInfo(uri);
+        var scheme = uriInfo.scheme;
+        var authority = uriInfo.authority;
+
+        if (scheme) {
+            uriInfo.scheme = scheme.toLowerCase();
+            if (authority) {
+                var matches = uriAuthorityRegEx.exec(authority);
+                if (matches) {
+                    uriInfo.authority = "//" +
+                    (matches[1] ? matches[1] + "@" : "") +
+                    (matches[2].toLowerCase()) +
+                    (matches[3] ? ":" + matches[3] : "");
+                }
+            }
+        }
+
+        uri = getURIFromInfo(uriInfo);
+
+        return uri.replace(pctEncodingRegEx, function (str) {
+            return str.toLowerCase();
+        });
+    };
+
+    var normalizeURI = function (uri, base) {
+        /// <summary>Normalizes a possibly relative URI with a base URI.</summary>
+        /// <param name="uri" type="String">URI to normalize, absolute or relative.</param>
+        /// <param name="base" type="String" mayBeNull="true">Base URI to compose with.</param>
+        /// <returns type="String">The composed URI if relative; the original one if absolute.</returns>
+
+        if (!base) {
+            return uri;
+        }
+
+        var uriInfo = getURIInfo(uri);
+        if (uriInfo.isAbsolute) {
+            return uri;
+        }
+
+        var baseInfo = getURIInfo(base);
+        var normInfo = {};
+        var path;
+
+        if (uriInfo.authority) {
+            normInfo.authority = uriInfo.authority;
+            path = uriInfo.path;
+            normInfo.query = uriInfo.query;
+        } else {
+            if (!uriInfo.path) {
+                path = baseInfo.path;
+                normInfo.query = uriInfo.query || baseInfo.query;
+            } else {
+                if (uriInfo.path.charAt(0) === '/') {
+                    path = uriInfo.path;
+                } else {
+                    path = mergeUriPathWithBase(uriInfo.path, baseInfo.path);
+                }
+                normInfo.query = uriInfo.query;
+            }
+            normInfo.authority = baseInfo.authority;
+        }
+
+        normInfo.path = removeDotsFromPath(path);
+
+        normInfo.scheme = baseInfo.scheme;
+        normInfo.fragment = uriInfo.fragment;
+
+        return getURIFromInfo(normInfo);
+    };
+
+    var mergeUriPathWithBase = function (uriPath, basePath) {
+        /// <summary>Merges the path of a relative URI and a base URI.</summary>
+        /// <param name="uriPath" type="String>Relative URI path.</param>
+        /// <param name="basePath" type="String">Base URI path.</param>
+        /// <returns type="String">A string with the merged path.</returns>
+
+        var path = "/";
+        var end;
+
+        if (basePath) {
+            end = basePath.lastIndexOf("/");
+            path = basePath.substring(0, end);
+
+            if (path.charAt(path.length - 1) !== "/") {
+                path = path + "/";
+            }
+        }
+
+        return path + uriPath;
+    };
+
+    var removeDotsFromPath = function (path) {
+        /// <summary>Removes the special folders . and .. from a URI's path.</summary>
+        /// <param name="path" type="string">URI path component.</param>
+        /// <returns type="String">Path without any . and .. folders.</returns>
+
+        var result = "";
+        var segment = "";
+        var end;
+
+        while (path) {
+            if (path.indexOf("..") === 0 || path.indexOf(".") === 0) {
+                path = path.replace(/^\.\.?\/?/g, "");
+            } else if (path.indexOf("/..") === 0) {
+                path = path.replace(/^\/\..\/?/g, "/");
+                end = result.lastIndexOf("/");
+                if (end === -1) {
+                    result = "";
+                } else {
+                    result = result.substring(0, end);
+                }
+            } else if (path.indexOf("/.") === 0) {
+                path = path.replace(/^\/\.\/?/g, "/");
+            } else {
+                segment = path;
+                end = path.indexOf("/", 1);
+                if (end !== -1) {
+                    segment = path.substring(0, end);
+                }
+                result = result + segment;
+                path = path.replace(segment, "");
+            }
+        }
+        return result;
+    };
+
+    var convertByteArrayToHexString = function (str) {
+        var arr = [];
+        if (window.atob === undefined) {
+            arr = decodeBase64(str);
+        } else {
+            var binaryStr = window.atob(str);
+            for (var i = 0; i < binaryStr.length; i++) {
+                arr.push(binaryStr.charCodeAt(i));
+            }
+        }
+        var hexValue = "";
+        var hexValues = "0123456789ABCDEF";
+        for (var j = 0; j < arr.length; j++) {
+            var t = arr[j];
+            hexValue += hexValues[t >> 4];
+            hexValue += hexValues[t & 0x0F];
+        }
+        return hexValue;
+    };
+
+    var decodeBase64 = function (str) {
+        var binaryString = "";
+        for (var i = 0; i < str.length; i++) {
+            var base65IndexValue = getBase64IndexValue(str[i]);
+            var binaryValue = "";
+            if (base65IndexValue !== null) {
+                binaryValue = base65IndexValue.toString(2);
+                binaryString += addBase64Padding(binaryValue);
+            }
+        }
+        var byteArray = [];
+        var numberOfBytes = parseInt(binaryString.length / 8, 10);
+        for (i = 0; i < numberOfBytes; i++) {
+            var intValue = parseInt(binaryString.substring(i * 8, (i + 1) * 8), 2);
+            byteArray.push(intValue);
+        }
+        return byteArray;
+    };
+
+    var getBase64IndexValue = function (character) {
+        var asciiCode = character.charCodeAt(0);
+        var asciiOfA = 65;
+        var differenceBetweenZanda = 6;
+        if (asciiCode >= 65 && asciiCode <= 90) {           // between "A" and "Z" inclusive
+            return asciiCode - asciiOfA;
+        } else if (asciiCode >= 97 && asciiCode <= 122) {   // between 'a' and 'z' inclusive
+            return asciiCode - asciiOfA - differenceBetweenZanda;
+        } else if (asciiCode >= 48 && asciiCode <= 57) {    // between '0' and '9' inclusive
+            return asciiCode + 4;
+        } else if (character == "+") {
+            return 62;
+        } else if (character == "/") {
+            return 63;
+        } else {
+            return null;
+        }
+    };
+
+    var addBase64Padding = function (binaryString) {
+        while (binaryString.length < 6) {
+            binaryString = "0" + binaryString;
+        }
+        return binaryString;
+    };
+
+
+    // URI prefixes to generate smaller code.
+    var http = "http://";
+    var w3org = http + "www.w3.org/";               // http://www.w3.org/
+
+    var xhtmlNS = w3org + "1999/xhtml";             // http://www.w3.org/1999/xhtml
+    var xmlnsNS = w3org + "2000/xmlns/";            // http://www.w3.org/2000/xmlns/
+    var xmlNS = w3org + "XML/1998/namespace";       // http://www.w3.org/XML/1998/namespace
+
+    var mozillaParserErroNS = http + "www.mozilla.org/newlayout/xml/parsererror.xml";
+
+    var hasLeadingOrTrailingWhitespace = function (text) {
+        /// <summary>Checks whether the specified string has leading or trailing spaces.</summary>
+        /// <param name="text" type="String">String to check.</param>
+        /// <returns type="Boolean">true if text has any leading or trailing whitespace; false otherwise.</returns>
+
+        var re = /(^\s)|(\s$)/;
+        return re.test(text);
+    };
+
+    var isWhitespace = function (text) {
+        /// <summary>Determines whether the specified text is empty or whitespace.</summary>
+        /// <param name="text" type="String">Value to inspect.</param>
+        /// <returns type="Boolean">true if the text value is empty or all whitespace; false otherwise.</returns>
+
+        var ws = /^\s*$/;
+        return text === null || ws.test(text);
+    };
+
+    var isWhitespacePreserveContext = function (domElement) {
+        /// <summary>Determines whether the specified element has xml:space='preserve' applied.</summary>
+        /// <param name="domElement">Element to inspect.</param>
+        /// <returns type="Boolean">Whether xml:space='preserve' is in effect.</returns>
+
+        while (domElement !== null && domElement.nodeType === 1) {
+            var val = xmlAttributeValue(domElement, "space", xmlNS);
+            if (val === "preserve") {
+                return true;
+            } else if (val === "default") {
+                break;
+            } else {
+                domElement = domElement.parentNode;
+            }
+        }
+
+        return false;
+    };
+
+    var isXmlNSDeclaration = function (domAttribute) {
+        /// <summary>Determines whether the attribute is a XML namespace declaration.</summary>
+        /// <param name="domAttribute">Element to inspect.</param>
+        /// <returns type="Boolean">
+        ///    True if the attribute is a namespace declaration (its name is 'xmlns' or starts with 'xmlns:'; false otherwise.
+        /// </returns>
+
+        var nodeName = domAttribute.nodeName;
+        return nodeName == "xmlns" || nodeName.indexOf("xmlns:") === 0;
+    };
+
+    var safeSetProperty = function (obj, name, value) {
+        /// <summary>Safely set as property in an object by invoking obj.setProperty.</summary>
+        /// <param name="obj">Object that exposes a setProperty method.</param>
+        /// <param name="name" type="String" mayBeNull="false">Property name.</param>
+        /// <param name="value">Property value.</param>
+
+        try {
+            obj.setProperty(name, value);
+        } catch (_) { }
+    };
+
+    var msXmlDom3 = function () {
+        /// <summary>Creates an configures new MSXML 3.0 ActiveX object.</summary>
+        /// <remakrs>
+        ///    This function throws any exception that occurs during the creation
+        ///    of the MSXML 3.0 ActiveX object.
+        /// <returns type="Object">New MSXML 3.0 ActiveX object.</returns>
+
+        var msxml3 = activeXObject("Msxml2.DOMDocument.3.0");
+        if (msxml3) {
+            safeSetProperty(msxml3, "ProhibitDTD", true);
+            safeSetProperty(msxml3, "MaxElementDepth", 256);
+            safeSetProperty(msxml3, "AllowDocumentFunction", false);
+            safeSetProperty(msxml3, "AllowXsltScript", false);
+        }
+        return msxml3;
+    };
+
+    var msXmlDom = function () {
+        /// <summary>Creates an configures new MSXML 6.0 or MSXML 3.0 ActiveX object.</summary>
+        /// <remakrs>
+        ///    This function will try to create a new MSXML 6.0 ActiveX object. If it fails then
+        ///    it will fallback to create a new MSXML 3.0 ActiveX object. Any exception that
+        ///    happens during the creation of the MSXML 6.0 will be handled by the function while
+        ///    the ones that happend during the creation of the MSXML 3.0 will be thrown.
+        /// <returns type="Object">New MSXML 3.0 ActiveX object.</returns>
+
+        try {
+            var msxml = activeXObject("Msxml2.DOMDocument.6.0");
+            if (msxml) {
+                msxml.async = true;
+            }
+            return msxml;
+        } catch (_) {
+            return msXmlDom3();
+        }
+    };
+
+    var msXmlParse = function (text) {
+        /// <summary>Parses an XML string using the MSXML DOM.</summary>
+        /// <remakrs>
+        ///    This function throws any exception that occurs during the creation
+        ///    of the MSXML ActiveX object.  It also will throw an exception
+        ///    in case of a parsing error.
+        /// <returns type="Object">New MSXML DOMDocument node representing the parsed XML string.</returns>
+
+        var dom = msXmlDom();
+        if (!dom) {
+            return null;
+        }
+
+        dom.loadXML(text);
+        var parseError = dom.parseError;
+        if (parseError.errorCode !== 0) {
+            xmlThrowParserError(parseError.reason, parseError.srcText, text);
+        }
+        return dom;
+    };
+
+    var xmlThrowParserError = function (exceptionOrReason, srcText, errorXmlText) {
+        /// <summary>Throws a new exception containing XML parsing error information.</summary>
+        /// <param name="exceptionOrReason">
+        ///    String indicatin the reason of the parsing failure or
+        ///    Object detailing the parsing error.
+        /// </param>
+        /// <param name="srcText" type="String">
+        ///    String indicating the part of the XML string that caused the parsing error.
+        /// </param>
+        /// <param name="errorXmlText" type="String">XML string for wich the parsing failed.</param>
+
+        if (typeof exceptionOrReason === "string") {
+            exceptionOrReason = { message: exceptionOrReason };
+        }
+        throw extend(exceptionOrReason, { srcText: srcText || "", errorXmlText: errorXmlText || "" });
+    };
+
+    var xmlParse = function (text) {
+        /// <summary>Returns an XML DOM document from the specified text.</summary>
+        /// <param name="text" type="String">Document text.</param>
+        /// <returns>XML DOM document.</returns>
+        /// <remarks>This function will throw an exception in case of a parse error.</remarks>
+
+        var domParser = window.DOMParser && new window.DOMParser();
+        var dom;
+
+        if (!domParser) {
+            dom = msXmlParse(text);
+            if (!dom) {
+                xmlThrowParserError("XML DOM parser not supported");
+            }
+            return dom;
+        }
+
+        try {
+            dom = domParser.parseFromString(text, "text/xml");
+        } catch (e) {
+            xmlThrowParserError(e, "", text);
+        }
+
+        var element = dom.documentElement;
+        var nsURI = element.namespaceURI;
+        var localName = xmlLocalName(element);
+
+        // Firefox reports errors by returing the DOM for an xml document describing the problem.
+        if (localName === "parsererror" && nsURI === mozillaParserErroNS) {
+            var srcTextElement = xmlFirstChildElement(element, mozillaParserErroNS, "sourcetext");
+            var srcText = srcTextElement ? xmlNodeValue(srcTextElement) : "";
+            xmlThrowParserError(xmlInnerText(element) || "", srcText, text);
+        }
+
+        // Chrome (and maybe other webkit based browsers) report errors by injecting a header with an error message.
+        // The error may be localized, so instead we simply check for a header as the
+        // top element or descendant child of the document.
+        if (localName === "h3" && nsURI === xhtmlNS || xmlFirstDescendantElement(element, xhtmlNS, "h3")) {
+            var reason = "";
+            var siblings = [];
+            var cursor = element.firstChild;
+            while (cursor) {
+                if (cursor.nodeType === 1) {
+                    reason += xmlInnerText(cursor) || "";
+                }
+                siblings.push(cursor.nextSibling);
+                cursor = cursor.firstChild || siblings.shift();
+            }
+            reason += xmlInnerText(element) || "";
+            xmlThrowParserError(reason, "", text);
+        }
+
+        return dom;
+    };
+
+    var xmlQualifiedName = function (prefix, name) {
+        /// <summary>Builds a XML qualified name string in the form of "prefix:name".</summary>
+        /// <param name="prefix" type="String" maybeNull="true">Prefix string.</param>
+        /// <param name="name" type="String">Name string to qualify with the prefix.</param>
+        /// <returns type="String">Qualified name.</returns>
+
+        return prefix ? prefix + ":" + name : name;
+    };
+
+    var xmlAppendText = function (domNode, textNode) {
+        /// <summary>Appends a text node into the specified DOM element node.</summary>
+        /// <param name="domNode">DOM node for the element.</param>
+        /// <param name="text" type="String" mayBeNull="false">Text to append as a child of element.</param>
+        if (hasLeadingOrTrailingWhitespace(textNode.data)) {
+            var attr = xmlAttributeNode(domNode, xmlNS, "space");
+            if (!attr) {
+                attr = xmlNewAttribute(domNode.ownerDocument, xmlNS, xmlQualifiedName("xml", "space"));
+                xmlAppendChild(domNode, attr);
+            }
+            attr.value = "preserve";
+        }
+        domNode.appendChild(textNode);
+        return domNode;
+    };
+
+    var xmlAttributes = function (element, onAttributeCallback) {
+        /// <summary>Iterates through the XML element's attributes and invokes the callback function for each one.</summary>
+        /// <param name="element">Wrapped element to iterate over.</param>
+        /// <param name="onAttributeCallback" type="Function">Callback function to invoke with wrapped attribute nodes.</param>
+
+        var attributes = element.attributes;
+        var i, len;
+        for (i = 0, len = attributes.length; i < len; i++) {
+            onAttributeCallback(attributes.item(i));
+        }
+    };
+
+    var xmlAttributeValue = function (domNode, localName, nsURI) {
+        /// <summary>Returns the value of a DOM element's attribute.</summary>
+        /// <param name="domNode">DOM node for the owning element.</param>
+        /// <param name="localName" type="String">Local name of the attribute.</param>
+        /// <param name="nsURI" type="String">Namespace URI of the attribute.</param>
+        /// <returns type="String" maybeNull="true">The attribute value, null if not found.</returns>
+
+        var attribute = xmlAttributeNode(domNode, localName, nsURI);
+        return attribute ? xmlNodeValue(attribute) : null;
+    };
+
+    var xmlAttributeNode = function (domNode, localName, nsURI) {
+        /// <summary>Gets an attribute node from a DOM element.</summary>
+        /// <param name="domNode">DOM node for the owning element.</param>
+        /// <param name="localName" type="String">Local name of the attribute.</param>
+        /// <param name="nsURI" type="String">Namespace URI of the attribute.</param>
+        /// <returns>The attribute node, null if not found.</returns>
+
+        var attributes = domNode.attributes;
+        if (attributes.getNamedItemNS) {
+            return attributes.getNamedItemNS(nsURI || null, localName);
+        }
+
+        return attributes.getQualifiedItem(localName, nsURI) || null;
+    };
+
+    var xmlBaseURI = function (domNode, baseURI) {
+        /// <summary>Gets the value of the xml:base attribute on the specified element.</summary>
+        /// <param name="domNode">Element to get xml:base attribute value from.</param>
+        /// <param name="baseURI" mayBeNull="true" optional="true">Base URI used to normalize the value of the xml:base attribute.</param>
+        /// <returns type="String">Value of the xml:base attribute if found; the baseURI or null otherwise.</returns>
+
+        var base = xmlAttributeNode(domNode, "base", xmlNS);
+        return (base ? normalizeURI(base.value, baseURI) : baseURI) || null;
+    };
+
+
+    var xmlChildElements = function (domNode, onElementCallback) {
+        /// <summary>Iterates through the XML element's child DOM elements and invokes the callback function for each one.</summary>
+        /// <param name="element">DOM Node containing the DOM elements to iterate over.</param>
+        /// <param name="onElementCallback" type="Function">Callback function to invoke for each child DOM element.</param>
+
+        xmlTraverse(domNode, /*recursive*/false, function (child) {
+            if (child.nodeType === 1) {
+                onElementCallback(child);
+            }
+            // continue traversing.
+            return true;
+        });
+    };
+
+    var xmlFindElementByPath = function (root, namespaceURI, path) {
+        /// <summary>Gets the descendant element under root that corresponds to the specified path and namespace URI.</summary>
+        /// <param name="root">DOM element node from which to get the descendant element.</param>
+        /// <param name="namespaceURI" type="String">The namespace URI of the element to match.</param>
+        /// <param name="path" type="String">Path to the desired descendant element.</param>
+        /// <returns>The element specified by path and namespace URI.</returns>
+        /// <remarks>
+        ///     All the elements in the path are matched against namespaceURI.
+        ///     The function will stop searching on the first element that doesn't match the namespace and the path.
+        /// </remarks>
+
+        var parts = path.split("/");
+        var i, len;
+        for (i = 0, len = parts.length; i < len; i++) {
+            root = root && xmlFirstChildElement(root, namespaceURI, parts[i]);
+        }
+        return root || null;
+    };
+
+    var xmlFindNodeByPath = function (root, namespaceURI, path) {
+        /// <summary>Gets the DOM element or DOM attribute node under root that corresponds to the specified path and namespace URI.</summary>
+        /// <param name="root">DOM element node from which to get the descendant node.</param>
+        /// <param name="namespaceURI" type="String">The namespace URI of the node to match.</param>
+        /// <param name="path" type="String">Path to the desired descendant node.</param>
+        /// <returns>The node specified by path and namespace URI.</returns>
+        /// <remarks>
+        ///     This function will traverse the path and match each node associated to a path segement against the namespace URI.
+        ///     The traversal stops when the whole path has been exahusted or a node that doesn't belogong the specified namespace is encountered.
+        ///
+        ///     The last segment of the path may be decorated with a starting @ character to indicate that the desired node is a DOM attribute.
+        /// </remarks>
+
+        var lastSegmentStart = path.lastIndexOf("/");
+        var nodePath = path.substring(lastSegmentStart + 1);
+        var parentPath = path.substring(0, lastSegmentStart);
+
+        var node = parentPath ? xmlFindElementByPath(root, namespaceURI, parentPath) : root;
+        if (node) {
+            if (nodePath.charAt(0) === "@") {
+                return xmlAttributeNode(node, nodePath.substring(1), namespaceURI);
+            }
+            return xmlFirstChildElement(node, namespaceURI, nodePath);
+        }
+        return null;
+    };
+
+    var xmlFirstChildElement = function (domNode, namespaceURI, localName) {
+        /// <summary>Returns the first child DOM element under the specified DOM node that matches the specified namespace URI and local name.</summary>
+        /// <param name="domNode">DOM node from which the child DOM element is going to be retrieved.</param>
+        /// <param name="namespaceURI" type="String" optional="true">The namespace URI of the element to match.</param>
+        /// <param name="localName" type="String" optional="true">Name of the element to match.</param>
+        /// <returns>The node's first child DOM element that matches the specified namespace URI and local name; null otherwise.</returns>
+
+        return xmlFirstElementMaybeRecursive(domNode, namespaceURI, localName, /*recursive*/false);
+    };
+
+    var xmlFirstDescendantElement = function (domNode, namespaceURI, localName) {
+        /// <summary>Returns the first descendant DOM element under the specified DOM node that matches the specified namespace URI and local name.</summary>
+        /// <param name="domNode">DOM node from which the descendant DOM element is going to be retrieved.</param>
+        /// <param name="namespaceURI" type="String" optional="true">The namespace URI of the element to match.</param>
+        /// <param name="localName" type="String" optional="true">Name of the element to match.</param>
+        /// <returns>The node's first descendant DOM element that matches the specified namespace URI and local name; null otherwise.</returns>
+
+        if (domNode.getElementsByTagNameNS) {
+            var result = domNode.getElementsByTagNameNS(namespaceURI, localName);
+            return result.length > 0 ? result[0] : null;
+        }
+        return xmlFirstElementMaybeRecursive(domNode, namespaceURI, localName, /*recursive*/true);
+    };
+
+    var xmlFirstElementMaybeRecursive = function (domNode, namespaceURI, localName, recursive) {
+        /// <summary>Returns the first descendant DOM element under the specified DOM node that matches the specified namespace URI and local name.</summary>
+        /// <param name="domNode">DOM node from which the descendant DOM element is going to be retrieved.</param>
+        /// <param name="namespaceURI" type="String" optional="true">The namespace URI of the element to match.</param>
+        /// <param name="localName" type="String" optional="true">Name of the element to match.</param>
+        /// <param name="recursive" type="Boolean">
+        ///     True if the search should include all the descendants of the DOM node.
+        ///     False if the search should be scoped only to the direct children of the DOM node.
+        /// </param>
+        /// <returns>The node's first descendant DOM element that matches the specified namespace URI and local name; null otherwise.</returns>
+
+        var firstElement = null;
+        xmlTraverse(domNode, recursive, function (child) {
+            if (child.nodeType === 1) {
+                var isExpectedNamespace = !namespaceURI || xmlNamespaceURI(child) === namespaceURI;
+                var isExpectedNodeName = !localName || xmlLocalName(child) === localName;
+
+                if (isExpectedNamespace && isExpectedNodeName) {
+                    firstElement = child;
+                }
+            }
+            return firstElement === null;
+        });
+        return firstElement;
+    };
+
+    var xmlInnerText = function (xmlElement) {
+        /// <summary>Gets the concatenated value of all immediate child text and CDATA nodes for the specified element.</summary>
+        /// <param name="domElement">Element to get values for.</param>
+        /// <returns type="String">Text for all direct children.</returns>
+
+        var result = null;
+        var root = (xmlElement.nodeType === 9 && xmlElement.documentElement) ? xmlElement.documentElement : xmlElement;
+        var whitespaceAlreadyRemoved = root.ownerDocument.preserveWhiteSpace === false;
+        var whitespacePreserveContext;
+
+        xmlTraverse(root, false, function (child) {
+            if (child.nodeType === 3 || child.nodeType === 4) {
+                // isElementContentWhitespace indicates that this is 'ignorable whitespace',
+                // but it's not defined by all browsers, and does not honor xml:space='preserve'
+                // in some implementations.
+                //
+                // If we can't tell either way, we walk up the tree to figure out whether
+                // xml:space is set to preserve; otherwise we discard pure-whitespace.
+                //
+                // For example <a>  <b>1</b></a>. The space between <a> and <b> is usually 'ignorable'.
+                var text = xmlNodeValue(child);
+                var shouldInclude = whitespaceAlreadyRemoved || !isWhitespace(text);
+                if (!shouldInclude) {
+                    // Walk up the tree to figure out whether we are in xml:space='preserve' context
+                    // for the cursor (needs to happen only once).
+                    if (whitespacePreserveContext === undefined) {
+                        whitespacePreserveContext = isWhitespacePreserveContext(root);
+                    }
+
+                    shouldInclude = whitespacePreserveContext;
+                }
+
+                if (shouldInclude) {
+                    if (!result) {
+                        result = text;
+                    } else {
+                        result += text;
+                    }
+                }
+            }
+            // Continue traversing?
+            return true;
+        });
+        return result;
+    };
+
+    var xmlLocalName = function (domNode) {
+        /// <summary>Returns the localName of a XML node.</summary>
+        /// <param name="domNode">DOM node to get the value from.</param>
+        /// <returns type="String">localName of domNode.</returns>
+
+        return domNode.localName || domNode.baseName;
+    };
+
+    var xmlNamespaceURI = function (domNode) {
+        /// <summary>Returns the namespace URI of a XML node.</summary>
+        /// <param name="node">DOM node to get the value from.</param>
+        /// <returns type="String">Namespace URI of domNode.</returns>
+
+        return domNode.namespaceURI || null;
+    };
+
+    var xmlNodeValue = function (domNode) {
+        /// <summary>Returns the value or the inner text of a XML node.</summary>
+        /// <param name="node">DOM node to get the value from.</param>
+        /// <returns>Value of the domNode or the inner text if domNode represents a DOM element node.</returns>
+        
+        if (domNode.nodeType === 1) {
+            return xmlInnerText(domNode);
+        }
+        return domNode.nodeValue;
+    };
+
+    var xmlTraverse = function (domNode, recursive, onChildCallback) {
+        /// <summary>Walks through the descendants of the domNode and invokes a callback for each node.</summary>
+        /// <param name="domNode">DOM node whose descendants are going to be traversed.</param>
+        /// <param name="recursive" type="Boolean">
+        ///    True if the traversal should include all the descenants of the DOM node.
+        ///    False if the traversal should be scoped only to the direct children of the DOM node.
+        /// </param>
+        /// <returns type="String">Namespace URI of node.</returns>
+
+        var subtrees = [];
+        var child = domNode.firstChild;
+        var proceed = true;
+        while (child && proceed) {
+            proceed = onChildCallback(child);
+            if (proceed) {
+                if (recursive && child.firstChild) {
+                    subtrees.push(child.firstChild);
+                }
+                child = child.nextSibling || subtrees.shift();
+            }
+        }
+    };
+
+    var xmlSiblingElement = function (domNode, namespaceURI, localName) {
+        /// <summary>Returns the next sibling DOM element of the specified DOM node.</summary>
+        /// <param name="domNode">DOM node from which the next sibling is going to be retrieved.</param>
+        /// <param name="namespaceURI" type="String" optional="true">The namespace URI of the element to match.</param>
+        /// <param name="localName" type="String" optional="true">Name of the element to match.</param>
+        /// <returns>The node's next sibling DOM element, null if there is none.</returns>
+
+        var sibling = domNode.nextSibling;
+        while (sibling) {
+            if (sibling.nodeType === 1) {
+                var isExpectedNamespace = !namespaceURI || xmlNamespaceURI(sibling) === namespaceURI;
+                var isExpectedNodeName = !localName || xmlLocalName(sibling) === localName;
+
+                if (isExpectedNamespace && isExpectedNodeName) {
+                    return sibling;
+                }
+            }
+            sibling = sibling.nextSibling;
+        }
+        return null;
+    };
+
+    var xmlDom = function () {
+        /// <summary>Creates a new empty DOM document node.</summary>
+        /// <returns>New DOM document node.</returns>
+        /// <remarks>
+        ///    This function will first try to create a native DOM document using
+        ///    the browsers createDocument function.  If the browser doesn't
+        ///    support this but supports ActiveXObject, then an attempt to create
+        ///    an MSXML 6.0 DOM will be made. If this attempt fails too, then an attempt
+        ///    for creating an MXSML 3.0 DOM will be made.  If this last attemp fails or
+        ///    the browser doesn't support ActiveXObject then an exception will be thrown.
+        /// </remarks>
+
+        var implementation = window.document.implementation;
+        return (implementation && implementation.createDocument) ?
+           implementation.createDocument(null, null, null) :
+           msXmlDom();
+    };
+
+    var xmlAppendChildren = function (parent, children) {
+        /// <summary>Appends a collection of child nodes or string values to a parent DOM node.</summary>
+        /// <param name="parent">DOM node to which the children will be appended.</param>
+        /// <param name="children" type="Array">Array containing DOM nodes or string values that will be appended to the parent.</param>
+        /// <returns>The parent with the appended children or string values.</returns>
+        /// <remarks>
+        ///    If a value in the children collection is a string, then a new DOM text node is going to be created
+        ///    for it and then appended to the parent.
+        /// </remarks>
+
+        if (!isArray(children)) {
+            return xmlAppendChild(parent, children);
+        }
+
+        var i, len;
+        for (i = 0, len = children.length; i < len; i++) {
+            children[i] && xmlAppendChild(parent, children[i]);
+        }
+        return parent;
+    };
+
+    var xmlAppendChild = function (parent, child) {
+        /// <summary>Appends a child node or a string value to a parent DOM node.</summary>
+        /// <param name="parent">DOM node to which the child will be appended.</param>
+        /// <param name="child">Child DOM node or string value to append to the parent.</param>
+        /// <returns>The parent with the appended child or string value.</returns>
+        /// <remarks>
+        ///    If child is a string value, then a new DOM text node is going to be created
+        ///    for it and then appended to the parent.
+        /// </remarks>
+
+        if (child) {
+            if (typeof child === "string") {
+                return xmlAppendText(parent, xmlNewText(parent.ownerDocument, child));
+            }
+            if (child.nodeType === 2) {
+                parent.setAttributeNodeNS ? parent.setAttributeNodeNS(child) : parent.setAttributeNode(child);
+            } else {
+                parent.appendChild(child);
+            }
+        }
+        return parent;
+    };
+
+    var xmlNewAttribute = function (dom, namespaceURI, qualifiedName, value) {
+        /// <summary>Creates a new DOM attribute node.</summary>
+        /// <param name="dom">DOM document used to create the attribute.</param>
+        /// <param name="prefix" type="String">Namespace prefix.</param>
+        /// <param name="namespaceURI" type="String">Namespace URI.</param>
+        /// <returns>DOM attribute node for the namespace declaration.</returns>
+
+        var attribute =
+            dom.createAttributeNS && dom.createAttributeNS(namespaceURI, qualifiedName) ||
+            dom.createNode(2, qualifiedName, namespaceURI || undefined);
+
+        attribute.value = value || "";
+        return attribute;
+    };
+
+    var xmlNewElement = function (dom, nampespaceURI, qualifiedName, children) {
+        /// <summary>Creates a new DOM element node.</summary>
+        /// <param name="dom">DOM document used to create the DOM element.</param>
+        /// <param name="namespaceURI" type="String">Namespace URI of the new DOM element.</param>
+        /// <param name="qualifiedName" type="String">Qualified name in the form of "prefix:name" of the new DOM element.</param>
+        /// <param name="children" type="Array" optional="true">
+        ///     Collection of child DOM nodes or string values that are going to be appended to the new DOM element.
+        /// </param>
+        /// <returns>New DOM element.</returns>
+        /// <remarks>
+        ///    If a value in the children collection is a string, then a new DOM text node is going to be created
+        ///    for it and then appended to the new DOM element.
+        /// </remarks>
+
+        var element =
+            dom.createElementNS && dom.createElementNS(nampespaceURI, qualifiedName) ||
+            dom.createNode(1, qualifiedName, nampespaceURI || undefined);
+
+        return xmlAppendChildren(element, children || []);
+    };
+
+    var xmlNewNSDeclaration = function (dom, namespaceURI, prefix) {
+        /// <summary>Creates a namespace declaration attribute.</summary>
+        /// <param name="dom">DOM document used to create the attribute.</param>
+        /// <param name="namespaceURI" type="String">Namespace URI.</param>
+        /// <param name="prefix" type="String">Namespace prefix.</param>
+        /// <returns>DOM attribute node for the namespace declaration.</returns>
+
+        return xmlNewAttribute(dom, xmlnsNS, xmlQualifiedName("xmlns", prefix), namespaceURI);
+    };
+
+    var xmlNewFragment = function (dom, text) {
+        /// <summary>Creates a new DOM document fragment node for the specified xml text.</summary>
+        /// <param name="dom">DOM document from which the fragment node is going to be created.</param>
+        /// <param name="text" type="String" mayBeNull="false">XML text to be represented by the XmlFragment.</param>
+        /// <returns>New DOM document fragment object.</returns>
+
+        var value = "<c>" + text + "</c>";
+        var tempDom = xmlParse(value);
+        var tempRoot = tempDom.documentElement;
+        var imported = ("importNode" in dom) ? dom.importNode(tempRoot, true) : tempRoot;
+        var fragment = dom.createDocumentFragment();
+
+        var importedChild = imported.firstChild;
+        while (importedChild) {
+            fragment.appendChild(importedChild);
+            importedChild = importedChild.nextSibling;
+        }
+        return fragment;
+    };
+
+    var xmlNewText = function (dom, text) {
+        /// <summary>Creates new DOM text node.</summary>
+        /// <param name="dom">DOM document used to create the text node.</param>
+        /// <param name="text" type="String">Text value for the DOM text node.</param>
+        /// <returns>DOM text node.</returns>
+
+        return dom.createTextNode(text);
+    };
+
+    var xmlNewNodeByPath = function (dom, root, namespaceURI, prefix, path) {
+        /// <summary>Creates a new DOM element or DOM attribute node as specified by path and appends it to the DOM tree pointed by root.</summary>
+        /// <param name="dom">DOM document used to create the new node.</param>
+        /// <param name="root">DOM element node used as root of the subtree on which the new nodes are going to be created.</param>
+        /// <param name="namespaceURI" type="String">Namespace URI of the new DOM element or attribute.</param>
+        /// <param name="namespacePrefix" type="String">Prefix used to qualify the name of the new DOM element or attribute.</param>
+        /// <param name="Path" type="String">Path string describing the location of the new DOM element or attribute from the root element.</param>
+        /// <returns>DOM element or attribute node for the last segment of the path.</returns>
+        /// <remarks>
+        ///     This function will traverse the path and will create a new DOM element with the specified namespace URI and prefix
+        ///     for each segment that doesn't have a matching element under root.
+        ///
+        ///     The last segment of the path may be decorated with a starting @ character. In this case a new DOM attribute node
+        ///     will be created.
+        /// </remarks>
+
+        var name = "";
+        var parts = path.split("/");
+        var xmlFindNode = xmlFirstChildElement;
+        var xmlNewNode = xmlNewElement;
+        var xmlNode = root;
+
+        var i, len;
+        for (i = 0, len = parts.length; i < len; i++) {
+            name = parts[i];
+            if (name.charAt(0) === "@") {
+                name = name.substring(1);
+                xmlFindNode = xmlAttributeNode;
+                xmlNewNode = xmlNewAttribute;
+            }
+
+            var childNode = xmlFindNode(xmlNode, namespaceURI, name);
+            if (!childNode) {
+                childNode = xmlNewNode(dom, namespaceURI, xmlQualifiedName(prefix, name));
+                xmlAppendChild(xmlNode, childNode);
+            }
+            xmlNode = childNode;
+        }
+        return xmlNode;
+    };
+
+    var xmlSerialize = function (domNode) {
+        /// <summary>
+        /// Returns the text representation of the document to which the specified node belongs.
+        /// </summary>
+        /// <param name="root">Wrapped element in the document to serialize.</param>
+        /// <returns type="String">Serialized document.</returns>
+
+        var xmlSerializer = window.XMLSerializer;
+        if (xmlSerializer) {
+            var serializer = new xmlSerializer();
+            return serializer.serializeToString(domNode);
+        }
+
+        if (domNode.xml) {
+            return domNode.xml;
+        }
+
+        throw { message: "XML serialization unsupported" };
+    };
+
+    var xmlSerializeDescendants = function (domNode) {
+        /// <summary>Returns the XML representation of the all the descendants of the node.</summary>
+        /// <param name="domNode" optional="false" mayBeNull="false">Node to serialize.</param>
+        /// <returns type="String">The XML representation of all the descendants of the node.</returns>
+
+        var children = domNode.childNodes;
+        var i, len = children.length;
+        if (len === 0) {
+            return "";
+        }
+
+        // Some implementations of the XMLSerializer don't deal very well with fragments that
+        // don't have a DOMElement as their first child. The work around is to wrap all the
+        // nodes in a dummy root node named "c", serialize it and then just extract the text between
+        // the <c> and the </c> substrings.
+
+        var dom = domNode.ownerDocument;
+        var fragment = dom.createDocumentFragment();
+        var fragmentRoot = dom.createElement("c");
+
+        fragment.appendChild(fragmentRoot);
+        // Move the children to the fragment tree.
+        for (i = 0; i < len; i++) {
+            fragmentRoot.appendChild(children[i]);
+        }
+
+        var xml = xmlSerialize(fragment);
+        xml = xml.substr(3, xml.length - 7);
+
+        // Move the children back to the original dom tree.
+        for (i = 0; i < len; i++) {
+            domNode.appendChild(fragmentRoot.childNodes[i]);
+        }
+
+        return xml;
+    };
+
+    var xmlSerializeNode = function (domNode) {
+        /// <summary>Returns the XML representation of the node and all its descendants.</summary>
+        /// <param name="domNode" optional="false" mayBeNull="false">Node to serialize.</param>
+        /// <returns type="String">The XML representation of the node and all its descendants.</returns>
+
+        var xml = domNode.xml;
+        if (xml !== undefined) {
+            return xml;
+        }
+
+        if (window.XMLSerializer) {
+            var serializer = new window.XMLSerializer();
+            return serializer.serializeToString(domNode);
+        }
+
+        throw { message: "XML serialization unsupported" };
+    };
+
+
+
+
+    var forwardCall = function (thisValue, name, returnValue) {
+        /// <summary>Creates a new function to forward a call.</summary>
+        /// <param name="thisValue" type="Object">Value to use as the 'this' object.</param>
+        /// <param name="name" type="String">Name of function to forward to.</param>
+        /// <param name="returnValue" type="Object">Return value for the forward call (helps keep identity when chaining calls).</param>
+        /// <returns type="Function">A new function that will forward a call.</returns>
+
+        return function () {
+            thisValue[name].apply(thisValue, arguments);
+            return returnValue;
+        };
+    };
+
+    var DjsDeferred = function () {
+        /// <summary>Initializes a new DjsDeferred object.</summary>
+        /// <remarks>
+        /// Compability Note A - Ordering of callbacks through chained 'then' invocations
+        ///
+        /// The Wiki entry at http://wiki.commonjs.org/wiki/Promises/A
+        /// implies that .then() returns a distinct object.
+        ////
+        /// For compatibility with http://api.jquery.com/category/deferred-object/
+        /// we return this same object. This affects ordering, as
+        /// the jQuery version will fire callbacks in registration
+        /// order regardless of whether they occur on the result
+        /// or the original object.
+        ///
+        /// Compability Note B - Fulfillment value
+        ///
+        /// The Wiki entry at http://wiki.commonjs.org/wiki/Promises/A
+        /// implies that the result of a success callback is the
+        /// fulfillment value of the object and is received by
+        /// other success callbacks that are chained.
+        ///
+        /// For compatibility with http://api.jquery.com/category/deferred-object/
+        /// we disregard this value instead.
+        /// </remarks>
+
+        this._arguments = undefined;
+        this._done = undefined;
+        this._fail = undefined;
+        this._resolved = false;
+        this._rejected = false;
+    };
+
+    DjsDeferred.prototype = {
+        then: function (fulfilledHandler, errorHandler /*, progressHandler */) {
+            /// <summary>Adds success and error callbacks for this deferred object.</summary>
+            /// <param name="fulfilledHandler" type="Function" mayBeNull="true" optional="true">Success callback.</param>
+            /// <param name="errorHandler" type="Function" mayBeNull="true" optional="true">Error callback.</param>
+            /// <remarks>See Compatibility Note A.</remarks>
+
+            if (fulfilledHandler) {
+                if (!this._done) {
+                    this._done = [fulfilledHandler];
+                } else {
+                    this._done.push(fulfilledHandler);
+                }
+            }
+
+            if (errorHandler) {
+                if (!this._fail) {
+                    this._fail = [errorHandler];
+                } else {
+                    this._fail.push(errorHandler);
+                }
+            }
+
+            //// See Compatibility Note A in the DjsDeferred constructor.
+            //// if (!this._next) {
+            ////    this._next = createDeferred();
+            //// }
+            //// return this._next.promise();
+
+            if (this._resolved) {
+                this.resolve.apply(this, this._arguments);
+            } else if (this._rejected) {
+                this.reject.apply(this, this._arguments);
+            }
+
+            return this;
+        },
+
+        resolve: function (/* args */) {
+            /// <summary>Invokes success callbacks for this deferred object.</summary>
+            /// <remarks>All arguments are forwarded to success callbacks.</remarks>
+
+
+            if (this._done) {
+                var i, len;
+                for (i = 0, len = this._done.length; i < len; i++) {
+                    //// See Compability Note B - Fulfillment value.
+                    //// var nextValue =
+                    this._done[i].apply(null, arguments);
+                }
+
+                //// See Compatibility Note A in the DjsDeferred constructor.
+                //// this._next.resolve(nextValue);
+                //// delete this._next;
+
+                this._done = undefined;
+                this._resolved = false;
+                this._arguments = undefined;
+            } else {
+                this._resolved = true;
+                this._arguments = arguments;
+            }
+        },
+
+        reject: function (/* args */) {
+            /// <summary>Invokes error callbacks for this deferred object.</summary>
+            /// <remarks>All arguments are forwarded to error callbacks.</remarks>
+            if (this._fail) {
+                var i, len;
+                for (i = 0, len = this._fail.length; i < len; i++) {
+                    this._fail[i].apply(null, arguments);
+                }
+
+                this._fail = undefined;
+                this._rejected = false;
+                this._arguments = undefined;
+            } else {
+                this._rejected = true;
+                this._arguments = arguments;
+            }
+        },
+
+        promise: function () {
+            /// <summary>Returns a version of this object that has only the read-only methods available.</summary>
+            /// <returns>An object with only the promise object.</returns>
+
+            var result = {};
+            result.then = forwardCall(this, "then", result);
+            return result;
+        }
+    };
+
+    var createDeferred = function () {
+        /// <summary>Creates a deferred object.</summary>
+        /// <returns type="DjsDeferred">
+        /// A new deferred object. If jQuery is installed, then a jQuery
+        /// Deferred object is returned, which provides a superset of features.
+        /// </returns>
+
+        if (window.jQuery && window.jQuery.Deferred) {
+            return new window.jQuery.Deferred();
+        } else {
+            return new DjsDeferred();
+        }
+    };
+
+
+
+
+    var dataItemTypeName = function (value, metadata) {
+        /// <summary>Gets the type name of a data item value that belongs to a feed, an entry, a complex type property, or a collection property.</summary>
+        /// <param name="value">Value of the data item from which the type name is going to be retrieved.</param>
+        /// <param name="metadata" type="object" optional="true">Object containing metadata about the data tiem.</param>
+        /// <remarks>
+        ///    This function will first try to get the type name from the data item's value itself if it is an object with a __metadata property; otherwise
+        ///    it will try to recover it from the metadata.  If both attempts fail, it will return null.
+        /// </remarks>
+        /// <returns type="String">Data item type name; null if the type name cannot be found within the value or the metadata</returns>
+
+        var valueTypeName = ((value && value.__metadata) || {}).type;
+        return valueTypeName || (metadata ? metadata.type : null);
+    };
+
+    var EDM = "Edm.";
+    var EDM_BINARY = EDM + "Binary";
+    var EDM_BOOLEAN = EDM + "Boolean";
+    var EDM_BYTE = EDM + "Byte";
+    var EDM_DATETIME = EDM + "DateTime";
+    var EDM_DATETIMEOFFSET = EDM + "DateTimeOffset";
+    var EDM_DECIMAL = EDM + "Decimal";
+    var EDM_DOUBLE = EDM + "Double";
+    var EDM_GUID = EDM + "Guid";
+    var EDM_INT16 = EDM + "Int16";
+    var EDM_INT32 = EDM + "Int32";
+    var EDM_INT64 = EDM + "Int64";
+    var EDM_SBYTE = EDM + "SByte";
+    var EDM_SINGLE = EDM + "Single";
+    var EDM_STRING = EDM + "String";
+    var EDM_TIME = EDM + "Time";
+
+    var EDM_GEOGRAPHY = EDM + "Geography";
+    var EDM_GEOGRAPHY_POINT = EDM_GEOGRAPHY + "Point";
+    var EDM_GEOGRAPHY_LINESTRING = EDM_GEOGRAPHY + "LineString";
+    var EDM_GEOGRAPHY_POLYGON = EDM_GEOGRAPHY + "Polygon";
+    var EDM_GEOGRAPHY_COLLECTION = EDM_GEOGRAPHY + "Collection";
+    var EDM_GEOGRAPHY_MULTIPOLYGON = EDM_GEOGRAPHY + "MultiPolygon";
+    var EDM_GEOGRAPHY_MULTILINESTRING = EDM_GEOGRAPHY + "MultiLineString";
+    var EDM_GEOGRAPHY_MULTIPOINT = EDM_GEOGRAPHY + "MultiPoint";
+
+    var EDM_GEOMETRY = EDM + "Geometry";
+    var EDM_GEOMETRY_POINT = EDM_GEOMETRY + "Point";
+    var EDM_GEOMETRY_LINESTRING = EDM_GEOMETRY + "LineString";
+    var EDM_GEOMETRY_POLYGON = EDM_GEOMETRY + "Polygon";
+    var EDM_GEOMETRY_COLLECTION = EDM_GEOMETRY + "Collection";
+    var EDM_GEOMETRY_MULTIPOLYGON = EDM_GEOMETRY + "MultiPolygon";
+    var EDM_GEOMETRY_MULTILINESTRING = EDM_GEOMETRY + "MultiLineString";
+    var EDM_GEOMETRY_MULTIPOINT = EDM_GEOMETRY + "MultiPoint";
+
+    var GEOJSON_POINT = "Point";
+    var GEOJSON_LINESTRING = "LineString";
+    var GEOJSON_POLYGON = "Polygon";
+    var GEOJSON_MULTIPOINT = "MultiPoint";
+    var GEOJSON_MULTILINESTRING = "MultiLineString";
+    var GEOJSON_MULTIPOLYGON = "MultiPolygon";
+    var GEOJSON_GEOMETRYCOLLECTION = "GeometryCollection";
+
+    var primitiveEdmTypes = [
+        EDM_STRING,
+        EDM_INT32,
+        EDM_INT64,
+        EDM_BOOLEAN,
+        EDM_DOUBLE,
+        EDM_SINGLE,
+        EDM_DATETIME,
+        EDM_DATETIMEOFFSET,
+        EDM_TIME,
+        EDM_DECIMAL,
+        EDM_GUID,
+        EDM_BYTE,
+        EDM_INT16,
+        EDM_SBYTE,
+        EDM_BINARY
+    ];
+
+    var geometryEdmTypes = [
+        EDM_GEOMETRY,
+        EDM_GEOMETRY_POINT,
+        EDM_GEOMETRY_LINESTRING,
+        EDM_GEOMETRY_POLYGON,
+        EDM_GEOMETRY_COLLECTION,
+        EDM_GEOMETRY_MULTIPOLYGON,
+        EDM_GEOMETRY_MULTILINESTRING,
+        EDM_GEOMETRY_MULTIPOINT
+    ];
+
+    var geographyEdmTypes = [
+        EDM_GEOGRAPHY,
+        EDM_GEOGRAPHY_POINT,
+        EDM_GEOGRAPHY_LINESTRING,
+        EDM_GEOGRAPHY_POLYGON,
+        EDM_GEOGRAPHY_COLLECTION,
+        EDM_GEOGRAPHY_MULTIPOLYGON,
+        EDM_GEOGRAPHY_MULTILINESTRING,
+        EDM_GEOGRAPHY_MULTIPOINT
+    ];
+
+    var forEachSchema = function (metadata, callback) {
+        /// <summary>Invokes a function once per schema in metadata.</summary>
+        /// <param name="metadata">Metadata store; one of edmx, schema, or an array of any of them.</param>
+        /// <param name="callback" type="Function">Callback function to invoke once per schema.</param>
+        /// <returns>
+        /// The first truthy value to be returned from the callback; null or the last falsy value otherwise.
+        /// </returns>
+
+        if (!metadata) {
+            return null;
+        }
+
+        if (isArray(metadata)) {
+            var i, len, result;
+            for (i = 0, len = metadata.length; i < len; i++) {
+                result = forEachSchema(metadata[i], callback);
+                if (result) {
+                    return result;
+                }
+            }
+
+            return null;
+        } else {
+            if (metadata.dataServices) {
+                return forEachSchema(metadata.dataServices.schema, callback);
+            }
+
+            return callback(metadata);
+        }
+    };
+
+    var formatMilliseconds = function (ms, ns) {
+        /// <summary>Formats a millisecond and a nanosecond value into a single string.</summary>
+        /// <param name="ms" type="Number" mayBeNull="false">Number of milliseconds to format.</param>
+        /// <param name="ns" type="Number" mayBeNull="false">Number of nanoseconds to format.</param>
+        /// <returns type="String">Formatted text.</returns>
+        /// <remarks>If the value is already as string it's returned as-is.</remarks>
+
+        // Avoid generating milliseconds if not necessary.
+        if (ms === 0) {
+            ms = "";
+        } else {
+            ms = "." + formatNumberWidth(ms.toString(), 3);
+        }
+        if (ns > 0) {
+            if (ms === "") {
+                ms = ".000";
+            }
+            ms += formatNumberWidth(ns.toString(), 4);
+        }
+        return ms;
+    };
+
+    var formatDateTimeOffset = function (value) {
+        /// <summary>Formats a DateTime or DateTimeOffset value a string.</summary>
+        /// <param name="value" type="Date" mayBeNull="false">Value to format.</param>
+        /// <returns type="String">Formatted text.</returns>
+        /// <remarks>If the value is already as string it's returned as-is.</remarks>
+
+        if (typeof value === "string") {
+            return value;
+        }
+
+        var hasOffset = isDateTimeOffset(value);
+        var offset = getCanonicalTimezone(value.__offset);
+        if (hasOffset && offset !== "Z") {
+            // We're about to change the value, so make a copy.
+            value = new Date(value.valueOf());
+
+            var timezone = parseTimezone(offset);
+            var hours = value.getUTCHours() + (timezone.d * timezone.h);
+            var minutes = value.getUTCMinutes() + (timezone.d * timezone.m);
+
+            value.setUTCHours(hours, minutes);
+        } else if (!hasOffset) {
+            // Don't suffix a 'Z' for Edm.DateTime values.
+            offset = "";
+        }
+
+        var year = value.getUTCFullYear();
+        var month = value.getUTCMonth() + 1;
+        var sign = "";
+        if (year <= 0) {
+            year = -(year - 1);
+            sign = "-";
+        }
+
+        var ms = formatMilliseconds(value.getUTCMilliseconds(), value.__ns);
+
+        return sign +
+            formatNumberWidth(year, 4) + "-" +
+            formatNumberWidth(month, 2) + "-" +
+            formatNumberWidth(value.getUTCDate(), 2) + "T" +
+            formatNumberWidth(value.getUTCHours(), 2) + ":" +
+            formatNumberWidth(value.getUTCMinutes(), 2) + ":" +
+            formatNumberWidth(value.getUTCSeconds(), 2) +
+            ms + offset;
+    };
+
+    var formatDuration = function (value) {
+        /// <summary>Converts a duration to a string in xsd:duration format.</summary>
+        /// <param name="value" type="Object">Object with ms and __edmType properties.</param>
+        /// <returns type="String">String representation of the time object in xsd:duration format.</returns>
+
+        var ms = value.ms;
+
+        var sign = "";
+        if (ms < 0) {
+            sign = "-";
+            ms = -ms;
+        }
+
+        var days = Math.floor(ms / 86400000);
+        ms -= 86400000 * days;
+        var hours = Math.floor(ms / 3600000);
+        ms -= 3600000 * hours;
+        var minutes = Math.floor(ms / 60000);
+        ms -= 60000 * minutes;
+        var seconds = Math.floor(ms / 1000);
+        ms -= seconds * 1000;
+
+        return sign + "P" +
+               formatNumberWidth(days, 2) + "DT" +
+               formatNumberWidth(hours, 2) + "H" +
+               formatNumberWidth(minutes, 2) + "M" +
+               formatNumberWidth(seconds, 2) +
+               formatMilliseconds(ms, value.ns) + "S";
+    };
+
+    var formatNumberWidth = function (value, width, append) {
+        /// <summary>Formats the specified value to the given width.</summary>
+        /// <param name="value" type="Number">Number to format (non-negative).</param>
+        /// <param name="width" type="Number">Minimum width for number.</param>
+        /// <param name="append" type="Boolean">Flag indicating if the value is padded at the beginning (false) or at the end (true).</param>
+        /// <returns type="String">Text representation.</returns>
+        var result = value.toString(10);
+        while (result.length < width) {
+            if (append) {
+                result += "0";
+            } else {
+                result = "0" + result;
+            }
+        }
+
+        return result;
+    };
+
+    var getCanonicalTimezone = function (timezone) {
+        /// <summary>Gets the canonical timezone representation.</summary>
+        /// <param name="timezone" type="String">Timezone representation.</param>
+        /// <returns type="String">An 'Z' string if the timezone is absent or 0; the timezone otherwise.</returns>
+
+        return (!timezone || timezone === "Z" || timezone === "+00:00" || timezone === "-00:00") ? "Z" : timezone;
+    };
+
+    var getCollectionType = function (typeName) {
+        /// <summary>Gets the type of a collection type name.</summary>
+        /// <param name="typeName" type="String">Type name of the collection.</param>
+        /// <returns type="String">Type of the collection; null if the type name is not a collection type.</returns>
+
+        if (typeof typeName === "string") {
+            var end = typeName.indexOf(")", 10);
+            if (typeName.indexOf("Collection(") === 0 && end > 0) {
+                return typeName.substring(11, end);
+            }
+        }
+        return null;
+    };
+
+    var invokeRequest = function (request, success, error, handler, httpClient, context) {
+        /// <summary>Sends a request containing OData payload to a server.</summary>
+        /// <param name="request">Object that represents the request to be sent..</param>
+        /// <param name="success">Callback for a successful read operation.</param>
+        /// <param name="error">Callback for handling errors.</param>
+        /// <param name="handler">Handler for data serialization.</param>
+        /// <param name="httpClient">HTTP client layer.</param>
+        /// <param name="context">Context used for processing the request</param>
+
+        return httpClient.request(request, function (response) {
+            try {
+                if (response.headers) {
+                    normalizeHeaders(response.headers);
+                }
+
+                if (response.data === undefined && response.statusCode !== 204) {
+                    handler.read(response, context);
+                }
+            } catch (err) {
+                if (err.request === undefined) {
+                    err.request = request;
+                }
+                if (err.response === undefined) {
+                    err.response = response;
+                }
+                error(err);
+                return;
+            }
+
+            success(response.data, response);
+        }, error);
+    };
+
+    var isBatch = function (value) {
+        /// <summary>Tests whether a value is a batch object in the library's internal representation.</summary>
+        /// <param name="value">Value to test.</param>
+        /// <returns type="Boolean">True is the value is a batch object; false otherwise.</returns>
+
+        return isComplex(value) && isArray(value.__batchRequests);
+    };
+
+    // Regular expression used for testing and parsing for a collection type.
+    var collectionTypeRE = /Collection\((.*)\)/;
+
+    var isCollection = function (value, typeName) {
+        /// <summary>Tests whether a value is a collection value in the library's internal representation.</summary>
+        /// <param name="value">Value to test.</param>
+        /// <param name="typeName" type="Sting">Type name of the value. This is used to disambiguate from a collection property value.</param>
+        /// <returns type="Boolean">True is the value is a feed value; false otherwise.</returns>
+
+        var colData = value && value.results || value;
+        return !!colData &&
+            (isCollectionType(typeName)) ||
+            (!typeName && isArray(colData) && !isComplex(colData[0]));
+    };
+
+    var isCollectionType = function (typeName) {
+        /// <summary>Checks whether the specified type name is a collection type.</summary>
+        /// <param name="typeName" type="String">Name of type to check.</param>
+        /// <returns type="Boolean">True if the type is the name of a collection type; false otherwise.</returns>
+        return collectionTypeRE.test(typeName);
+    };
+
+    var isComplex = function (value) {
+        /// <summary>Tests whether a value is a complex type value in the library's internal representation.</summary>
+        /// <param name="value">Value to test.</param>
+        /// <returns type="Boolean">True is the value is a complex type value; false otherwise.</returns>
+
+        return !!value &&
+            isObject(value) &&
+            !isArray(value) &&
+            !isDate(value);
+    };
+
+    var isDateTimeOffset = function (value) {
+        /// <summary>Checks whether a Date object is DateTimeOffset value</summary>
+        /// <param name="value" type="Date" mayBeNull="false">Value to check.</param>
+        /// <returns type="Boolean">true if the value is a DateTimeOffset, false otherwise.</returns>
+        return (value.__edmType === "Edm.DateTimeOffset" || (!value.__edmType && value.__offset));
+    };
+
+    var isDeferred = function (value) {
+        /// <summary>Tests whether a value is a deferred navigation property in the library's internal representation.</summary>
+        /// <param name="value">Value to test.</param>
+        /// <returns type="Boolean">True is the value is a deferred navigation property; false otherwise.</returns>
+
+        if (!value && !isComplex(value)) {
+            return false;
+        }
+        var metadata = value.__metadata || {};
+        var deferred = value.__deferred || {};
+        return !metadata.type && !!deferred.uri;
+    };
+
+    var isEntry = function (value) {
+        /// <summary>Tests whether a value is an entry object in the library's internal representation.</summary>
+        /// <param name="value">Value to test.</param>
+        /// <returns type="Boolean">True is the value is an entry object; false otherwise.</returns>
+
+        return isComplex(value) && value.__metadata && "uri" in value.__metadata;
+    };
+
+    var isFeed = function (value, typeName) {
+        /// <summary>Tests whether a value is a feed value in the library's internal representation.</summary>
+        /// <param name="value">Value to test.</param>
+        /// <param name="typeName" type="Sting">Type name of the value. This is used to disambiguate from a collection property value.</param>
+        /// <returns type="Boolean">True is the value is a feed value; false otherwise.</returns>
+
+        var feedData = value && value.results || value;
+        return isArray(feedData) && (
+            (!isCollectionType(typeName)) &&
+            (isComplex(feedData[0]))
+        );
+    };
+
+    var isGeographyEdmType = function (typeName) {
+        /// <summary>Checks whether the specified type name is a geography EDM type.</summary>
+        /// <param name="typeName" type="String">Name of type to check.</param>
+        /// <returns type="Boolean">True if the type is a geography EDM type; false otherwise.</returns>
+
+        return contains(geographyEdmTypes, typeName);
+    };
+
+    var isGeometryEdmType = function (typeName) {
+        /// <summary>Checks whether the specified type name is a geometry EDM type.</summary>
+        /// <param name="typeName" type="String">Name of type to check.</param>
+        /// <returns type="Boolean">True if the type is a geometry EDM type; false otherwise.</returns>
+
+        return contains(geometryEdmTypes, typeName);
+    };
+
+    var isNamedStream = function (value) {
+        /// <summary>Tests whether a value is a named stream value in the library's internal representation.</summary>
+        /// <param name="value">Value to test.</param>
+        /// <returns type="Boolean">True is the value is a named stream; false otherwise.</returns>
+
+        if (!value && !isComplex(value)) {
+            return false;
+        }
+        var metadata = value.__metadata;
+        var mediaResource = value.__mediaresource;
+        return !metadata && !!mediaResource && !!mediaResource.media_src;
+    };
+
+    var isPrimitive = function (value) {
+        /// <summary>Tests whether a value is a primitive type value in the library's internal representation.</summary>
+        /// <param name="value">Value to test.</param>
+        /// <remarks>
+        ///    Date objects are considered primitive types by the library.
+        /// </remarks>
+        /// <returns type="Boolean">True is the value is a primitive type value.</returns>
+
+        return isDate(value) ||
+            typeof value === "string" ||
+            typeof value === "number" ||
+            typeof value === "boolean";
+    };
+
+    var isPrimitiveEdmType = function (typeName) {
+        /// <summary>Checks whether the specified type name is a primitive EDM type.</summary>
+        /// <param name="typeName" type="String">Name of type to check.</param>
+        /// <returns type="Boolean">True if the type is a primitive EDM type; false otherwise.</returns>
+
+        return contains(primitiveEdmTypes, typeName);
+    };
+
+    var navigationPropertyKind = function (value, propertyModel) {
+        /// <summary>Gets the kind of a navigation property value.</summary>
+        /// <param name="value">Value of the navigation property.</param>
+        /// <param name="propertyModel" type="Object" optional="true">
+        ///     Object that describes the navigation property in an OData conceptual schema.
+        /// </param>
+        /// <remarks>
+        ///     The returned string is as follows
+        /// </remarks>
+        /// <returns type="String">String value describing the kind of the navigation property; null if the kind cannot be determined.</returns>
+
+        if (isDeferred(value)) {
+            return "deferred";
+        }
+        if (isEntry(value)) {
+            return "entry";
+        }
+        if (isFeed(value)) {
+            return "feed";
+        }
+        if (propertyModel && propertyModel.relationship) {
+            if (value === null || value === undefined || !isFeed(value)) {
+                return "entry";
+            }
+            return "feed";
+        }
+        return null;
+    };
+
+    var lookupProperty = function (properties, name) {
+        /// <summary>Looks up a property by name.</summary>
+        /// <param name="properties" type="Array" mayBeNull="true">Array of property objects as per EDM metadata.</param>
+        /// <param name="name" type="String">Name to look for.</param>
+        /// <returns type="Object">The property object; null if not found.</returns>
+
+        return find(properties, function (property) {
+            return property.name === name;
+        });
+    };
+
+    var lookupInMetadata = function (name, metadata, kind) {
+        /// <summary>Looks up a type object by name.</summary>
+        /// <param name="name" type="String">Name, possibly null or empty.</param>
+        /// <param name="metadata">Metadata store; one of edmx, schema, or an array of any of them.</param>
+        /// <param name="kind" type="String">Kind of object to look for as per EDM metadata.</param>
+        /// <returns>An type description if the name is found; null otherwise.</returns>
+
+        return (name) ? forEachSchema(metadata, function (schema) {
+            return lookupInSchema(name, schema, kind);
+        }) : null;
+    };
+
+    var lookupEntitySet = function (entitySets, name) {
+        /// <summary>Looks up a entity set by name.</summary>
+        /// <param name="properties" type="Array" mayBeNull="true">Array of entity set objects as per EDM metadata.</param>
+        /// <param name="name" type="String">Name to look for.</param>
+        /// <returns type="Object">The entity set object; null if not found.</returns>
+
+        return find(entitySets, function (entitySet) {
+            return entitySet.name === name;
+        });
+    };
+
+    var lookupComplexType = function (name, metadata) {
+        /// <summary>Looks up a complex type object by name.</summary>
+        /// <param name="name" type="String">Name, possibly null or empty.</param>
+        /// <param name="metadata">Metadata store; one of edmx, schema, or an array of any of them.</param>
+        /// <returns>A complex type description if the name is found; null otherwise.</returns>
+
+        return lookupInMetadata(name, metadata, "complexType");
+    };
+
+    var lookupEntityType = function (name, metadata) {
+        /// <summary>Looks up an entity type object by name.</summary>
+        /// <param name="name" type="String">Name, possibly null or empty.</param>
+        /// <param name="metadata">Metadata store; one of edmx, schema, or an array of any of them.</param>
+        /// <returns>An entity type description if the name is found; null otherwise.</returns>
+
+        return lookupInMetadata(name, metadata, "entityType");
+    };
+
+    var lookupDefaultEntityContainer = function (metadata) {
+        /// <summary>Looks up an</summary>
+        /// <param name="name" type="String">Name, possibly null or empty.</param>
+        /// <param name="metadata">Metadata store; one of edmx, schema, or an array of any of them.</param>
+        /// <returns>An entity container description if the name is found; null otherwise.</returns>
+
+        return forEachSchema(metadata, function (schema) {
+            return find(schema.entityContainer, function (container) {
+                return parseBool(container.isDefaultEntityContainer);
+            });
+        });
+    };
+
+    var lookupEntityContainer = function (name, metadata) {
+        /// <summary>Looks up an entity container object by name.</summary>
+        /// <param name="name" type="String">Name, possibly null or empty.</param>
+        /// <param name="metadata">Metadata store; one of edmx, schema, or an array of any of them.</param>
+        /// <returns>An entity container description if the name is found; null otherwise.</returns>
+
+        return lookupInMetadata(name, metadata, "entityContainer");
+    };
+
+    var lookupFunctionImport = function (functionImports, name) {
+        /// <summary>Looks up a function import by name.</summary>
+        /// <param name="properties" type="Array" mayBeNull="true">Array of function import objects as per EDM metadata.</param>
+        /// <param name="name" type="String">Name to look for.</param>
+        /// <returns type="Object">The entity set object; null if not found.</returns>
+
+        return find(functionImports, function (functionImport) {
+            return functionImport.name === name;
+        });
+    };
+
+    var lookupNavigationPropertyType = function (navigationProperty, metadata) {
+        /// <summary>Looks up the target entity type for a navigation property.</summary>
+        /// <param name="navigationProperty" type="Object"></param>
+        /// <param name="metadata" type="Object"></param>
+        /// <returns type="String">The entity type name for the specified property, null if not found.</returns>
+
+        var result = null;
+        if (navigationProperty) {
+            var rel = navigationProperty.relationship;
+            var association = forEachSchema(metadata, function (schema) {
+                // The name should be the namespace qualified name in 'ns'.'type' format.
+                var nameOnly = removeNamespace(schema["namespace"], rel);
+                var associations = schema.association;
+                if (nameOnly && associations) {
+                    var i, len;
+                    for (i = 0, len = associations.length; i < len; i++) {
+                        if (associations[i].name === nameOnly) {
+                            return associations[i];
+                        }
+                    }
+                }
+                return null;
+            });
+
+            if (association) {
+                var end = association.end[0];
+                if (end.role !== navigationProperty.toRole) {
+                    end = association.end[1];
+                    // For metadata to be valid, end.role === navigationProperty.toRole now.
+                }
+                result = end.type;
+            }
+        }
+        return result;
+    };
+
+    var lookupNavigationPropertyEntitySet = function (navigationProperty, sourceEntitySetName, metadata) {
+        /// <summary>Looks up the target entityset name for a navigation property.</summary>
+        /// <param name="navigationProperty" type="Object"></param>
+        /// <param name="metadata" type="Object"></param>
+        /// <returns type="String">The entityset name for the specified property, null if not found.</returns>
+
+        if (navigationProperty) {
+            var rel = navigationProperty.relationship;
+            var associationSet = forEachSchema(metadata, function (schema) {
+                var containers = schema.entityContainer;
+                for (var i = 0; i < containers.length; i++) {
+                    var associationSets = containers[i].associationSet;
+                    if (associationSets) {
+                        for (var j = 0; j < associationSets.length; j++) {
+                            if (associationSets[j].association == rel) {
+                                return associationSets[j];
+                            }
+                        }
+                    }
+                }
+                return null;
+            });
+            if (associationSet && associationSet.end[0] && associationSet.end[1]) {
+                return (associationSet.end[0].entitySet == sourceEntitySetName) ? associationSet.end[1].entitySet : associationSet.end[0].entitySet;
+            }
+        }
+        return null;
+    };
+
+    var getEntitySetInfo = function (entitySetName, metadata) {
+        /// <summary>Gets the entitySet info, container name and functionImports for an entitySet</summary>
+        /// <param name="navigationProperty" type="Object"></param>
+        /// <param name="metadata" type="Object"></param>
+        /// <returns type="Object">The info about the entitySet.</returns>
+
+        var info = forEachSchema(metadata, function (schema) {
+            var containers

<TRUNCATED>

[4/5] [OLINGO-407] JS- V4's window.OData is not defined yet: part 1 - change window.datajs.V4 into window.odatajs (while V3: window.datajs).

Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/tests/store-indexeddb-tests.js
----------------------------------------------------------------------
diff --git a/JSLib/tests/store-indexeddb-tests.js b/JSLib/tests/store-indexeddb-tests.js
index 76fbb30..6751363 100644
--- a/JSLib/tests/store-indexeddb-tests.js
+++ b/JSLib/tests/store-indexeddb-tests.js
@@ -58,14 +58,14 @@
         });
 
         djstest.addTest(function testIndexedDBStoreConstructor() {
-            var store = this.store = window.datajs.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.IndexedDBStore.create(getCurrentStoreName());
             djstest.assertAreEqual(store.name, getCurrentStoreName());
             djstest.assertAreEqual(store.mechanism, "indexeddb");
             djstest.done();
         });
 
         djstest.addTest(function testIndexedDBStoreAddGet() {
-            var store = this.store = window.datajs.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.IndexedDBStore.create(getCurrentStoreName());
             store.add("key", "value", function (key, value) {
                 djstest.assertAreEqual(key, "key");
                 djstest.assertAreEqual(value, "value");
@@ -78,7 +78,7 @@
         });
 
         djstest.addTest(function testIndexedDBStoreAddUpdateGet() {
-            var store = this.store = window.datajs.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.IndexedDBStore.create(getCurrentStoreName());
             store.add("key", "value", function (key, value) {
                 store.update("key", "value2", function (key, value) {
                     djstest.assertAreEqual(key, "key");
@@ -93,7 +93,7 @@
         });
 
         djstest.addTest(function testIndexedDBStoreAddOrUpdateGet() {
-            var store = this.store = window.datajs.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.IndexedDBStore.create(getCurrentStoreName());
             store.addOrUpdate("key", "value", function (key, value) {
                 djstest.assertAreEqual(key, "key");
                 djstest.assertAreEqual(value, "value");
@@ -110,7 +110,7 @@
         });
 
         djstest.addTest(function testIndexedDBStoreAddRemoveContains() {
-            var store = this.store = window.datajs.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.IndexedDBStore.create(getCurrentStoreName());
             store.add("key", "value", function (key, value) {
                 store.contains("key", function (result) {
                     djstest.assert(result);
@@ -126,7 +126,7 @@
         });
 
         djstest.addTest(function testIndexedDBStoreAddConsecutiveGetAllKeys() {
-            var store = this.store = window.datajs.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.IndexedDBStore.create(getCurrentStoreName());
             store.add("key", "value", function (key, value) {
                 store.add("key2", "value2", function (key, value) {
                     store.add("key3", "value3", function (key, value) {
@@ -142,7 +142,7 @@
         djstest.addTest(function testIndexedDBStoreAddArrayClear() {
             var addedKeys = ["key", "key2", "key3"];
             var addedValues = ["value", "value2", "value3"];
-            var store = this.store = window.datajs.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.IndexedDBStore.create(getCurrentStoreName());
             store.add(addedKeys, addedValues, function (keys, values) {
                 djstest.assertAreEqualDeep(keys, addedKeys);
                 djstest.assertAreEqualDeep(values, addedValues);
@@ -158,7 +158,7 @@
         djstest.addTest(function testIndexedDBStoreAddArrayUpdateArrayGetArray() {
             var addedKeys = ["key", "key2", "key3"];
             var addedValues = ["value", "value2", "value3"];
-            var store = this.store = window.datajs.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.IndexedDBStore.create(getCurrentStoreName());
             store.add(addedKeys, addedValues, function (keys, values) {
                 djstest.assertAreEqualDeep(keys, addedKeys);
                 djstest.assertAreEqualDeep(values, addedValues);
@@ -179,7 +179,7 @@
         djstest.addTest(function testIndexedDBStoreAddOrUpdateArrayGetArray() {
             var expectedKeys = ["key", "key2", "key3"];
             var expectedValues = ["value", "value2", "value3"];
-            var store = this.store = window.datajs.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.IndexedDBStore.create(getCurrentStoreName());
             store.add("key2", "value", function (key, value) {
                 store.addOrUpdate(expectedKeys, expectedValues, function (keys, values) {
                     djstest.assertAreEqualDeep(keys, expectedKeys);
@@ -193,7 +193,7 @@
         });
 
         djstest.addTest(function testIndexedDBStoreAddDuplicate() {
-            var store = this.store = window.datajs.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.IndexedDBStore.create(getCurrentStoreName());
             store.add("key", "value", function (key, value) {
                 store.add("key", "value2", unexpectedSuccess, function (err) {
                     djstest.pass("Error callback called as expected");
@@ -203,7 +203,7 @@
         });
 
         djstest.addTest(function testIndexedDBStoreAddArrayDuplicate() {
-            var store = this.store = window.datajs.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.IndexedDBStore.create(getCurrentStoreName());
             store.add(["key", "key2", "key"], ["value", "value2", "value3"], unexpectedSuccess, function (err) {
                 djstest.pass("Error callback called as expected");
                 djstest.done();
@@ -211,7 +211,7 @@
         });
 
         djstest.addTest(function testIndexedDBStoreGetArrayNonExistent() {
-            var store = this.store = window.datajs.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.IndexedDBStore.create(getCurrentStoreName());
             store.add("key", "value", function (key, value) {
                 store.read(["key", "badkey"], function (keys, values) {
                     djstest.assertAreEqualDeep(keys, ["key", "badkey"]);
@@ -222,7 +222,7 @@
         });
 
         djstest.addTest(function testIndexedDBStoreUpdateNonExistent() {
-            var store = this.store = window.datajs.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.IndexedDBStore.create(getCurrentStoreName());
             store.update("badkey", "badvalue", unexpectedSuccess, function (err) {
                 djstest.pass("Error callback called as expected");
                 djstest.done();
@@ -230,7 +230,7 @@
         });
 
         djstest.addTest(function testIndexedDBStoreUpdateArrayNonExistent() {
-            var store = this.store = window.datajs.IndexedDBStore.create(getCurrentStoreName());
+            var store = this.store = window.odatajs.IndexedDBStore.create(getCurrentStoreName());
             store.add("key", "value", function (key, value) {
                 store.update(["key", "badkey"], ["value", "badvalue"], unexpectedSuccess, function (err) {
                     djstest.pass("Error callback called as expected");

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/JSLib/tests/store-tests.js
----------------------------------------------------------------------
diff --git a/JSLib/tests/store-tests.js b/JSLib/tests/store-tests.js
index 1a05849..4bf6d3e 100644
--- a/JSLib/tests/store-tests.js
+++ b/JSLib/tests/store-tests.js
@@ -67,9 +67,9 @@
     };
 
     var mechanismImplementations = {
-        indexeddb: { factory: datajs.IndexedDBStore, canCreate: canCreateIndexedDb, cleanup: cleanIndexedDbStorage },
-        dom: { factory: datajs.DomStore, canCreate: canCreateDomStore, cleanup: cleanDomStorage },
-        memory: { factory: datajs.MemoryStore, canCreate: canCreateMemoryStore, cleanup: cleanMemoryStorage }
+        indexeddb: { factory: odatajs.IndexedDBStore, canCreate: canCreateIndexedDb, cleanup: cleanIndexedDbStorage },
+        dom: { factory: odatajs.DomStore, canCreate: canCreateDomStore, cleanup: cleanDomStorage },
+        memory: { factory: odatajs.MemoryStore, canCreate: canCreateMemoryStore, cleanup: cleanMemoryStorage }
     };
 
     var oldWindowOnError;
@@ -78,7 +78,7 @@
         module("Unit", {
             mechanism: mechanism,
             createStore: function (name) {
-                var store = datajs.createStore(name + "_" + this.mechanism, this.mechanism);
+                var store = odatajs.createStore(name + "_" + this.mechanism, this.mechanism);
                 this.stores.push(store);
                 return store;
             },
@@ -641,7 +641,7 @@
         for (i = 0, len = tests.length; i < len; i++) {
             try {
                 var test = tests[i];
-                var store = datajs.createStore("testStore" + i, tests[i].mechanism);
+                var store = odatajs.createStore("testStore" + i, tests[i].mechanism);
 
                 if (!test.exception) {
                     djstest.assertAreEqual(store.mechanism, test.expected, "Created store of the expected mechanism");
@@ -672,7 +672,7 @@
             ];
 
             for (var i in tests) {
-                var store = datajs.createStore("best store ever " + i, tests[i]);
+                var store = odatajs.createStore("best store ever " + i, tests[i]);
                 djstest.assertAreEqual(store.mechanism, bestMechanism, "Mechanisms match");
             }
         } else {

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/datajs/demo/scripts/datajs_demo.js
----------------------------------------------------------------------
diff --git a/datajs/demo/scripts/datajs_demo.js b/datajs/demo/scripts/datajs_demo.js
index e2b830d..dbbb5db 100644
--- a/datajs/demo/scripts/datajs_demo.js
+++ b/datajs/demo/scripts/datajs_demo.js
@@ -38,7 +38,7 @@ var runSimpleReadRequest = function() {
         alert("err");
         alert(JSON.stringify(err));
     };
-    datajs.V4.oData.read(request, successFunction, failFunction);
+    odatajs.oData.read(request, successFunction, failFunction);
 };
 
 var runSimpleReadRequestWithMetadata = function () {
@@ -65,7 +65,7 @@ var runSimpleReadRequestWithMetadata = function () {
             alert("err");
             alert(JSON.stringify(err));
         };
-        datajs.V4.oData.read(request, successFunction, failFunction, null, null, metadata);
+        odatajs.oData.read(request, successFunction, failFunction, null, null, metadata);
     };
 
     var readMetadataFail = function (err) {
@@ -82,7 +82,7 @@ var runSimpleReadRequestWithMetadata = function () {
         data: null,
     };
 
-    datajs.V4.oData.read(metadataRequest, readMetadataSuccess, readMetadataFail, datajs.V4.oData.metadataHandler);
+    odatajs.oData.read(metadataRequest, readMetadataSuccess, readMetadataFail, odatajs.V4.oData.metadataHandler);
 };
 
 var readWithJsonP = function() {

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/datajs/src/index.js
----------------------------------------------------------------------
diff --git a/datajs/src/index.js b/datajs/src/index.js
index dbe1e64..739e53f 100644
--- a/datajs/src/index.js
+++ b/datajs/src/index.js
@@ -17,15 +17,15 @@
  * under the License.
  */
 
-if ( window.datajs===undefined) {
-    window.datajs = {};
+if ( window.odatajs===undefined) {
+    window.odatajs = {};
 }
 
-window.datajs.V4 = require('./lib/datajs.js');
-window.datajs.V4.oData = require('./lib/odata.js');
+window.odatajs = require('./lib/datajs.js');
+window.odatajs.oData = require('./lib/odata.js');
 
-window.datajs.V4.store = require('./lib/store.js');
-window.datajs.V4.cache = require('./lib/cache.js');
+window.odatajs.store = require('./lib/store.js');
+window.odatajs.cache = require('./lib/cache.js');
 
 /*
 function extend(target) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/datajs/src/lib/cache.js
----------------------------------------------------------------------
diff --git a/datajs/src/lib/cache.js b/datajs/src/lib/cache.js
index 4afc5cc..1a7e3c2 100644
--- a/datajs/src/lib/cache.js
+++ b/datajs/src/lib/cache.js
@@ -20,9 +20,9 @@
  /** @module cache */
 
 var datajs = require('./datajs.js');
-var utils = datajs.utils;
-var deferred = datajs.deferred;
-var storeReq = datajs.store;
+var utils = odatajs.utils;
+var deferred = odatajs.deferred;
+var storeReq = odatajs.store;
 var cacheSource = require('./cache/source');
 
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/datajs/tests/cache-tests.js
----------------------------------------------------------------------
diff --git a/datajs/tests/cache-tests.js b/datajs/tests/cache-tests.js
index dc9fa4e..d5ceac9 100644
--- a/datajs/tests/cache-tests.js
+++ b/datajs/tests/cache-tests.js
@@ -34,7 +34,7 @@
     };
 
     djstest.addTest(function dataCacheCountTest() {
-        var cache = datajs.cache.createDataCache({ name: "cache", source: foodsFeed });
+        var cache = odatajs.cache.createDataCache({ name: "cache", source: foodsFeed });
         cache.count().then(function (count) {
             djstest.assertAreEqual(count, collectionSize, "expected count for Foods");
             djstest.destroyCacheAndDone(cache);
@@ -42,7 +42,7 @@
     });
 
     djstest.addTest(function dataCacheCountOnLocalTest() {
-        var cache = datajs.cache.createDataCache({ name: "cache", source: foodsFeed, pageSize: collectionSize + 10, mechanism: "memory" });
+        var cache = odatajs.cache.createDataCache({ name: "cache", source: foodsFeed, pageSize: collectionSize + 10, mechanism: "memory" });
         cache.readRange(0, collectionSize + 10).then(function (data) {
             var expectedCount = data.value ? data.value.length : 0;
             cache.count().then(function (count) {
@@ -54,7 +54,7 @@
 
     djstest.addTest(function dataCacheCountAbortTest() {
         // Abort before completion.
-        var cache = datajs.cache.createDataCache({ name: "cache", source: foodsFeed });
+        var cache = odatajs.cache.createDataCache({ name: "cache", source: foodsFeed });
         var item = cache.count().then(thenFailTest, function (err) {
             djstest.assertAreEqual(true, err.canceled, "err.aborted is true");
             djstest.destroyCacheAndDone(cache);
@@ -86,9 +86,9 @@
             }
         };
 
-        var cache = datajs.cache.createDataCache(options);
+        var cache = odatajs.cache.createDataCache(options);
         cache.clear().then(function () {
-            var newCache = datajs.cache.createDataCache(options);
+            var newCache = odatajs.cache.createDataCache(options);
             resolve(newCache);
         }, function (err) {
             rejected = true;
@@ -349,7 +349,7 @@
             then(function (cache) {
                 cache.readRange(0, 2).then(function () {
                     options.source = "HtTp://ExampleURI.cOm/my%20service.svc";
-                    var newCache = datajs.cache.createDataCache(options);
+                    var newCache = odatajs.cache.createDataCache(options);
                     newCache.readRange(0, 2).then(function (data) {
                         djstest.assertAreEqualDeep(data.value, [1, 2], "Got the expected data from the new cache instance");
                         newCache.clear().then(function () {
@@ -502,7 +502,7 @@
                 return null;
             }
         };
-        var cache = datajs.cache.createDataCache({
+        var cache = odatajs.cache.createDataCache({
             name: "mem", mechanism: "memory", source: "http://www.example.org/service/",
             httpClient: httpClient
         });
@@ -675,53 +675,53 @@
         var cache;
 
         // Verify the defaults.
-        cache = datajs.cache.createDataCache({ name: "name", source: "src" });
+        cache = odatajs.cache.createDataCache({ name: "name", source: "src" });
 
         djstest.assertAreEqual(cache.onidle, undefined, "onidle is undefined");
 
         // Verify specific values.
-        cache = datajs.cache.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: 2, prefetchSize: 3, idle: 123 });
+        cache = odatajs.cache.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: 2, prefetchSize: 3, idle: 123 });
 
         djstest.assertAreEqual(cache.onidle, 123, "onidle is as specified");
 
         // Verify 0 pageSize 
         djstest.expectException(function () {
-            datajs.cache.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: 0, prefetchSize: 3, idle: 123 });
+            odatajs.cache.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: 0, prefetchSize: 3, idle: 123 });
         }, "zero pageSize");
 
         // Verify negative pageSize
         djstest.expectException(function () {
-            datajs.cache.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: -2, prefetchSize: 3, idle: 123 });
+            odatajs.cache.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: -2, prefetchSize: 3, idle: 123 });
         }, "negative pageSize");
 
         // Verify NaN pageSize
         djstest.expectException(function () {
-            cache = datajs.cache.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: "2", prefetchSize: 3, idle: 123 });
+            cache = odatajs.cache.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: "2", prefetchSize: 3, idle: 123 });
         }, "NaN pageSize");
 
         // Verify NaN cacheSize
         djstest.expectException(function () {
-            cache = datajs.cache.createDataCache({ name: "name", source: "src", cacheSize: "1", pageSize: 2, prefetchSize: 3, idle: 123 });
+            cache = odatajs.cache.createDataCache({ name: "name", source: "src", cacheSize: "1", pageSize: 2, prefetchSize: 3, idle: 123 });
         }, "NaN cacheSize");
 
         // Verify NaN prefetchSize
         djstest.expectException(function () {
-            cache = datajs.cache.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: 2, prefetchSize: "3", idle: 123 });
+            cache = odatajs.cache.createDataCache({ name: "name", source: "src", cacheSize: 1, pageSize: 2, prefetchSize: "3", idle: 123 });
         }, "NaN prefetchSize");
 
         // Verify undefined name 
         djstest.expectException(function () {
-            datajs.cache.createDataCache({ source: "src", cacheSize: 1, pageSize: 1, prefetchSize: 3, idle: 123 });
+            odatajs.cache.createDataCache({ source: "src", cacheSize: 1, pageSize: 1, prefetchSize: 3, idle: 123 });
         }, "undefined name");
 
         // Verify null name 
         djstest.expectException(function () {
-            datajs.cache.createDataCache({ name: null, source: "src", cacheSize: 1, pageSize: 1, prefetchSize: 3, idle: 123 });
+            odatajs.cache.createDataCache({ name: null, source: "src", cacheSize: 1, pageSize: 1, prefetchSize: 3, idle: 123 });
         }, "null name");
 
         // Verify undefined source 
         djstest.expectException(function () {
-            datajs.cache.createDataCache({ name: "name", cacheSize: 1, pageSize: 1, prefetchSize: 3, idle: 123 });
+            odatajs.cache.createDataCache({ name: "name", cacheSize: 1, pageSize: 1, prefetchSize: 3, idle: 123 });
         }, "undefined source");
 
         djstest.done();
@@ -747,7 +747,7 @@
             }
         };
 
-        var cache = datajs.cache.createDataCache({ name: "name", source: cacheSource, mechanism: "memory", pageSize: 10 });
+        var cache = odatajs.cache.createDataCache({ name: "name", source: cacheSource, mechanism: "memory", pageSize: 10 });
         cache.count().then(function () {
             cache.readRange(0, 5).then(function () {
                 djstest.done();
@@ -760,13 +760,13 @@
         var failures = ["read-settings", "write-settings", "v2"];
         var failureIndex = 0;
 
-        var originalStore = datajs.store.createStore;
+        var originalStore = odatajs.store.createStore;
         var restoreStore = function () {
-            datajs.store.createStore = originalStore;
+            odatajs.store.createStore = originalStore;
         };
 
         var storeError = { message: "cacheInitializationFailTest error" };
-        datajs.store.createStore = function (name, mechanism) {
+        odatajs.store.createStore = function (name, mechanism) {
             return {
                 addOrUpdate: function (key, value, successCallback, errorCallback) {
                     if (failures[failureIndex] === "write-settings") {
@@ -795,7 +795,7 @@
 
         var nextFailure = function () {
             djstest.log("Failure mode: " + failures[failureIndex]);
-            var cache = datajs.cache.createDataCache({ name: "name", source: "foo", mechanism: "memory", pageSize: 10 });
+            var cache = odatajs.cache.createDataCache({ name: "name", source: "foo", mechanism: "memory", pageSize: 10 });
             try {
                 // The first readRange should succeed, because the data cache isn't really initialized at this time.
                 cache.readRange(1, 2).then(djstest.failAndDoneCallback("No function should succeed"), function (err) {
@@ -854,7 +854,7 @@
             }
         };
 
-        var cache = datajs.cache.createDataCache({ name: "name", source: cacheSource, mechanism: "memory", pageSize: 10 });
+        var cache = odatajs.cache.createDataCache({ name: "name", source: cacheSource, mechanism: "memory", pageSize: 10 });
         cache.readRange(0, 5).then(function () {
             djstest.fail("unexpected call to then success");
             djstest.done();
@@ -975,7 +975,7 @@
 
     djstest.addTest(function createDeferredTest() {
         // Verify basic use of deferred object.
-        var deferred = datajs.deferred.createDeferred();
+        var deferred = odatajs.deferred.createDeferred();
         deferred.then(function (val1, val2) {
             djstest.assertAreEqual(val1, 1, "val1 is as specified");
             djstest.assertAreEqual(val2, 2, "val2 is as specified");
@@ -986,7 +986,7 @@
 
     djstest.addTest(function deferredThenTest() {
         // Verify then registration and chaining.
-        var deferred = datajs.deferred.createDeferred();
+        var deferred = odatajs.deferred.createDeferred();
         deferred.then(function (val1, val2) {
             djstest.assertAreEqual(val1, 1, "val1 is as specified");
             djstest.assertAreEqual(val2, 2, "val2 is as specified");
@@ -996,7 +996,7 @@
             djstest.assert(foo !== "foo", "argument for chained 'then' is *not* result of previous call");
             djstest.assert(foo === 1, "argument for chained 'then' is same as for previous call");
 
-            var other = datajs.deferred.createDeferred();
+            var other = odatajs.deferred.createDeferred();
             other.then(null, function (err, msg) {
                 djstest.assertAreEqual("error", err, "err is as specified");
                 djstest.assertAreEqual("message", msg, "msg is as specified");
@@ -1007,7 +1007,7 @@
                 djstest.assertAreEqual("error", err, "err is as specified");
                 djstest.assertAreEqual("message", msg, "msg is as specified");
 
-                var multiple = datajs.deferred.createDeferred();
+                var multiple = odatajs.deferred.createDeferred();
                 var count = 0;
 
                 // See Compatibility Note A in DjsDeferred remarks.
@@ -1037,12 +1037,12 @@
 
     djstest.addTest(function deferredResolveTest() {
         // Resolve with no arguments.
-        var deferred = datajs.deferred.createDeferred();
+        var deferred = odatajs.deferred.createDeferred();
         deferred.then(function (arg) {
             djstest.assertAreEqual(arg, undefined, "resolve with no args shows up as undefined");
 
             // Resolve with no callbacks.
-            var other = datajs.deferred.createDeferred();
+            var other = odatajs.deferred.createDeferred();
             other.resolve();
             djstest.done();
         });
@@ -1052,12 +1052,12 @@
 
     djstest.addTest(function deferredRejectTest() {
         // Resolve with no arguments.   
-        var deferred = datajs.deferred.createDeferred();
+        var deferred = odatajs.deferred.createDeferred();
         deferred.then(null, function (arg) {
             djstest.assertAreEqual(arg, undefined, "reject with no args shows up as undefined");
 
             // Resolve with no callbacks.
-            var other = datajs.deferred.createDeferred();
+            var other = odatajs.deferred.createDeferred();
             other.reject();
             djstest.done();
         });
@@ -1079,7 +1079,7 @@
         var i, len;
         for (i = 0, len = tests.length; i < len; i++) {
             var test = tests[i];
-            djstest.assertAreEqual(datajs.cache.estimateSize(test.i), test.e);
+            djstest.assertAreEqual(odatajs.cache.estimateSize(test.i), test.e);
         }
         djstest.done();
     });
@@ -1099,7 +1099,7 @@
             }
         });
 
-        var cache = datajs.cache.createDataCache({
+        var cache = odatajs.cache.createDataCache({
             name: "cacheOptionsTunnel",
             source: "http://foo-bar/",
             user: "the-user",
@@ -1121,7 +1121,7 @@
     djstest.addTest(function dataCacheHandlesFullStoreTest() {
 
         var TestStore = function (name) {
-            var that = new window.datajs.store.MemoryStore(name);
+            var that = new window.odatajs.store.MemoryStore(name);
             that.addOrUpdate = function (key, value, success, error) {
                 if (key === "__settings") {
                     window.setTimeout(function () {
@@ -1160,14 +1160,14 @@
             }
         };
 
-        var originalCreateStore = window.datajs.store.createStore;
+        var originalCreateStore = window.odatajs.store.createStore;
 
-        window.datajs.store.createStore = function (name, mechanism) {
+        window.odatajs.store.createStore = function (name, mechanism) {
             return TestStore(name);
         };
 
         try {
-            var cache = datajs.cache.createDataCache({
+            var cache = odatajs.cache.createDataCache({
                 name: "cache",
                 pageSize: 5,
                 prefetchSize: 0,
@@ -1175,7 +1175,7 @@
                 mechanism: "teststore"
             });
         } finally {
-            window.datajs.store.createStore = originalCreateStore;
+            window.odatajs.store.createStore = originalCreateStore;
         }
 
         cache.readRange(0, 5).then(function (data) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/datajs/tests/common/common.js
----------------------------------------------------------------------
diff --git a/datajs/tests/common/common.js b/datajs/tests/common/common.js
index cd764a9..f43fd99 100644
--- a/datajs/tests/common/common.js
+++ b/datajs/tests/common/common.js
@@ -17,10 +17,10 @@
  * under the License.
 */
 (function (window, undefined) {
-        window.OData = window.datajs.V4.oData;
-        window.temp = window.datajs.V4;
-        window.temp.store = window.datajs.V4.store;
-        window.temp.cache = window.datajs.V4.cache;
-        window.datajs = window.temp;
+        window.OData = window.odatajs.oData;
+        window.temp = window.odatajs;
+        window.temp.store = window.odatajs.store;
+        window.temp.cache = window.odatajs.cache;
+        window.odatajs = window.temp;
         delete window.temp;
 })(this);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/5c98f9f3/datajs/tests/datajs-cache-large-collection-functional-tests.js
----------------------------------------------------------------------
diff --git a/datajs/tests/datajs-cache-large-collection-functional-tests.js b/datajs/tests/datajs-cache-large-collection-functional-tests.js
index d3c9a87..02a9c1f 100644
--- a/datajs/tests/datajs-cache-large-collection-functional-tests.js
+++ b/datajs/tests/datajs-cache-large-collection-functional-tests.js
@@ -128,7 +128,7 @@
                         mechanism: params.mechanism, cacheSize: params.cacheSize
                     };
 
-                    var cache = datajs.cache.createDataCache(options);
+                    var cache = odatajs.cache.createDataCache(options);
                     this.caches.push({ name: options.name,
                         cache: cache
                     });
@@ -161,7 +161,7 @@
                             mechanism: params.mechanism, cacheSize: params.cacheSize
                         };
 
-                        var cache = datajs.cache.createDataCache(options);
+                        var cache = odatajs.cache.createDataCache(options);
                         this.caches.push({ name: options.name, cache: cache });
 
                         var cacheOracle = new CacheOracle(params.feed, params.pageSize, itemsInCollection);