Author: gotcha
Date: Sat Nov 15 13:37:09 2008
New Revision: 59931
Modified:
kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/registries.js
kukit/kukit.js/branch/gotcha-simplify-service-layer/tests/test_registries.js
Log:
remove loader
Modified:
kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/registries.js
==============================================================================
--- kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/registries.js
(original)
+++ kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/registries.js
Sat Nov 15 13:37:09 2008
@@ -147,12 +147,7 @@
return factory;
};
- this.bindItems = function(registries, registry, loader) {
- // singleton: the singleton we want to finalize on.
- // loader (optional): use it for all operations
- // (this means we never get errors but the loader
- // will be set up to load missing resources)
- //
+ this.bindItems = function(registries, registry) {
// Check if we are finalized.
if (this.bound) {
;;; kukit.E = 'Attempt to bind already bound registry [';
@@ -163,7 +158,7 @@
;;; kukit.logDebug(kukit.E);
for (var name in this.factories) {
var factory = this.factories[name];
- var item = factory.produceItem(loader);
+ var item = factory.produceItem();
if (typeof(item) != 'undefined') {
// Set the item on the registry
registry[name] = item;
@@ -173,14 +168,7 @@
// this means that it can be accessed as registries.registryname
registries[this.registryName] = registry;
// Set bound state.
- // We are bound if the loader has no items to load.
- // If there is no loader, we are always bound at this point.
- this.bound = ! loader || loader.empty();
-;;; if (! this.bound) {
-;;; kukit.E = 'Postpone binding of registry [' + this.registryName +
'],';
-;;; kukit.E = ' and request sources [', loader.getSources() + ']';
-;;; kukit.logDebug(kukit.E);
-;;; }
+ this.bound = true;
};
this.initialize.apply(this, arguments);
@@ -229,6 +217,16 @@
}
};
+ this.getRegistryByType = function(type) {
+ var registry = this.schema[type];
+ if (typeof(registrar) == 'undefined') {
+;;; kukit.E = 'Registries.getRegistryByType() is called with
unregistered type [';
+;;; kukit.E += type + '].';
+ throw new Error(kukit.E);
+ }
+ return registry;
+ };
+
}; /* end NamedRegistries */
/*
@@ -297,7 +295,7 @@
this.sources[config.sourceName] = config;
};
- this.produceItem = function(loader) {
+ this.produceItem = function() {
var func;
if (! this.preferredSources) {
;;; kukit.E = 'Undefined method [';
@@ -324,12 +322,6 @@
// if not, we continue with the next best choice.
}
if (! func) {
- if (typeof(loader) != 'undefined') {
- // We have a loading method. Let's add our needs.
- loader.add(this.fallbackProvider);
- // ... and simply go on.
- return;
- } else {
// We raise an error.
;;; kukit.E = 'Could not bind item [';
;;; kukit.E += this.name + '] on registry [';
@@ -338,9 +330,8 @@
;;; kukit.E += 'of the following preferences: [';
;;; kukit.E += this.preferredSources + ']';
throw new Error(kukit.E);
- }
} else {
- // We found the func that we can finalze now.
+ // We found the func that we can finalize now.
;;; kukit.E = 'Using method [';
;;; kukit.E += this.name + '] from source [';
;;; kukit.E += item.sourceName + '] version [';
@@ -390,7 +381,7 @@
this.config = config;
};
- this.produceItem = function(loader) {
+ this.produceItem = function() {
// Just return the registered item.
// If register was not called, we will return undefined,
// which means the method will not be bound on the
@@ -458,7 +449,7 @@
};
- this.produceItem = function(loader) {
+ this.produceItem = function() {
// Just return the registered value.
return this.config;
};
@@ -555,7 +546,7 @@
*
*/
-this.registerPlugins = function(items, registries) {
+this.registerPlugins = function(registries, items) {
for (var i=0; i<items.length; i++) {
var item = items[i];
if (item == null) {
@@ -567,29 +558,24 @@
}
;;; if (item.length != 3) {
;;; kukit.E = 'List items in registerPlugins call must have ';
-;;; kukit.E += '3 members (registryName, itemName, config), ';
+;;; kukit.E += '3 members (itemType, itemName, config), ';
;;; kukit.E += 'got [' + item.length + '] instead.';
;;; throw new Error(kukit.E);
;;; }
- var registryName = item[0];
+ var itemType = item[0];
var itemName = item[1];
var config = item[2];
- // Register it.
- var registrar = registries.schema[registryName];
-;;; if (! registrar) {
-;;; kukit.E = 'Bad registry name in registerPlugins call [';
-;;; kukit.E += registryName + '].';
-;;; throw new Error(kukit.E);
-;;; }
+ var registrar = registries.getRegistryByType(itemType);
var factory = registrar.getItemFactory(itemName);
;;; // Check that we are in a plugin registry.
;;; // It must have a register method.
;;; // (for example, core service cannot register this way.)
;;; if (typeof(factory.register) == 'undefined') {
;;; kukit.E = 'Bad registry name in registerPlugins call [';
-;;; kukit.E += registryName + '], it is not a valid plugin registry.';
+;;; kukit.E += itemType + '], it is not a valid plugin registry.';
;;; throw new Error(kukit.E);
;;; }
+ // Register it.
factory.register(config);
}
};
Modified:
kukit/kukit.js/branch/gotcha-simplify-service-layer/tests/test_registries.js
==============================================================================
---
kukit/kukit.js/branch/gotcha-simplify-service-layer/tests/test_registries.js
(original)
+++
kukit/kukit.js/branch/gotcha-simplify-service-layer/tests/test_registries.js
Sat Nov 15 13:37:09 2008
@@ -122,7 +122,7 @@
var TestFactory2 = function(registrar, name) {
this.registrar = registrar;
this.name = name;
- this.bindItems = function(loader) {
+ this.bindItems = function() {
var signature = "REG2 " + this.name;
return signature;
}
@@ -350,65 +350,6 @@
Error);
};
- this.testWithLoader = function() {
- // If no preferred providers are found, loaders will
- // call up.
- // Make a simple loader
- var loader = new function() {
- this.loaded = [];
- this.add = function(src) {
- this.loaded.push(src);
- };
- this.empty = function(src) {
- return ! this.loaded;
- };
- this.getSources = function(src) {
- return this.loaded;
- };
- }();
- // Now, for the registry part
- var s = {};
- var registrar = this.registries.schema.dummyservice;
- // Define the method with loader and fallback script
- registrar.getItemFactory('first').require({
- preferredSources: ['corelib', 'extralib'],
- fallbackProvider: '++resource++one'});
- registrar.getItemFactory('second').require({
- preferredSources: ['corelib', 'extralib'],
- fallbackProvider: '++resource++two'});
- registrar.getItemFactory('third').require({
- preferredSources: ['corelib', 'extralib'],
- fallbackProvider: '++resource++three'});
- // Someone provides the method, but it's not good.
- registrar.getItemFactory('first').provide({
- sourceName: 'craplib',
- sourceVersion: '1.1',
- getter: function() {return function() {return 'first/crap';}}});
- // Third will be satisfied.
- registrar.getItemFactory('third').provide({
- sourceName: 'extralib',
- sourceVersion: '12.4',
- getter: function() {return function() {return 'third/extra';}}});
- // Now bind all items. It goes without error.
- registrar.bindItems(this.registries, s, loader);
- // We see the contents of the loader. Third is not in there.
- this.assertListEquals(loader.loaded, ['++resource++one',
'++resource++two'], 'Loaded contents differs.');
- // Third is actually working.
- this.assertEquals(this.registries.dummyservice.third(), 'third/extra');
- // First and second are undefined.
- this.assertEquals(typeof(this.registries.dummyservice.first),
'undefined');
- this.assertEquals(typeof(this.registries.dummyservice.second),
'undefined');
- // Now the loader can go to load the needed files...
- // then it is supposed to re-bind with and without a loader. Check if
this is possible:
- registrar.bindItems(this.registries, s, loader);
- // If we re-bound without a loader, and the sources are still not
loaded,
- // we get an error:
- this.assertThrows(function() {
- registrar.bindItems(this.registries, s);
- },
- Error);
- };
-
}; /* end ServiceRegistryTestCase */
kukit.ServiceRegistryTestCase.prototype = new kukit.RegistriesTestCaseBase();
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins