1 /** 2 * @fileoverview An abstract class which allows 3 * custom functions for the XPath processor. 4 */ 5 6 goog.provide('xrx.xpath.Function'); 7 8 9 10 /** 11 * A function in a function call expression. 12 * 13 * @constructor 14 * @param {string} name Name of the function. 15 * @param {xrx.xpath.DataType} dataType Datatype of the function return value. 16 * @param {boolean} needContextPosition Whether the function needs a context 17 * position. 18 * @param {boolean} needContextNodeWithoutArgs Whether the function needs a 19 * context node when not given arguments. 20 * @param {boolean} needContextNodeWithArgs Whether the function needs a context 21 * node when the function is given arguments. 22 * @param {function(!xrx.xpath.Context, ...[!xrx.xpath.Expr]):*} evaluate 23 * Evaluates the function in a context with any number of expression 24 * arguments. 25 * @param {number} minArgs Minimum number of arguments accepted by the function. 26 * @param {?number=} opt_maxArgs Maximum number of arguments accepted by the 27 * function; null means there is no max; defaults to minArgs. 28 * @param {boolean=} opt_nodesetsRequired Whether the args must be nodesets. 29 * @private 30 */ 31 xrx.xpath.Function = function(name, returnType, needContextPosition, 32 needContextNodeWithoutArgs, needContextNodeWithArgs, evaluate, minArgs, 33 opt_maxArgs, opt_nodesetsRequired) { 34 35 /** 36 * @type {string} 37 * @private 38 */ 39 this.name = name; 40 41 /** 42 * @type {xrx.xpath.DataType} 43 * @private 44 */ 45 this.returnType = returnType; 46 47 /** 48 * @type {boolean} 49 * @private 50 */ 51 this.needContextPosition_ = needContextPosition; 52 53 /** 54 * @type {boolean} 55 * @private 56 */ 57 this.needContextNodeWithoutArgs_ = needContextNodeWithoutArgs; 58 59 /** 60 * @type {boolean} 61 * @private 62 */ 63 this.needContextNodeWithArgs_ = needContextNodeWithArgs; 64 65 /** 66 * @type {function(!xrx.xpath.Context, ...[!xrx.xpath.Expr]):*} 67 * @private 68 */ 69 this.evaluate = evaluate; 70 71 /** 72 * @type {number} 73 * @private 74 */ 75 this.minArgs = minArgs; 76 77 /** 78 * @type {?number} 79 * @private 80 */ 81 this.maxArgs = goog.isDef(opt_maxArgs) ? opt_maxArgs : minArgs; 82 83 /** 84 * @type {boolean} 85 * @private 86 */ 87 this.nodesetsRequired_ = !!opt_nodesetsRequired; 88 }; 89 90 91 92 xrx.xpath.Function.prototype.toString = function() { 93 return this.name_; 94 };