[KSS-checkins] r53820 - in kukit/kukit.js/branch/ree-service-layer-and-refactoring: kukit tests
reebalazs at codespeak.net
reebalazs at codespeak.net
Wed Apr 16 12:15:38 CEST 2008
Author: reebalazs
Date: Wed Apr 16 12:15:37 2008
New Revision: 53820
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/actionreg.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/commandreg.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/eventreg.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/interfaces.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/kukit.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/providerreg.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/selectorreg.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/service.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_interfaces.js
Log:
Changing of names in interfaces.js after discussion on snowsprint
Modified: kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/actionreg.js
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/actionreg.js (original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/actionreg.js Wed Apr 16 12:15:37 2008
@@ -37,7 +37,7 @@
;;; throw new Error(kukit.E);
;;; }
var actions = kukit.pluginregistry.schema.actions;
- actions.getAttribute(name).register({actionFunc: func});
+ actions.getItemFactory(name).register({actionFunc: func});
};
this.get = function(name) {
Modified: kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/commandreg.js
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/commandreg.js (original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/commandreg.js Wed Apr 16 12:15:37 2008
@@ -36,26 +36,26 @@
var actions = kukit.pluginregistry.schema.actions;
//
// register a given action as a command, using the given vactor
- var attrib = actions.getAttribute(srcname);
- if (! attrib.config) {
+ var action_factory = actions.getItemFactory(srcname);
+ if (! action_factory.config) {
;;; 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(attrib.config.actionFunc);
+ var commandClass = factory(action_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.getAttribute(name).register(attrib.config);
+ actions.getItemFactory(name).register(action_factory.config);
// only declare the command class if it's missing
- if (typeof(attrib.config.commandClass) == 'undefined') {
- this._register(name, commandClass, attrib);
+ if (typeof(action_factory.config.commandClass) == 'undefined') {
+ this._register(name, commandClass, action_factory);
}
} else {
// This is the normal case - just register it
- this._register(srcname, commandClass, attrib);
+ this._register(srcname, commandClass, action_factory);
}
@@ -63,7 +63,7 @@
this.register = function(name, commandClass) {
var actions = kukit.pluginregistry.schema.actions;
- var attrib = actions.getAttribute(name);
+ var attrib = actions.getItemFactory(name);
this._register(name, commandClass, attrib);
};
Modified: kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/eventreg.js
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/eventreg.js (original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/eventreg.js Wed Apr 16 12:15:37 2008
@@ -79,7 +79,7 @@
namespacedEventNames.push(eventName);
// register the event informataion
var events = kukit.pluginregistry.schema.events;
- events.getAttribute(eventName).register({
+ events.getItemFactory(eventName).register({
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.pluginregistry.schema.bindsequences;
- bindsequences.getAttribute('').register({
+ bindsequences.getItemFactory('').register({
eventNames: namespacedEventNames,
iterName: iterName,
binderClass: binderClass,
Modified: kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/interfaces.js
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/interfaces.js (original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/interfaces.js Wed Apr 16 12:15:37 2008
@@ -2,27 +2,24 @@
kukit.ifa = new function() { /* BEGIN CLOSURE kukit.ifa */
/*
- * Kukit interfaces
+ * Kukit registry
*
- * Warning: this is not comparable with Zope interfaces. It has much
- * smaller scope and aims at a different use case.
- *
- * We want a way to initialize a "set of attributes". An attribute can
- * be the an event, action, etc. registry, or method of a service
- * interface. The initialization of these attributes depends only on
+ * We want a way to initialize a set of registration items. An item can
+ * be the descriptor of an event, action, etc., or method of a service
+ * API. The initialization of these items depends only on
* what javascript code is present and how it is defining these
- * interfaces.
+ * items.
*
- * The atributes or methods have method descriptors that can get their
- * methods called and have a state that represents offers and demands
- * on that given attribute or method.
+ * The items have a factory that provides various
+ * methods that can be called on it, as well as a state
+ * that results from these calls.
*
* In case of an action plugin, this is just storing registry info
* keyed by the action name. However in case of a service interface,
* different components may provide the requested item, and the final
* value of the method is decided at finalization and all this logic
- * is handled by the method descriptor. In case of service
- * interfaces, this allows that "define service" and "provide service"
+ * is handled by the Factory. In case of service
+ * registries, this allows that "define service" and "provide service"
* sections can be in different javascript files (plugins), and the
* final outcome is independent of the order of their execution.
*
@@ -33,14 +30,16 @@
* -------------------
*
* When various javascript code is loaded, it can set up the
- * schema for the interfaces it handles. For example, during 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.
*
- * Before accessing the scnema of any named interfaces, its context
- * need to be initialized. This may be happen several times, but at
+ * The registries are managed by name in a collection of registries.
+ * Before accessing the schema of any registry, it needs to
+ * be initialized at one of the names registries object.
+ * This may be happen several times, but at
* least once it has been done before the schema is looked up from
- * code. (It is only needed for getSchema.)
+ * code.
*
* This is the only dependency what we have for the order of the code.
* Ewerywhere else, order is independent. This means that if all
@@ -49,238 +48,238 @@
* case of the plugins), then the order of these javascripts is
* arbitrary for interfaces to work.
*
- * In the initialization the interface name and the attribute class
- * (describing the attribute schema) needs to be supplied as
- * parameters.
+ * In the initialization the interface name and the item factory
+ * need to be supplied as parameters.
*
- * interfaces.initializeContext('myinterface', MyAttributeClass);
+ * registries.initializeRegistry('myregistry', MyFactory);
*
- * After this the schema of the interface can be looked up with:
+ * After this the registrar object can be looked up with:
*
- * var iface = interfaces.schema.myinterface;
+ * var registrar = registries.schema.myregistry;
*
* Or the schema of an attribute can be looked up, and various methods
* can be called on it. This depends on what the attribute class
* actually implements.
*
- * var attrib = interfaces.schema.myinterface.getAttribute('mykey');
- * attrib.doWhateverAttributeClassImplements(blah);
+ * var factory = registries.schema.myregistry.getItemFactory('mykey');
+ * factory.doWhateverTheFactoryImplements(blah);
*
- * This concludes everything we can do, before finalization.
- * Finalization freezes the setup of attributes on the interface and
- * allows its direct use, without the schema. For the finalization, a
- * singleton has to be provided. The interface is finalized on this
- * singleton.
+ * This concludes everything we can do, before binding the registry.
+ * Binding freezes the factorization of items in the registrar and
+ * allows its direct use, without the schema. For the binding, a
+ * singleton registry object has to be provided. The items are
+ * bound on this registry.
*
- * iface.finalize(singleton);
+ * registrar.bindItems(registry);
*
- * In most cases, the singleton can simply be a normal object. So
+ * In most cases, the registry can simply be a normal object. So
* the usual setup what we have a registry for plugins is:
*
- * iface.finalize({});
+ * registrar.bindItems({});
*
- * However an interface could have attributes inherited with
- * a prototype, and if we want to have this, we could finalize
- * it on an object with a different prototype.
+ * However a registry could have attributes inherited with
+ * a prototype, and if we want to have this, we could bind the items
+ * on an object with a different prototype.
*
- * After being finalized, the singleton set up for this interface,
- * will appear directly accessable from interfaces.
+ * After being bound, the registry set up,
+ * will appear directly accessable from registries.
*
- * interfaces.myinterface == singleton
+ * registries.myregistry == registry
*
- * This will be equal to the singleton we used for finalizing it.
- * The singleton contains our attributes directly. (not the schema
- * but already the actual values returned be the attribute's
- * finalize.
+ * This will be identical to the registry object we bound to.
+ * The registry contains our items directly. (not the factory,
+ * but already the actual item values as returned be the factory's
+ * getItem method.)
*
- * interfaces.myinterface.mykey == value
+ * registries.myregistry.mykey == item
*
- * After being finalized, all named interfaces can be accessed from
- * the interfaces object, e.g. in the following way:
+ * After being bound, all named registries can be accessed from
+ * the registries object, e.g. in the following way:
*
- * interfaces.events.click - is an event's registry
- * interfaces.actions.setAttr - is an action's registry
- * interfaces.core.cssQuery - is a core service method
- * interfaces.core.forEach - is a core service method
+ * 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 interfaces for its own use. The
- * finalization of these interfaces is done by kukit at the beginning
+ * Kukit sets up the following registries for its own use. The
+ * binding of these registries is done by kukit at the beginning
* of bootstrap.
*
- * Created on the global interfaces "kukit.pluginregistry":
+ * Created on the global registries "kukit.pluginregistry":
*
* name purpose attribute class
* ---- ------- ---------------
- * events kss event name registry kukit.ifa.PluginResource
- * bindsequences kss event binding reg. kukit.ifa.BindIterationResource
- * actions kss action registry kukit.ifa.PluginResource
- * valueproviders value provider registry kukit.ifa.PluginResource
+ * events kss event name registry kukit.ifa.PluginFactory
+ * bindsequences kss event binding reg. kukit.ifa.BindSequenceFactory
+ * actions kss action registry kukit.ifa.PluginFactory
+ * valueproviders value provider registry kukit.ifa.PluginFactory
*
- * Created on the global interfaces "kukit.service":
+ * Created on the global registries "kukit.service":
*
* name purpose attribute class
* ---- ------- ---------------
- * core core services kukit.ifa.ServiceMethod
+ * core core services kukit.ifa.ServiceFactory
*
- * They are initialized into kukit.interfaces.global during the kukit
- * bootstrap. This means that if the finalization is done from a load
- * event, it does not raise any additional contstraint on the order of
- * javascript files.
*
* For more information, see ../tests/test_interfaces.js .
*
*/
-var Interface = function(interfaces, interfaceName, AttributeClass) {
- // A parameters are the name of the interface, and
- // the method descriptor class it uses.
- //
- this.interfaces = interfaces;
- this.interfaceName = interfaceName;
- this.finalized = false;
- this._registry = {};
- this.AttributeClass = AttributeClass;
+var Registrar = function() {
+
+ this.initialize = function(namedRegistries, registryName, Factory) {
+ this.namedRegistries = namedRegistries;
+ this.registryName = registryName;
+ this.bound = false;
+ this.factories = {};
+ this.Factory = Factory;
+ };
- this.getAttribute = function(attributeName) {
+ this.getItemFactory = function(name) {
// create the attribute on demand
- var attrib = this._registry[attributeName];
- if (typeof(attrib) == 'undefined') {
+ 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 descriptor
- attrib = this._registry[attributeName] = new this.AttributeClass(this, attributeName);
+ // instantiate the factory
+ factory = this.factories[name] = new this.Factory(this, name);
}
- return attrib;
+ return factory;
};
- /* Apply functions on attributes of the interface */
+ /* Iterate a function on each factory of this registrar */
- this.forEachAttribute = function(f, a1, a2, a3, a4, a5) {
- // Execute f for each attribute.
+ this.forEachFactory = function(f, a1, a2, a3, a4, a5) {
+ // Apply f for each factory.
// f will receive attributeName, attribute, and the rest
- // of the parameters passed to forEach.
+ // of the parameters passed to forEachFactory.
// methodName and MethodDescriptor will be passed to f as parameters.
// Extra arguments will be passed in addition.
- for (var attributeName in this._registry) {
- var attribute = this._registry[attributeName];
+ for (var name in this.factories) {
+ var factory = this.factories[name];
// Provide the necessary parameters and call f
- f(attributeName, attribute, a1, a2, a3, a4, a5);
+ f(name, factory, a1, a2, a3, a4, a5);
}
};
- this.finalize = function(singleton, loader) {
+ this.bindItems = function(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)
//
// Check if we are finalized.
- if (this.finalized) {
-;;; kukit.E = 'Attempt to finalize already finalized plugin interface [';
-;;; kukit.E += this.interfaceName + ']';
+ if (this.bound) {
+;;; kukit.E = 'Attempt to bind already bound registry [';
+;;; kukit.E += this.registryName + ']';
throw new Error(kukit.E);
}
-;;; kukit.E = 'Finalizing interface [' + this.interfaceName + ']';
+;;; kukit.E = 'Binding registry [' + this.registryName + ']';
;;; kukit.logDebug(kukit.E);
// Finalize all methods.
- this.forEachAttribute(function(attributeName, attribute) {
- // finalize the attributes and store them on the singleton
+ this.forEachFactory(function(name, factory) {
+ // finalize the attributes and store them on the registry
//
- // Get the finalized value for this attribute
- var value = attribute.finalize(loader);
- if (typeof(value) != 'undefined') {
- // Set the attribute on the singleton
- singleton[attributeName] = value;
+
+ // Get the finalized item from this factory
+ var item = factory.produceItem(loader);
+ if (typeof(item) != 'undefined') {
+ // Set the item on the registry
+ registry[name] = item;
};
});
- // Store the singleton itself on interfaces
- this.interfaces[this.interfaceName] = singleton;
- // Set finalized state.
- // We are finalized if the loader has no items to load.
- // If there is no loader, we are finalized always.
- this.finalized = ! loader || loader.empty();
-;;; if (! this.finalized) {
-;;; kukit.E = 'Postpone finalization of interface [' + this.interfaceName + '],';
+ // Store the registry itself on the registries
+ // this means that it can be accessed as registries.registryname
+ this.namedRegistries[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);
;;; }
};
-
-}; /* end Interface */
+
+ this.initialize.apply(this, arguments);
+
+}; /* end Registrar */
-this.NamedInterfaces = function() {
+this.NamedRegistries = function() {
this.schema = {};
- this.initializeContext = function(interfaceName, AttributeClass) {
- // This sets up the interface given by name with the
- // specified Attribute class, or checks it.
+ this.initializeRegistry = function(registryName, Factory) {
+ // This sets up the registry given by name with the
+ // specified Factory class, or checks it.
// This method needs to be called preceding the calls
- // to getSchema on the given interface.
- // It can be called more times with the same method
- // descriptor.
+ // 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 (! AttributeClass) {
-;;; kukit.E = 'NamedInterfaces.initializeContext() is called for interface [';
-;;; kukit.E += interfaceName + '] without an AttributeClass parameter.';
+;;; if (! Factory) {
+;;; kukit.E = 'Registries.initializeRegistry() is called for registry [';
+;;; kukit.E += registryName + '] without a Factory parameter.';
;;; throw new Error(kukit.E);
;;; }
// Check prohibited names
- if (interfaceName == 'schema' || interfaceName == 'initializeContext') {
-;;; kukit.E = 'NamedInterfaces.initializeContext() cannot be called ';
+ if (registryName == 'schema' || registryName == 'initializeRegistry') {
+;;; kukit.E = 'Registries.initializeRegistry() cannot be called ';
;;; kukit.E += 'with a reserved name [';
-;;; kukit.E += interfaceName + '].';
+;;; kukit.E += registryName + '].';
throw new Error(kukit.E);
}
- // see if we already have an attribute
- var iface = this.schema[interfaceName];
- // create the interface on demand
- if (typeof(iface) == 'undefined') {
- // create the interface and store it on myself
- this.schema[interfaceName] = new Interface(this, interfaceName, AttributeClass);
+ // see if we already have this registrar
+ var registrar = this.schema[registryName];
+ // create the registrar on demand
+ if (typeof(registrar) == 'undefined') {
+ // create the registrar and store it on myself
+ this.schema[registryName] = new Registrar(this, registryName, Factory);
} else {
- // check that the same AtributeClass was provided. If not,
+ // check that the same Factory was provided. If not,
// it's a conflict.
- if (iface.AttributeClass != AttributeClass) {
-;;; kukit.E = 'NamedInterfaces.initializeContext() is called for interface [';
-;;; kukit.E += interfaceName + '] with a different AttributeClass than earlier.';
+ if (registrar.Factory != Factory) {
+;;; kukit.E = 'Registries.initializeRegistry() is called for registry [';
+;;; kukit.E += interfaceName + '] with a different Factory than earlier.';
throw new Error(kukit.E);
}
}
};
-}; /* end NamedInterfaces */
+}; /* end NamedRegistries */
/*
* KSS service layer resource
*/
-this.ServiceMethod = function(iface, methodName) {
+this.ServiceFactory = function() {
- this.iface = iface;
- this.methodName = methodName;
- this.registry = {};
- this.preferredSources = null;
+ this.initialize = function(registrar, name) {
+ this.registrar = registrar;
+ this.name = name;
+ this.sources = {};
+ this.preferredSources = null;
+ };
;;; this._makeError = function(componentName, name) {
;;; kukit.E = 'In a call to ' + componentName + ', ';
;;; kukit.E += name + ' must be provided for method [';
-;;; kukit.E += this.methodName + '] on interface [';
-;;; kukit.E += this.iface.interfaceName + ']';
+;;; kukit.E += this.name + '] on registry [';
+;;; kukit.E += this.registrar.registryName + ']';
;;; return new Error(kukit.E);
;;; };
this.require = function(config) {
;;; // Diagnose if parameters are all right.
;;; if (! config.preferredSources) {
-;;; throw this._makeError('ServiceMethod.require', 'config.getter');
+;;; throw this._makeError('ServiceFactory.require', 'config.getter');
;;; };
if (this.preferredSources) {
-;;; kukit.E = 'ServiceMethod.require is called twice on [';
-;;; kukit.E += this.methodName + '] on interface [';
-;;; kukit.E += this.iface.interfaceName + ']';
+;;; kukit.E = 'ServiceFactory.require is called twice on [';
+;;; kukit.E += this.name + '] on registry [';
+;;; kukit.E += this.registrar.registryName + ']';
throw new Error(kukit.E);
};
this.preferredSources = config.preferredSources;
@@ -290,7 +289,7 @@
this.provide = function(config) {
;;; // Diagnose if parameters are all right.
-;;; var componentName = 'SericeDescriptor.provide';
+;;; var componentName = 'ServiceFactory.provide';
;;; if (! config.getter) {
;;; throw this._makeError(componentName, 'config.getter');
;;; }
@@ -300,36 +299,36 @@
;;; if (! config.sourceVersion) {
;;; throw this._makeError(componentName, 'config.sourceVersion');
;;; }
- if (this.iface.finalized) {
+ if (this.registrar.bound) {
;;; kukit.E = 'Attempt to provide implementation to method [';
-;;; kukit.E += this.methodName + '] on already finalized interface [';
-;;; kukit.E += this.iface.interfaceName + ']';
+;;; kukit.E += this.methodName + '] on already finalized registry [';
+;;; kukit.E += this.registrar.registryName + ']';
throw new Error(kukit.E);
- } else if (typeof(this.registry[config.sourceName]) != 'undefined') {
+ } else if (typeof(this.sources[config.sourceName]) != 'undefined') {
;;; kukit.E = 'Double registration by [' + config.sourceName + '][';
;;; kukit.E += providerVersion;
-;;; kukit.E += '] of method [' + this.methodName;
-;;; kukit.E += '] in interface [' + this.iface.interfaceName + ']';
+;;; kukit.E += '] of method [' + this.name;
+;;; kukit.E += '] in interface [' + this.registrar.registryName + ']';
throw new Error(kukit.E);
}
- // Use the config to set the registry
- config.methodName = this.methodName;
- this.registry[config.sourceName] = config;
+ // Store the config
+ config.methodName = this.name;
+ this.sources[config.sourceName] = config;
};
- this.finalize = function(loader) {
+ this.produceItem = function(loader) {
var func;
if (! this.preferredSources) {
;;; kukit.E = 'Undefined method [';
-;;; kukit.E += this.methodName + '] on interface [';
-;;; kukit.E += this.iface.interfaceName + '], ';
+;;; kukit.E += this.name + '] on registry [';
+;;; kukit.E += this.registrar.registryName + '], ';
;;; kukit.E += 'but the following were provided:';
-;;; kukit.E += this.registry + ']';
+;;; kukit.E += this.sources + ']';
throw new Error(kukit.E);
}
// loop through all preferred providers
for (var i = 0; i < this.preferredSources.length; i++) {
- var item = this.registry[this.preferredSources[i]];
+ var item = this.sources[this.preferredSources[i]];
// Did we have an item?
if (typeof(item) == 'undefined') {
continue;
@@ -351,9 +350,10 @@
return;
} else {
// We raise an error.
-;;; kukit.E = 'Could not finalize method [';
-;;; kukit.E += this.methodName + '] on interface [';
-;;; kukit.E += this.iface.interfaceName + '], because no provider found ';
+;;; 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 + ']';
throw new Error(kukit.E);
@@ -361,7 +361,7 @@
} else {
// We found the func that we can finalze now.
;;; kukit.E = 'Using method [';
-;;; kukit.E += this.methodName + '] from source [';
+;;; kukit.E += this.name + '] from source [';
;;; kukit.E += item.sourceName + '] version [';
;;; kukit.E += item.sourceVersion + '].';
;;; kukit.log(kukit.E);
@@ -380,49 +380,55 @@
}
};
-}; /* end ServiceMethod */
+ this.initialize.apply(this, arguments);
+
+}; /* end ServiceFactory */
/*
* KSS plugin registry
*/
-this.PluginResource = function(iface, attributeName) {
+this.PluginFactory = function() {
- this.iface = iface;
- this.attributeName = attributeName;
- // Set the config to undefined, this means that methods
- // that were fetched but not registered during the configuration,
- // will not be finalized.
- this.config = undefined;
+ this.initialize = function(registrar, name) {
+ this.registrar = registrar;
+ this.name = name;
+ // Set the config to undefined, this means that the items
+ // that were produced but not registered during the configuration,
+ // will not be bound.
+ this.config = undefined;
+ };
this.register = function(config) {
if (typeof(this.config) != 'undefined') {
-;;; kukit.E = 'Double registration of plugin [' + this.attributeName;
-;;; kukit.E += '] in plugin interface [' + this.iface.interfaceName + ']';
+;;; kukit.E = 'Double registration of plugin [' + this.name;
+;;; kukit.E += '] in registry [' + this.registrar.registryName + ']';
throw new Error(kukit.E);
}
this.config = config;
};
- this.finalize = function(loader) {
- // Just return the registered value.
+ this.produceItem = function(loader) {
+ // Just return the registered item.
// If register was not called, we will return undefined,
- // which means the method will not be finalized on the
- // interface. This makes sure that if the registry is found,
+ // which means the method will not be bound on the
+ // registry. This makes sure that if the item is found,
// it will for sure have a value.
return this.config;
};
-}; /* end PluginResource */
+ this.initialize.apply(this, arguments);
+
+}; /* end PluginFactory */
/*
- * BindIterationDescriptor
+ * BindSequenceFactory
*
- * We need this method descriptor because we need to
+ * 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 iterator that defines how binding will
+ * class, and a binding strategy that defines how binding will
* be called.
*
* The event names arrive in a namespace format (dash-separated),
@@ -431,11 +437,13 @@
* may make sense, it can be put back in form of asserts on the
* event names.
*/
-this.BindIterationResource = function(iface, attributeName) {
+this.BindSequenceFactory = function() {
- this.iface = iface;
- this.attributeName = attributeName;
- this.config = null;
+ this.initialize = function(registrar, name) {
+ this.registrar = registrar;
+ this.name = name;
+ this.config = null;
+ };
this.register = function(config) {
// This is called on any method descriptors,
@@ -444,19 +452,19 @@
// Take names from the config.
for (var i = 0; i < config.eventNames.length; i++) {
var name = config.eventNames[i];
- this.iface.getAttribute(name)._register(config);
+ this.registrar.getItemFactory(name)._register(config);
}
};
this._register = function(config) {
if (this.config != null) {
-;;; kukit.E = 'Double registration of attribute [' + this.attributeName;
-;;; kukit.E += '] in plugin interface [' + this.iface.interfaceName + ']';
+;;; kukit.E = 'Double registration of item [' + this.name;
+;;; kukit.E += '] in plugin interface [' + this.registrar.registryName + ']';
throw new Error(kukit.E);
}
// Do some diagnostics // check the iterator.
;;; if (! kukit.er.getBindIterator(config.iterName)) {
-;;; kukit.E = 'In BindIterationDescriptor.register: unknown bind iterator [';
+;;; kukit.E = 'In BindSequenceFactory.register: unknown bind strategy [';
;;; kukit.E += config.iterName + '].';
;;; throw new Error(kukit.E);
;;; }
@@ -469,12 +477,14 @@
};
- this.finalize = function(loader) {
+ this.produceItem = function(loader) {
// Just return the registered value.
return this.config;
};
-}; /* end BindIterationResource */
+ this.initialize.apply(this, arguments);
+
+}; /* end BindSequenceFactory */
@@ -482,35 +492,37 @@
* Instantiation
*/
-this._createGlobalInterfaces = function() {
- // create singleton for interfaces
- kukit.pluginregistry = new this.NamedInterfaces();
- kukit.service = new this.NamedInterfaces();
+this._createGlobalRegistries = function() {
+ // create registries
+ kukit.pluginregistry = new this.NamedRegistries();
+ kukit.service = new this.NamedRegistries();
};
-// The following methods can acquire a given interface
-
-/* XXX If we want to use interfaces in a more placeful way, we can provide
+/*
+ * Global handling of registries in kukit
+ *
+ * If we want to use registries in a more placeful way, we can provide
* cloning ang merging to them. Since we don't really use them this way,
* the only support needed is for tests to establish a clean room.
* For this, we provide simple save and restore methods. These can
- * be celled from setUp and tearDown of tests that want to provide their
+ * be called from setUp and tearDown of tests that want to provide their
* own interfaces setup.
+ *
*/
this.cleanRoomSetUp = function(suite) {
this._saved_pluginregistry = kukit.pluginregistry;
this._saved_service = kukit.service;
- // now create interfaces
- this._createGlobalInterfaces();
+ // now create registries
+ this._createGlobalRegistries();
// and initialize them
- this.initializeGlobalInterfaces();
+ this.initializeGlobalRegistries();
};
this.cleanRoomFinalize = function(suite) {
- // Need to finalize these interfaces
- this.finalizeGlobalInterfaces();
+ // Need to finalize (bind) these registries
+ this.finalizeGlobalRegistries();
};
this.cleanRoomTearDown = function(suite) {
@@ -519,41 +531,43 @@
kukit.service = this._saved_service;
};
-/* These methods handle the specific interfaces
- * used by kukit itself. They are all stored on
- * interfaces.global.
+/* These methods handle the specific registries
+ * used by kukit itself. They are two of then,
+ * stored globally:
+ *
+ * kukit.pluginregistry Plugin registration
+ * kukit.service Service layer
+ *
*/
-// Initialize global interfaces
-this.initializeGlobalInterfaces = function() {
- var i = kukit.pluginregistry;
- i.initializeContext('events', this.PluginResource);
- i.initializeContext('bindsequences', this.BindIterationResource);
- i.initializeContext('actions', this.PluginResource);
- i.initializeContext('valueproviders', this.PluginResource);
- i = kukit.service;
- i.initializeContext('core', this.ServiceMethod);
+// Initialize global registries
+this.initializeGlobalRegistries = function() {
+ var r = kukit.pluginregistry;
+ r.initializeRegistry('events', this.PluginFactory);
+ r.initializeRegistry('bindsequences', this.BindSequenceFactory);
+ r.initializeRegistry('actions', this.PluginFactory);
+ r.initializeRegistry('valueproviders', this.PluginFactory);
+ r = kukit.service;
+ r.initializeRegistry('core', this.ServiceFactory);
};
-// Finalize global interfaces
-this.finalizeGlobalInterfaces = function() {
+// Finalize global registries
+this.finalizeGlobalRegistries = function() {
var schema = kukit.pluginregistry.schema;
- schema.events.finalize({});
- schema.bindsequences.finalize({});
- schema.actions.finalize({});
- schema.valueproviders.finalize({});
+ schema.events.bindItems({});
+ schema.bindsequences.bindItems({});
+ schema.actions.bindItems({});
+ schema.valueproviders.bindItems({});
schema = kukit.service.schema;
- schema.core.finalize({});
+ schema.core.bindItems({});
};
-// Now, create the global interfaces
-this._createGlobalInterfaces();
-// At this point we initialize the interfaces used by kukit, that means
+// Now, create the global registries
+this._createGlobalRegistries();
+// At this point we initialize the registries used by kukit, that means
// any code can use them from top level, without initialization.
-this.initializeGlobalInterfaces();
-// The finalization of these interfaces will be done from bootstrap.
-
-
+this.initializeGlobalRegistries();
+// The finalization of these registries will be done from bootstrap.
/*
@@ -573,11 +587,11 @@
*
*/
-this.registerPlugins = function(items, interfaces) {
+this.registerPlugins = function(items, registries) {
// interfaces is optional, and mainly used for tests
- if (typeof(interfaces) == 'undefined') {
+ if (typeof(registries) == 'undefined') {
// use global interfaces
- interfaces = kukit.pluginregistry;
+ registries = kukit.pluginregistry;
}
//
for (var i=0; i<items.length; i++) {
@@ -591,32 +605,32 @@
}
;;; if (item.length != 3) {
;;; kukit.E = 'List items in registerPlugins call must have ';
-;;; kukit.E += '3 members (interfaceName, attributeName, config), ';
+;;; kukit.E += '3 members (registryName, itemName, config), ';
;;; kukit.E += 'got [' + item.length + '] instead.';
;;; throw new Error(kukit.E);
;;; }
- var interfaceName = item[0];
- var attributeName = item[1];
+ var registryName = item[0];
+ var itemName = item[1];
var config = item[2];
// Register it.
- var iface = interfaces.schema[interfaceName];
-;;; if (! iface) {
-;;; kukit.E = 'Bad interfaceName in registerPlugins call [';
-;;; kukit.E += interfaceName + '].';
+ var registrar = registries.schema[registryName];
+;;; if (! registrar) {
+;;; kukit.E = 'Bad registry name in registerPlugins call [';
+;;; kukit.E += registryName + '].';
;;; throw new Error(kukit.E);
;;; }
- var attrib = iface.getAttribute(attributeName);
-;;; // Check that we are in a plugin insterface.
+ 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(attrib.register) == 'undefined') {
-;;; kukit.E = 'Bad interfaceName in registerPlugins call [';
-;;; kukit.E += interfaceName + '], it is not a valid plugin interface.';
+;;; if (typeof(factory.register) == 'undefined') {
+;;; kukit.E = 'Bad registry name in registerPlugins call [';
+;;; kukit.E += registryName + '], it is not a valid plugin registry.';
;;; throw new Error(kukit.E);
;;; }
- attrib.register(config);
+ factory.register(config);
}
};
-}(); /* END CLOSURE kukit.interfaces */
+}(); /* END CLOSURE kukit.ifa */
Modified: kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/kukit.js
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/kukit.js (original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/kukit.js Wed Apr 16 12:15:37 2008
@@ -231,10 +231,10 @@
;;; kukit.log('[initializeRules] is called twice.');
return;
}
- // We finalize the core interfaces.
- kukit.ifa.finalizeGlobalInterfaces();
-;;; kukit.log('All interfaces finalized.');
-;;; // If we have firebug, log the interfaces to
+ // We finalize the global registries.
+ kukit.ifa.finalizeGlobalRegistries();
+;;; kukit.log('All registries bound.');
+;;; // If we have firebug, log the registries to
;;; // be introspected from the console.
;;; if (kukit.hasFirebug) {
;;; kukit.logDebug('Next line shows kukit.pluginregistry:');
Modified: kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/providerreg.js
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/providerreg.js (original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/providerreg.js Wed Apr 16 12:15:37 2008
@@ -43,8 +43,8 @@
returnType = 'string';
}
// Always use the global interfaces to get the descriptor.
- var iface = kukit.pluginregistry.schema[this.name];
- iface.getAttribute(name).register({providerClass: func,
+ var registry = kukit.pluginregistry.schema[this.name];
+ registry.getItemFactory(name).register({providerClass: func,
returnType: returnType});
};
this.initialize.apply(this, arguments);
Modified: kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/selectorreg.js
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/selectorreg.js (original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/selectorreg.js Wed Apr 16 12:15:37 2008
@@ -84,8 +84,8 @@
};
-var iface = kukit.pluginregistry.schema.valueproviders;
-iface.getAttribute('passnode').register({
+var registrar = kukit.pluginregistry.schema.valueproviders;
+registrar.getItemFactory('passnode').register({
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 iface = kukit.pluginregistry.schema.valueproviders;
+ var registrar = kukit.pluginregistry.schema.valueproviders;
var providerClass = sr.makeAnySelectorProvider(selectorFunc);
- iface.getAttribute(name).register({
+ registrar.getItemFactory(name).register({
providerClass: providerClass,
selectorFunc: selectorFunc,
returnType: 'selection'});
Modified: kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/service.js
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/service.js (original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/service.js Wed Apr 16 12:15:37 2008
@@ -9,7 +9,7 @@
// kukit's preferences to choose between sources
// that implement a given functionality.
-core.getAttribute('cssQuery').require({
+core.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.getAttribute('cssQuery').provide({
+core.getItemFactory('cssQuery').provide({
sourceName:'cssQuery',
sourceVersion: '2.0.2',
getter: function() {
@@ -53,7 +53,7 @@
return results;
};
-core.getAttribute('cssQuery').provide({
+core.getItemFactory('cssQuery').provide({
sourceName: 'base2-legacy',
sourceVersion: '<<20020070816',
getter: function() {
@@ -73,7 +73,7 @@
};
}});
-core.getAttribute('cssQuery').provide({
+core.getItemFactory('cssQuery').provide({
sourceName: 'base2',
sourceVersion: '0.??',
getter: function() {
Modified: kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_interfaces.js
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_interfaces.js (original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_interfaces.js Wed Apr 16 12:15:37 2008
@@ -25,7 +25,7 @@
this.setUp = function() {
// work with our own object, not interfering
//interfaces.js
- this.interfaces = new kukit.ifa.NamedInterfaces();
+ this.registries = new kukit.ifa.NamedRegistries();
};
}; /* end InterfacesTestCase */
kukit.InterfacesTestCaseBase.prototype = new kukit.UtilsTestCaseBase();
@@ -33,22 +33,22 @@
kukit.InterfacesTestCase = function() {
this.name = 'kukit.InterfacesTestCase';
/*
- * Plugin interfaces
+ * Plugin registries
*/
var called = [];
- var TestAttribute = function(iface, attributeName) {
- this.iface = iface;
- this.attributeName = attributeName;
+ var TestFactory = function(registrar, name) {
+ this.registrar = registrar;
+ this.name = name;
this.doThis = function() {
called.push("doThis");
}
this.doThat = function() {
called.push("doThat");
}
- this.finalize = function(loader) {
- var signature = "FUNC " + this.attributeName;
+ this.produceItem = function(loader) {
+ var signature = "FUNC " + this.name;
called.push(signature);
return signature;
}
@@ -58,28 +58,28 @@
// We can create a simple method descriptor for an interface we want.
// The method descriptor is managing the method's registration state
called = [];
- // Let's create an interface that uses TestAttribute.
+ // Let's create a registry that uses TestFactory.
// We need to initialize it
- this.interfaces.initializeContext('dummytest', TestAttribute);
+ this.registries.initializeRegistry('dummytest', TestFactory);
// Now we can access the schema.
- var iface = this.interfaces.schema.dummytest;
- this.assert(typeof(iface), 'object');
- // Let's get two methods
- iface.getAttribute('fooMethod').doThis()
- iface.getAttribute('barMethod').doThat()
+ var registrar = this.registries.schema.dummytest;
+ 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...
- iface.getAttribute('fooMethod').doThis()
- iface.getAttribute('barMethod').doThat()
+ registrar.getItemFactory('fooItem').doThis()
+ registrar.getItemFactory('barItem').doThat()
// Check
this.assertListEquals(called, ['doThis', 'doThat']);
called = [];
//
- // Now let's iterate on all instantiated methods:
- iface.forEachAttribute(function(attributeName, attribute) {
- attribute.doThis();
+ // Now let's iterate on all factories:
+ registrar.forEachFactory(function(name, factory) {
+ factory.doThis();
});
// Check
this.assertListEquals(called, ['doThis', 'doThis']);
@@ -87,15 +87,15 @@
};
this.testReservedInterfaceNames = function() {
- // Reversed interface names are prohibited.
- // (thex would conflict with the interface class)
+ // Reserved registry names are prohibited.
+ // (thex would conflict with the NamedRegistries class)
var self = this;
this.assertThrows(function() {
- this.interfaces.initializeContext('initializeContext', TestAttribute);
+ this.registries.initializeRegistry('initializeRegistry', TestFactory);
},
Error);
this.assertThrows(function() {
- this.interfaces.initializeContext('schema', TestAttribute);
+ this.registries.initializeRegistry('schema', TestFactory);
},
Error);
};
@@ -103,53 +103,52 @@
this.testFinalizeInterfaces = function() {
// We have a singleton, called s.
var s = {};
- // We eill create a simple attribute for a selected interface .
- // The attribute is managing the attribute's registration state
+ // We eill create a simple item for a selected registry.
+ // The factory is managing the item's registration state
called = [];
- // Let's initialize a dimmytest interface.
- this.interfaces.initializeContext('dummytest', TestAttribute);
- var iface = this.interfaces.schema.dummytest;
- // Let's get two methods
- iface.getAttribute('fooMethod').doThis()
- iface.getAttribute('barMethod').doThat()
+ // Let's initialize a dummytest registry.
+ this.registries.initializeRegistry('dummytest', TestFactory);
+ var registrar = this.registries.schema.dummytest;
+ // Let's get two factories
+ registrar.getItemFactory('fooItem').doThis()
+ registrar.getItemFactory('barItem').doThat()
// Check
this.assertListEquals(called, ['doThis', 'doThat']);
called = [];
//
- // At this point we are also ready to finalize the interface.
- iface.finalize(s);
- // This calls finalize on all method descriptors.
- this.assertListEquals(called, ['FUNC fooMethod', 'FUNC barMethod']);
+ // At this point we are also ready to bind the items the registrar.
+ registrar.bindItems(s);
+ // This binds all the items.
+ this.assertListEquals(called, ['FUNC fooItem', 'FUNC barItem']);
called = [];
// At the same time it also set up these on the class prototype.
- this.assertEquals(this.interfaces.dummytest.fooMethod, 'FUNC fooMethod');
- this.assertEquals(this.interfaces.dummytest.barMethod, 'FUNC barMethod');
- // ... so if the descriptor sets methodFunc on the
+ this.assertEquals(this.registries.dummytest.fooItem, 'FUNC fooItem');
+ this.assertEquals(this.registries.dummytest.barItem, 'FUNC barItem');
};
this.testInitializationIsRepeatable = function() {
- // Let's have a second method descriptor class
- var TestAttribute2 = function(iface, attributeName) {
- this.iface = iface;
- this.attributeName = attributeName;
- this.finalize = function(loader) {
- var signature = "IFACE2 " + this.attributeName;
+ // Let's have a second factory
+ var TestFactory2 = function(registrar, name) {
+ this.registrar = registrar;
+ this.name = name;
+ this.bindItems = function(loader) {
+ var signature = "REG2 " + this.name;
return signature;
}
};
- // Let's initialize a dimmytest interface.
- this.interfaces.initializeContext('dummytest', TestAttribute);
- // We can get the same interface again...
- this.interfaces.initializeContext('dummytest', TestAttribute);
- // however not with a different descriptor class!
+ // 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.interfaces.initializeContext('dummytest', TestAttribute2);
+ this.registries.initializeRegistry('dummytest', TestFactory2);
},
Error);
//
- // On the other hand setting up a second interface is no problem.
- this.interfaces.initializeContext('dummytest2', TestAttribute2);
+ // On the other hand setting up with a second registry, is no problem.
+ this.registries.initializeRegistry('dummytest2', TestFactory2);
};
}; /* end InterfacesTestCase */
@@ -159,95 +158,95 @@
kukit.ServiceInterfacesTestCase = function() {
this.name = 'kukit.ServiceInterfacesTestCase';
/*
- * Service interfaces
+ * Service registries
*/
this.setUp = function() {
- // work with our own object, not interfering
- // kukit.interfaces
- this.interfaces = new kukit.ifa.NamedInterfaces();
- // Let's initialize an events and binditeration interface.
- this.interfaces.initializeContext('dummyservice', kukit.ifa.ServiceMethod);
+ // work with our own registries, not interfering
+ // kukit.service or kukit.pluginregistry.
+ this.registries = new kukit.ifa.NamedRegistries();
+ // Let's initialize a dummyservice registry.
+ this.registries.initializeRegistry('dummyservice', kukit.ifa.ServiceFactory);
};
this.testServiceInterfaces = function() {
// We have a singleton, called s.
var s = {};
- var iface = this.interfaces.schema.dummyservice;
+ var registrar = this.registries.schema.dummyservice;
// Requires four methods, thie defines their necessity and preferred providers
- iface.getAttribute('first').require({
+ registrar.getItemFactory('first').require({
preferredSources: ['corelib', 'extralib']});
- iface.getAttribute('second').require({
+ registrar.getItemFactory('second').require({
preferredSources: ['extralib', 'corelib']});
- iface.getAttribute('third').require({
+ registrar.getItemFactory('third').require({
preferredSources: ['corelib']});
- iface.getAttribute('fourth').require({
+ registrar.getItemFactory('fourth').require({
preferredSources: ['extralib']});
//
// somewhere else, source "corelib" provides the methods:
- iface.getAttribute('first').provide({
+ registrar.getItemFactory('first').provide({
sourceName: 'corelib',
sourceVersion: '1.1',
getter: function() {return function() {return 'first/core';}}});
- iface.getAttribute('second').provide({
+ registrar.getItemFactory('second').provide({
sourceName: 'corelib',
sourceVersion: '1.1',
getter: function() {return function() {return 'second/core';}}});
- iface.getAttribute('third').provide({
+ registrar.getItemFactory('third').provide({
sourceName: 'corelib',
sourceVersion: '1.1',
getter: function() {return function() {return 'third/core';}}});
//
// somewhere else, source "extras" provides the methods:
- iface.getAttribute('first').provide({
+ registrar.getItemFactory('first').provide({
sourceName: 'extralib',
sourceVersion: '12.4',
getter: function() {return function() {return 'first/extra';}}});
- iface.getAttribute('second').provide({
+ registrar.getItemFactory('second').provide({
sourceName: 'extralib',
sourceVersion: '12.4',
getter: function() {return function() {return 'second/extra';}}});
- iface.getAttribute('fourth').provide({
+ registrar.getItemFactory('fourth').provide({
sourceName: 'extralib',
sourceVersion: '12.4',
getter: function() {return function() {return 'fourth/extra';}}});
//
- // Now finalize it.
- iface.finalize(s);
+ // Now bind the items.
+ registrar.bindItems(s);
// We can call the methods on it,
- this.assertEquals(this.interfaces.dummyservice.first(), 'first/core');
- this.assertEquals(this.interfaces.dummyservice.second(), 'second/extra');
- this.assertEquals(this.interfaces.dummyservice.third(), 'third/core');
- this.assertEquals(this.interfaces.dummyservice.fourth(), 'fourth/extra');
+ this.assertEquals(this.registries.dummyservice.first(), 'first/core');
+ this.assertEquals(this.registries.dummyservice.second(), 'second/extra');
+ this.assertEquals(this.registries.dummyservice.third(), 'third/core');
+ this.assertEquals(this.registries.dummyservice.fourth(), 'fourth/extra');
};
this.testChecker = function() {
// Test with a checker function.
// We have a singleton, called s.
var s = {};
- var iface = this.interfaces.schema.dummyservice;
+ var registrar = this.registries.schema.dummyservice;
// and a counter for the checker
var checker_counter = 0;
// Define three methods
- iface.getAttribute('first').require({
+ registrar.getItemFactory('first').require({
preferredSources: ['corelib', 'extralib'],
checker: function() {checker_counter++;}});
//
// somewhere else, core provides the methods:
- iface.getAttribute('first').provide({
+ registrar.getItemFactory('first').provide({
sourceName: 'corelib',
sourceVersion: '1.1',
getter: function() {return function() {return 'first/core';}}});
//
// somewhere else, extras provides the methods:
- iface.getAttribute('first').provide({
+ registrar.getItemFactory('first').provide({
sourceName: 'extralib',
sourceVersion: '12.4',
getter: function() {return function() {return 'first/extra';}}});
//
- // Now finalize it.
- iface.finalize(s);
+ // Now bind the items.
+ registrar.bindItems(s);
// call it
- this.assertEquals(this.interfaces.dummyservice.first(), 'first/core');
+ this.assertEquals(this.registries.dummyservice.first(), 'first/core');
// Check that the checker has been called.
this.assertEquals(checker_counter, 1);
};
@@ -257,38 +256,38 @@
// a plugin first provides a method that another plugin later requires.
// We have a singleton, called s.
var s = {};
- var iface = this.interfaces.schema.dummyservice;
+ var registrar = this.registries.schema.dummyservice;
// Provide the method first
- iface.getAttribute('first').provide({
+ registrar.getItemFactory('first').provide({
sourceName: 'corelib',
sourceVersion: '1.1',
getter: function() {return function() {return 'first/core';}}});
// Define the method later
- iface.getAttribute('first').require({
+ registrar.getItemFactory('first').require({
preferredSources: ['corelib', 'extralib']});
- // Now finalize it.
- iface.finalize(s);
+ // Now bind the items.
+ registrar.bindItems(s);
// We can call the methods on it,
- this.assertEquals(this.interfaces.dummyservice.first(), 'first/core');
+ this.assertEquals(this.registries.dummyservice.first(), 'first/core');
};
this.testFinalizeTwice = function() {
- // An interface can only be finalized once.
+ // A registrar can only be bound once.
var s = {};
- var iface = this.interfaces.schema.dummyservice;
+ var registrar = this.registries.schema.dummyservice;
// Provide the method first
- iface.getAttribute('first').provide({
+ registrar.getItemFactory('first').provide({
sourceName: 'corelib',
sourceVersion: '1.1',
getter: function() {return function() {return 'first/core';}}});
// Define the method later
- iface.getAttribute('first').require({
+ registrar.getItemFactory('first').require({
preferredSources: ['corelib', 'extralib']});
- // Now finalize it.
- iface.finalize(s);
- // Finalize it again.
+ // Now bind all items.
+ registrar.bindItems(s);
+ // Bind it again.
this.assertThrows(function() {
- iface.finalize(s);
+ registrar.bindItems(s);
},
Error);
};
@@ -296,15 +295,15 @@
this.testNotDefined = function() {
// A method is provided but not required.
var s = {};
- var iface = this.interfaces.schema.dummyservice;
+ var registrar = this.registries.schema.dummyservice;
// Provide the method first
- iface.getAttribute('first').provide({
+ registrar.getItemFactory('first').provide({
sourceName: 'corelib',
sourceVersion: '1.1',
getter: function() {return function() {return 'first/core';}}});
- // Now finalize it.
+ // Now bind all items.
this.assertThrows(function() {
- iface.finalize(s);
+ registrar.bindItems(s);
},
Error)
};
@@ -312,15 +311,15 @@
this.testDoubleProvided = function() {
// A method cannot be provided twice by the same source.
// Let's initialize a dimmytest interface.
- var iface = this.interfaces.schema.dummyservice;
+ var registrar = this.registries.schema.dummyservice;
// Provide the method first
- iface.getAttribute('first').provide({
+ registrar.getItemFactory('first').provide({
sourceName: 'corelib',
sourceVersion: '1.1',
getter: function() {return function() {return 'first/core';}}});
// Now provide it for the second time.
this.assertThrows(function() {
- iface.getAttribute('first').provide({
+ registrar.getItemFactory('first').provide({
sourceName: 'corelib',
sourceVersion: '1.1',
getter: function() {return function() {return 'first/core';}}});
@@ -330,32 +329,32 @@
this.testDoubleDefined = function() {
// A method can only be required once.
- var iface = this.interfaces.schema.dummyservice;
+ var registrar = this.registries.schema.dummyservice;
// Define the method first
- iface.getAttribute('first').require({
+ registrar.getItemFactory('first').require({
preferredSources: ['corelib', 'extralib']});
// require it again.
this.assertThrows(function() {
- iface.getAttribute('first').require({
+ registrar.getItemFactory('first').require({
preferredSources: ['corelib', 'extralib']})},
Error);
};
this.testNotProvided = function() {
- // No preferred vendor can be found for a method.
+ // No preferred provider can be found for a method.
var s = {};
- var iface = this.interfaces.schema.dummyservice;
+ var registrar = this.registries.schema.dummyservice;
// Define the method first
- iface.getAttribute('first').require({
+ registrar.getItemFactory('first').require({
preferredSources: ['corelib', 'extralib']});
// Someone provides the method, but it's not good.
- iface.getAttribute('first').provide({
+ registrar.getItemFactory('first').provide({
sourceName: 'craplib',
sourceVersion: '1.1',
getter: function() {return function() {return 'first/crap';}}});
- // Now finalize it.
+ // Now bind all items.
this.assertThrows(function() {
- iface.finalize(s);
+ registrar.bindItems(s);
},
Error);
};
@@ -378,43 +377,43 @@
}();
// Now, for the interface part
var s = {};
- var iface = this.interfaces.schema.dummyservice;
+ var registrar = this.registries.schema.dummyservice;
// Define the method with loader and fallback script
- iface.getAttribute('first').require({
+ registrar.getItemFactory('first').require({
preferredSources: ['corelib', 'extralib'],
fallbackProvider: '++resource++one'});
- iface.getAttribute('second').require({
+ registrar.getItemFactory('second').require({
preferredSources: ['corelib', 'extralib'],
fallbackProvider: '++resource++two'});
- iface.getAttribute('third').require({
+ registrar.getItemFactory('third').require({
preferredSources: ['corelib', 'extralib'],
fallbackProvider: '++resource++three'});
// Someone provides the method, but it's not good.
- iface.getAttribute('first').provide({
+ registrar.getItemFactory('first').provide({
sourceName: 'craplib',
sourceVersion: '1.1',
getter: function() {return function() {return 'first/crap';}}});
// Third will be satisfied.
- iface.getAttribute('third').provide({
+ registrar.getItemFactory('third').provide({
sourceName: 'extralib',
sourceVersion: '12.4',
getter: function() {return function() {return 'third/extra';}}});
- // Now finalize it. It goes without error.
- iface.finalize(s, loader);
+ // Now bind all items. It goes without error.
+ registrar.bindItems(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.interfaces.dummyservice.third(), 'third/extra');
+ this.assertEquals(this.registries.dummyservice.third(), 'third/extra');
// First and second are undefined.
- this.assertEquals(typeof(this.interfaces.dummyservice.first), 'undefined');
- this.assertEquals(typeof(this.interfaces.dummyservice.second), '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-finalize with and without a loader. Check if this is possible:
- iface.finalize(s, loader);
- // If we re-finalize without a loader, and the sources are still not loaded,
+ // then it is supposed to re-bind with and without a loader. Check if this is possible:
+ registrar.bindItems(s, loader);
+ // If we re-bound without a loader, and the sources are still not loaded,
// we get an error:
this.assertThrows(function() {
- iface.finalize(s);
+ registrar.bindItems(s);
},
Error);
};
@@ -426,83 +425,83 @@
kukit.PluginInterfacesTestCase = function() {
this.name = 'kukit.PluginInterfacesTestCase';
/*
- * Plugin interfaces
+ * Plugin registries
*/
this.setUp = function() {
// work with our own object, not interfering
- // kukit.interfaces
- this.interfaces = new kukit.ifa.NamedInterfaces();
- // Let's initialize an events and binditeration interface.
- this.interfaces.initializeContext('dummyevents', kukit.ifa.PluginResource);
- this.interfaces.initializeContext('dummybindsequences', kukit.ifa.BindIterationResource);
+ // kukit.pluginregistry
+ this.registries = new kukit.ifa.NamedRegistries();
+ // Let's initialize an events and binditeration registry.
+ this.registries.initializeRegistry('dummyevents', kukit.ifa.PluginFactory);
+ this.registries.initializeRegistry('dummybindsequences', kukit.ifa.BindSequenceFactory);
};
var M = function() {
this.bind = function(oper) {};
};
this.testPluginInterfaces = function() {
- var events = this.interfaces.schema.dummyevents;
- var bindsequences = this.interfaces.schema.dummybindsequences;
- // somewhere else, core registers the methods:
- events.getAttribute('click').register({
+ var events = this.registries.schema.dummyevents;
+ var bindsequences = this.registries.schema.dummybindsequences;
+ // somewhere else, core registers the items:
+ events.getItemFactory('click').register({
name: 'click',
defaultActionMethodName: null,
parmtypes: [
['preventDefault', 'bool', true],
['allowBubbling', 'bool', false]]});
- events.getAttribute('keydown').register({
+ events.getItemFactory('keydown').register({
name: 'keydown',
defaultActionMethodName: null,
parmtypes: [
['preventDefault', 'bool', true],
['allowBubbling', 'bool', false]]});
- bindsequences.getAttribute('').register({
+ bindsequences.getItemFactory('').register({
eventNames: ['click', 'keydown'],
iterName: 'Each',
binderClass: M,
bindMethodName: 'bind'});
//*/
//
- // somewhere else, extras registers the methods:
- events.getAttribute('timeout').register({
+ // somewhere else, extras registers the items:
+ events.getItemFactory('timeout').register({
name: 'timeout',
defaultActionMethodName: null,
parmtypes: [
['millis', 'int'],
['renew', 'bool', false]]});
// It needs a bind iterator even though it is a single
- // group.
- bindsequences.getAttribute('').register({
+ // sequence.
+ bindsequences.getItemFactory('').register({
eventNames: ['timeout'],
iterName: 'Each',
binderClass: M,
bindMethodName: 'bind'});
//
- // Now finalize it.
- events.finalize({});
- bindsequences.finalize({});
+ // Now bind all items.
+ events.bindItems({});
+ bindsequences.bindItems({});
// We can call the methods on it,
- this.assertEquals(this.interfaces.dummyevents.click.defaultActionMethodName, null);
- this.assertEquals(this.interfaces.dummyevents.keydown.defaultActionMethodName, null);
- this.assertEquals(this.interfaces.dummyevents.timeout.defaultActionMethodName, null);
- this.assertEquals(this.interfaces.dummybindsequences.timeout.iterName, 'Each');
+ this.assertEquals(this.registries.dummyevents.click.defaultActionMethodName, null);
+ this.assertEquals(this.registries.dummyevents.keydown.defaultActionMethodName, null);
+ this.assertEquals(this.registries.dummyevents.timeout.defaultActionMethodName, null);
+ this.assertEquals(this.registries.dummybindsequences.timeout.iterName, 'Each');
};
this.testPluginNoDoubleReg = function() {
// No double registration for test plugins.
- var events = this.interfaces.schema.dummyevents;
- var bindsequences = this.interfaces.schema.dummybindsequences;
- // somewhere a plugin registers something:
- events.getAttribute('click').register({
+ var events = this.registries.schema.dummyevents;
+ var bindsequences = this.registries.schema.dummybindsequences;
+ // somewhere a plugin registers an item:
+ events.getItemFactory('click').register({
name: 'click',
defaultActionMethodName: null,
parmtypes: [
['preventDefault', 'bool', true],
['allowBubbling', 'bool', false]]});
- // But another providing attempt is punished by an Error.
+ // But another registration attempt is harshly punished by an Error.
this.assertThrows(function() {
- events.getAttribute('click').register({
+ events.getItemFactory('click').register({
name: 'click',
defaultActionMethodName: null,
parmtypes: [
@@ -514,11 +513,11 @@
this.testBindIterationNoDoubleReg = function() {
// No double registration for test plugins.
- var events = this.interfaces.schema.dummyevents;
- var bindsequences = this.interfaces.schema.dummybindsequences;
- // somewhere else, core registers the methods:
- // XXX attribute '' is used to call interface level methods
- bindsequences.getAttribute('').register({
+ var events = this.registries.schema.dummyevents;
+ var bindsequences = this.registries.schema.dummybindsequences;
+ // somewhere else, core registers the items.
+ // XXX registry name '' is used to call interface level methods
+ bindsequences.getItemFactory('').register({
eventNames: ['click', 'timeout'],
iterName: 'Each',
binderClass: M,
@@ -531,18 +530,18 @@
this.bind2 = function(oper) {};
};
MSub.prototype = new M();
- bindsequences.getAttribute('').register({
+ bindsequences.getItemFactory('').register({
eventNames: ['keydown', 'keypress'],
iterName: 'Each',
binderClass: MSub,
bindMethodName: 'bind'});
- // finalize
- bindsequences.finalize({});
+ // bind
+ bindsequences.bindItems({});
// Check that our classes are set as expected.
- this.assertEquals(this.interfaces.dummybindsequences.click.binderClass, M);
- this.assertEquals(this.interfaces.dummybindsequences.timeout.binderClass, M);
- this.assertEquals(this.interfaces.dummybindsequences.keydown.binderClass, MSub);
- this.assertEquals(this.interfaces.dummybindsequences.keypress.binderClass, MSub);
+ this.assertEquals(this.registries.dummybindsequences.click.binderClass, M);
+ this.assertEquals(this.registries.dummybindsequences.timeout.binderClass, M);
+ this.assertEquals(this.registries.dummybindsequences.keydown.binderClass, MSub);
+ this.assertEquals(this.registries.dummybindsequences.keypress.binderClass, MSub);
// Check that both classes have a class name.
this.assert(M.prototype.__className__);
this.assert(MSub.prototype.__className__);
@@ -550,22 +549,22 @@
this.assertNotEquals(M.prototype.__className__, MSub.prototype.__className__);
};
- this.testOnlyRegisteredPluginsAreFinalized = function() {
- // We assure that if a method descriptor is get but it is not registered,
- // it will not be finalized on the configuration.
- var events = this.interfaces.schema.dummyevents;
- var bindsequences = this.interfaces.schema.dummybindsequences;
- // Just call up the method descriptor: this will create it with config=null.
- events.getAttribute('click');
- // finalize
- events.finalize({});
+ this.testOnlyRegisteredPluginsCanBeBound = function() {
+ // We assure that if an item is produced but it is not registered,
+ // it will not be bound on the configuration.
+ var events = this.registries.schema.dummyevents;
+ var bindsequences = this.registries.schema.dummybindsequences;
+ // Just call up the factoryr: this will create it with config=null.
+ events.getItemFactory('click');
+ // bind
+ events.bindItems({});
// 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.interfaces.dummyevents.click), 'undefined');
+ this.assertEquals(typeof(this.registries.dummyevents.click), 'undefined');
};
this.testRegisterPlugins = function() {
- // Test registerPlugins method-
+ // Test registerPlugins method.
//
kukit.ifa.registerPlugins(
[
@@ -593,8 +592,8 @@
// the problem of the closing comma
null]
- // XXX the interfaces is needed for the test, but not in normal usage
- , this.interfaces
+ // XXX the registries is needed for the test, but not in normal usage
+ , this.registries
);
};
@@ -616,8 +615,8 @@
// the problem of the closing comma
null]
- // XXX the interfaces is needed for the test, but not in normal usage
- , this.interfaces
+ // XXX the registries is needed for the test, but not in normal usage
+ , this.registries
);
}, Error);
};
@@ -640,20 +639,21 @@
// the problem of the closing comma
null]
- // XXX the interfaces is needed for the test, but not in normal usage
- , this.interfaces
+ // XXX the registries is needed for the test, but not in normal usage
+ , this.registries
);
}, Error);
};
this.testRegisterPluginsServiceInterfaceProhibites = function() {
- // In registerPlugins, the 'core' service interface cannot
- // be used. This means only method descriptors that have 'register'
- // method, can be used.
+ // 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 regoster "dummyservice" so it does not fail because
+ // We register "dummyservice" so it does not fail because
// it's missing
- kukit.pluginregistry.initializeContext('dummyservice', kukit.ifa.ServiceMethod);
+ kukit.pluginregistry.initializeRegistry('dummyservice', kukit.ifa.ServiceFactory);
//
this.assertThrows(function() {
kukit.ifa.registerPlugins(
@@ -664,8 +664,8 @@
// the problem of the closing comma
null]
- // XXX the interfaces is needed for the test, but not in normal usage
- , this.interfaces
+ // XXX the registries is needed for the test, but not in normal usage
+ , this.registries
);
}, Error);
};
More information about the Kukit-checkins
mailing list