org.exolab.adaptx.xpath.functions

Class SumFunctionCall

Implemented Interfaces:
XPathExpression

public class SumFunctionCall
extends FunctionCallImpl

A class that represents the XPath 1.0 sum function call. The Sum function takes as an argument an experession which evaluates to a node-set. Each node in the node-set will have it's string-value converted into a number. Each resulting number will then added together to compute the sum. Nodes whose string value is the empty-string will be ignored. If any node within the node-set has a non-zero length string value that cannot be sucessfully converted to a number, an XPathException will be thrown.

Version:
$Revision: 1.2 $

Author:
Keith Visco

Field Summary

Fields inherited from class org.exolab.adaptx.xpath.functions.FunctionCallImpl

INVALID_NUMBER_PARAMS, INVALID_RESULT

Fields inherited from class org.exolab.adaptx.xpath.expressions.PrimaryExpr

EXPR, FUNCTION_CALL, LITERAL, NUMBER, VARIABLE_REFERENCE

Fields inherited from interface org.exolab.adaptx.xpath.XPathExpression

BOOLEAN, ERROR, FILTER_EXPR, LOCATION_PATH, NODE_TEST, NUMBER, PATH_EXPR, PRIMARY, STEP, STRING, UNION_EXPR

Constructor Summary

SumFunctionCall()
Creates a new SumFunctionCall

Method Summary

double
computeSum(NodeSet nodeSet)
Computes the sum of the given NodeSet.
XPathResult
evaluate(XPathContext context)
Evaluates the expression and returns the XPath result.

Methods inherited from class org.exolab.adaptx.xpath.functions.FunctionCallImpl

addParameter, getFunctionName, getParameter, getParameterCount, toString

Methods inherited from class org.exolab.adaptx.xpath.expressions.FunctionCall

getFunctionName, getParameter, getParameterCount

Methods inherited from class org.exolab.adaptx.xpath.expressions.PrimaryExpr

getExprType, getType

Constructor Details

SumFunctionCall

public SumFunctionCall()
Creates a new SumFunctionCall

Method Details

computeSum

public double computeSum(NodeSet nodeSet)
            throws XPathException
Computes the sum of the given NodeSet. The sum is computed by adding up the number values of each node within the node set. If any non-numeric node values are encountered, an XPathException will be thrown.

Parameters:
nodeSet - the NodeSet to the compute the sum of

Returns:
the sum as a double

Throws:
XPathException - when a non-numeric value is encountered.


evaluate

public XPathResult evaluate(XPathContext context)
            throws XPathException
Evaluates the expression and returns the XPath result.
Specified by:
evaluate in interface XPathExpression

Parameters:
context - The XPathContext to use during evaluation.

Returns:
The XPathResult (not null).

Throws:
XPathException - if an error occured while evaluating this expression.