Author: gotcha
Date: Sun Nov 16 15:51:27 2008
New Revision: 59948
Modified:
kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/dom.js
kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/registries.js
kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/service.js
kukit/kukit.js/branch/gotcha-simplify-service-layer/tests/test_registries.js
Log:
NamedRegistries removed
Modified: kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/dom.js
==============================================================================
--- kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/dom.js
(original)
+++ kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/dom.js Sun Nov
16 15:51:27 2008
@@ -77,7 +77,7 @@
;;; kukit.E = 'Selection error in kukit.dom.cssQuery';
throw new Error(kukit.E);
}
- return kukit.services.core.cssQuery(selector, inNodes);
+ return kukit.services.cssQuery(selector, inNodes);
};
/*
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
Sun Nov 16 15:51:27 2008
@@ -1,6 +1,8 @@
kukit.reg = new function() { /* BEGIN CLOSURE kukit.reg */
+var reg = this;
+
/*
* Kukit registry
*
@@ -32,7 +34,7 @@
* When various javascript code is loaded, it can set up the
* schema for the registry it handles. For example, during the
* loading of javascript, plugin code set up its registry, other code
- * sets up core services it provides or depends on.
+ * sets up services it provides or depends on.
*
* The registries are managed by name in a collection of registries.
* Before accessing the schema of any registry, it needs to
@@ -98,8 +100,6 @@
*
* registries.events.click - is an event's registry
* registries.actions.setAttr - is an action's registry
- * registries.core.cssQuery - is a core service method
- * registries.core.forEach - is a core service method
*
* Kukit sets up the following registries for its own use. The
* binding of these registries is done by kukit at the beginning
@@ -118,14 +118,14 @@
*
* name purpose attribute class
* ---- ------- ---------------
- * core core services kukit.reg.ServiceFactory
+ * services services kukit.reg.ServiceFactory
*
*
* For more information, see ../tests/test_registries.js .
*
*/
-var Registrar = function() {
+reg.Registrar = function() {
this.initialize = function(registryName, FactoryClass) {
this.registryName = registryName;
@@ -176,61 +176,11 @@
}; /* end Registrar */
-this.NamedRegistries = function() {
-
- this.initialize = function(registrars) {
- this.registrars = registrars;
- };
-
- this.initializeRegistry = function(registryName, FactoryClass) {
- // This sets up the registry given by name with the
- // specified FactoryClass class, or checks it.
- // This method needs to be called preceding the calls
- // to getItemFactory on the given registrar.
- // It can be called more times for the same registry.
- //
-;;; // Check for missing parameter; this will cause an error later anyway.
-;;; if (! FactoryClass) {
-;;; kukit.E = 'Registries.initializeRegistry() is called for
registry [';
-;;; kukit.E += registryName + '] without a FactoryClass
parameter.';
-;;; throw new Error(kukit.E);
-;;; }
- // see if we already have this registrar
- var registrar = this.registrars[registryName];
- // create the registrar on demand
- if (typeof(registrar) == 'undefined') {
- // create the registrar and store it on myself
- this.registrars[registryName] = new Registrar(registryName,
FactoryClass);
- } else {
- // check that the same FactoryClass was provided. If not,
- // it's a conflict.
- if (registrar.FactoryClass != FactoryClass) {
-;;; kukit.E = 'Registries.initializeRegistry() is called for
registry [';
-;;; kukit.E += registryName + '] with a different FactoryClass
than earlier.';
- throw new Error(kukit.E);
- }
- }
- };
-
- this.getRegistryByType = function(type) {
- var registry = this.registrars[type];
- if (typeof(registrar) == 'undefined') {
-;;; kukit.E = 'Registries.getRegistryByType() is called with
unregistered type [';
-;;; kukit.E += type + '].';
- throw new Error(kukit.E);
- }
- return registry;
- };
-
- this.initialize.apply(this, arguments);
-
-}; /* end NamedRegistries */
-
/*
* KSS service layer resource
*/
-this.ServiceFactory = function() {
+reg.ServiceFactory = function() {
this.initialize = function(registrar, name) {
this.registrar = registrar;
@@ -358,7 +308,7 @@
* KSS plugin registry
*/
-this.PluginFactory = function() {
+reg.PluginFactory = function() {
this.initialize = function(registrar, name) {
this.registrar = registrar;
@@ -406,7 +356,7 @@
* may make sense, it can be put back in form of asserts on the
* event names.
*/
-this.BindSequenceFactory = function() {
+reg.BindSequenceFactory = function() {
this.initialize = function(registrar, name) {
this.registrar = registrar;
@@ -467,18 +417,18 @@
*
*/
-this.cleanRoomSetUp = function(suite) {
+reg.cleanRoomSetUp = function(suite) {
this._saved_plugins = kukit.plugins;
this._saved_services = kukit.services;
this.setupGlobalRegistries();
};
-this.cleanRoomFinalize = function(suite) {
+reg.cleanRoomFinalize = function(suite) {
// Need to finalize (bind) these registries
this.finalizeGlobalRegistries();
};
-this.cleanRoomTearDown = function(suite) {
+reg.cleanRoomTearDown = function(suite) {
// Revert the saved state
kukit.plugins = this._saved_plugins;
kukit.services = this._saved_services;
@@ -494,35 +444,32 @@
*/
// Initialize global registries
-this.setupGlobalRegistries = function() {
+reg.setupGlobalRegistries = function() {
// instantiate registries
- kukit.registrars = {}
- kukit.plugins = new this.NamedRegistries(kukit.registrars);
- kukit.services = new this.NamedRegistries(kukit.registrars);
- var r = kukit.plugins;
- r.initializeRegistry('events', this.PluginFactory);
- r.initializeRegistry('bindsequences', this.BindSequenceFactory);
- r.initializeRegistry('actions', this.PluginFactory);
- r.initializeRegistry('valueproviders', this.PluginFactory);
- r = kukit.services;
- r.initializeRegistry('core', this.ServiceFactory);
+ kukit.registrars = {};
+ kukit.plugins = {};
+ kukit.registrars.events = new reg.Registrar('events', this.PluginFactory)
+ kukit.registrars.bindsequences = new reg.Registrar('bindsequences',
this.BindSequenceFactory)
+ kukit.registrars.actions = new reg.Registrar('actions',
this.PluginFactory)
+ kukit.registrars.valueproviders = new reg.Registrar('valueproviders',
this.PluginFactory)
+ kukit.registrars.services = new reg.Registrar('services',
this.ServiceFactory)
};
// Finalize global registries
-this.finalizeGlobalRegistries = function() {
+reg.finalizeGlobalRegistries = function() {
var registrars = kukit.registrars;
registrars.events.bindItems(kukit.plugins, {});
registrars.bindsequences.bindItems(kukit.plugins, {});
registrars.actions.bindItems(kukit.plugins, {});
registrars.valueproviders.bindItems(kukit.plugins, {});
- registrars.core.bindItems(kukit.services, {});
+ registrars.services.bindItems(kukit, {});
};
// At this point we setup the registries used by kukit,
// that implies that any code can access them in the kukit namespace
// kukit.plugins
// kukit.services
-this.setupGlobalRegistries();
+reg.setupGlobalRegistries();
// The finalization of these registries is done from bootstrap.
@@ -543,7 +490,7 @@
*
*/
-this.registerPlugins = function(registries, items) {
+reg.registerPlugins = function(registries, items) {
for (var i=0; i<items.length; i++) {
var item = items[i];
if (item == null) {
@@ -562,11 +509,10 @@
var itemType = item[0];
var itemName = item[1];
var config = item[2];
- var registrar = registries.getRegistryByType(itemType);
+ var registrar = registries[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 += itemType + '], it is not a valid plugin registry.';
Modified: kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/service.js
==============================================================================
--- kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/service.js
(original)
+++ kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/service.js
Sun Nov 16 15:51:27 2008
@@ -2,14 +2,14 @@
new function() { // BEGIN CLOSURE service
-var core = kukit.registrars.core;
+var services = kukit.registrars.services;
// Requirements towards core services. It contains
// kukit's preferences to choose between sources
// that implement a given functionality.
-core.getItemFactory('cssQuery').require({
+services.getItemFactory('cssQuery').require({
preferredSources: ['base2', 'base2-legacy', 'cssQuery'],
// a parameter checker common for each implementation
checker: function(selector, inNodes) {
@@ -24,7 +24,7 @@
// that we can detect ourselves. by inspecting if a given
// library is loaded.
-core.getItemFactory('cssQuery').provide({
+services.getItemFactory('cssQuery').provide({
sourceName:'cssQuery',
sourceVersion: '2.0.2',
getter: function() {
@@ -53,7 +53,7 @@
return results;
};
-core.getItemFactory('cssQuery').provide({
+services.getItemFactory('cssQuery').provide({
sourceName: 'base2-legacy',
sourceVersion: '<<20020070816',
getter: function() {
@@ -73,7 +73,7 @@
};
}});
-core.getItemFactory('cssQuery').provide({
+services.getItemFactory('cssQuery').provide({
sourceName: 'base2',
sourceVersion: '0.??',
getter: function() {
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
Sun Nov 16 15:51:27 2008
@@ -21,21 +21,8 @@
var kukit = {};
}
-kukit.RegistriesTestCaseBase = function() {
- this.setUp = function() {
- // work with our own object, not interfering
- // with global object setup in registries.js
- this.registrars = {}
- this.registries = new kukit.reg.NamedRegistries(this.registrars);
- };
-}; /* end RegistriesTestCase */
-kukit.RegistriesTestCaseBase.prototype = new kukit.UtilsTestCaseBase();
-
kukit.RegistriesTestCase = function() {
this.name = 'kukit.RegistriesTestCase';
- /*
- * Plugin registries
- */
var called = [];
@@ -55,15 +42,18 @@
}
};
+ this.setUp = function() {
+ // work with our own object, not interfering
+ // with global object setup in registries.js
+ this.registrars = {};
+ this.registries = {};
+ };
+
this.testRegistries = function() {
// We can create a simple method descriptor for an registry we want.
// The method descriptor is managing the method's registration state
called = [];
- // Let's create a registry that uses TestFactory.
- // We need to initialize it
- this.registries.initializeRegistry('dummytest', TestFactory);
- // Now we can access the schema.
- var registrar = this.registrars.dummytest;
+ var registrar = new kukit.reg.Registrar('dummytest', TestFactory);
this.assert(typeof(registrar), 'object');
// Let's get two items
registrar.getItemFactory('fooItem').doThis()
@@ -84,9 +74,7 @@
// We eill create a simple item for a selected registry.
// The factory is managing the item's registration state
called = [];
- // Let's initialize a dummytest registry.
- this.registries.initializeRegistry('dummytest', TestFactory);
- var registrar = this.registrars.dummytest;
+ var registrar = new kukit.reg.Registrar('dummytest', TestFactory);
// Let's get two factories
registrar.getItemFactory('fooItem').doThis()
registrar.getItemFactory('barItem').doThat()
@@ -104,47 +92,19 @@
this.assertEquals(this.registries.dummytest.barItem, 'FUNC barItem');
};
- this.testInitializationIsRepeatable = function() {
- // Let's have a second factory
- var TestFactory2 = function(registrar, name) {
- this.registrar = registrar;
- this.name = name;
- this.bindItems = function() {
- var signature = "REG2 " + this.name;
- return signature;
- }
- };
- // Let's initialize a dummytest registry.
- this.registries.initializeRegistry('dummytest', TestFactory);
- // We can get the same registry again...
- this.registries.initializeRegistry('dummytest', TestFactory);
- // however not with a different Factory!
- var self = this;
- this.assertThrows(function() {
- this.registries.initializeRegistry('dummytest', TestFactory2);
- },
- Error);
- //
- // On the other hand setting up with a second registry, is no problem.
- this.registries.initializeRegistry('dummytest2', TestFactory2);
- };
-
}; /* end RegistriesTestCase */
-kukit.RegistriesTestCase.prototype = new kukit.RegistriesTestCaseBase();
+kukit.RegistriesTestCase.prototype = new kukit.UtilsTestCaseBase();
kukit.ServiceRegistryTestCase = function() {
this.name = 'kukit.ServiceRegistryTestCase';
- /*
- * Service registries
- */
+
this.setUp = function() {
// work with our own registries, not interfering
// kukit.service or kukit.plugins.
+ this.registries = {};
this.registrars = {}
- this.registries = new kukit.reg.NamedRegistries(this.registrars);
- // Let's initialize a dummyservice registry.
- this.registries.initializeRegistry('dummyservice',
kukit.reg.ServiceFactory);
+ this.registrars.dummyservice = new kukit.reg.Registrar('dummyservice',
kukit.reg.ServiceFactory);
};
this.testServiceRegistry = function() {
@@ -289,7 +249,6 @@
this.testDoubleProvided = function() {
// A method cannot be provided twice by the same source.
- // Let's initialize a dimmytest registry.
var registrar = this.registrars.dummyservice;
// Provide the method first
registrar.getItemFactory('first').provide({
@@ -339,23 +298,19 @@
};
}; /* end ServiceRegistryTestCase */
-kukit.ServiceRegistryTestCase.prototype = new kukit.RegistriesTestCaseBase();
+kukit.ServiceRegistryTestCase.prototype = new kukit.UtilsTestCaseBase();
kukit.PluginRegistriesTestCase = function() {
this.name = 'kukit.PluginRegistriesTestCase';
- /*
- * Plugin registries
- */
this.setUp = function() {
// work with our own object, not interfering
// kukit.plugins
+ this.registries = {};
this.registrars = {}
- this.registries = new kukit.reg.NamedRegistries(this.registrars);
- // Let's initialize an events and binditeration registry.
- this.registries.initializeRegistry('dummyevents',
kukit.reg.PluginFactory);
- this.registries.initializeRegistry('dummybindsequences',
kukit.reg.BindSequenceFactory);
+ this.registrars.dummyevents = new kukit.reg.Registrar('dummyevents',
kukit.reg.PluginFactory);
+ this.registrars.dummybindsequences = new
kukit.reg.Registrar('dummybindsequences', kukit.reg.BindSequenceFactory);
};
var M = function() {
@@ -513,7 +468,6 @@
// the problem of the closing comma
null]
- // XXX the registries is needed for the test, but not in normal usage
, this.registries
);
};
@@ -536,7 +490,6 @@
// the problem of the closing comma
null]
- // XXX the registries is needed for the test, but not in
normal usage
, this.registries
);
}, Error);
@@ -560,42 +513,14 @@
// the problem of the closing comma
null]
- // XXX the registries is needed for the test, but not in
normal usage
, this.registries
);
}, Error);
};
- this.testRegisterPluginsServiceInterfaceProhibites = function() {
- // The registerPlugins methods cannot be used to fill up
- // registries that are initialized with a ServiceFactory.
- // This means only factories that have 'register'
- // method, can be used (PluginFactory, BindSequenceFactory).
- //
- // We register "dummyservice" so it does not fail because
- // it's missing
- kukit.plugins.initializeRegistry('dummyservice',
kukit.reg.ServiceFactory);
- //
- this.assertThrows(function() {
- kukit.reg.registerPlugins(
- [
- ['dummyservice', 'blah', {}],
-
- // XXX putting a null in the end eliminates
- // the problem of the closing comma
- null]
-
- // XXX the registries is needed for the test, but not in
normal usage
- , this.registries
- );
- }, Error);
- };
-
-
-
}; /* end PluginRegistriesTestCase */
-kukit.PluginRegistriesTestCase.prototype = new kukit.RegistriesTestCaseBase();
+kukit.PluginRegistriesTestCase.prototype = new kukit.UtilsTestCaseBase();
if (typeof(testcase_registry) != 'undefined') {
testcase_registry.registerTestCase(kukit.RegistriesTestCase,
'kukit.RegistriesTestCase');
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins