Author: gotcha
Date: Sun Oct 26 12:22:28 2008
New Revision: 59414
Added:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/registries.js
(contents, props changed)
- copied, changed from r59413,
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/interfaces.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_registries.js
(contents, props changed)
- copied, changed from r59044,
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_interfaces.js
Removed:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/interfaces.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_interfaces.js
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runner.html
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runtests.sh
Log:
rename files : from interfaces to registries
Deleted:
/kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/interfaces.js
==============================================================================
---
/kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/interfaces.js
Sun Oct 26 12:22:28 2008
+++ (empty file)
@@ -1,621 +0,0 @@
-
-kukit.ifa = new function() { /* BEGIN CLOSURE kukit.ifa */
-
-/*
- * Kukit registry
- *
- * 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
- * items.
- *
- * 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 registry,
- * 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 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.
- *
- * The order in which they are loaded is irrelevant, provided they
- * load after interfaces.js.
- *
- * Managing the schema
- * -------------------
- *
- * When various javascript code is loaded, it can set up the
- * schema for the registry it handles. For example, during the
- * loading of javascript, plugin code set up its registry, other code
- * sets up core services it provides or depends on.
- *
- * 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.
- *
- * This is the only dependency what we have for the order of the code.
- * Ewerywhere else, order is independent. This means that if all
- * javascript file does the initialization for itself, (or otherwise
- * can assume that it cas been called by preceding code like in the
- * case of the plugins), then the order of these javascripts is
- * arbitrary for registries to work.
- *
- * In the initialization the registry name and the item factory
- * need to be supplied as parameters.
- *
- * registries.initializeRegistry('myregistry', MyFactory);
- *
- * After this the registrar object can be looked up with:
- *
- * 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 factory = registries.schema.myregistry.getItemFactory('mykey');
- * factory.doWhateverTheFactoryImplements(blah);
- *
- * 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.
- *
- * registrar.bindItems(registry);
- *
- * In most cases, the registry can simply be a normal object. So
- * the usual setup what we have a registry for plugins is:
- *
- * registrar.bindItems({});
- *
- * 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 bound, the registry set up,
- * will appear directly accessable from registries.
- *
- * registries.myregistry == registry
- *
- * 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.)
- *
- * registries.myregistry.mykey == item
- *
- * After being bound, all named registries can be accessed from
- * the registries object, e.g. in the following way:
- *
- * registries.events.click - is an event's registry
- * registries.actions.setAttr - is an action's registry
- * registries.core.cssQuery - is a core service method
- * registries.core.forEach - is a core service method
- *
- * Kukit sets up the following registries for its own use. The
- * binding of these registries is done by kukit at the beginning
- * of bootstrap.
- *
- * Created on the global registries "kukit.pluginregistry":
- *
- * name purpose attribute class
- * ---- ------- ---------------
- * 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 registries "kukit.service":
- *
- * name purpose attribute class
- * ---- ------- ---------------
- * core core services kukit.ifa.ServiceFactory
- *
- *
- * For more information, see ../tests/test_interfaces.js .
- *
- */
-
-var Registrar = function() {
-
- this.initialize = function(namedRegistries, registryName, Factory) {
- this.namedRegistries = namedRegistries;
- this.registryName = registryName;
- this.bound = false;
- this.factories = {};
- this.Factory = Factory;
- };
-
- 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.Factory(this, name);
- }
- return factory;
- };
-
- /* Iterate a function on each factory of this registrar */
-
- 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 forEachFactory.
- // methodName and MethodDescriptor will be passed to f as parameters.
- // Extra arguments will be passed in addition.
- for (var name in this.factories) {
- var factory = this.factories[name];
- // Provide the necessary parameters and call f
- f(name, factory, a1, a2, a3, a4, a5);
- }
- };
-
- 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.bound) {
-;;; kukit.E = 'Attempt to bind already bound registry [';
-;;; kukit.E += this.registryName + ']';
- throw new Error(kukit.E);
- }
-;;; kukit.E = 'Binding registry [' + this.registryName + ']';
-;;; kukit.logDebug(kukit.E);
- // Finalize all methods.
- this.forEachFactory(function(name, factory) {
- // finalize the attributes and store them on the registry
- //
-
- // 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 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);
-;;; }
- };
-
- this.initialize.apply(this, arguments);
-
-}; /* end Registrar */
-
-this.NamedRegistries = function() {
-
- this.schema = {};
-
- 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 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 (! 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 (registryName == 'schema' || registryName == 'initializeRegistry') {
-;;; kukit.E = 'Registries.initializeRegistry() cannot be called ';
-;;; kukit.E += 'with a reserved name [';
-;;; kukit.E += registryName + '].';
- throw new Error(kukit.E);
- }
- // 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 Factory was provided. If not,
- // it's a conflict.
- if (registrar.Factory != Factory) {
-;;; kukit.E = 'Registries.initializeRegistry() is called for
registry [';
-;;; kukit.E += registryName + '] with a different Factory than
earlier.';
- throw new Error(kukit.E);
- }
- }
- };
-
-}; /* end NamedRegistries */
-
-/*
- * KSS service layer resource
- */
-
-this.ServiceFactory = function() {
-
- 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.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('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 + ']';
- throw new Error(kukit.E);
- };
- this.preferredSources = config.preferredSources;
- this.checker = config.checker;
- this.fallbackProvider = config.fallbackProvider;
- };
-
- 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.bound) {
-;;; 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 + ']';
- throw new Error(kukit.E);
- }
- // Store the config
- config.methodName = this.name;
- this.sources[config.sourceName] = config;
- };
-
- this.produceItem = function(loader) {
- 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 + ']';
- 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]];
- // Did we have an item?
- if (typeof(item) == 'undefined') {
- continue;
- }
- // Execute the item's getter
- func = item.getter();
- // Did it return the function?
- if (func) {
- // found it
- break;
- }
- // if not, we continue with the next best choice.
- }
- if (! func) {
- if (typeof(loader) != 'undefined') {
- // We have a loading method. Let's add our needs.
- loader.add(this.fallbackProvider);
- // ... and simply go on.
- return;
- } else {
- // We raise an error.
-;;; kukit.E = 'Could not bind item [';
-;;; kukit.E += this.name + '] on registry [';
-;;; 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);
- }
- } else {
- // We found the func that we can finalze now.
-;;; kukit.E = 'Using method [';
-;;; kukit.E += this.name + '] from source [';
-;;; kukit.E += item.sourceName + '] version [';
-;;; kukit.E += item.sourceVersion + '].';
-;;; kukit.log(kukit.E);
- // Return the func, optionally prefixed with a checker.
- if (this.checker) {
- // if there is a checker, merge them together
- var self = this;
- return function() {
- self.checker.apply(null, arguments);
- return func.apply(null, arguments);
- };
- } else {
- // else, just store the function
- return func;
- }
- }
- };
-
- this.initialize.apply(this, arguments);
-
-}; /* end ServiceFactory */
-
-
-/*
- * KSS plugin registry
- */
-
-this.PluginFactory = function() {
-
- 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.name;
-;;; kukit.E += '] in registry [' + this.registrar.registryName + ']';
- throw new Error(kukit.E);
- }
- this.config = config;
- };
-
- 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 bound on the
- // registry. This makes sure that if the item is found,
- // it will for sure have a value.
- return this.config;
- };
-
- 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.
- */
-this.BindSequenceFactory = function() {
-
- 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,
- // 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._register = function(config) {
- if (this.config != null) {
-;;; kukit.E = 'Double registration of item [' + this.name;
-;;; kukit.E += '] in plugin registry [' + this.registrar.registryName
+ ']';
- 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;
-
- };
-
- this.produceItem = function(loader) {
- // Just return the registered value.
- return this.config;
- };
-
- this.initialize.apply(this, arguments);
-
-}; /* end BindSequenceFactory */
-
-/*
- * 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 called from setUp and tearDown of tests that want to provide their
- * own registries setup.
- *
- */
-
-this.cleanRoomSetUp = function(suite) {
- this._saved_pluginregistry = kukit.pluginregistry;
- this._saved_service = kukit.service;
- this.initializeGlobalRegistries();
-};
-
-this.cleanRoomFinalize = function(suite) {
- // Need to finalize (bind) these registries
- this.finalizeGlobalRegistries();
-};
-
-this.cleanRoomTearDown = function(suite) {
- // Revert the saved state
- kukit.pluginregistry = this._saved_pluginregistry;
- kukit.service = this._saved_service;
-};
-
-/* 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 registries
-this.initializeGlobalRegistries = function() {
- // instantiate registries
- kukit.pluginregistry = new this.NamedRegistries();
- kukit.service = new this.NamedRegistries();
- 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 registries
-this.finalizeGlobalRegistries = function() {
- var schema = kukit.pluginregistry.schema;
- schema.events.bindItems({});
- schema.bindsequences.bindItems({});
- schema.actions.bindItems({});
- schema.valueproviders.bindItems({});
- schema = kukit.service.schema;
- schema.core.bindItems({});
-};
-
-// At this point we initialize the registries used by kukit, that means
-// any code can use them from top level, without initialization.
-this.initializeGlobalRegistries();
-// The finalization of these registries is done from bootstrap.
-
-
-/*
- * Plugin registration method
- *
- * To allow an easy way to register plugin registries, a
- * simple method is provided.
- *
- * This appends a batch of information into the plugin
- * registry.
- *
- * It is intended to be the new method for registering
- * plugins. It also fulfills the need that we will
- * be able to parse the actual information from the
- * javascript files, and access the complete plugin
- * registry, from the server side.
- *
- */
-
-this.registerPlugins = function(items, registries) {
- // registries is optional, and mainly used for tests
- if (typeof(registries) == 'undefined') {
- // use global registries
- registries = kukit.pluginregistry;
- }
- //
- for (var i=0; i<items.length; i++) {
- var item = items[i];
- if (item == null) {
- // ignore null, this allows that we can put
- // a null in the end of the list, and then
- // even the last elemwent can be closed with a , (comma)
- // This will ease parsing information from the server.
- continue;
- }
-;;; if (item.length != 3) {
-;;; kukit.E = 'List items in registerPlugins call must have ';
-;;; kukit.E += '3 members (registryName, itemName, config), ';
-;;; kukit.E += 'got [' + item.length + '] instead.';
-;;; throw new Error(kukit.E);
-;;; }
- var registryName = item[0];
- var itemName = item[1];
- var config = item[2];
- // Register it.
- var registrar = registries.schema[registryName];
-;;; if (! registrar) {
-;;; kukit.E = 'Bad registry name in registerPlugins call [';
-;;; kukit.E += registryName + '].';
-;;; throw new Error(kukit.E);
-;;; }
- var factory = registrar.getItemFactory(itemName);
-;;; // Check that we are in a plugin registry.
-;;; // It must have a register method.
-;;; // (for example, core service cannot register this way.)
-;;; if (typeof(factory.register) == 'undefined') {
-;;; kukit.E = 'Bad registry name in registerPlugins call [';
-;;; kukit.E += registryName + '], it is not a valid plugin registry.';
-;;; throw new Error(kukit.E);
-;;; }
- factory.register(config);
- }
-};
-
-
-}(); /* END CLOSURE kukit.ifa */
Copied:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/registries.js
(from r59413,
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/registries.js
Sun Oct 26 12:22:28 2008
@@ -24,7 +24,7 @@
* final outcome is independent of the order of their execution.
*
* The order in which they are loaded is irrelevant, provided they
- * load after interfaces.js.
+ * load after registries.js.
*
* Managing the schema
* -------------------
@@ -121,7 +121,7 @@
* core core services kukit.ifa.ServiceFactory
*
*
- * For more information, see ../tests/test_interfaces.js .
+ * For more information, see ../tests/test_registries.js .
*
*/
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runner.html
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runner.html
(original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runner.html
Sun Oct 26 12:22:28 2008
@@ -73,7 +73,7 @@
src="../kukit/utils.js">
</script>
- <script type="text/javascript" src="../kukit/interfaces.js"
+ <script type="text/javascript" src="../kukit/registries.js"
tal:replace="nothing"> </script>
<script type="text/javascript" src="../kukit/errors.js"
tal:replace="nothing"> </script>
@@ -115,7 +115,7 @@
<script type="text/javascript" src="test_requestmanager.js"> </script>
<script type="text/javascript" src="test_tokenizer.js"> </script>
<script type="text/javascript" src="test_kssparser.js"> </script>
- <script type="text/javascript" src="test_interfaces.js"> </script>
+ <script type="text/javascript" src="test_registries.js"> </script>
<script type="text/javascript" src="test_errors.js"> </script>
</head>
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runtests.sh
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runtests.sh
(original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/runtests.sh
Sun Oct 26 12:22:28 2008
@@ -8,7 +8,7 @@
-f ../3rd_party/johnnydebris.net/dommer/dommer.js \
-f ../kukit/kukit.js \
-f ../kukit/utils.js \
- -f ../kukit/interfaces.js \
+ -f ../kukit/registries.js \
-f ../kukit/errors.js \
-f ../kukit/oper.js \
-f ../kukit/tokenizer.js \
@@ -31,6 +31,6 @@
-f test_requestmanager.js \
-f test_tokenizer.js \
-f test_kssparser.js \
- -f test_interfaces.js \
+ -f test_registries.js \
-f test_errors.js \
runtests.js
Deleted:
/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
Sun Oct 26 12:22:28 2008
+++ (empty file)
@@ -1,683 +0,0 @@
-/*
-* Copyright (c) 2005-2007
-* Authors: KSS Project Contributors (see doc/CREDITS.txt)
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License version 2 as published
-* by the Free Software Foundation.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-* 02111-1307, USA.
-*/
-
-if (typeof(kukit) == "undefined") {
- var kukit = {};
-}
-
-kukit.InterfacesTestCaseBase = function() {
- this.setUp = function() {
- // work with our own object, not interfering
- //interfaces.js
- this.registries = new kukit.ifa.NamedRegistries();
- };
-}; /* end InterfacesTestCase */
-kukit.InterfacesTestCaseBase.prototype = new kukit.UtilsTestCaseBase();
-
-kukit.InterfacesTestCase = function() {
- this.name = 'kukit.InterfacesTestCase';
- /*
- * Plugin registries
- */
-
- 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.produceItem = function(loader) {
- var signature = "FUNC " + this.name;
- called.push(signature);
- return signature;
- }
- };
-
- this.testInterfaces = function() {
- // 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 a registry that uses TestFactory.
- // We need to initialize it
- this.registries.initializeRegistry('dummytest', TestFactory);
- // Now we can access the schema.
- 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...
- registrar.getItemFactory('fooItem').doThis()
- registrar.getItemFactory('barItem').doThat()
- // Check
- this.assertListEquals(called, ['doThis', 'doThat']);
- called = [];
- //
- // Now let's iterate on all factories:
- registrar.forEachFactory(function(name, factory) {
- factory.doThis();
- });
- // Check
- this.assertListEquals(called, ['doThis', 'doThis']);
- called = [];
- };
-
- this.testReservedInterfaceNames = function() {
- // Reserved registry names are prohibited.
- // (thex would conflict with the NamedRegistries class)
- var self = this;
- this.assertThrows(function() {
- this.registries.initializeRegistry('initializeRegistry',
TestFactory);
- },
- Error);
- this.assertThrows(function() {
- this.registries.initializeRegistry('schema', TestFactory);
- },
- Error);
- };
-
- this.testFinalizeInterfaces = 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 = [];
- // 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 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.registries.dummytest.fooItem, 'FUNC fooItem');
- this.assertEquals(this.registries.dummytest.barItem, 'FUNC barItem');
- };
-
- this.testInitializationIsRepeatable = function() {
- // Let's have a second factory
- var TestFactory2 = function(registrar, name) {
- this.registrar = registrar;
- this.name = name;
- this.bindItems = function(loader) {
- var signature = "REG2 " + this.name;
- return signature;
- }
- };
- // Let's initialize a dummytest registry.
- this.registries.initializeRegistry('dummytest', TestFactory);
- // We can get the same registry again...
- this.registries.initializeRegistry('dummytest', TestFactory);
- // however not with a different Factory!
- var self = this;
- this.assertThrows(function() {
- this.registries.initializeRegistry('dummytest', TestFactory2);
- },
- Error);
- //
- // On the other hand setting up with a second registry, is no problem.
- this.registries.initializeRegistry('dummytest2', TestFactory2);
- };
-
-}; /* end InterfacesTestCase */
-kukit.InterfacesTestCase.prototype = new kukit.InterfacesTestCaseBase();
-
-
-kukit.ServiceInterfacesTestCase = function() {
- this.name = 'kukit.ServiceInterfacesTestCase';
- /*
- * Service registries
- */
- this.setUp = function() {
- // 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 registrar = this.registries.schema.dummyservice;
- // Requires four methods, thie defines their necessity and preferred
providers
- registrar.getItemFactory('first').require({
- preferredSources: ['corelib', 'extralib']});
- registrar.getItemFactory('second').require({
- preferredSources: ['extralib', 'corelib']});
- registrar.getItemFactory('third').require({
- preferredSources: ['corelib']});
- registrar.getItemFactory('fourth').require({
- preferredSources: ['extralib']});
- //
- // somewhere else, source "corelib" provides the methods:
- registrar.getItemFactory('first').provide({
- sourceName: 'corelib',
- sourceVersion: '1.1',
- getter: function() {return function() {return 'first/core';}}});
- registrar.getItemFactory('second').provide({
- sourceName: 'corelib',
- sourceVersion: '1.1',
- getter: function() {return function() {return 'second/core';}}});
- registrar.getItemFactory('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({
- sourceName: 'extralib',
- sourceVersion: '12.4',
- getter: function() {return function() {return 'first/extra';}}});
- registrar.getItemFactory('second').provide({
- sourceName: 'extralib',
- sourceVersion: '12.4',
- getter: function() {return function() {return 'second/extra';}}});
- registrar.getItemFactory('fourth').provide({
- sourceName: 'extralib',
- sourceVersion: '12.4',
- getter: function() {return function() {return 'fourth/extra';}}});
- //
- // Now bind the items.
- registrar.bindItems(s);
- // We can call the methods on it,
- 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 registrar = this.registries.schema.dummyservice;
- // and a counter for the checker
- var checker_counter = 0;
- // Define three methods
- registrar.getItemFactory('first').require({
- preferredSources: ['corelib', 'extralib'],
- checker: function() {checker_counter++;}});
- //
- // somewhere else, core provides the methods:
- registrar.getItemFactory('first').provide({
- sourceName: 'corelib',
- sourceVersion: '1.1',
- getter: function() {return function() {return 'first/core';}}});
- //
- // somewhere else, extras provides the methods:
- registrar.getItemFactory('first').provide({
- sourceName: 'extralib',
- sourceVersion: '12.4',
- getter: function() {return function() {return 'first/extra';}}});
- //
- // Now bind the items.
- registrar.bindItems(s);
- // call it
- this.assertEquals(this.registries.dummyservice.first(), 'first/core');
- // Check that the checker has been called.
- this.assertEquals(checker_counter, 1);
- };
-
- this.testReverseOrder = function() {
- // Method creation also works in reverse order:
- // a plugin first provides a method that another plugin later requires.
- // We have a singleton, called s.
- var s = {};
- var registrar = this.registries.schema.dummyservice;
- // Provide the method first
- registrar.getItemFactory('first').provide({
- sourceName: 'corelib',
- sourceVersion: '1.1',
- getter: function() {return function() {return 'first/core';}}});
- // Define the method later
- registrar.getItemFactory('first').require({
- preferredSources: ['corelib', 'extralib']});
- // Now bind the items.
- registrar.bindItems(s);
- // We can call the methods on it,
- this.assertEquals(this.registries.dummyservice.first(), 'first/core');
- };
-
- this.testFinalizeTwice = function() {
- // A registrar can only be bound once.
- var s = {};
- var registrar = this.registries.schema.dummyservice;
- // Provide the method first
- registrar.getItemFactory('first').provide({
- sourceName: 'corelib',
- sourceVersion: '1.1',
- getter: function() {return function() {return 'first/core';}}});
- // Define the method later
- registrar.getItemFactory('first').require({
- preferredSources: ['corelib', 'extralib']});
- // Now bind all items.
- registrar.bindItems(s);
- // Bind it again.
- this.assertThrows(function() {
- registrar.bindItems(s);
- },
- Error);
- };
-
- this.testNotDefined = function() {
- // A method is provided but not required.
- var s = {};
- var registrar = this.registries.schema.dummyservice;
- // Provide the method first
- registrar.getItemFactory('first').provide({
- sourceName: 'corelib',
- sourceVersion: '1.1',
- getter: function() {return function() {return 'first/core';}}});
- // Now bind all items.
- this.assertThrows(function() {
- registrar.bindItems(s);
- },
- Error)
- };
-
- this.testDoubleProvided = function() {
- // A method cannot be provided twice by the same source.
- // Let's initialize a dimmytest interface.
- var registrar = this.registries.schema.dummyservice;
- // Provide the method first
- 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() {
- registrar.getItemFactory('first').provide({
- sourceName: 'corelib',
- sourceVersion: '1.1',
- getter: function() {return function() {return
'first/core';}}});
- },
- Error);
- };
-
- this.testDoubleDefined = function() {
- // A method can only be required once.
- var registrar = this.registries.schema.dummyservice;
- // Define the method first
- registrar.getItemFactory('first').require({
- preferredSources: ['corelib', 'extralib']});
- // require it again.
- this.assertThrows(function() {
- registrar.getItemFactory('first').require({
- preferredSources: ['corelib', 'extralib']})},
- Error);
- };
-
- this.testNotProvided = function() {
- // No preferred provider can be found for a method.
- var s = {};
- var registrar = this.registries.schema.dummyservice;
- // Define the method first
- registrar.getItemFactory('first').require({
- preferredSources: ['corelib', 'extralib']});
- // Someone provides the method, but it's not good.
- registrar.getItemFactory('first').provide({
- sourceName: 'craplib',
- sourceVersion: '1.1',
- getter: function() {return function() {return 'first/crap';}}});
- // Now bind all items.
- this.assertThrows(function() {
- registrar.bindItems(s);
- },
- Error);
- };
-
- this.testWithLoader = function() {
- // If no preferred providers are found, loaders will
- // call up.
- // Make a simple loader
- var loader = new function() {
- this.loaded = [];
- this.add = function(src) {
- this.loaded.push(src);
- };
- this.empty = function(src) {
- return ! this.loaded;
- };
- this.getSources = function(src) {
- return this.loaded;
- };
- }();
- // Now, for the interface part
- var s = {};
- var registrar = this.registries.schema.dummyservice;
- // Define the method with loader and fallback script
- registrar.getItemFactory('first').require({
- preferredSources: ['corelib', 'extralib'],
- fallbackProvider: '++resource++one'});
- registrar.getItemFactory('second').require({
- preferredSources: ['corelib', 'extralib'],
- fallbackProvider: '++resource++two'});
- registrar.getItemFactory('third').require({
- preferredSources: ['corelib', 'extralib'],
- fallbackProvider: '++resource++three'});
- // Someone provides the method, but it's not good.
- registrar.getItemFactory('first').provide({
- sourceName: 'craplib',
- sourceVersion: '1.1',
- getter: function() {return function() {return 'first/crap';}}});
- // Third will be satisfied.
- registrar.getItemFactory('third').provide({
- sourceName: 'extralib',
- sourceVersion: '12.4',
- getter: function() {return function() {return 'third/extra';}}});
- // Now bind all items. It goes without error.
- registrar.bindItems(s, loader);
- // We see the contents of the loader. Third is not in there.
- this.assertListEquals(loader.loaded, ['++resource++one',
'++resource++two'], 'Loaded contents differs.');
- // Third is actually working.
- this.assertEquals(this.registries.dummyservice.third(), 'third/extra');
- // First and second are undefined.
- this.assertEquals(typeof(this.registries.dummyservice.first),
'undefined');
- this.assertEquals(typeof(this.registries.dummyservice.second),
'undefined');
- // Now the loader can go to load the needed files...
- // then it is supposed to re-bind with and without a loader. Check if
this is possible:
- registrar.bindItems(s, loader);
- // If we re-bound without a loader, and the sources are still not
loaded,
- // we get an error:
- this.assertThrows(function() {
- registrar.bindItems(s);
- },
- Error);
- };
-
-}; /* end ServiceInterfacesTestCase */
-kukit.ServiceInterfacesTestCase.prototype = new kukit.InterfacesTestCaseBase();
-
-
-kukit.PluginInterfacesTestCase = function() {
- this.name = 'kukit.PluginInterfacesTestCase';
- /*
- * Plugin registries
- */
-
- this.setUp = function() {
- // work with our own object, not interfering
- // 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.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.getItemFactory('keydown').register({
- name: 'keydown',
- defaultActionMethodName: null,
- parmtypes: [
- ['preventDefault', 'bool', true],
- ['allowBubbling', 'bool', false]]});
- bindsequences.getItemFactory('').register({
- eventNames: ['click', 'keydown'],
- iterName: 'Each',
- binderClass: M,
- bindMethodName: 'bind'});
- //*/
- //
- // 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
- // sequence.
- bindsequences.getItemFactory('').register({
- eventNames: ['timeout'],
- iterName: 'Each',
- binderClass: M,
- bindMethodName: 'bind'});
- //
- // Now bind all items.
- events.bindItems({});
- bindsequences.bindItems({});
- // We can call the methods on it,
-
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.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 registration attempt is harshly punished by an Error.
- this.assertThrows(function() {
- events.getItemFactory('click').register({
- name: 'click',
- defaultActionMethodName: null,
- parmtypes: [
- ['preventDefault', 'bool', true],
- ['allowBubbling', 'bool', false]]});
- },
- Error);
- };
-
- this.testBindIterationNoDoubleReg = function() {
- // No double registration for test plugins.
- 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,
- bindMethodName: 'bind'});
- // Suppose we have now a binder class that is a
- // subclass of the previous one. In this case,
- // it is essential to check that they got a different
- // className.
- var MSub = function() {
- this.bind2 = function(oper) {};
- };
- MSub.prototype = new M();
- bindsequences.getItemFactory('').register({
- eventNames: ['keydown', 'keypress'],
- iterName: 'Each',
- binderClass: MSub,
- bindMethodName: 'bind'});
- // bind
- bindsequences.bindItems({});
- // Check that our classes are set as expected.
-
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__);
- // Check the two classes have distinct class names
- this.assertNotEquals(M.prototype.__className__,
MSub.prototype.__className__);
- };
-
- 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.registries.dummyevents.click),
'undefined');
- };
-
- this.testRegisterPlugins = function() {
- // Test registerPlugins method.
- //
- kukit.ifa.registerPlugins(
- [
- ['dummyevents', 'click', {
- name: 'click',
- defaultActionMethodName: null,
- parmtypes: [
- ['preventDefault', 'bool', true],
- ['allowBubbling', 'bool', false]]}],
-
-
- ['dummyevents', 'keydown', {
- name: 'keydown',
- defaultActionMethodName: null,
- parmtypes: [
- ['preventDefault', 'bool', true],
- ['allowBubbling', 'bool', false]]}],
-
- ['dummybindsequences', '', {
- eventNames: ['click', 'keydown'],
- iterName: 'Each',
- binderClass: M,
- bindMethodName: 'bind'}],
- // XXX putting a null in the end eliminates
- // the problem of the closing comma
- null]
-
- // XXX the registries is needed for the test, but not in normal usage
- , this.registries
- );
- };
-
- this.testRegisterPluginsWrongNumberOfItems = function() {
- // In registerPlugins, list items must have 3 members
- // (interfaceName, attributeName, config)
- //
- this.assertThrows(function() {
- kukit.ifa.registerPlugins(
- [
- ['dummyevents', 'click', 'blah blah', {
- name: 'click',
- defaultActionMethodName: null,
- parmtypes: [
- ['preventDefault', 'bool', true],
- ['allowBubbling', 'bool', false]]}],
-
- // XXX putting a null in the end eliminates
- // the problem of the closing comma
- null]
-
- // XXX the registries is needed for the test, but not in
normal usage
- , this.registries
- );
- }, Error);
- };
-
- this.testRegisterPluginsWrongInterface = function() {
- // In registerPlugins, list items must have 3 members
- // (interfaceName, attributeName, config)
- //
- this.assertThrows(function() {
- kukit.ifa.registerPlugins(
- [
- ['nosuchinterface', 'click', {
- name: 'click',
- defaultActionMethodName: null,
- parmtypes: [
- ['preventDefault', 'bool', true],
- ['allowBubbling', 'bool', false]]}],
-
- // XXX putting a null in the end eliminates
- // the problem of the closing comma
- null]
-
- // XXX the registries is needed for the test, but not in
normal usage
- , this.registries
- );
- }, Error);
- };
-
- this.testRegisterPluginsServiceInterfaceProhibites = function() {
- // The registerPlugins methods cannot be used to fill up
- // registries that are initialized with a ServiceFactory.
- // This means only factories that have 'register'
- // method, can be used (PluginFactory, BindSequenceFactory).
- //
- // We register "dummyservice" so it does not fail because
- // it's missing
- kukit.pluginregistry.initializeRegistry('dummyservice',
kukit.ifa.ServiceFactory);
- //
- this.assertThrows(function() {
- kukit.ifa.registerPlugins(
- [
- ['dummyservice', 'blah', {}],
-
- // XXX putting a null in the end eliminates
- // the problem of the closing comma
- null]
-
- // XXX the registries is needed for the test, but not in
normal usage
- , this.registries
- );
- }, Error);
- };
-
-
-
-
-}; /* end PluginInterfacesTestCase */
-kukit.PluginInterfacesTestCase.prototype = new kukit.InterfacesTestCaseBase();
-
-if (typeof(testcase_registry) != 'undefined') {
- testcase_registry.registerTestCase(kukit.InterfacesTestCase,
'kukit.InterfacesTestCase');
- testcase_registry.registerTestCase(kukit.ServiceInterfacesTestCase,
'kukit.ServiceInterfacesTestCase');
- testcase_registry.registerTestCase(kukit.PluginInterfacesTestCase,
'kukit.PluginInterfacesTestCase');
-}
Copied:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_registries.js
(from r59044,
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_registries.js
Sun Oct 26 12:22:28 2008
@@ -24,7 +24,7 @@
kukit.InterfacesTestCaseBase = function() {
this.setUp = function() {
// work with our own object, not interfering
- //interfaces.js
+ // with global object setup in registries.js
this.registries = new kukit.ifa.NamedRegistries();
};
}; /* end InterfacesTestCase */
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins