Author: reebalazs
Date: Tue Dec 25 16:50:29 2007
New Revision: 50097

Modified:
   kukit/kukit.js/branch/ree-service-layer-and-refactoring/   (props changed)
   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/interfaces.js
   kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/kukit.js
Log:
Move actions and commands to the new registry

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  
Tue Dec 25 16:50:29 2007
@@ -27,7 +27,6 @@
 *  The local event actions need to be registered here.
 */
 var ActionRegistry = function () {
-    this.content = {};
 };
 
 ActionRegistry.prototype.register = function(name, func) {
@@ -36,24 +35,15 @@
 ;;;    kukit.E += ' [ActionRegistry.register].';
 ;;;    throw new Error(kukit.E);
 ;;;}
-    if (this.content[name]) {
-        // Do not allow redefinition
-;;;    kukit.logError('Error : action [' + name + '] already registered.');
-        return;
-        }
-    this.content[name] = func;
-};
-
-ActionRegistry.prototype.exists = function(name) {
-    var entry = this.content[name];
-    return (typeof(entry) != 'undefined');
+    var actions = kukit.interfaces.global.get('actions', 
kukit.interfaces.PluginMethodDescriptor);
+    actions.getMethodDescriptor(name).register(func);
 };
 
 ActionRegistry.prototype.get = function(name) {
-    var func = this.content[name];
+    var func = kukit.interfaces.global.actions[name];
     if (! func) {
         // not found
-;;;    kukit.E = 'Error : undefined local action [' + name + '].';
+;;;     kukit.E = 'Error : undefined client action [' + name + '].';
         throw Error(kukit.E);
         }
     return func;

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 
Tue Dec 25 16:50:29 2007
@@ -27,7 +27,6 @@
 *  class _CommandRegistry
 */
 var _CommandRegistry = function () {
-    this.commands = {};
 };
 
 /* 
@@ -46,34 +45,60 @@
 */
 _CommandRegistry.prototype.registerFromAction =
     function(srcname, factory, name) {
-    if (typeof(name) == 'undefined') {
-        // allows to set a different name as the action name,
-        // usable for backward
-        // compatibility setups
-        name = srcname;
-    }
+    var actions = kukit.interfaces.global.get('actions', 
kukit.interfaces.PluginMethodDescriptor);
+    //
     // register a given action as a command, using the given vactor
-    var f = kukit.actionsGlobalRegistry.get(srcname);
-    factory(name, f);
+    var descriptor = actions.getMethodDescriptor(srcname);
+    if (! descriptor.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(descriptor.config);
+    // 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.getMethodDescriptor(name).register(descriptor.config);
+        // only declare the command class if it's missing
+        if (typeof(descriptor.config.commandClass) == 'undefined') {
+            this._register(name, commandClass, descriptor);
+        }
+    } else {
+        // This is the normal case - just register it
+        this._register(srcname, commandClass, descriptor);
+    }
+
+};
+
+_CommandRegistry.prototype.register = function(name, commandClass) {
+    var actions = kukit.interfaces.global.get('actions', 
kukit.interfaces.PluginMethodDescriptor);
+    var descriptor = actions.getMethodDescriptor(name);
+    this._register(name, commandClass, descriptor);
 };
 
-_CommandRegistry.prototype.register = function(name, klass) {
-    if (this.commands[name]) {
+_CommandRegistry.prototype._register = function(name, commandClass, 
descriptor) {
+    if (! descriptor.config) {
+;;;     kukit.E = 'undefined client action [' + name + '] in 
CommandRegistry.register.';
+        throw Error(kukit.E);
+    } else if (descriptor.config.commandClass) {
         // Do not allow redefinition
-;;;    var msg = 'ValueError : command [' + name + '] is already registered.';
-;;;    kukit.logError(msg);
-        return;
+;;;     kukit.E = 'command [' + name + '] is already defined, in 
CommandRegistry.register.';
+        throw Error(kukit.E);
         }
-    this.commands[name] = klass;
+    // Store the command class on the config
+    descriptor.config.commandClass = commandClass;
 };
 
 _CommandRegistry.prototype.get = function(name) {
-    var klass = this.commands[name];
-;;;if (! klass) {
+    var action = kukit.interfaces.global.actions[name];
+    var klass = action.commandClass;
+    if (! klass) {
 ;;;    // not found
-;;;    var msg = 'ValueError : no command registered under [' + name + '].';
-;;;    kukit.logError(msg);
-;;;   }
+;;;     kukit.E = 'undefined command [' + name + ']';
+        throw Error(kukit.E);
+    }
     return klass;
 };
 
@@ -140,24 +165,24 @@
     }
 };
 
-cr.makeSelectorCommand = function(name, executeOnSingleNode) {
+cr.makeSelectorCommand = function(executeOnSingleNode) {
     var commandClass = function() {};
     commandClass.prototype = {
         execute: _executeCommand,
         executeOnScope: _executeCommandOnSelector,
         executeOnSingleNode: executeOnSingleNode
     };
-    kukit.commandsGlobalRegistry.register(name, commandClass); 
+    return commandClass;
 };
 
-cr.makeGlobalCommand = function(name, executeOnce) {
+cr.makeGlobalCommand = function(executeOnce) {
     var commandClass = function() {};
     commandClass.prototype = {
         execute: _executeCommand,
         executeOnScope: executeOnce,
         executeOnSingleNode: executeOnce
     };
-    kukit.commandsGlobalRegistry.register(name, commandClass); 
+    return commandClass;
 };
 
 }();                              /// MODULE END

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 Dec 25 16:50:29 2007
@@ -124,6 +124,8 @@
 ;;;         kukit.E += this.name + ']';
             throw new Error(kukit.E);
         }
+;;;     kukit.E = 'Finalizing interface [' + this.name + ']';
+;;;     kukit.logDebug(kukit.E);
         // Finalize all methods.
         this.forEachMethod(function(methodName, methodDescriptor) {
             // finalize the functions and store them on the singleton
@@ -135,10 +137,7 @@
         // 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 = 'Finalizing interface [' + this.name + ']';
-;;;         kukit.logDebug(kukit.E);
-;;;    } else {
+;;;     if (! this.finalized) {
 ;;;         kukit.E = 'Postpone finalization of interface [' + this.name + 
'],';
 ;;;         kukit.E = ' and request sources [', loader.getSources() + ']';
 ;;;         kukit.logDebug(kukit.E);
@@ -387,6 +386,8 @@
     // Need to finalize these interfaces
     this.global.get('events', this.PluginMethodDescriptor).finalize({});
     this.global.get('binditerations', 
this.BindIterationDescriptor).finalize({});
+    // this is not strictly necessary, as we don't get as far as execution
+    this.global.get('actions', this.PluginMethodDescriptor).finalize({});
 };
 
 this.cleanRoomTearDown = function(suite) {

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      
Tue Dec 25 16:50:29 2007
@@ -240,12 +240,13 @@
 ;;;     kukit.log('[initializeRules] is called twice.');
         return;
     }
-;;; kukit.log('Finalizing interfaces.');
     // We finalize the core interface.
     var interfaces = kukit.interfaces.global;
     interfaces.get('core', 
kukit.interfaces.ServiceMethodDescriptor).finalize({});
     interfaces.get('events', 
kukit.interfaces.PluginMethodDescriptor).finalize({});
     interfaces.get('binditerations', 
kukit.interfaces.BindIterationDescriptor).finalize({});
+    interfaces.get('actions', 
kukit.interfaces.PluginMethodDescriptor).finalize({});
+;;; kukit.log('All interfaces finalized.');
 ;;; kukit.log('Initializing kinetic stylesheets.');
     // Succesful initialization. At the moment the engine is kept
     // as a global variable, but this needs refinement in the future.
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to