protected XPathContextMajor initialContext(DynamicQueryContext dynamicEnv, Controller controller) throws XPathException { Item<?> contextItem = controller.getGlobalContextItem(); XPathContextMajor context = controller.newXPathContext(); if (contextItem != null) { ManualIterator<Item<?>> single = new ManualIterator<>(contextItem); context.setCurrentIterator(single); controller.setGlobalContextItem(contextItem); } return context; }
protected XPathContextMajor initialContext(DynamicQueryContext dynamicEnv, Controller controller) throws XPathException { Item<?> contextItem = controller.getGlobalContextItem(); XPathContextMajor context = controller.newXPathContext(); if (contextItem != null) { ManualIterator<Item<?>> single = new ManualIterator<>(contextItem); context.setCurrentIterator(single); controller.setGlobalContextItem(contextItem); } return context; }
/** * Return an Iterator to iterate over the values of the sequence. * * @exception XPathException if any dynamic error occurs evaluating the * expression * @param context supplies the context for evaluation * @return a SequenceIterator that can be used to iterate over the result * of the expression */ public SequenceIterator iterate(XPathContext context) throws XPathException { SequenceIterator master = select.iterate(context); XPathContextMajor c2 = context.newContext(); c2.setOrigin(this); c2.setCurrentTemplateRule(null); c2.setCurrentIterator(master); master = new ContextMappingIterator(this, c2); return master; }
/** * Return an Iterator to iterate over the values of the sequence. * * @exception XPathException if any dynamic error occurs evaluating the * expression * @param context supplies the context for evaluation * @return a SequenceIterator that can be used to iterate over the result * of the expression */ public SequenceIterator iterate(XPathContext context) throws XPathException { SequenceIterator master = select.iterate(context); XPathContextMajor c2 = context.newContext(); c2.setOrigin(this); c2.setCurrentTemplateRule(null); c2.setCurrentIterator(master); master = new ContextMappingIterator(this, c2); return master; }
/** * Set the context item for evaluation of the XPath Expression * @param item the context item * @throws XPathException if the node is in a document that was built under the wrong configuration */ public void setContextItem(Item item) throws XPathException { if (item instanceof NodeInfo) { if (!((NodeInfo)item).getConfiguration().isCompatible(contextObject.getConfiguration())) { throw new XPathException( "Supplied node must be built using the same or a compatible Configuration", SaxonErrorCode.SXXP0004); } } UnfailingIterator iter = SingletonIterator.makeIterator(item); iter.next(); contextObject.setCurrentIterator(iter); }
/** * Set the context item for evaluation of the XPath Expression * @param item the context item * @throws XPathException if the node is in a document that was built under the wrong configuration */ public void setContextItem(Item item) throws XPathException { if (item instanceof NodeInfo) { if (!((NodeInfo)item).getConfiguration().isCompatible(contextObject.getConfiguration())) { throw new XPathException( "Supplied node must be built using the same or a compatible Configuration", SaxonErrorCode.SXXP0004); } } UnfailingIterator iter = SingletonIterator.makeIterator(item); iter.next(); contextObject.setCurrentIterator(iter); }
/** * Return an Iterator to iterate over the values of a sequence. The value of every * expression can be regarded as a sequence, so this method is supported for all * expressions. This default implementation relies on the process() method: it * "pushes" the results of the instruction to a sequence in memory, and then * iterates over this in-memory sequence. * <p/> * In principle instructions should implement a pipelined iterate() method that * avoids the overhead of intermediate storage. * * @param context supplies the context for evaluation * @return a SequenceIterator that can be used to iterate over the result * of the expression * @throws XPathException if any dynamic error occurs evaluating the * expression */ public SequenceIterator iterate(XPathContext context) throws XPathException { GroupIterator master = getGroupIterator(context); XPathContextMajor c2 = context.newContext(); c2.setOrigin(this); c2.setCurrentIterator(master); c2.setCurrentGroupIterator(master); c2.setCurrentTemplateRule(null); return new ContextMappingIterator(this, c2); }
/** * Return an Iterator to iterate over the values of a sequence. The value of every * expression can be regarded as a sequence, so this method is supported for all * expressions. This default implementation handles iteration for expressions that * return singleton values: for non-singleton expressions, the subclass must * provide its own implementation. * * @param context supplies the context for evaluation * @return a SequenceIterator that can be used to iterate over the result * of the expression * @throws net.sf.saxon.trans.XPathException * if any dynamic error occurs evaluating the * expression */ public SequenceIterator iterate(XPathContext context) throws XPathException { RegexIterator iter = getRegexIterator(context); XPathContextMajor c2 = context.newContext(); c2.setOrigin(this); c2.setCurrentIterator(iter); c2.setCurrentRegexIterator(iter); AnalyzeMappingFunction fn = new AnalyzeMappingFunction(iter, c2); return new ContextMappingIterator(fn, c2); }
/** * Return an Iterator to iterate over the values of a sequence. The value of every * expression can be regarded as a sequence, so this method is supported for all * expressions. This default implementation relies on the process() method: it * "pushes" the results of the instruction to a sequence in memory, and then * iterates over this in-memory sequence. * <p/> * In principle instructions should implement a pipelined iterate() method that * avoids the overhead of intermediate storage. * * @param context supplies the context for evaluation * @return a SequenceIterator that can be used to iterate over the result * of the expression * @throws XPathException if any dynamic error occurs evaluating the * expression */ public SequenceIterator iterate(XPathContext context) throws XPathException { GroupIterator master = getGroupIterator(context); XPathContextMajor c2 = context.newContext(); c2.setOrigin(this); c2.setCurrentIterator(master); c2.setCurrentGroupIterator(master); c2.setCurrentTemplateRule(null); return new ContextMappingIterator(this, c2); }
/** * Return an Iterator to iterate over the values of a sequence. The value of every * expression can be regarded as a sequence, so this method is supported for all * expressions. This default implementation handles iteration for expressions that * return singleton values: for non-singleton expressions, the subclass must * provide its own implementation. * * @param context supplies the context for evaluation * @return a SequenceIterator that can be used to iterate over the result * of the expression * @throws net.sf.saxon.trans.XPathException * if any dynamic error occurs evaluating the * expression */ public SequenceIterator iterate(XPathContext context) throws XPathException { RegexIterator iter = getRegexIterator(context); XPathContextMajor c2 = context.newContext(); c2.setOrigin(this); c2.setCurrentIterator(iter); c2.setCurrentRegexIterator(iter); AnalyzeMappingFunction fn = new AnalyzeMappingFunction(iter, c2); return new ContextMappingIterator(fn, c2); }
/** * Evaluate the variable. That is, * get the value of the select expression if present or the content * of the element otherwise, either as a tree or as a sequence */ public ValueRepresentation getSelectValue(XPathContext context) throws XPathException { if (select==null) { throw new AssertionError("*** No select expression for global variable $" + getVariableQName().getDisplayName() + "!!"); } else { XPathContextMajor c2 = context.newCleanContext(); c2.setOrigin(this); UnfailingIterator initialNode = SingletonIterator.makeIterator(c2.getController().getContextForGlobalVariables()); initialNode.next(); c2.setCurrentIterator(initialNode); if (stackFrameMap != null) { c2.openStackFrame(stackFrameMap); } return ExpressionTool.evaluate(select, evaluationMode, c2, referenceCount); } }
/** * Evaluate the variable. That is, * get the value of the select expression if present or the content * of the element otherwise, either as a tree or as a sequence */ public ValueRepresentation getSelectValue(XPathContext context) throws XPathException { if (select==null) { throw new AssertionError("*** No select expression for global variable $" + getVariableQName().getDisplayName() + "!!"); } else { XPathContextMajor c2 = context.newCleanContext(); c2.setOrigin(this); UnfailingIterator initialNode = SingletonIterator.makeIterator(c2.getController().getContextForGlobalVariables()); initialNode.next(); c2.setCurrentIterator(initialNode); if (stackFrameMap != null) { c2.openStackFrame(stackFrameMap); } return ExpressionTool.evaluate(select, evaluationMode, c2, referenceCount); } }
/** * Build a data structure containing the values of the accumulator for each node in a document. * The data structure holds the value for all nodes where the value changes; the value for other * nodes is obtained by interpolation * * @param doc the root of the tree for which the accumulator is to be evaluated * @param context the dynamic evaluation context * @throws XPathException if a dynamic error occurs while evaluating the accumulator */ public void buildIndex(NodeInfo doc, XPathContext context) throws XPathException { //System.err.println("Building accData " + this); if (building) { throw new XPathException("Accumulator " + accumulator.getAccumulatorName().getDisplayName() + " requires access to its own value", "XTDE3400"); } building = true; Expression initialValue = accumulator.getInitialValueExpression(); XPathContextMajor c2 = context.newContext(); SlotManager sf = accumulator.getSlotManagerForInitialValueExpression(); Sequence[] slots = new Sequence[sf.getNumberOfVariables()]; c2.setStackFrame(sf, slots); c2.setCurrentIterator(new ManualIterator<>(doc)); Sequence<?> val = initialValue.iterate(c2).materialize(); values.add(new DataPoint(new Visit(doc, false), val)); val = visit(doc, val, c2); values.add(new DataPoint(new Visit(doc, true), val)); ((ArrayList) values).trimToSize(); building = false; //diagnosticPrint(); }
/** * Set the context item for evaluation of the XPath Expression * * @param item the context item * @throws XPathException if the node is in a document that was built under the wrong configuration */ public void setContextItem(Item<?> item) throws XPathException { if (item instanceof NodeInfo) { if (!((NodeInfo) item).getConfiguration().isCompatible(contextObject.getConfiguration())) { throw new XPathException( "Supplied node must be built using the same or a compatible Configuration", SaxonErrorCode.SXXP0004); } } TypeHierarchy th = contextObject.getConfiguration().getTypeHierarchy(); if (!contextItemType.matches(item, th)) { throw new XPathException("Supplied context item does not match required context item type " + contextItemType); } ManualIterator<Item<?>> iter = new ManualIterator<>(item); contextObject.setCurrentIterator(iter); }
/** * Set the context item for evaluation of the XPath Expression * * @param item the context item * @throws XPathException if the node is in a document that was built under the wrong configuration */ public void setContextItem(Item<?> item) throws XPathException { if (item instanceof NodeInfo) { if (!((NodeInfo) item).getConfiguration().isCompatible(contextObject.getConfiguration())) { throw new XPathException( "Supplied node must be built using the same or a compatible Configuration", SaxonErrorCode.SXXP0004); } } TypeHierarchy th = contextObject.getConfiguration().getTypeHierarchy(); if (!contextItemType.matches(item, th)) { throw new XPathException("Supplied context item does not match required context item type " + contextItemType); } ManualIterator<Item<?>> iter = new ManualIterator<>(item); contextObject.setCurrentIterator(iter); }
private XPathContextMajor initialContext(DynamicQueryContext dynamicEnv, Controller controller) throws XPathException { Item contextItem = dynamicEnv.getContextItem(); controller.defineGlobalParameters(); XPathContextMajor context = controller.newXPathContext(); if (contextItem != null) { if (!staticContext.getUserQueryContext().getRequiredContextItemType().matchesItem( contextItem, false, dynamicEnv.getConfiguration())) { throw new XPathException("The supplied context item does not match the required context item type"); } UnfailingIterator single = SingletonIterator.makeIterator(contextItem); single.next(); context.setCurrentIterator(single); controller.setInitialContextItem(contextItem); } return context; }
private XPathContextMajor initialContext(DynamicQueryContext dynamicEnv, Controller controller) throws XPathException { Item contextItem = dynamicEnv.getContextItem(); controller.defineGlobalParameters(); XPathContextMajor context = controller.newXPathContext(); if (contextItem != null) { if (!staticContext.getUserQueryContext().getRequiredContextItemType().matchesItem( contextItem, false, dynamicEnv.getConfiguration())) { throw new XPathException("The supplied context item does not match the required context item type"); } UnfailingIterator single = SingletonIterator.makeIterator(contextItem); single.next(); context.setCurrentIterator(single); controller.setInitialContextItem(contextItem); } return context; }
/** * 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)); } }