Author: gotcha
Date: Sun Dec 28 22:50:13 2008
New Revision: 60717

Modified:
   kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/actionreg.js
   kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/commandreg.js
   kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/eventreg.js
   kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/providerreg.js
   kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/registries.js
   kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/selectorreg.js
   kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/service.js
   kukit/kukit.js/branch/gotcha-simplify-service-layer/tests/runtests.js
   kukit/kukit.js/branch/gotcha-simplify-service-layer/tests/test_registries.js
Log:
remove Factory classes; use different Registrars instead

Modified: kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/actionreg.js
==============================================================================
--- kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/actionreg.js      
(original)
+++ kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/actionreg.js      
Sun Dec 28 22:50:13 2008
@@ -37,7 +37,7 @@
 ;;;     throw new Error(kukit.e);
 ;;; }
     var actions = kukit.registrars.actions;
-    actions.getItemFactory(name).register({actionFunc: func});
+    actions.register(name, {actionFunc: func});
 };
 
 this.get = function(name) {

Modified: 
kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/commandreg.js
==============================================================================
--- kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/commandreg.js     
(original)
+++ kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/commandreg.js     
Sun Dec 28 22:50:13 2008
@@ -34,50 +34,46 @@
 this.registerFromAction =
     function(srcname, factory, name) {
     var actions = kukit.registrars.actions;
-    //
+    var config = actions.get(srcname);
     // register a given action as a command, using the given vactor
-    var action_factory = actions.getItemFactory(srcname);
-    if (! action_factory.config) {
+    if (typeof(config) == 'undefined') {
 ;;;     kukit.E = 'undefined client action [' + srcname + '] in 
CommandRegistry.registerFromAction.';
         throw Error(kukit.E);
     }
     // Set a command of the required class for the action
-    var commandClass = factory(action_factory.config.actionFunc);
+    var commandClass = factory(config.actionFunc);
     // Allow to set a different name (used for BBB)
     if (typeof(name) != 'undefined') {
         // Add the BBB config if there is not
         // by mirroring the config
         // this makes sure the _registry below won't fail
-        actions.getItemFactory(name).register(action_factory.config);
+        actions.register(name, config);
         // only declare the command class if it's missing
-        if (typeof(action_factory.config.commandClass) == 'undefined') {
-            this._register(name, commandClass, action_factory);
+        if (typeof(config.commandClass) == 'undefined') {
+            this._register(name, commandClass, config);
         }
     } else {
         // This is the normal case - just register it
-        this._register(srcname, commandClass, action_factory);
+        this._register(srcname, commandClass, config);
     }
 
 
 };
 
 this.register = function(name, commandClass) {
-    var actions = kukit.plugins.actions;
-    var attrib = actions.getItemFactory(name);
-    this._register(name, commandClass, attrib);
+    var actions = kukit.registrars.actions;
+    var config = actions[name];
+    this._register(name, commandClass, config);
 };
 
-this._register = function(name, commandClass, descriptor) {
-    if (! descriptor.config) {
-;;;     kukit.E = 'undefined client action [' + name + '] in 
CommandRegistry.register.';
-        throw Error(kukit.E);
-    } else if (descriptor.config.commandClass) {
+this._register = function(name, commandClass, config) {
+    if (config.commandClass) {
         // Do not allow redefinition
-;;;     kukit.E = 'command [' + name + '] is already defined, in 
CommandRegistry.register.';
+;;;     kukit.E = 'command [' + name + '] has already been registered, in 
CommandRegistry.register.';
         throw Error(kukit.E);
         }
     // Store the command class on the config
-    descriptor.config.commandClass = commandClass;
+    config.commandClass = commandClass;
 };
 
 this.get = function(name) {
@@ -109,17 +105,6 @@
 kukit.commandsGlobalRegistry = new _CommandRegistry();
 
 
-/* XXX deprecated methods, to be removed asap */
-
-cr.commandRegistry = {};
-cr.commandRegistry.registerFromAction = function(srcname, factory, name) {
-;;;var msg = 'Deprecated kukit.cr.commandRegistry.registerFromAction,';
-;;;msg += ' use kukit.commandsGlobalRegistry.registerFromAction instead! (';
-;;;msg += srcname + ')';
-;;;kukit.logWarning(msg);
-    kukit.commandsGlobalRegistry.registerFromAction(srcname, factory, name);
-};
-
 /* Command factories */
 
 cr.makeCommand = function(selector, name, type, parms, transport) {

Modified: kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/eventreg.js
==============================================================================
--- kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/eventreg.js       
(original)
+++ kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/eventreg.js       
Sun Dec 28 22:50:13 2008
@@ -79,7 +79,7 @@
         namespacedEventNames.push(eventName);
         // register the event informataion
         var events = kukit.registrars.events;
-        events.getItemFactory(eventName).register({
+        events.register(eventName, {
             defaultActionMethodName: defaultActionMethodName,
             parmTypes: null    // missing from this api.
             });
@@ -88,7 +88,7 @@
     // This will specify the set of events that will be bound together,
     // with the specified iterator
     var bindsequences = kukit.registrars.bindsequences;
-    bindsequences.getItemFactory('').register({
+    bindsequences.register({
             eventNames: namespacedEventNames,
             iterName: iterName,
             binderClass: binderClass,

Modified: 
kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/providerreg.js
==============================================================================
--- kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/providerreg.js    
(original)
+++ kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/providerreg.js    
Sun Dec 28 22:50:13 2008
@@ -44,7 +44,7 @@
     }
     // Always use the global plugins to get the descriptor.
     var registry = kukit.registrars[this.name]; 
-    registry.getItemFactory(name).register({providerClass: func,
+    registry.register(name, {providerClass: func,
                                        returnType: returnType});
 };
 this.initialize.apply(this, arguments);

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 Dec 28 22:50:13 2008
@@ -59,24 +59,16 @@
     this.initialize = function(registryName, FactoryClass) {
         this.registryName = registryName;
         this.built = false;
+        this.configs = {};
         this.factories = {};
         this.FactoryClass = FactoryClass;
     };
 
-    this.getItemFactory = function(name) {
-        // create the attribute on demand
-        var factory = this.factories[name];
-        if (typeof(factory) == 'undefined') {
-            // Use the registry in the instance, to look up the 
MethodDescriptor class
-            // for this method name
-            //
-            // instantiate the factory
-            factory = this.factories[name] = new this.FactoryClass(this, name);
-        }
-        return factory;
+    this.get = function(name) {
+        return this.configs[name];
     };
 
-    this.buildRegistry = function() {
+    this.checkBuilt = function() {
         if (this.built) {
 ;;;         kukit.E = 'Registry [';
 ;;;         kukit.E += this.registryName + '] already built !';
@@ -84,17 +76,12 @@
         }
 ;;;     kukit.E = 'Building registry [' + this.registryName + ']';
 ;;;     kukit.logDebug(kukit.E);
-        var registry = {};
-        for (var name in this.factories) {
-            var factory = this.factories[name];
-            var item = factory.create();
-            if (typeof(item) != 'undefined') {
-                // Set the item on the registry
-                registry[name] = item;
-            };
-        };
         this.built = true;
-        return registry;
+    };
+
+    this.buildRegistry = function() {
+        this.checkBuilt();
+        return this.configs;
     };
     
     this.initialize.apply(this, arguments);
@@ -103,84 +90,117 @@
 
 
 /*
- * KSS service layer resource
- */
-
-reg.ServiceFactory = function() {
+ *
+ * class PluginRegistrar
+ *
+ *
+ */ 
 
-    this.initialize = function(registrar, name) {
-        this.registrar = registrar;
-        this.name = name;
-        this.sources = {};
-        this.preferredsources = null;
+reg.PluginRegistrar = function() {
+    
+    this.register = function(name, config) {
+        if (typeof(this.get(name)) != 'undefined') {
+;;;         kukit.E = 'Double registration of plugin [' + name;
+;;;         kukit.E += '] in registry [' + this.registryName + ']';
+            throw new Error(kukit.E);
+        }
+        this.configs[name] = config;
     };
 
-;;; this._makeError = function(componentName, name) {
-;;;     kukit.E =  'In a call to ' + componentName + ', ';
-;;;     kukit.E += name + ' must be provided for method [';
-;;;     kukit.E += this.name + '] on registry [';
-;;;     kukit.E += this.registrar.registryName + ']';
-;;;     return new Error(kukit.E);
-;;; };
+    this.initialize.apply(this, arguments);
 
-    this.require = function(config) {
-;;;     // Diagnose if parameters are all right.
-;;;     if (! config.preferredSources) {
-;;;         throw this._makeError('ServiceFactory.require', 'config.getter');
-;;;     };
-        if (this.preferredSources) {
-;;;         kukit.E = 'ServiceFactory.require is called twice on [';
-;;;         kukit.E += this.name + '] on registry [';
-;;;         kukit.E += this.registrar.registryName + ']';
+};
+reg.PluginRegistrar.prototype = new reg.Registrar();
+/* end PluginRegistrar */
+
+/*
+ *
+ * class BindSequenceRegistrar
+ *
+ *
+ */ 
+
+reg.BindSequenceRegistrar = function() {
+    
+    this.register = function(config) {
+        // This is called on any method descriptors,
+        // i.e. this is a "class method".
+        // Register config to all event names individually.
+        // Take names from the config.
+        for (var i = 0; i < config.eventNames.length; i++) {
+            var name = config.eventNames[i];
+            this._register(name, config);
+        }
+    };
+    
+    this._register = function(name, config) {
+        if (typeof(this.get(name)) != 'undefined') {
+;;;         kukit.E = 'Double registration of plugin [' + name;
+;;;         kukit.E += '] in registry [' + this.registryName + ']';
             throw new Error(kukit.E);
-        };
-        this.preferredSources = config.preferredSources;
-        this.checker = config.checker;
-        this.fallbackProvider = config.fallbackProvider;
+        }
+        kukit.logDebug('Register bind sequence [' + name + ']');
+        // check the iterator.
+;;;     if  (! kukit.er.getBindIterator(config.iterName)) {
+;;;         kukit.E = 'In BindSequenceFactory.register: unknown bind strategy 
[';
+;;;         kukit.E += config.iterName + '].';
+;;;         throw new Error(kukit.E);
+;;;     }
+        // Decorate binder class.
+        kukit.er.decorateEventBinderClass(config.binderClass);
+
+        this.configs[name] = config;
     };
 
-    this.provide = function(config) {
-;;;     // Diagnose if parameters are all right.
-;;;     var componentName = 'ServiceFactory.provide';
-;;;     if (! config.getter) {
-;;;         throw this._makeError(componentName, 'config.getter');
-;;;     }
-;;;     if (! config.sourceName) {
-;;;         throw this._makeError(componentName, 'config.sourceName');
-;;;     }
-;;;     if (! config.sourceVersion) {
-;;;         throw this._makeError(componentName, 'config.sourceVersion');
-;;;     }
-        if (this.registrar.built) {
-;;;         kukit.E = 'Attempt to provide implementation to method [';
-;;;         kukit.E += this.methodName + '] on already finalized registry [';
-;;;         kukit.E += this.registrar.registryName + ']';
-            throw new Error(kukit.E);
-        } else if (typeof(this.sources[config.sourceName]) != 'undefined') {
-;;;         kukit.E = 'Double registration by [' + config.sourceName + '][';
-;;;         kukit.E += providerVersion; 
-;;;         kukit.E += '] of method [' + this.name;
-;;;         kukit.E += '] in registry [' + this.registrar.registryName + ']';
+    this.initialize.apply(this, arguments);
+
+};
+reg.BindSequenceRegistrar.prototype = new reg.Registrar();
+/* end BindSequenceRegistrar */
+
+
+/*
+ *
+ * class ServiceRegistrar
+ *
+ *
+ */ 
+
+reg.ServiceRegistrar = function() {
+    
+    this.register = function(name) {
+        if (typeof(this.get(name)) != 'undefined') {
+;;;         kukit.E = 'Double registration of service [' + name;
+;;;         kukit.E += '] in registry [' + this.registryName + ']';
             throw new Error(kukit.E);
         }
-        // Store the config
-        config.methodName = this.name;
-        this.sources[config.sourceName] = config;
+
+        this.configs[name] = new reg.ServiceConfig(name);
+        return this.configs[name];
     };
 
-    this.create = function() {
+    this.buildRegistry = function() {
+        this.checkBuilt();
+        var registry = {};
+        for (var name in this.configs) {
+            var config = this.configs[name];
+            registry[name] = this.createService(config);
+        };
+        return registry;
+    };
+    
+    this.createService = function(config) {
         var func;
-        if (! this.preferredSources) {
-;;;         kukit.E = 'Undefined method [';
-;;;         kukit.E += this.name + '] on registry [';
-;;;         kukit.E += this.registrar.registryName + '], ';
-;;;         kukit.E += 'but the following were provided:';
-;;;         kukit.E += this.sources + ']';
+        if (! config.preferredSources) {
+;;;         kukit.E = 'Method [';
+;;;         kukit.E += config.name + '] did not specify its preferred sources';
+;;;         kukit.E += 'even though sources were provided:';
+;;;         kukit.E += config.sources + ']';
             throw new Error(kukit.E);
         }
         // loop through all preferred providers
-        for (var i = 0; i < this.preferredSources.length; i++) {
-            var item = this.sources[this.preferredSources[i]];
+        for (var i = 0; i < config.preferredSources.length; i++) {
+            var item = config.sources[config.preferredSources[i]];
             // Did we have an item?
             if (typeof(item) == 'undefined') {
                 continue;
@@ -196,24 +216,23 @@
         }
         if (! func) {
             // We raise an error.
-;;;         kukit.E = 'Could not bind item [';
-;;;         kukit.E += this.name + '] on registry [';
-;;;         kukit.E += this.registrar.registryName;
-;;;         kukit.E += '], because no provider found ';
-;;;         kukit.E += 'of the following preferences: [';
-;;;         kukit.E += this.preferredSources + ']';
+;;;         kukit.E = 'Cannot build item [';
+;;;         kukit.E += config.name + ']';
+;;;         kukit.E += 'because we found no provider ';
+;;;         kukit.E += 'complying to the following preferences: [';
+;;;         kukit.E += config.preferredSources + ']';
             throw new Error(kukit.E);
         } else {
             // We found the func that we can finalize now.
 ;;;         var msg = 'Using method [';
-;;;         msg += this.name + '] from source [';
+;;;         msg += config.name + '] from source [';
 ;;;         msg += item.sourceName + '] version [';
 ;;;         msg += item.sourceVersion + '].';
 ;;;         kukit.log(msg);
             // Return the func, optionally prefixed with a checker.
-            if (this.checker) {
+            if (config.checker) {
                 // if there is a checker, merge them together
-                var self = this;
+                var self = config;
                 return function() {
                     self.checker.apply(null, arguments);
                     return func.apply(null, arguments);
@@ -224,104 +243,78 @@
             }
         }
     };
-
     this.initialize.apply(this, arguments);
 
-}; /* end ServiceFactory */
-
+};
+reg.ServiceRegistrar.prototype = new reg.Registrar();
+/* end ServiceRegistrar */
 
 /*
- * KSS plugin registry
+ * KSS service layer resource
  */
 
-reg.PluginFactory = function() {
+reg.ServiceConfig = function() {
 
-    this.initialize = function(registrar, name) {
-        this.registrar = registrar;
+    this.initialize = function(name) {
         this.name = name;
-        this.config = undefined;
-    };
-
-    this.register = function(config) {
-        if (typeof(this.config) != 'undefined') {
-;;;         kukit.E = 'Double registration of plugin [' + this.name;
-;;;         kukit.E += '] in registry [' + this.registrar.registryName + ']';
-            throw new Error(kukit.E);
-        }
-        this.config = config;
-    };
-
-    this.create = function() {
-        return this.config;
+        this.sources = {};
+        this.preferredsources = null;
+        this.built = false;
     };
 
-    this.initialize.apply(this, arguments);
-
-}; /* end PluginFactory */
-
-/*
- * BindSequenceFactory
- *
- * We need this factory because we need to
- * register the binding of events. This is done by a binding
- * class and a set of events that bind together on this
- * class, and a binding strategy that defines how binding will
- * be called.
- *
- * The event names arrive in a namespace format (dash-separated),
- * formerly we only accepted to register an event set with events
- * of the same namespace. This restriction is dropped now. Since it
- * may make sense, it can be put back in form of asserts on the
- * event names.
- */
-reg.BindSequenceFactory = function() {
-
-    this.initialize = function(registrar, name) {
-        this.registrar = registrar;
-        this.name = name;
-        this.config = null;
-    };
+;;; this._makeError = function(componentName, name) {
+;;;     kukit.E =  'In a call to ' + componentName + ', ';
+;;;     kukit.E += name + ' must be provided for method [';
+;;;     kukit.E += this.name + '].';
+;;;     return new Error(kukit.E);
+;;; };
 
-    this.register = function(config) {
-        // This is called on any method descriptors,
-        // i.e. this is a "class method".
-        // Register config to all event names individually.
-        // Take names from the config.
-        for (var i = 0; i < config.eventNames.length; i++) {
-            var name = config.eventNames[i];
-            this.registrar.getItemFactory(name)._register(config);
-        }
+    this.require = function(config) {
+;;;     // Diagnose if parameters are all right.
+;;;     if (! config.preferredSources) {
+;;;         throw this._makeError('ServiceConfig.require', 
'config.preferredSources');
+;;;     };
+        if (this.preferredSources) {
+;;;         kukit.E = 'ServiceConfig.require is called twice on [';
+;;;         kukit.E += this.name + '].';
+            throw new Error(kukit.E);
+        };
+        this.preferredSources = config.preferredSources;
+        this.checker = config.checker;
+        this.fallbackProvider = config.fallbackProvider;
     };
 
-    this._register = function(config) {
-        if (this.config != null) {
-;;;         kukit.E = 'Double registration of item [' + this.name;
-;;;         kukit.E += '] in plugin registry [' + this.registrar.registryName 
+ ']';
+    this.provide = function(config) {
+;;;     // Diagnose if parameters are all right.
+;;;     var componentName = 'ServiceConfig.provide';
+;;;     if (! config.getter) {
+;;;         throw this._makeError(componentName, 'config.getter');
+;;;     }
+;;;     if (! config.sourceName) {
+;;;         throw this._makeError(componentName, 'config.sourceName');
+;;;     }
+;;;     if (! config.sourceVersion) {
+;;;         throw this._makeError(componentName, 'config.sourceVersion');
+;;;     }
+        if (this.built) {
+;;;         kukit.E = 'Attempt to provide implementation to method [';
+;;;         kukit.E += this.methodName + '] on already built registry.';
+            throw new Error(kukit.E);
+        } else if (typeof(this.sources[config.sourceName]) != 'undefined') {
+;;;         kukit.E = 'Double registration by [' + config.sourceName + '][';
+;;;         kukit.E += providerVersion; 
+;;;         kukit.E += '] of method [' + this.name + '].';
             throw new Error(kukit.E);
         }
-        // Do some diagnostics    // check the iterator.
-;;;     if  (! kukit.er.getBindIterator(config.iterName)) {
-;;;         kukit.E = 'In BindSequenceFactory.register: unknown bind strategy 
[';
-;;;         kukit.E += config.iterName + '].';
-;;;         throw new Error(kukit.E);
-;;;     }
-
-        // Decorate binder class.
-        kukit.er.decorateEventBinderClass(config.binderClass);
-
-        // store the config
-        this.config = config;
-
+        // Store the config
+        config.methodName = this.name;
+        this.sources[config.sourceName] = config;
     };
 
-    this.create = function() {
-        // Just return the registered value.
-        return this.config;
-    };
 
     this.initialize.apply(this, arguments);
 
-}; /* end BindSequenceFactory */
+}; /* end ServiceConfig */
 
 /* 
  * Global handling of registries in kukit
@@ -365,11 +358,11 @@
 reg.setupGlobalRegistries = function() {
     // instantiate registries
     kukit.registrars = {};
-    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) 
+    kukit.registrars.events = new reg.PluginRegistrar('events') 
+    kukit.registrars.bindsequences = new 
reg.BindSequenceRegistrar('bindsequences')
+    kukit.registrars.actions = new reg.PluginRegistrar('actions') 
+    kukit.registrars.valueproviders = new 
reg.PluginRegistrar('valueproviders') 
+    kukit.registrars.services = new reg.ServiceRegistrar('services') 
 };
 
 // Finalize global registries
@@ -428,16 +421,15 @@
         var itemName = item[1];
         var config = item[2];
         var registrar = registries[itemType];
-        var factory = registrar.getItemFactory(itemName);
 ;;;     // Check that we are in a plugin registry.
 ;;;     // It must have a register method.
-;;;     if (typeof(factory.register) == 'undefined') {
+;;;     if (typeof(registrar.register) == 'undefined') {
 ;;;         kukit.E = 'Bad registry name in registerPlugins call [';
 ;;;         kukit.E += itemType + '], it is not a valid plugin registry.';
 ;;;         throw new Error(kukit.E);
 ;;;     }
         // Register it.
-        factory.register(config);
+        registrar.register(itemName, config);
     }
 };
 

Modified: 
kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/selectorreg.js
==============================================================================
--- kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/selectorreg.js    
(original)
+++ kukit/kukit.js/branch/gotcha-simplify-service-layer/kukit/selectorreg.js    
Sun Dec 28 22:50:13 2008
@@ -85,7 +85,7 @@
 };
 
 var registrar = kukit.registrars.valueproviders;
-registrar.getItemFactory('passnode').register({
+registrar.register('passnode', {
         providerClass: sr.PassnodePP,
         returnType: 'selection'});
 // the item now will contain providerClass only,
@@ -114,9 +114,9 @@
 ;;;     throw new Error(kukit.E);
 ;;; }
     // Also register the selector param provider
-    var registrar = kukit.registrars.valueproviders;
     var providerClass = sr.makeAnySelectorProvider(selectorFunc);
-    registrar.getItemFactory(name).register({
+    var registrar = kukit.registrars.valueproviders;
+    registrar.register(name, {
         providerClass: providerClass,
         selectorFunc: selectorFunc,
         returnType: 'selection'});

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 Dec 28 22:50:13 2008
@@ -9,7 +9,9 @@
 // kukit's preferences to choose between sources
 // that implement a given functionality.
 
-services.getItemFactory('cssQuery').require({
+var cssQuery = services.register('cssQuery');
+
+cssQuery.require({
     preferredSources: ['base2', 'base2-legacy', 'cssQuery'],
     // a parameter checker common for each implementation
     checker: function(selector, inNodes) {
@@ -24,7 +26,7 @@
 // that we can detect ourselves. by inspecting if a given
 // library is loaded.
 
-services.getItemFactory('cssQuery').provide({
+cssQuery.provide({
     sourceName:'cssQuery', 
     sourceVersion: '2.0.2', 
     getter: function() {
@@ -53,7 +55,7 @@
     return results;
 };
 
-services.getItemFactory('cssQuery').provide({
+cssQuery.provide({
     sourceName: 'base2-legacy', 
     sourceVersion: '<<20020070816', 
     getter: function() {
@@ -73,7 +75,7 @@
         };
     }});
 
-services.getItemFactory('cssQuery').provide({
+cssQuery.provide({
     sourceName: 'base2', 
     sourceVersion: '0.??', 
     getter: function() {

Modified: kukit/kukit.js/branch/gotcha-simplify-service-layer/tests/runtests.js
==============================================================================
--- kukit/kukit.js/branch/gotcha-simplify-service-layer/tests/runtests.js       
(original)
+++ kukit/kukit.js/branch/gotcha-simplify-service-layer/tests/runtests.js       
Sun Dec 28 22:50:13 2008
@@ -25,7 +25,6 @@
     testsuite.registerTest(kukit.KssParserSelectorsTestCase);
     testsuite.registerTest(kukit.KssParserValueProvidersCheckTestCase);
     testsuite.registerTest(kukit.KssParserSelectorTestCase);
-    testsuite.registerTest(kukit.RegistriesTestCase);
     testsuite.registerTest(kukit.ServiceRegistryTestCase);
     testsuite.registerTest(kukit.PluginRegistriesTestCase);
     testsuite.registerTest(kukit.ErrorsTestCase);

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 Dec 28 22:50:13 2008
@@ -21,78 +21,6 @@
     var kukit = {};
 }
 
-kukit.RegistriesTestCase = function() {
-    this.name = 'kukit.RegistriesTestCase';
-   
-   var called = [];
-
-   var TestFactory = function(registrar, name) {
-        this.registrar = registrar;
-        this.name = name;
-        this.doThis = function() {
-            called.push("doThis");
-        }
-        this.doThat = function() {
-            called.push("doThat");
-        }
-        this.create = function() {
-            var signature = "FUNC " + this.name;
-            called.push(signature);
-            return signature;
-        }
-    };
-
-    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 = [];
-        var registrar = new kukit.reg.Registrar('dummytest', TestFactory);
-        this.assert(typeof(registrar), 'object');
-        // Let's get two items
-        registrar.getItemFactory('fooItem').doThis()
-        registrar.getItemFactory('barItem').doThat()
-        // Check
-        this.assertListEquals(called, ['doThis', 'doThat']);
-        called = [];
-        // Ok. Now get the descriptors again...
-        registrar.getItemFactory('fooItem').doThis()
-        registrar.getItemFactory('barItem').doThat()
-        // Check
-        this.assertListEquals(called, ['doThis', 'doThat']);
-    };
-
-    this.testFinalizeRegistries = function() {
-        // We have a singleton, called s.
-        var s = {};
-        // We eill create a simple item for a selected registry.
-        // The factory is managing the item's registration state 
-        called = [];
-        var registrar = new kukit.reg.Registrar('dummytest', TestFactory);
-        // Let's get two factories
-        registrar.getItemFactory('fooItem').doThis()
-        registrar.getItemFactory('barItem').doThat()
-        // Check
-        this.assertListEquals(called, ['doThis', 'doThat']);
-        called = [];
-        this.dummytest = registrar.buildRegistry();
-        this.assertListEquals(called, ['FUNC fooItem', 'FUNC barItem']);
-        called = [];
-        // At the same time it also set up these on the class prototype.
-        this.assertEquals(this.dummytest.fooItem, 'FUNC fooItem');
-        this.assertEquals(this.dummytest.barItem, 'FUNC barItem');
-    };
-
-}; /* end RegistriesTestCase */
-kukit.RegistriesTestCase.prototype = new kukit.UtilsTestCaseBase();
-
-
 kukit.ServiceRegistryTestCase = function() {
     this.name = 'kukit.ServiceRegistryTestCase';
     
@@ -101,7 +29,7 @@
         // kukit.service or kukit.plugins.
         this.registries = {};
         this.registrars = {}
-        this.registrars.dummyservice = new kukit.reg.Registrar('dummyservice', 
kukit.reg.ServiceFactory);
+        this.registrars.dummyservice = new 
kukit.reg.ServiceRegistrar('dummyservice');
     };
 
     this.testServiceRegistry = function() {
@@ -109,39 +37,43 @@
         var s = {};
         var registrar = this.registrars.dummyservice;
         // Requires four methods, thie defines their necessity and preferred 
providers
-        registrar.getItemFactory('first').require({
+        var first = registrar.register('first');
+        first.require({
             preferredSources: ['corelib', 'extralib']});
-        registrar.getItemFactory('second').require({
+        var second = registrar.register('second');
+        second.require({
             preferredSources: ['extralib', 'corelib']});
-        registrar.getItemFactory('third').require({
+        var third = registrar.register('third');
+        third.require({
             preferredSources: ['corelib']});
-        registrar.getItemFactory('fourth').require({
+        var fourth = registrar.register('fourth');
+        fourth.require({
             preferredSources: ['extralib']});
         //
         // somewhere else, source "corelib" provides the methods:
-        registrar.getItemFactory('first').provide({
+        first.provide({
             sourceName: 'corelib', 
             sourceVersion: '1.1', 
             getter: function() {return function() {return 'first/core';}}});
-        registrar.getItemFactory('second').provide({ 
+        second.provide({ 
             sourceName: 'corelib', 
             sourceVersion: '1.1', 
             getter: function() {return function() {return 'second/core';}}});
-        registrar.getItemFactory('third').provide({ 
+        third.provide({ 
             sourceName: 'corelib', 
             sourceVersion: '1.1', 
             getter: function() {return function() {return 'third/core';}}});
         //
         // somewhere else, source "extras" provides the methods:
-        registrar.getItemFactory('first').provide({
+        first.provide({
             sourceName: 'extralib', 
             sourceVersion: '12.4', 
             getter: function() {return function() {return 'first/extra';}}});
-        registrar.getItemFactory('second').provide({
+        second.provide({
             sourceName: 'extralib', 
             sourceVersion: '12.4', 
             getter: function() {return function() {return 'second/extra';}}});
-        registrar.getItemFactory('fourth').provide({
+        fourth.provide({
             sourceName: 'extralib', 
             sourceVersion: '12.4', 
             getter: function() {return function() {return 'fourth/extra';}}});
@@ -161,18 +93,19 @@
         // and a counter for the checker
         var checker_counter = 0;
         // Define three methods
-        registrar.getItemFactory('first').require({
+        var first = registrar.register('first');
+        first.require({
             preferredSources: ['corelib', 'extralib'],
             checker: function() {checker_counter++;}});
         //
         // somewhere else, core provides the methods:
-        registrar.getItemFactory('first').provide({
+        first.provide({
             sourceName: 'corelib',
             sourceVersion: '1.1',
             getter: function() {return function() {return 'first/core';}}});
         //
         // somewhere else, extras provides the methods:
-        registrar.getItemFactory('first').provide({
+        first.provide({
             sourceName: 'extralib', 
             sourceVersion: '12.4', 
             getter: function() {return function() {return 'first/extra';}}});
@@ -189,13 +122,14 @@
         // We have a singleton, called s.
         var s = {};
         var registrar = this.registrars.dummyservice;
+        var first = registrar.register('first');
         // Provide the method first
-        registrar.getItemFactory('first').provide({
+        first.provide({
             sourceName: 'corelib',
             sourceVersion: '1.1',
             getter: function() {return function() {return 'first/core';}}});
         // Define the method later
-        registrar.getItemFactory('first').require({
+        first.require({
             preferredSources: ['corelib', 'extralib']});
         this.dummyservice = registrar.buildRegistry();
         // We can call the methods on it,
@@ -206,13 +140,14 @@
         // A registrar can only be built once.
         var s = {};
         var registrar = this.registrars.dummyservice;
+        var first = registrar.register('first');
         // Provide the method first
-        registrar.getItemFactory('first').provide({
+        first.provide({
             sourceName: 'corelib',
             sourceVersion: '1.1',
             getter: function() {return function() {return 'first/core';}}});
         // Define the method later
-        registrar.getItemFactory('first').require({
+        first.require({
             preferredSources: ['corelib', 'extralib']});
         registrar.buildRegistry();
         this.assertThrows(function() {
@@ -225,8 +160,9 @@
         // A method is provided but not required.
         var s = {};
         var registrar = this.registrars.dummyservice;
+        var first = registrar.register('first');
         // Provide the method first
-        registrar.getItemFactory('first').provide({
+        first.provide({
             sourceName: 'corelib',
             sourceVersion: '1.1',
             getter: function() {return function() {return 'first/core';}}});
@@ -239,14 +175,15 @@
     this.testDoubleProvided = function() {
         // A method cannot be provided twice by the same source.
         var registrar = this.registrars.dummyservice;
+        var first = registrar.register('first');
         // Provide the method first
-        registrar.getItemFactory('first').provide({
+        first.provide({
             sourceName: 'corelib',
             sourceVersion: '1.1',
             getter: function() {return function() {return 'first/core';}}});
         // Now provide it for the second time.
         this.assertThrows(function() {
-            registrar.getItemFactory('first').provide({
+            first.provide({
                 sourceName: 'corelib',
                 sourceVersion: '1.1',
                 getter: function() {return function() {return 
'first/core';}}});
@@ -257,12 +194,13 @@
     this.testDoubleDefined = function() {
         // A method can only be required once.
         var registrar = this.registrars.dummyservice;
+        var first = registrar.register('first');
         // Define the method first
-        registrar.getItemFactory('first').require({
+        first.require({
             preferredSources: ['corelib', 'extralib']});
         // require it again.
         this.assertThrows(function() {
-            registrar.getItemFactory('first').require({
+            first.require({
                 preferredSources: ['corelib', 'extralib']})},
             Error);
     };
@@ -271,11 +209,12 @@
         // No preferred provider can be found for a method.
         var s = {};
         var registrar = this.registrars.dummyservice;
+        var first = registrar.register('first');
         // Define the method first
-        registrar.getItemFactory('first').require({
+        first.require({
             preferredSources: ['corelib', 'extralib']});
         // Someone provides the method, but it's not good.
-        registrar.getItemFactory('first').provide({
+        first.provide({
             sourceName: 'craplib',
             sourceVersion: '1.1',
             getter: function() {return function() {return 'first/crap';}}});
@@ -297,8 +236,8 @@
         // kukit.plugins
         this.registries = {};
         this.registrars = {}
-        this.registrars.dummyevents = new kukit.reg.Registrar('dummyevents', 
kukit.reg.PluginFactory);
-        this.registrars.dummybindsequences = new 
kukit.reg.Registrar('dummybindsequences', kukit.reg.BindSequenceFactory);
+        this.registrars.dummyevents = new 
kukit.reg.PluginRegistrar('dummyevents');
+        this.registrars.dummybindsequences = new 
kukit.reg.BindSequenceRegistrar('dummybindsequences');
     };
 
     var M = function() {
@@ -308,19 +247,19 @@
         var events = this.registrars.dummyevents;
         var bindsequences = this.registrars.dummybindsequences;
         // somewhere else, core registers the items:
-        events.getItemFactory('click').register({
+        events.register('click', {
             name: 'click',
             defaultActionMethodName: null,
             parmtypes: [
                 ['preventDefault', 'bool', true],
                 ['allowBubbling', 'bool', false]]});
-        events.getItemFactory('keydown').register({
+        events.register('keydown', {
             name: 'keydown',
             defaultActionMethodName: null,
             parmtypes: [
                 ['preventDefault', 'bool', true],
                 ['allowBubbling', 'bool', false]]});
-        bindsequences.getItemFactory('').register({
+        bindsequences.register({
             eventNames: ['click', 'keydown'],
             iterName: 'Each',
             binderClass: M,
@@ -328,7 +267,7 @@
         //*/
         //
         // somewhere else, extras registers the items:
-        events.getItemFactory('timeout').register({
+        events.register('timeout', {
             name: 'timeout',
             defaultActionMethodName: null,
             parmtypes: [
@@ -336,7 +275,7 @@
                 ['renew', 'bool', false]]});
         // It needs a bind iterator even though it is a single
         // sequence.
-        bindsequences.getItemFactory('').register({
+        bindsequences.register({
             eventNames: ['timeout'],
             iterName: 'Each',
             binderClass: M,
@@ -355,7 +294,7 @@
         var events = this.registrars.dummyevents;
         var bindsequences = this.registrars.dummybindsequences;
         // somewhere a plugin registers an item:
-        events.getItemFactory('click').register({
+        events.register('click', {
             name: 'click',
             defaultActionMethodName: null,
             parmtypes: [
@@ -363,7 +302,7 @@
                     ['allowBubbling', 'bool', false]]});
         // But another registration attempt is harshly punished by an Error.
         this.assertThrows(function() {
-            events.getItemFactory('click').register({
+            events.register('click', {
                 name: 'click',
                 defaultActionMethodName: null,
                 parmtypes: [
@@ -379,7 +318,7 @@
         var bindsequences = this.registrars.dummybindsequences;
         // somewhere else, core registers the items.
         // XXX registry name '' is used to call registry level methods
-        bindsequences.getItemFactory('').register({
+        bindsequences.register({
             eventNames: ['click', 'timeout'],
             iterName: 'Each',
             binderClass: M,
@@ -392,7 +331,7 @@
             this.bind2 = function(oper) {};
         };
         MSub.prototype = new M();
-        bindsequences.getItemFactory('').register({
+        bindsequences.register({
             eventNames: ['keydown', 'keypress'],
             iterName: 'Each',
             binderClass: MSub,
@@ -410,19 +349,6 @@
         this.assertNotEquals(M.prototype.__className__, 
MSub.prototype.__className__);
     };
 
-    this.testOnlyRegisteredPluginsCanBeBuilt = function() {
-        // We assure that if an item is produced but it is not registered,
-        // it will not be built on the configuration.
-        var events = this.registrars.dummyevents;
-        var bindsequences = this.registrars.dummybindsequences;
-        // Just call up the factoryr: this will create it with config=null.
-        events.getItemFactory('click');
-        this.dummyevents = events.buildRegistry();
-        // Check that click is not defined at all. (in particular, it should 
not be null or {}.) 
-        // Since other code that uses it, depends that if it has a value, it 
is the real config.
-        this.assertEquals(typeof(this.dummyevents.click), 'undefined');
-    };
-
     this.testRegisterPlugins = function() {
         // Test registerPlugins method.
         //
@@ -507,7 +433,6 @@
 kukit.PluginRegistriesTestCase.prototype = new kukit.UtilsTestCaseBase();
 
 if (typeof(testcase_registry) != 'undefined') {
-    testcase_registry.registerTestCase(kukit.RegistriesTestCase, 
'kukit.RegistriesTestCase');
     testcase_registry.registerTestCase(kukit.ServiceRegistryTestCase, 
'kukit.ServiceRegistryTestCase');
     testcase_registry.registerTestCase(kukit.PluginRegistriesTestCase, 
'kukit.PluginRegistriesTestCase');
 }
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to