1 package net.sf.saxon.xpath; 2 import net.sf.saxon.expr.*; 3 import net.sf.saxon.om.SequenceIterator; 4 import net.sf.saxon.om.ValueRepresentation; 5 import net.sf.saxon.trans.DynamicError; 6 import net.sf.saxon.trans.XPathException; 7 import net.sf.saxon.type.ItemType; 8 import net.sf.saxon.type.Type; 9 import net.sf.saxon.value.SequenceType; 10 import net.sf.saxon.value.Value; 11 import net.sf.saxon.Configuration; 12 13 import javax.xml.xpath.XPathFunction ; 14 import javax.xml.xpath.XPathFunctionException ; 15 import java.util.ArrayList ; 16 import java.util.List ; 17 18 19 20 24 25 public class XPathFunctionCall extends FunctionCall { 26 27 private XPathFunction function; 28 31 32 public XPathFunctionCall(XPathFunction function) { 33 this.function = function; 34 } 35 36 40 41 public Expression preEvaluate(StaticContext env) { 42 return this; 43 } 44 45 46 49 50 public void checkArguments(StaticContext env) throws XPathException { 51 } 52 53 54 59 60 public int getIntrinsicDependencies() { 61 return 0; 62 } 63 64 65 71 72 public SequenceIterator iterate(XPathContext context) throws XPathException { 73 ValueRepresentation[] argValues = new ValueRepresentation[argument.length]; 74 for (int i=0; i<argValues.length; i++) { 75 argValues[i] = ExpressionTool.lazyEvaluate(argument[i], context, 10); 76 } 77 return call(argValues, context); 78 } 79 80 81 87 88 public SequenceIterator call(ValueRepresentation[] argValues, XPathContext context) throws XPathException { 89 List convertedArgs = new ArrayList (argValues.length); 90 for (int i=0; i<argValues.length; i++) { 91 convertedArgs.add(Value.asValue(argValues[i]).convertToJava(Object .class, context)); 92 } 93 try { 94 Object result = function.evaluate(convertedArgs); 95 Configuration config = context.getController().getConfiguration(); 96 return Value.convertJavaObjectToXPath(result, SequenceType.ANY_SEQUENCE, config).iterate(context); 97 } catch (XPathFunctionException e) { 98 throw new DynamicError(e); 99 } 100 } 101 102 113 114 public ItemType getItemType() { 115 return Type.ITEM_TYPE; 116 } 117 118 122 public int computeCardinality() { 123 return StaticProperty.ALLOWS_ZERO_OR_MORE; 124 } 125 126 127 } 128 129 | Popular Tags |