/** * 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; }
/** * 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; }
/** * This is the method that actually does the function call * @param c the dynamic context * @return the result of the function * @throws XPathException if dynamic errors occur */ private ValueRepresentation callFunction(XPathContext c) throws XPathException { ValueRepresentation[] actualArgs = evaluateArguments(c); if (tailCall) { ((XPathContextMajor)c).requestTailCall(function, actualArgs); return EmptySequence.getInstance(); } XPathContextMajor c2 = c.newCleanContext(); c2.setOrigin(this); c2.setTemporaryOutputState(true); try { return function.call(actualArgs, c2); } catch (StackOverflowError err) { throw new XPathException("Too many nested function calls. May be due to infinite recursion.", this); } catch (NullPointerException err) { if (function == null) { throw new NullPointerException("Unbound function call " + function.getFunctionName().getDisplayName()); } else { throw err; } } }
/** * This is the method that actually does the function call * @param c the dynamic context * @return the result of the function * @throws XPathException if dynamic errors occur */ private ValueRepresentation callFunction(XPathContext c) throws XPathException { ValueRepresentation[] actualArgs = evaluateArguments(c); if (tailCall) { ((XPathContextMajor)c).requestTailCall(function, actualArgs); return EmptySequence.getInstance(); } XPathContextMajor c2 = c.newCleanContext(); c2.setOrigin(this); c2.setTemporaryOutputState(true); try { return function.call(actualArgs, c2); } catch (StackOverflowError err) { throw new XPathException("Too many nested function calls. May be due to infinite recursion.", this); } catch (NullPointerException err) { if (function == null) { throw new NullPointerException("Unbound function call " + function.getFunctionName().getDisplayName()); } else { throw err; } } }
/** * This is the method that actually does the function call * @param c the dynamic context * @return the result of the function * @throws XPathException if dynamic errors occur */ private ValueRepresentation callFunction(XPathContext c) throws XPathException { ValueRepresentation[] actualArgs = evaluateArguments(c); if (tailCall) { ((XPathContextMajor)c).requestTailCall(function, actualArgs); return EmptySequence.getInstance(); } XPathContextMajor c2 = c.newCleanContext(); c2.setOrigin(this); c2.setTemporaryOutputState(true); try { return function.call(actualArgs, c2); } catch (StackOverflowError err) { throw new XPathException("Too many nested function calls. May be due to infinite recursion.", this); } catch (NullPointerException err) { if (function == null) { throw new NullPointerException("Unbound function call " + function.getFunctionName().getDisplayName()); } else { throw err; } } }
context.setTemporaryOutputState(StandardNames.XSL_FUNCTION); Sequence<?> result = uf.call(context, vr); result = result.materialize();
context.setTemporaryOutputState(StandardNames.XSL_FUNCTION); Sequence<?> result = uf.call(context, vr); result = result.materialize();
/** * Process one key definition to add entries to the index * * * @param doc the document to be indexed * @param keydef the key definition used to build the index * @param context the XPath dynamic evaluation context * @param isFirst true if this is the first index to be built for this key * @throws XPathException if a dynamic error is encountered */ private void constructIndex(TreeInfo doc, KeyDefinition keydef, XPathContext context, boolean isFirst) throws XPathException { //System.err.println("build index for doc " + doc.getDocumentNumber()); Pattern match = keydef.getMatch(); //NodeInfo curr; XPathContextMajor xc = context.newContext(); xc.setOrigin(keydef); xc.setCurrentComponent(keydef.getDeclaringComponent()); xc.setTemporaryOutputState(StandardNames.XSL_KEY); // The use expression (or sequence constructor) may contain local variables. SlotManager map = keydef.getStackFrameMap(); if (map != null) { xc.openStackFrame(map); } match.selectNodes(doc, xc).forEachOrFail(node -> processNode(node, keydef, xc, isFirst)); }
/** * Apply an accumulator rule * * @param rule the rule to apply * @param node the node that was matched * @param isPostDescent false for the pre-descent visit to a node, true for the post-descent visit * @param value the value of the accumulator before applying the rule * @param context the dynamic evaluation context * @return the value of the accumulator after applying the rule * @throws XPathException if a dynamic error occurs during the evaluation */ private Sequence<?> processRule(Rule rule, NodeInfo node, boolean isPostDescent, Sequence<?> value, XPathContext context) throws XPathException { AccumulatorRule target = (AccumulatorRule) rule.getAction(); Expression delta = target.getNewValueExpression(); XPathContextMajor c2 = context.newCleanContext(); final Controller controller = c2.getController(); assert controller != null; ManualIterator<NodeInfo> initialNode = new ManualIterator<>(node); c2.setCurrentIterator(initialNode); c2.openStackFrame(target.getStackFrameMap()); c2.setLocalVariable(0, value); c2.setCurrentComponent(accumulator.getDeclaringComponent()); c2.setTemporaryOutputState(StandardNames.XSL_ACCUMULATOR_RULE); value = Evaluator.EAGER_SEQUENCE.evaluate(delta, c2); //System.err.println("Node " + ((TinyNodeImpl) node).getNodeNumber() + " : " + value); values.add(new DataPoint(new Visit(node, isPostDescent), value)); return value; }
/** * Process one key definition to add entries to the index * * * @param doc the document to be indexed * @param keydef the key definition used to build the index * @param context the XPath dynamic evaluation context * @param isFirst true if this is the first index to be built for this key * @throws XPathException if a dynamic error is encountered */ private void constructIndex(TreeInfo doc, KeyDefinition keydef, XPathContext context, boolean isFirst) throws XPathException { //System.err.println("build index for doc " + doc.getDocumentNumber()); Pattern match = keydef.getMatch(); //NodeInfo curr; XPathContextMajor xc = context.newContext(); xc.setOrigin(keydef); xc.setCurrentComponent(keydef.getDeclaringComponent()); xc.setTemporaryOutputState(StandardNames.XSL_KEY); // The use expression (or sequence constructor) may contain local variables. SlotManager map = keydef.getStackFrameMap(); if (map != null) { xc.openStackFrame(map); } match.selectNodes(doc, xc).forEachOrFail(node -> processNode(node, keydef, xc, isFirst)); }
/** * Apply an accumulator rule * * @param rule the rule to apply * @param node the node that was matched * @param isPostDescent false for the pre-descent visit to a node, true for the post-descent visit * @param value the value of the accumulator before applying the rule * @param context the dynamic evaluation context * @return the value of the accumulator after applying the rule * @throws XPathException if a dynamic error occurs during the evaluation */ private Sequence<?> processRule(Rule rule, NodeInfo node, boolean isPostDescent, Sequence<?> value, XPathContext context) throws XPathException { AccumulatorRule target = (AccumulatorRule) rule.getAction(); Expression delta = target.getNewValueExpression(); XPathContextMajor c2 = context.newCleanContext(); final Controller controller = c2.getController(); assert controller != null; ManualIterator<NodeInfo> initialNode = new ManualIterator<>(node); c2.setCurrentIterator(initialNode); c2.openStackFrame(target.getStackFrameMap()); c2.setLocalVariable(0, value); c2.setCurrentComponent(accumulator.getDeclaringComponent()); c2.setTemporaryOutputState(StandardNames.XSL_ACCUMULATOR_RULE); value = Evaluator.EAGER_SEQUENCE.evaluate(delta, c2); //System.err.println("Node " + ((TinyNodeImpl) node).getNodeNumber() + " : " + value); values.add(new DataPoint(new Visit(node, isPostDescent), value)); return value; }
c2.setTemporaryOutputState(StandardNames.XSL_VARIABLE); c2.setCurrentOutputUri(null); GroundedValue<?> result; result = select.iterate(c2).materialize(); c2.setTemporaryOutputState(savedOutputState); return result; } catch (XPathException e) {
c2.setTemporaryOutputState(StandardNames.XSL_VARIABLE); c2.setCurrentOutputUri(null); GroundedValue<?> result; result = select.iterate(c2).materialize(); c2.setTemporaryOutputState(savedOutputState); return result; } catch (XPathException e) {
context.setTemporaryOutputState(StandardNames.XSL_FUNCTION);
context.setTemporaryOutputState(StandardNames.XSL_FUNCTION);