/** * Post-process the result if required */ public GroundedValue<?> postProcess(String uri, Sequence<?> result) throws XPathException { if (postProcessor != null) { result = postProcessor.call(context.newCleanContext(), new Sequence[]{new StringValue(uri), result}); } return result.materialize(); } }
/** * Post-process the result if required */ public GroundedValue<?> postProcess(String uri, Sequence<?> result) throws XPathException { if (postProcessor != null) { result = postProcessor.call(context.newCleanContext(), new Sequence[]{new StringValue(uri), result}); } return result.materialize(); } }
/** * Evaluate an updating expression, adding the results to a Pending Update List. * The default implementation of this method, which is used for non-updating expressions, * throws an UnsupportedOperationException * * @param context the XPath dynamic evaluation context * @param pul the pending update list to which the results should be written */ public void evaluatePendingUpdates(XPathContext context, PendingUpdateList pul) throws XPathException { ValueRepresentation[] actualArgs = evaluateArguments(context); XPathContextMajor c2 = context.newCleanContext(); c2.setOrigin(this); function.callUpdating(actualArgs, c2, pul); }
/** * Evaluate an updating expression, adding the results to a Pending Update List. * The default implementation of this method, which is used for non-updating expressions, * throws an UnsupportedOperationException * * @param context the XPath dynamic evaluation context * @param pul the pending update list to which the results should be written */ public void evaluatePendingUpdates(XPathContext context, PendingUpdateList pul) throws XPathException { Sequence[] actualArgs = evaluateArguments(context); XPathContextMajor c2 = context.newCleanContext(); c2.setOrigin(this); function.callUpdating(actualArgs, c2, pul); }
/** * Evaluate an updating expression, adding the results to a Pending Update List. * The default implementation of this method, which is used for non-updating expressions, * throws an UnsupportedOperationException * * @param context the XPath dynamic evaluation context * @param pul the pending update list to which the results should be written */ public void evaluatePendingUpdates(XPathContext context, PendingUpdateList pul) throws XPathException { Sequence[] actualArgs = evaluateArguments(context); XPathContextMajor c2 = context.newCleanContext(); c2.setOrigin(this); function.callUpdating(actualArgs, c2, pul); }
/** * Evaluate the expression * * @param context the dynamic evaluation context * @param arguments the values of the arguments, supplied as Sequences * @return the result of the evaluation, in the form of a Sequence * @throws net.sf.saxon.trans.XPathException * if a dynamic error occurs during the evaluation of the expression */ public Sequence<?> call(XPathContext context, Sequence<?>[] arguments) throws XPathException { if (function == null) { throw new XPathException("Forwards reference to XQuery function has not been resolved"); } Sequence[] args = new Sequence[arguments.length]; for (int i = 0; i < arguments.length; i++) { args[i] = ((SequenceIterator<?>) arguments[i].iterate()).materialize(); } return function.call(context.newCleanContext(), args); }
/** * Evaluate the expression * * @param context the dynamic evaluation context * @param arguments the values of the arguments, supplied as Sequences * @return the result of the evaluation, in the form of a Sequence * @throws net.sf.saxon.trans.XPathException * if a dynamic error occurs during the evaluation of the expression */ public Sequence<?> call(XPathContext context, Sequence<?>[] arguments) throws XPathException { if (function == null) { throw new XPathException("Forwards reference to XQuery function has not been resolved"); } Sequence[] args = new Sequence[arguments.length]; for (int i = 0; i < arguments.length; i++) { args[i] = ((SequenceIterator<?>) arguments[i].iterate()).materialize(); } return function.call(context.newCleanContext(), args); }
/** * Process the function call in push mode * @param context the XPath dynamic context * @throws XPathException */ public void process(XPathContext context) throws XPathException { ValueRepresentation[] actualArgs = evaluateArguments(context); if (tailCall) { ((XPathContextMajor)context).requestTailCall(function, actualArgs); } else { SequenceReceiver out = context.getReceiver(); XPathContextMajor c2 = context.newCleanContext(); c2.setReceiver(out); c2.setOrigin(this); function.process(actualArgs, c2); } }
/** * Process the function call in push mode * @param context the XPath dynamic context * @throws XPathException */ public void process(XPathContext context) throws XPathException { ValueRepresentation[] actualArgs = evaluateArguments(context); if (tailCall) { ((XPathContextMajor)context).requestTailCall(function, actualArgs); } else { SequenceReceiver out = context.getReceiver(); XPathContextMajor c2 = context.newCleanContext(); c2.setReceiver(out); c2.setOrigin(this); function.process(actualArgs, c2); } }
/** * Process the function call in push mode * @param context the XPath dynamic context * @throws XPathException */ public void process(XPathContext context) throws XPathException { ValueRepresentation[] actualArgs = evaluateArguments(context); if (tailCall) { ((XPathContextMajor)context).requestTailCall(function, actualArgs); } else { SequenceReceiver out = context.getReceiver(); XPathContextMajor c2 = context.newCleanContext(); c2.setReceiver(out); c2.setOrigin(this); function.process(actualArgs, c2); } }
/** * Create a context for evaluating this function * * @param oldContext the existing context of the caller * @param originator * @return a new context which should be supplied to the call() method. */ public XPathContextMajor makeNewContext(XPathContext oldContext, ContextOriginator originator) { XPathContextMajor c2 = oldContext.newCleanContext(); c2.setReceiver(oldContext.getReceiver()); c2.setTemporaryOutputState(StandardNames.XSL_FUNCTION); c2.setCurrentOutputUri(null); c2.setCurrentComponent(getDeclaringComponent()); // default value for the caller to override if necessary c2.setOrigin(originator); return c2; }
/** * Create a context for evaluating this function * * @param oldContext the existing context of the caller * @return a new context which should be supplied to the call() method. */ public XPathContextMajor makeNewContext(XPathContext oldContext) { XPathContextMajor c2 = oldContext.newCleanContext(); c2.setOrigin(this); c2.setReceiver(oldContext.getReceiver()); c2.setTemporaryOutputState(StandardNames.XSL_FUNCTION); c2.setCurrentOutputUri(null); c2.setCurrentComponent(getDeclaringComponent()); // default value for the caller to override if necessary return c2; }
/** * Process the function call in pull mode * @param context the XPath dynamic context * @throws XPathException */ public EventIterator iterateEvents(XPathContext context) throws XPathException { ValueRepresentation[] actualArgs = evaluateArguments(context); if (tailCall) { ((XPathContextMajor)context).requestTailCall(function, actualArgs); return EmptyEventIterator.getInstance(); } else { SequenceReceiver out = context.getReceiver(); XPathContextMajor c2 = context.newCleanContext(); c2.setReceiver(out); c2.setOrigin(this); return function.iterateEvents(actualArgs, c2); } }
/** * Process the function call in pull mode * @param context the XPath dynamic context * @throws XPathException */ public EventIterator iterateEvents(XPathContext context) throws XPathException { ValueRepresentation[] actualArgs = evaluateArguments(context); if (tailCall) { ((XPathContextMajor)context).requestTailCall(function, actualArgs); return EmptyEventIterator.getInstance(); } else { SequenceReceiver out = context.getReceiver(); XPathContextMajor c2 = context.newCleanContext(); c2.setReceiver(out); c2.setOrigin(this); return function.iterateEvents(actualArgs, c2); } }
/** * Process the function call in pull mode * @param context the XPath dynamic context * @throws XPathException */ public EventIterator iterateEvents(XPathContext context) throws XPathException { ValueRepresentation[] actualArgs = evaluateArguments(context); if (tailCall) { ((XPathContextMajor)context).requestTailCall(function, actualArgs); return EmptyEventIterator.getInstance(); } else { SequenceReceiver out = context.getReceiver(); XPathContextMajor c2 = context.newCleanContext(); c2.setReceiver(out); c2.setOrigin(this); return function.iterateEvents(actualArgs, c2); } }
private XPathContext makeDynamicContext(UseWhenStaticContext staticContext) throws XPathException { Controller controller = new Controller(getConfiguration()); controller.getExecutable().setFunctionLibrary((FunctionLibraryList) staticContext.getFunctionLibrary()); if (staticContext.getXPathVersion() < 30) { controller.setURIResolver(new URIPreventer()); } controller.setCurrentDateTime(currentDateTime); // this is to ensure that all use-when expressions in a module use the same date and time XPathContext dynamicContext = controller.newXPathContext(); dynamicContext = dynamicContext.newCleanContext(); return dynamicContext; }
private XPathContext makeDynamicContext(UseWhenStaticContext staticContext) throws XPathException { Controller controller = new Controller(getConfiguration()); controller.getExecutable().setFunctionLibrary((FunctionLibraryList) staticContext.getFunctionLibrary()); if (staticContext.getXPathVersion() < 30) { controller.setURIResolver(new URIPreventer()); } controller.setCurrentDateTime(currentDateTime); // this is to ensure that all use-when expressions in a module use the same date and time XPathContext dynamicContext = controller.newXPathContext(); dynamicContext = dynamicContext.newCleanContext(); return dynamicContext; }
/** * Iterate over the results of the function */ public SequenceIterator iterate(XPathContext c) throws XPathException { PreparedExpression pexpr = prepareExpression(c); if (operation == EXPRESSION) { return SingletonIterator.makeIterator(new ObjectValue(pexpr)); } else { XPathContextMajor c2 = c.newCleanContext(); c2.setOrigin(details); c2.openStackFrame(pexpr.stackFrameMap); c2.setCurrentIterator(c.getCurrentIterator()); for (int i=1; i<argument.length; i++) { int slot = pexpr.variables[i-1].getLocalSlotNumber(); c2.setLocalVariable(slot, ExpressionTool.eagerEvaluate(argument[i],c)); } return Value.getIterator( ExpressionTool.lazyEvaluate(pexpr.expression, c2, 1)); } }
/** * Iterate over the results of the function */ public SequenceIterator iterate(XPathContext c) throws XPathException { PreparedExpression pexpr = prepareExpression(c); if (operation == EXPRESSION) { return SingletonIterator.makeIterator(new ObjectValue(pexpr)); } else { XPathContextMajor c2 = c.newCleanContext(); c2.setOrigin(details); c2.openStackFrame(pexpr.stackFrameMap); c2.setCurrentIterator(c.getCurrentIterator()); for (int i=1; i<argument.length; i++) { int slot = pexpr.variables[i-1].getLocalSlotNumber(); c2.setLocalVariable(slot, ExpressionTool.eagerEvaluate(argument[i],c)); } return Value.getIterator( ExpressionTool.lazyEvaluate(pexpr.expression, c2, 1)); } }
/** * Iterate over the results of the function */ public SequenceIterator iterate(XPathContext c) throws XPathException { PreparedExpression pexpr = prepareExpression(c); if (operation == EXPRESSION) { return SingletonIterator.makeIterator(new ObjectValue(pexpr)); } else { XPathContextMajor c2 = c.newCleanContext(); c2.setOrigin(details); c2.openStackFrame(pexpr.stackFrameMap); c2.setCurrentIterator(c.getCurrentIterator()); for (int i=1; i<argument.length; i++) { int slot = pexpr.variables[i-1].getLocalSlotNumber(); c2.setLocalVariable(slot, ExpressionTool.eagerEvaluate(argument[i],c)); } return Value.getIterator( ExpressionTool.lazyEvaluate(pexpr.expression, c2, 1)); } }