[KSS-checkins] r50444 - in kukit/kukit.js/branch/ree-service-layer-and-refactoring: . kukit tests

reebalazs at codespeak.net reebalazs at codespeak.net
Tue Jan 8 15:25:59 CET 2008


Author: reebalazs
Date: Tue Jan  8 15:25:58 2008
New Revision: 50444

Modified:
   kukit/kukit.js/branch/ree-service-layer-and-refactoring/   (props changed)
   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/plugin.js
   kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_interfaces.js
Log:
Add kukit.interfaces.registerPlugin method, that can be used for
batch registering plugin information.
Since we only register data, we can parse the entire
registry from the server by a simple markup
and json.

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	Tue Jan  8 15:25:58 2008
@@ -76,7 +76,6 @@
         // register the event informataion
         var events = kukit.interfaces.global.schema.events;
         events.getAttribute(eventName).register({
-            eventName: eventName,
             defaultActionMethodName: defaultActionMethodName,
             parmTypes: null    // missing from this api.
             });

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	Tue Jan  8 15:25:58 2008
@@ -548,4 +548,69 @@
 // The finalization of these interfaces will be done from bootstrap.
 
 
+
+
+/*
+ * Plugin registration method
+ *
+ * To allow an easy way to register plugin interfaces, 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, interfaces) {
+    // interfaces is optional, and mainly used for tests
+    if (typeof(interfaces) == 'undefined') {
+        // use global interfaces
+        interfaces = this.global;
+    }
+    //
+    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 (interfaceName, attributeName, config), ';
+;;;         kukit.E += 'got [' + item.length + '] instead.';
+;;;         throw new Error(kukit.E);
+;;;     }
+        var interfaceName = item[0];
+        var attributeName = 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 + '].';
+;;;         throw new Error(kukit.E);
+;;;     }
+        var attrib = iface.getAttribute(attributeName);
+;;;     // Check that we are in a plugin insterface.
+;;;     // 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.';
+;;;         throw new Error(kukit.E);
+;;;     }
+        attrib.register(config);
+    }
+};
+
+
 }(); /* END CLOSURE kukit.interfaces */

Modified: kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/plugin.js
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/plugin.js	(original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/plugin.js	Tue Jan  8 15:25:58 2008
@@ -329,6 +329,41 @@
 //kukit.eventsGlobalRegistry.registerForAllEvents(null, 'unload',
 //    kukit.pl.NativeEventBinder, '__bind__window', null, 'Each');
 
+/* XXX Example for using the interfaces registry
+ *
+ * The markup selects the part that should be parsed by the server.
+ * Some info, that contains class names, should be outside this.
+ * (binditerations falls into this category, it is only needed
+ * on the client.)
+ */
+
+/*
+kukit.interfaces.registerPlugins([
+// START KSS REGISTRY
+    ['events', click, {
+        defaultActionMethodName: null}],
+    ['events', dblclick, {
+        defaultActionMethodName: null}],
+    ['events', 'keyup', {
+        defaultActionMethodName: null}],
+    ['events', 'keydown', {
+        defaultActionMethodName: null}],
+// END KSS REGISTRY
+    ['binditerations', '', {
+        eventNames: ['click', 'dblclick'],
+        iterName: 'Each',
+        binderClass: kukit.pl.NativeEventBinder,
+        bindMethodName:  '__bind_node'}],
+    ['binditerations', '', {
+        eventNames: ['keyup', 'keydown'],
+        iterName: 'Each',
+        binderClass: kukit.pl.NativeEventBinder,
+        bindMethodName:  '__bind_key__'}],
+// XXX putting a null in the end eliminates
+// the problem of the closing comma
+null]);
+*/
+
 /*
 * class TimeoutEventBinder
 *

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	Tue Jan  8 15:25:58 2008
@@ -564,6 +564,115 @@
         this.assertEquals(typeof(this.interfaces.dummyevents.click), 'undefined');
     };
 
+    this.testRegisterPlugins = function() {
+        // Test registerPlugins method-
+        //
+        kukit.interfaces.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]]}],
+
+                ['dummybinditerations', '', {
+                    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 interfaces is needed for the test, but not in normal usage
+            , this.interfaces
+        );
+    };
+
+    this.testRegisterPluginsWrongNumberOfItems = function() {
+        // In registerPlugins, list items must have 3 members
+        // (interfaceName, attributeName, config)
+        //
+        this.assertThrows(function() {
+                kukit.interfaces.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 interfaces is needed for the test, but not in normal usage
+                    , this.interfaces
+                );
+            }, Error);
+    };
+
+    this.testRegisterPluginsWrongInterface = function() {
+        // In registerPlugins, list items must have 3 members
+        // (interfaceName, attributeName, config)
+        //
+        this.assertThrows(function() {
+                kukit.interfaces.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 interfaces is needed for the test, but not in normal usage
+                    , this.interfaces
+                );
+            }, 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.
+        //
+        // We regoster "dummyservice" so it does not fail because
+        // it's missing
+        this.interfaces.initializeContext('dummyservice', kukit.interfaces.ServiceMethod);
+        //
+        this.assertThrows(function() {
+                kukit.interfaces.registerPlugins(
+                    [
+                        ['dummyservice', 'blah', {}],
+
+                    // XXX putting a null in the end eliminates
+                    // the problem of the closing comma
+                    null]
+
+                // XXX the interfaces is needed for the test, but not in normal usage
+                    , this.interfaces
+                );
+            }, Error);
+    };
+
+
+
+
 }; /* end PluginInterfacesTestCase */
 kukit.PluginInterfacesTestCase.prototype = new kukit.InterfacesTestCaseBase();
 


More information about the Kukit-checkins mailing list