1 /** 2 * @fileoverview A class representing operations on filter expressions. 3 */ 4 5 goog.provide('xrx.xpath.FilterExpr'); 6 7 goog.require('xrx.xpath.Expr'); 8 9 10 11 /** 12 * Constructor for FilterExpr. 13 * 14 * @param {!xrx.xpath.Expr} primary The primary expression. 15 * @param {!xrx.xpath.Predicates} predicates The predicates. 16 * @extends {xrx.xpath.Expr} 17 * @constructor 18 */ 19 xrx.xpath.FilterExpr = function(primary, predicates) { 20 if (predicates.getLength() && primary.getDataType() != 21 xrx.xpath.DataType.NODESET) { 22 throw Error('Primary expression must evaluate to nodeset ' + 23 'if filter has predicate(s).'); 24 } 25 xrx.xpath.Expr.call(this, primary.getDataType()); 26 27 /** 28 * @type {!xrx.xpath.Expr} 29 * @private 30 */ 31 this.primary_ = primary; 32 33 34 /** 35 * @type {!xrx.xpath.Predicates} 36 * @private 37 */ 38 this.predicates_ = predicates; 39 40 this.setNeedContextPosition(primary.doesNeedContextPosition()); 41 this.setNeedContextNode(primary.doesNeedContextNode()); 42 }; 43 goog.inherits(xrx.xpath.FilterExpr, xrx.xpath.Expr); 44 45 46 /** 47 * @override 48 * @return {!xrx.xpath.NodeSet} The nodeset result. 49 */ 50 xrx.xpath.FilterExpr.prototype.evaluate = function(ctx) { 51 var result = this.primary_.evaluate(ctx); 52 console.log(result); 53 return this.predicates_.evaluatePredicates( 54 /** @type {!xrx.xpath.NodeSet} */ (result)); 55 }; 56 57 58 /** 59 * @override 60 */ 61 xrx.xpath.FilterExpr.prototype.toString = function() { 62 var text = 'Filter:'; 63 text += xrx.xpath.Expr.indent(this.primary_); 64 text += xrx.xpath.Expr.indent(this.predicates_); 65 return text; 66 }; 67