net.sf.saxon.functions
Class SystemFunction

java.lang.Object
  extended by net.sf.saxon.expr.Expression
      extended by net.sf.saxon.expr.FunctionCall
          extended by net.sf.saxon.functions.SystemFunction
All Implemented Interfaces:
Serializable, SourceLocator, EvaluableItem, SequenceIterable, InstructionInfoProvider
Direct Known Subclasses:
Adjust, Aggregate, Available, BaseURI, BooleanFn, CodepointEqual, CodepointsToString, CollatingFunction, Collection, CompileTimeFunction, Component, Concat, Current, CurrentDateTime, CurrentGroup, DateTimeConstructor, Doc, DocAvailable, Document, DynamicFunctionCall, Error, EscapeURI, Evaluate, Existence, Find, ForceCase, ForEachGroupFunction, FormatDate, FormatNumber, Id, Idref, InScopePrefixes, Insert, IsWholeNumber, ItemAt, KeyFn, Lang, Last, Matches, NamePart, NamespaceForPrefix, Nilled, NormalizeSpace, NormalizeUnicode, NumberFn, Parse, Position, QNameFn, RegexGroup, Remove, Replace, ResolveQName, ResolveURI, Reverse, Root, Rounding, Serialize, StringFn, StringJoin, StringLength, StringToCodepoints, Subsequence, Substring, SystemProperty, Tokenize, Trace, Translate, TreatFn, Try, UnparsedEntity, UnparsedText

public abstract class SystemFunction
extends FunctionCall

Abstract superclass for system-defined and user-defined functions

See Also:
Serialized Form

Field Summary
 
Fields inherited from class net.sf.saxon.expr.Expression
EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD
 
Constructor Summary
SystemFunction()
           
 
Method Summary
 PathMap.PathMapNodeSet addDocToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodes)
          Add a representation of a doc() call or similar function to a PathMap.
 void checkArguments(ExpressionVisitor visitor)
          Method called during static type checking
 int computeCardinality()
          Determine the cardinality of the function.
 int computeSpecialProperties()
          Determine the special properties of this expression.
 Expression copy()
          Copy an expression.
 StandardFunction.Entry getDetails()
          Get the details of the function signature
 String getErrorCodeForTypeErrors()
          Return the error code to be used for type errors.
 ItemType getItemType(TypeHierarchy th)
          Determine the item type of the value returned by the function
static FunctionCall makeSystemFunction(String name, Expression[] arguments)
          Make a system function call (one in the standard function namespace).
 Expression optimize(ExpressionVisitor visitor, ItemType contextItemType)
          Perform optimisation of an expression and its subexpressions.
 void setDetails(StandardFunction.Entry entry)
          Set the details of this type of function
 
Methods inherited from class net.sf.saxon.expr.FunctionCall
addExternalFunctionCallToPathMap, equals, explain, getArguments, getDisplayName, getFunctionName, getNumberOfArguments, hashCode, iterateSubExpressions, preEvaluate, promote, replaceSubExpression, setArguments, setFunctionName, simplify, toString, typeCheck
 
Methods inherited from class net.sf.saxon.expr.Expression
addToPathMap, adoptChildExpression, checkPermittedContents, computeDependencies, computeStaticProperties, display, doPromotion, effectiveBooleanValue, evaluateAsString, evaluateItem, explain, findParentOf, getCardinality, getColumnNumber, getContainer, getDependencies, getExecutable, getHostLanguage, getImplementationMethod, getInstructionInfo, getIntrinsicDependencies, getLineNumber, getLocationId, getLocationProvider, getPublicId, getSlotsUsed, getSpecialProperties, getSystemId, hasLoopingSubexpression, implementsStaticTypeCheck, iterate, iterateEvents, markTailFunctionCalls, process, setContainer, setFiltered, setFlattened, setLocationId, staticTypeCheck, suppressValidation
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SystemFunction

public SystemFunction()
Method Detail

makeSystemFunction

public static FunctionCall makeSystemFunction(String name,
                                              Expression[] arguments)
Make a system function call (one in the standard function namespace).

Parameters:
name - The local name of the function.
arguments - the arguments to the function call
Returns:
a FunctionCall that implements this function, if it exists, or null if the function is unknown.

setDetails

public void setDetails(StandardFunction.Entry entry)
Set the details of this type of function

Parameters:
entry - information giving details of the function signature

getDetails

public StandardFunction.Entry getDetails()
Get the details of the function signature

Returns:
information about the function signature

checkArguments

public void checkArguments(ExpressionVisitor visitor)
                    throws XPathException
Method called during static type checking

Parameters:
visitor - the expression visitor
Throws:
XPathException

optimize

public Expression optimize(ExpressionVisitor visitor,
                           ItemType contextItemType)
                    throws XPathException
Perform optimisation of an expression and its subexpressions.

This method is called after all references to functions and variables have been resolved to the declaration of the function or variable, and after all type checking has been done.

Overrides:
optimize in class FunctionCall
Parameters:
visitor - an expression visitor
contextItemType - the static type of "." at the point where this expression is invoked. The parameter is set to null if it is known statically that the context item will be undefined. If the type of the context item is not known statically, the argument is set to Type.ITEM_TYPE
Returns:
the original expression, rewritten if appropriate to optimize execution
Throws:
XPathException - if an error is discovered during this phase (typically a type error)

copy

public Expression copy()
Copy an expression. This makes a deep copy.

Specified by:
copy in class Expression
Returns:
the copy of the original expression

getErrorCodeForTypeErrors

public String getErrorCodeForTypeErrors()
Return the error code to be used for type errors. This is overridden for functions such as exactly-one(), one-or-more(), ...

Returns:
the error code to be used for type errors in the function call. Normally XPTY0004, but different codes are used for functions such as exactly-one()

getItemType

public ItemType getItemType(TypeHierarchy th)
Determine the item type of the value returned by the function

Specified by:
getItemType in class Expression
Parameters:
th - the type hierarchy cache
Returns:
a value such as Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE, or Type.ITEM (meaning not known at compile time)

computeCardinality

public int computeCardinality()
Determine the cardinality of the function.

Returns:
the computed cardinality, as one of the values StaticProperty.ALLOWS_ZERO_OR_ONE, StaticProperty.EXACTLY_ONE, StaticProperty.ALLOWS_ONE_OR_MORE, StaticProperty.ALLOWS_ZERO_OR_MORE

computeSpecialProperties

public int computeSpecialProperties()
Determine the special properties of this expression. The general rule is that a system function call is non-creative if its return type is atomic, or if all its arguments are non-creative. This is overridden for the generate-id() function, which is considered creative if its operand is creative (because the result depends on the identity of the operand)

Returns:
the special properties, as a bit-significant integer

addDocToPathMap

public PathMap.PathMapNodeSet addDocToPathMap(PathMap pathMap,
                                              PathMap.PathMapNodeSet pathMapNodes)
Add a representation of a doc() call or similar function to a PathMap. This is a convenience method called by the addToPathMap() methods for doc(), document(), collection() and similar functions. These all create a new root expression in the path map.

Parameters:
pathMap - the PathMap to which the expression should be added
pathMapNodes - the node in the PathMap representing the focus at the point where this expression is called. Set to null if this expression appears at the top level.
Returns:
the pathMapNode representing the focus established by this expression, in the case where this expression is the first operand of a path expression or filter expression


Copyright (C) Michael H. Kay. All rights reserved.