<@interface name="KitHelpers" alias="$ENV"> Extension point for defining kit helper objects (c) SAP AG 2003-2006. All rights reserved. + ? # The name of the helper class * # An argument to pass to the helper class constructor. See further explanations about ARGS in XML definition of channel: @env:KitChannels!defineChannel Example com.sap.vctests:HelperClass {id: "someid"} function defineHelper(className, p1, p2, p3, p4, p5, p6, p7) { // case of helper anonymous object if (arguments.length == 2 && typeof arguments[0] == 'object' && typeof arguments[1] == 'string') { var name=arguments[1], obj=arguments[0]; if (!isValidId(name)) return raiseKitError('Invalid namespace specification of helper object name:'+ name + " in kit :" + _currentPackage); if (name in _kitHelpers) return raiseKitError('Helper object "'+name+'" is already defined'); _kitHelpers[UPPER(name)] = obj; return obj; } // case of helper function if (arguments.length == 2 && typeof arguments[0] == 'string' && typeof arguments[1] == 'function') { var name=arguments[0], func=arguments[1]; if (!isValidId(name)) return raiseKitError('Invalid namespace specification of helper function name:'+ name + " in kit :" + _currentPackage); if (name in _kitHelpers) return raiseKitError('Helper function "'+name+'" is already defined'); try { eval('func = '+func); } catch(e) { return raiseKitError('Syntax error in helper function "'+name+'": '+e.description); } _kitHelpers[UPPER(name)] = func; return func; } // case of helper object var obj = $ENV.createObject(className, p1, p2, p3, p4, p5, p6, p7); if (!obj) return raiseKitError('Invalid helper "'+className+'" definition' ); #DEVTIME[ if (!ISA(obj , 'core.gml:Object') ) return raiseKitError(className +' is not sub class of Object'); ] var id = UPPER(obj.id); if (!isValidId(obj.id)) return raiseKitError('Invalid namespace specification of helper object Id:'+ obj.id + " in kit :" + _currentPackage); if (!id) return raiseKitError('Id is missing from helper "'+className+'" definition'); if (id in _kitHelpers) raiseKitError('Helper object "'+id+'" is already defined'); _kitHelpers[id] = obj return obj; } <@method name="getHelper"> Returns a specified helper object/function The Id of the helper object/function to get The requested helper object/function function getHelper(id) { return _kitHelpers[UPPER(id)] || null; } <@method name="getHelpersTable"> Returns the complete helpers table Table of helpers objects, indexed by their identifiers Helper id's are stored in uppercase. Use @lib:Basic!UPPER macro to convert the helper id to uppercase before using it as the index in this table. function getHelpersTable() { return _kitHelpers; } <@method name="parseHelper" scope="private"> Parses the given helper node and returns a string which represents its details channel node to parse Helper functions are not supported by this method function parseHelper(helperNode) { var map = getNodeProps(helperNode); var classname = map['classname']; if (!classname) return ""; var args = getNodeArgs(helperNode); var res = "$ENV.defineHelper(" + STR(classname) + "," + JOIN(args,",") + ");"; return res; } <@method name="removeHelper"> Removes a specified helper object/function The Id of the helper object/function to remove function removeHelper(id) { delete _kitHelpers[UPPER(id)]; } <@method name="executeHelper"> Executes a specified helper function The Id of the helper function to execute A variable list of arguments to pass to the helper function The helper function result function executeHelper(id, p1, p2, p3, p4, p5, p6, p7) { try { var fn = _kitHelpers[UPPER(id)] || null; return fn ? fn(p1, p2, p3, p4, p5, p6, p7) : undefined; } catch(e) { raiseKitError('Failed to execute helper function "'+id+'": '+e.description); return undefined; } }